1 /* 2 * Copyright (c) 2004 Ulrich Drepper <drepper (at) redhat.com> 3 * Copyright (c) 2005 Roland McGrath <roland (at) redhat.com> 4 * Copyright (c) 2012-2015 Dmitry V. Levin <ldv (at) altlinux.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #include "defs.h" 31 32 #include <sched.h> 33 34 #include "xlat/schedulers.h" 35 #include "xlat/sched_flags.h" 36 37 SYS_FUNC(sched_getscheduler) 38 { 39 if (entering(tcp)) { 40 tprintf("%d", (int) tcp->u_arg[0]); 41 } else if (!syserror(tcp)) { 42 tcp->auxstr = xlookup(schedulers, (kernel_ulong_t) tcp->u_rval); 43 if (tcp->auxstr != NULL) 44 return RVAL_STR; 45 } 46 return 0; 47 } 48 49 SYS_FUNC(sched_setscheduler) 50 { 51 tprintf("%d, ", (int) tcp->u_arg[0]); 52 printxval(schedulers, tcp->u_arg[1], "SCHED_???"); 53 tprints(", "); 54 printnum_int(tcp, tcp->u_arg[2], "%d"); 55 56 return RVAL_DECODED; 57 } 58 59 SYS_FUNC(sched_getparam) 60 { 61 if (entering(tcp)) 62 tprintf("%d, ", (int) tcp->u_arg[0]); 63 else 64 printnum_int(tcp, tcp->u_arg[1], "%d"); 65 return 0; 66 } 67 68 SYS_FUNC(sched_setparam) 69 { 70 tprintf("%d, ", (int) tcp->u_arg[0]); 71 printnum_int(tcp, tcp->u_arg[1], "%d"); 72 73 return RVAL_DECODED; 74 } 75 76 SYS_FUNC(sched_get_priority_min) 77 { 78 printxval(schedulers, tcp->u_arg[0], "SCHED_???"); 79 80 return RVAL_DECODED; 81 } 82 83 SYS_FUNC(sched_rr_get_interval) 84 { 85 if (entering(tcp)) { 86 tprintf("%d, ", (int) tcp->u_arg[0]); 87 } else { 88 if (syserror(tcp)) 89 printaddr(tcp->u_arg[1]); 90 else 91 print_timespec(tcp, tcp->u_arg[1]); 92 } 93 return 0; 94 } 95 96 static void 97 print_sched_attr(struct tcb *const tcp, const kernel_ulong_t addr, 98 unsigned int size) 99 { 100 struct { 101 uint32_t size; 102 uint32_t sched_policy; 103 uint64_t sched_flags; 104 uint32_t sched_nice; 105 uint32_t sched_priority; 106 uint64_t sched_runtime; 107 uint64_t sched_deadline; 108 uint64_t sched_period; 109 } attr = {}; 110 111 if (size > sizeof(attr)) 112 size = sizeof(attr); 113 if (umoven_or_printaddr(tcp, addr, size, &attr)) 114 return; 115 116 tprintf("{size=%u, sched_policy=", attr.size); 117 printxval(schedulers, attr.sched_policy, "SCHED_???"); 118 tprints(", sched_flags="); 119 printflags64(sched_flags, attr.sched_flags, "SCHED_FLAG_???"); 120 tprintf(", sched_nice=%d", attr.sched_nice); 121 tprintf(", sched_priority=%u", attr.sched_priority); 122 tprintf(", sched_runtime=%" PRIu64, attr.sched_runtime); 123 tprintf(", sched_deadline=%" PRIu64, attr.sched_deadline); 124 tprintf(", sched_period=%" PRIu64 "}", attr.sched_period); 125 } 126 127 SYS_FUNC(sched_setattr) 128 { 129 tprintf("%d, ", (int) tcp->u_arg[0]); 130 print_sched_attr(tcp, tcp->u_arg[1], 0x100); 131 tprintf(", %u", (unsigned int) tcp->u_arg[2]); 132 133 return RVAL_DECODED; 134 } 135 136 SYS_FUNC(sched_getattr) 137 { 138 if (entering(tcp)) { 139 tprintf("%d, ", (int) tcp->u_arg[0]); 140 } else { 141 print_sched_attr(tcp, tcp->u_arg[1], tcp->u_arg[2]); 142 tprintf(", %u, %u", 143 (unsigned int) tcp->u_arg[2], 144 (unsigned int) tcp->u_arg[3]); 145 } 146 147 return 0; 148 } 149