Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 1 | /* |
| 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> |
Elliott Hughes | 28e98bc | 2018-06-14 16:59:04 -0700 | [diff] [blame] | 5 | * Copyright (c) 2014-2018 The strace developers. |
Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. The name of the author may not be used to endorse or promote products |
| 17 | * derived from this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 31 | #include "defs.h" |
| 32 | |
| 33 | #include <sched.h> |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 34 | #include "sched_attr.h" |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 35 | |
| 36 | #include "xlat/schedulers.h" |
Dmitry V. Levin | 3456bcc | 2015-07-29 07:59:56 +0000 | [diff] [blame] | 37 | #include "xlat/sched_flags.h" |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 38 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 39 | SYS_FUNC(sched_getscheduler) |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 40 | { |
| 41 | if (entering(tcp)) { |
| 42 | tprintf("%d", (int) tcp->u_arg[0]); |
| 43 | } else if (!syserror(tcp)) { |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 44 | tcp->auxstr = xlookup(schedulers, (kernel_ulong_t) tcp->u_rval); |
Elliott Hughes | 28e98bc | 2018-06-14 16:59:04 -0700 | [diff] [blame] | 45 | return RVAL_STR; |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 46 | } |
| 47 | return 0; |
| 48 | } |
| 49 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 50 | SYS_FUNC(sched_setscheduler) |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 51 | { |
Dmitry V. Levin | 10c408a | 2015-07-17 16:16:24 +0000 | [diff] [blame] | 52 | tprintf("%d, ", (int) tcp->u_arg[0]); |
| 53 | printxval(schedulers, tcp->u_arg[1], "SCHED_???"); |
| 54 | tprints(", "); |
| 55 | printnum_int(tcp, tcp->u_arg[2], "%d"); |
| 56 | |
| 57 | return RVAL_DECODED; |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 60 | SYS_FUNC(sched_getparam) |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 61 | { |
Dmitry V. Levin | f8bf1d5 | 2015-07-17 16:12:22 +0000 | [diff] [blame] | 62 | if (entering(tcp)) |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 63 | tprintf("%d, ", (int) tcp->u_arg[0]); |
Dmitry V. Levin | f8bf1d5 | 2015-07-17 16:12:22 +0000 | [diff] [blame] | 64 | else |
| 65 | printnum_int(tcp, tcp->u_arg[1], "%d"); |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 69 | SYS_FUNC(sched_setparam) |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 70 | { |
Dmitry V. Levin | 10c408a | 2015-07-17 16:16:24 +0000 | [diff] [blame] | 71 | tprintf("%d, ", (int) tcp->u_arg[0]); |
| 72 | printnum_int(tcp, tcp->u_arg[1], "%d"); |
| 73 | |
| 74 | return RVAL_DECODED; |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 77 | SYS_FUNC(sched_get_priority_min) |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 78 | { |
Dmitry V. Levin | 10c408a | 2015-07-17 16:16:24 +0000 | [diff] [blame] | 79 | printxval(schedulers, tcp->u_arg[0], "SCHED_???"); |
| 80 | |
| 81 | return RVAL_DECODED; |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 84 | SYS_FUNC(sched_rr_get_interval) |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 85 | { |
| 86 | if (entering(tcp)) { |
Dmitry V. Levin | f8bf1d5 | 2015-07-17 16:12:22 +0000 | [diff] [blame] | 87 | tprintf("%d, ", (int) tcp->u_arg[0]); |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 88 | } else { |
| 89 | if (syserror(tcp)) |
Dmitry V. Levin | f8bf1d5 | 2015-07-17 16:12:22 +0000 | [diff] [blame] | 90 | printaddr(tcp->u_arg[1]); |
Dmitry V. Levin | fff2f31 | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 91 | else |
| 92 | print_timespec(tcp, tcp->u_arg[1]); |
| 93 | } |
| 94 | return 0; |
| 95 | } |
Dmitry V. Levin | 3456bcc | 2015-07-29 07:59:56 +0000 | [diff] [blame] | 96 | |
| 97 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 98 | print_sched_attr(struct tcb *const tcp, const kernel_ulong_t addr, |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 99 | unsigned int usize) |
Dmitry V. Levin | 3456bcc | 2015-07-29 07:59:56 +0000 | [diff] [blame] | 100 | { |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 101 | struct sched_attr attr = {}; |
| 102 | unsigned int size; |
Dmitry V. Levin | 3456bcc | 2015-07-29 07:59:56 +0000 | [diff] [blame] | 103 | |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 104 | if (usize) { |
| 105 | /* called from sched_getattr */ |
| 106 | size = usize <= sizeof(attr) ? usize : (unsigned) sizeof(attr); |
| 107 | if (umoven_or_printaddr(tcp, addr, size, &attr)) |
| 108 | return; |
| 109 | /* the number of bytes written by the kernel */ |
| 110 | size = attr.size; |
| 111 | } else { |
| 112 | /* called from sched_setattr */ |
| 113 | if (umove_or_printaddr(tcp, addr, &attr.size)) |
| 114 | return; |
| 115 | usize = attr.size; |
| 116 | if (!usize) |
| 117 | usize = SCHED_ATTR_MIN_SIZE; |
| 118 | size = usize <= sizeof(attr) ? usize : (unsigned) sizeof(attr); |
| 119 | if (size >= SCHED_ATTR_MIN_SIZE) { |
| 120 | if (umoven_or_printaddr(tcp, addr, size, &attr)) |
| 121 | return; |
| 122 | } |
| 123 | } |
Dmitry V. Levin | 3456bcc | 2015-07-29 07:59:56 +0000 | [diff] [blame] | 124 | |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 125 | tprintf("{size=%u", attr.size); |
| 126 | |
| 127 | if (size >= SCHED_ATTR_MIN_SIZE) { |
| 128 | tprints(", sched_policy="); |
| 129 | printxval(schedulers, attr.sched_policy, "SCHED_???"); |
| 130 | tprints(", sched_flags="); |
| 131 | printflags64(sched_flags, attr.sched_flags, "SCHED_FLAG_???"); |
| 132 | |
| 133 | #define PRINT_SCHED_FIELD(field, fmt) \ |
| 134 | tprintf(", " #field "=%" fmt, attr.field) |
| 135 | |
| 136 | PRINT_SCHED_FIELD(sched_nice, "d"); |
| 137 | PRINT_SCHED_FIELD(sched_priority, "u"); |
| 138 | PRINT_SCHED_FIELD(sched_runtime, PRIu64); |
| 139 | PRINT_SCHED_FIELD(sched_deadline, PRIu64); |
| 140 | PRINT_SCHED_FIELD(sched_period, PRIu64); |
| 141 | |
| 142 | if (usize > size) |
| 143 | tprints(", ..."); |
| 144 | } |
| 145 | |
| 146 | tprints("}"); |
Dmitry V. Levin | 3456bcc | 2015-07-29 07:59:56 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | SYS_FUNC(sched_setattr) |
| 150 | { |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 151 | if (entering(tcp)) { |
| 152 | tprintf("%d, ", (int) tcp->u_arg[0]); |
| 153 | print_sched_attr(tcp, tcp->u_arg[1], 0); |
| 154 | } else { |
| 155 | struct sched_attr attr; |
Dmitry V. Levin | 3456bcc | 2015-07-29 07:59:56 +0000 | [diff] [blame] | 156 | |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 157 | if (verbose(tcp) && tcp->u_error == E2BIG |
| 158 | && umove(tcp, tcp->u_arg[1], &attr.size) == 0) { |
| 159 | tprintf(" => {size=%u}", attr.size); |
| 160 | } |
| 161 | |
| 162 | tprintf(", %u", (unsigned int) tcp->u_arg[2]); |
| 163 | } |
| 164 | |
| 165 | return 0; |
Dmitry V. Levin | 3456bcc | 2015-07-29 07:59:56 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | SYS_FUNC(sched_getattr) |
| 169 | { |
| 170 | if (entering(tcp)) { |
| 171 | tprintf("%d, ", (int) tcp->u_arg[0]); |
| 172 | } else { |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 173 | const unsigned int size = tcp->u_arg[2]; |
| 174 | |
| 175 | if (size) |
| 176 | print_sched_attr(tcp, tcp->u_arg[1], size); |
| 177 | else |
| 178 | printaddr(tcp->u_arg[1]); |
| 179 | tprints(", "); |
| 180 | #ifdef AARCH64 |
| 181 | /* |
| 182 | * Due to a subtle gcc bug that leads to miscompiled aarch64 |
| 183 | * kernels, the 3rd argument of sched_getattr is not quite 32-bit |
| 184 | * as on other architectures. For more details see |
Elliott Hughes | 28e98bc | 2018-06-14 16:59:04 -0700 | [diff] [blame] | 185 | * https://lists.strace.io/pipermail/strace-devel/2017-March/006085.html |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 186 | */ |
| 187 | if (syserror(tcp)) |
| 188 | print_abnormal_hi(tcp->u_arg[2]); |
| 189 | #endif |
| 190 | tprintf("%u", size); |
| 191 | tprintf(", %u", (unsigned int) tcp->u_arg[3]); |
Dmitry V. Levin | 3456bcc | 2015-07-29 07:59:56 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | return 0; |
| 195 | } |