2 * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <asm/unistd.h>
31 #if defined __NR_sched_getattr && defined __NR_sched_setattr
33 # include <inttypes.h>
37 # include "sched_attr.h"
39 # include "xlat/schedulers.h"
41 static const char *errstr;
44 sys_sched_getattr(kernel_ulong_t pid, kernel_ulong_t attr,
45 kernel_ulong_t size, kernel_ulong_t flags)
47 long rc = syscall(__NR_sched_getattr, pid, attr, size, flags);
48 errstr = sprintrc(rc);
53 sys_sched_setattr(kernel_ulong_t pid, kernel_ulong_t attr, kernel_ulong_t flags)
55 long rc = syscall(__NR_sched_setattr, pid, attr, flags);
56 errstr = sprintrc(rc);
63 static const kernel_ulong_t bogus_pid =
64 (kernel_ulong_t) 0xdefacedfacefeedULL;
65 static const kernel_ulong_t bogus_size =
66 (kernel_ulong_t) 0xdefacedcafef00dULL;
67 static const kernel_ulong_t bogus_flags =
68 (kernel_ulong_t) 0xdefaceddeadc0deULL;
70 struct sched_attr *const attr = tail_alloc(sizeof(*attr));
71 void *const efault = attr + 1;
73 sys_sched_getattr(bogus_pid, 0, 0, 0);
74 printf("sched_getattr(%d, NULL, 0, 0) = %s\n", (int) bogus_pid, errstr);
76 sys_sched_getattr(-1U, (unsigned long) attr, bogus_size, bogus_flags);
77 printf("sched_getattr(-1, %p, %u, %u) = %s\n",
78 attr, (unsigned) bogus_size, (unsigned) bogus_flags, errstr);
80 sys_sched_getattr(0, (unsigned long) efault, sizeof(*attr), 0);
81 printf("sched_getattr(0, %p, %u, 0) = %s\n",
82 efault, (unsigned) sizeof(*attr), errstr);
84 if (sys_sched_getattr(0, (unsigned long) attr, sizeof(*attr), 0))
85 perror_msg_and_skip("sched_getattr");
86 printf("sched_getattr(0, {size=%u, sched_policy=", attr->size);
87 printxval(schedulers, attr->sched_policy, NULL);
88 printf(", sched_flags=%s, sched_nice=%d, sched_priority=%u"
89 ", sched_runtime=%" PRIu64 ", sched_deadline=%" PRIu64
90 ", sched_period=%" PRIu64 "}, %u, 0) = 0\n",
91 attr->sched_flags ? "SCHED_FLAG_RESET_ON_FORK" : "0",
97 (unsigned) sizeof(*attr));
99 attr->sched_flags |= 1;
101 if (sys_sched_setattr(0, (unsigned long) attr, 0))
102 perror_msg_and_skip("sched_setattr");
103 printf("sched_setattr(0, {size=%u, sched_policy=", attr->size);
104 printxval(schedulers, attr->sched_policy, NULL);
105 printf(", sched_flags=%s, sched_nice=%d, sched_priority=%u"
106 ", sched_runtime=%" PRIu64 ", sched_deadline=%" PRIu64
107 ", sched_period=%" PRIu64 "}, 0) = 0\n",
108 "SCHED_FLAG_RESET_ON_FORK",
110 attr->sched_priority,
112 attr->sched_deadline,
115 attr->size = 0x90807060;
116 attr->sched_policy = 0xca7faced;
117 attr->sched_flags = 0xbadc0ded1057da7aULL;
118 attr->sched_nice = 0xafbfcfdf;
119 attr->sched_priority = 0xb8c8d8e8;
120 attr->sched_runtime = 0xbadcaffedeadf157ULL;
121 attr->sched_deadline = 0xc0de70a57badac75ULL;
122 attr->sched_period = 0xded1ca7edda7aca7ULL;
124 sys_sched_setattr(bogus_pid, (unsigned long) attr, bogus_flags);
125 printf("sched_setattr(%d, {size=%u, sched_policy=%#x /* SCHED_??? */, "
126 "sched_flags=%#" PRIx64 " /* SCHED_FLAG_??? */, "
127 "sched_nice=%d, sched_priority=%u, sched_runtime=%" PRIu64 ", "
128 "sched_deadline=%" PRIu64 ", sched_period=%" PRIu64 "}, %u)"
135 attr->sched_priority,
137 attr->sched_deadline,
139 (unsigned) bogus_flags, errstr);
141 puts("+++ exited with 0 +++");
147 SKIP_MAIN_UNDEFINED("__NR_sched_getattr && __NR_sched_setattr")