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>
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
SYS_FUNC(sched_getscheduler)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, tcp->u_rval);
43 if (tcp->auxstr != NULL)
44 return RVAL_STR;
45 }
46 return 0;
47 }
48
SYS_FUNC(sched_setscheduler)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
SYS_FUNC(sched_getparam)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
SYS_FUNC(sched_setparam)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
SYS_FUNC(sched_get_priority_min)76 SYS_FUNC(sched_get_priority_min)
77 {
78 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
79
80 return RVAL_DECODED;
81 }
82
SYS_FUNC(sched_rr_get_interval)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
print_sched_attr(struct tcb * tcp,const long addr,unsigned int size)97 print_sched_attr(struct tcb *tcp, const long addr, unsigned int size)
98 {
99 struct {
100 uint32_t size;
101 uint32_t sched_policy;
102 uint64_t sched_flags;
103 uint32_t sched_nice;
104 uint32_t sched_priority;
105 uint64_t sched_runtime;
106 uint64_t sched_deadline;
107 uint64_t sched_period;
108 } attr = {};
109
110 if (size > sizeof(attr))
111 size = sizeof(attr);
112 if (umoven_or_printaddr(tcp, addr, size, &attr))
113 return;
114
115 tprintf("{size=%u, sched_policy=", attr.size);
116 printxval(schedulers, attr.sched_policy, "SCHED_???");
117 tprints(", sched_flags=");
118 printflags(sched_flags, attr.sched_flags, "SCHED_FLAG_???");
119 tprintf(", sched_nice=%d", attr.sched_nice);
120 tprintf(", sched_priority=%u", attr.sched_priority);
121 tprintf(", sched_runtime=%" PRIu64, attr.sched_runtime);
122 tprintf(", sched_deadline=%" PRIu64, attr.sched_deadline);
123 tprintf(", sched_period=%" PRIu64 "}", attr.sched_period);
124 }
125
SYS_FUNC(sched_setattr)126 SYS_FUNC(sched_setattr)
127 {
128 tprintf("%d, ", (int) tcp->u_arg[0]);
129 print_sched_attr(tcp, tcp->u_arg[1], 0x100);
130 tprintf(", %u", (unsigned int) tcp->u_arg[2]);
131
132 return RVAL_DECODED;
133 }
134
SYS_FUNC(sched_getattr)135 SYS_FUNC(sched_getattr)
136 {
137 if (entering(tcp)) {
138 tprintf("%d, ", (int) tcp->u_arg[0]);
139 } else {
140 print_sched_attr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
141 tprintf(", %u, %u",
142 (unsigned int) tcp->u_arg[2],
143 (unsigned int) tcp->u_arg[3]);
144 }
145
146 return 0;
147 }
148