2 * Copyright (c) 2004 Ulrich Drepper <drepper@redhat.com>
3 * Copyright (c) 2005 Roland McGrath <roland@redhat.com>
4 * Copyright (c) 2012-2015 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2014-2019 The strace developers.
8 * SPDX-License-Identifier: LGPL-2.1-or-later
14 #include "sched_attr.h"
16 #include "xlat/schedulers.h"
17 #include "xlat/sched_flags.h"
19 SYS_FUNC(sched_getscheduler)
22 tprintf("%d", (int) tcp->u_arg[0]);
23 } else if (!syserror(tcp)) {
24 tcp->auxstr = xlookup(schedulers, (kernel_ulong_t) tcp->u_rval);
30 SYS_FUNC(sched_setscheduler)
32 tprintf("%d, ", (int) tcp->u_arg[0]);
33 printxval(schedulers, tcp->u_arg[1], "SCHED_???");
35 printnum_int(tcp, tcp->u_arg[2], "%d");
40 SYS_FUNC(sched_getparam)
43 tprintf("%d, ", (int) tcp->u_arg[0]);
45 printnum_int(tcp, tcp->u_arg[1], "%d");
49 SYS_FUNC(sched_setparam)
51 tprintf("%d, ", (int) tcp->u_arg[0]);
52 printnum_int(tcp, tcp->u_arg[1], "%d");
57 SYS_FUNC(sched_get_priority_min)
59 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
65 do_sched_rr_get_interval(struct tcb *const tcp,
66 const print_obj_by_addr_fn print_ts)
69 tprintf("%d, ", (int) tcp->u_arg[0]);
72 printaddr(tcp->u_arg[1]);
74 print_ts(tcp, tcp->u_arg[1]);
79 #if HAVE_ARCH_TIME32_SYSCALLS
80 SYS_FUNC(sched_rr_get_interval_time32)
82 return do_sched_rr_get_interval(tcp, print_timespec32);
86 SYS_FUNC(sched_rr_get_interval_time64)
88 return do_sched_rr_get_interval(tcp, print_timespec64);
92 print_sched_attr(struct tcb *const tcp, const kernel_ulong_t addr,
95 struct sched_attr attr = {};
99 /* called from sched_getattr */
100 size = usize <= sizeof(attr) ? usize : (unsigned) sizeof(attr);
101 if (umoven_or_printaddr(tcp, addr, size, &attr))
103 /* the number of bytes written by the kernel */
106 /* called from sched_setattr */
107 if (umove_or_printaddr(tcp, addr, &attr.size))
111 usize = SCHED_ATTR_MIN_SIZE;
112 size = usize <= sizeof(attr) ? usize : (unsigned) sizeof(attr);
113 if (size >= SCHED_ATTR_MIN_SIZE) {
114 if (umoven_or_printaddr(tcp, addr, size, &attr))
119 tprintf("{size=%u", attr.size);
121 if (size >= SCHED_ATTR_MIN_SIZE) {
122 tprints(", sched_policy=");
123 printxval(schedulers, attr.sched_policy, "SCHED_???");
124 tprints(", sched_flags=");
125 printflags64(sched_flags, attr.sched_flags, "SCHED_FLAG_???");
127 #define PRINT_SCHED_FIELD(field, fmt) \
128 tprintf(", " #field "=%" fmt, attr.field)
130 PRINT_SCHED_FIELD(sched_nice, "d");
131 PRINT_SCHED_FIELD(sched_priority, "u");
132 PRINT_SCHED_FIELD(sched_runtime, PRIu64);
133 PRINT_SCHED_FIELD(sched_deadline, PRIu64);
134 PRINT_SCHED_FIELD(sched_period, PRIu64);
143 SYS_FUNC(sched_setattr)
146 tprintf("%d, ", (int) tcp->u_arg[0]);
147 print_sched_attr(tcp, tcp->u_arg[1], 0);
149 struct sched_attr attr;
151 if (verbose(tcp) && tcp->u_error == E2BIG
152 && umove(tcp, tcp->u_arg[1], &attr.size) == 0) {
153 tprintf(" => {size=%u}", attr.size);
156 tprintf(", %u", (unsigned int) tcp->u_arg[2]);
162 SYS_FUNC(sched_getattr)
165 tprintf("%d, ", (int) tcp->u_arg[0]);
167 const unsigned int size = tcp->u_arg[2];
170 print_sched_attr(tcp, tcp->u_arg[1], size);
172 printaddr(tcp->u_arg[1]);
176 * Due to a subtle gcc bug that leads to miscompiled aarch64
177 * kernels, the 3rd argument of sched_getattr is not quite 32-bit
178 * as on other architectures. For more details see
179 * https://lists.strace.io/pipermail/strace-devel/2017-March/006085.html
182 print_abnormal_hi(tcp->u_arg[2]);
185 tprintf(", %u", (unsigned int) tcp->u_arg[3]);