]> granicus.if.org Git - strace/blob - sched.c
Move definition of struct sched_attr to a separate header file
[strace] / sched.c
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 #include "sched_attr.h"
34
35 #include "xlat/schedulers.h"
36 #include "xlat/sched_flags.h"
37
38 SYS_FUNC(sched_getscheduler)
39 {
40         if (entering(tcp)) {
41                 tprintf("%d", (int) tcp->u_arg[0]);
42         } else if (!syserror(tcp)) {
43                 tcp->auxstr = xlookup(schedulers, (kernel_ulong_t) tcp->u_rval);
44                 if (tcp->auxstr != NULL)
45                         return RVAL_STR;
46         }
47         return 0;
48 }
49
50 SYS_FUNC(sched_setscheduler)
51 {
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;
58 }
59
60 SYS_FUNC(sched_getparam)
61 {
62         if (entering(tcp))
63                 tprintf("%d, ", (int) tcp->u_arg[0]);
64         else
65                 printnum_int(tcp, tcp->u_arg[1], "%d");
66         return 0;
67 }
68
69 SYS_FUNC(sched_setparam)
70 {
71         tprintf("%d, ", (int) tcp->u_arg[0]);
72         printnum_int(tcp, tcp->u_arg[1], "%d");
73
74         return RVAL_DECODED;
75 }
76
77 SYS_FUNC(sched_get_priority_min)
78 {
79         printxval(schedulers, tcp->u_arg[0], "SCHED_???");
80
81         return RVAL_DECODED;
82 }
83
84 SYS_FUNC(sched_rr_get_interval)
85 {
86         if (entering(tcp)) {
87                 tprintf("%d, ", (int) tcp->u_arg[0]);
88         } else {
89                 if (syserror(tcp))
90                         printaddr(tcp->u_arg[1]);
91                 else
92                         print_timespec(tcp, tcp->u_arg[1]);
93         }
94         return 0;
95 }
96
97 static void
98 print_sched_attr(struct tcb *const tcp, const kernel_ulong_t addr,
99                  unsigned int size)
100 {
101         struct sched_attr attr = {};
102
103         if (size > sizeof(attr))
104                 size = sizeof(attr);
105         if (umoven_or_printaddr(tcp, addr, size, &attr))
106                 return;
107
108         tprintf("{size=%u, sched_policy=", attr.size);
109         printxval(schedulers, attr.sched_policy, "SCHED_???");
110         tprints(", sched_flags=");
111         printflags64(sched_flags, attr.sched_flags, "SCHED_FLAG_???");
112         tprintf(", sched_nice=%d", attr.sched_nice);
113         tprintf(", sched_priority=%u", attr.sched_priority);
114         tprintf(", sched_runtime=%" PRIu64, attr.sched_runtime);
115         tprintf(", sched_deadline=%" PRIu64, attr.sched_deadline);
116         tprintf(", sched_period=%" PRIu64 "}", attr.sched_period);
117 }
118
119 SYS_FUNC(sched_setattr)
120 {
121         tprintf("%d, ", (int) tcp->u_arg[0]);
122         print_sched_attr(tcp, tcp->u_arg[1], 0x100);
123         tprintf(", %u", (unsigned int) tcp->u_arg[2]);
124
125         return RVAL_DECODED;
126 }
127
128 SYS_FUNC(sched_getattr)
129 {
130         if (entering(tcp)) {
131                 tprintf("%d, ", (int) tcp->u_arg[0]);
132         } else {
133                 print_sched_attr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
134                 tprintf(", %u, %u",
135                         (unsigned int) tcp->u_arg[2],
136                         (unsigned int) tcp->u_arg[3]);
137         }
138
139         return 0;
140 }