blob: 86d4c22286ec0218e4770ff22b8288c67047d4db [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
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
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000030#include "defs.h"
31
32#include <sched.h>
33
34#include "xlat/schedulers.h"
Dmitry V. Levin3456bcc2015-07-29 07:59:56 +000035#include "xlat/sched_flags.h"
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000036
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000037SYS_FUNC(sched_getscheduler)
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000038{
39 if (entering(tcp)) {
40 tprintf("%d", (int) tcp->u_arg[0]);
41 } else if (!syserror(tcp)) {
Dmitry V. Levin9134aab2016-05-14 21:46:05 +000042 tcp->auxstr = xlookup(schedulers, (unsigned long) tcp->u_rval);
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000043 if (tcp->auxstr != NULL)
44 return RVAL_STR;
45 }
46 return 0;
47}
48
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000049SYS_FUNC(sched_setscheduler)
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000050{
Dmitry V. Levin10c408a2015-07-17 16:16:24 +000051 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;
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000057}
58
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000059SYS_FUNC(sched_getparam)
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000060{
Dmitry V. Levinf8bf1d52015-07-17 16:12:22 +000061 if (entering(tcp))
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000062 tprintf("%d, ", (int) tcp->u_arg[0]);
Dmitry V. Levinf8bf1d52015-07-17 16:12:22 +000063 else
64 printnum_int(tcp, tcp->u_arg[1], "%d");
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000065 return 0;
66}
67
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000068SYS_FUNC(sched_setparam)
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000069{
Dmitry V. Levin10c408a2015-07-17 16:16:24 +000070 tprintf("%d, ", (int) tcp->u_arg[0]);
71 printnum_int(tcp, tcp->u_arg[1], "%d");
72
73 return RVAL_DECODED;
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000074}
75
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000076SYS_FUNC(sched_get_priority_min)
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000077{
Dmitry V. Levin10c408a2015-07-17 16:16:24 +000078 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
79
80 return RVAL_DECODED;
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000081}
82
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000083SYS_FUNC(sched_rr_get_interval)
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000084{
85 if (entering(tcp)) {
Dmitry V. Levinf8bf1d52015-07-17 16:12:22 +000086 tprintf("%d, ", (int) tcp->u_arg[0]);
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000087 } else {
88 if (syserror(tcp))
Dmitry V. Levinf8bf1d52015-07-17 16:12:22 +000089 printaddr(tcp->u_arg[1]);
Dmitry V. Levinfff2f312014-12-11 19:25:02 +000090 else
91 print_timespec(tcp, tcp->u_arg[1]);
92 }
93 return 0;
94}
Dmitry V. Levin3456bcc2015-07-29 07:59:56 +000095
96static void
97print_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=");
Dmitry V. Levinba62f342016-05-16 22:16:17 +0000118 printflags64(sched_flags, attr.sched_flags, "SCHED_FLAG_???");
Dmitry V. Levin3456bcc2015-07-29 07:59:56 +0000119 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
126SYS_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
135SYS_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}