1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4 * AUTHOR : Saji Kumar.V.R <[email protected]>
5 */
6 /*\
7 * [Description]
8 *
9 * Gets round-robin time quantum by calling sched_rr_get_interval() and
10 * checks that the value is sane.
11 *
12 * It is also a regression test for:
13 *
14 * - 975e155ed873 (sched/rt: Show the 'sched_rr_timeslice' SCHED_RR timeslice tuning knob in milliseconds)
15 * - c7fcb99877f9 ( sched/rt: Fix sysctl_sched_rr_timeslice intial value)
16 */
17
18 #include "time64_variants.h"
19 #include "tst_timer.h"
20 #include "tst_sched.h"
21
22 #define PROC_SCHED_RR_TIMESLICE_MS "/proc/sys/kernel/sched_rr_timeslice_ms"
23 static int proc_flag;
24
25 struct tst_ts tp;
26
27 static struct time64_variants variants[] = {
28 { .sched_rr_get_interval = libc_sched_rr_get_interval, .ts_type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
29
30 #if (__NR_sched_rr_get_interval != __LTP__NR_INVALID_SYSCALL)
31 { .sched_rr_get_interval = sys_sched_rr_get_interval, .ts_type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"},
32 #endif
33
34 #if (__NR_sched_rr_get_interval_time64 != __LTP__NR_INVALID_SYSCALL)
35 { .sched_rr_get_interval = sys_sched_rr_get_interval64, .ts_type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"},
36 #endif
37 };
38
setup(void)39 static void setup(void)
40 {
41 struct time64_variants *tv = &variants[tst_variant];
42 struct sched_param p = { 1 };
43
44 tst_res(TINFO, "Testing variant: %s", tv->desc);
45
46 tp.type = tv->ts_type;
47
48 if ((sys_sched_setscheduler(0, SCHED_RR, &p)) == -1)
49 tst_res(TFAIL | TERRNO, "sched_setscheduler() failed");
50
51 proc_flag = !access(PROC_SCHED_RR_TIMESLICE_MS, F_OK);
52 }
53
run(void)54 static void run(void)
55 {
56 struct time64_variants *tv = &variants[tst_variant];
57
58 TEST(tv->sched_rr_get_interval(0, tst_ts_get(&tp)));
59
60 if (!TST_RET) {
61 tst_res(TPASS, "sched_rr_get_interval() passed");
62 } else {
63 tst_res(TFAIL | TTERRNO, "Test Failed, sched_rr_get_interval() returned %ld",
64 TST_RET);
65 }
66
67 if (!tst_ts_valid(&tp)) {
68 tst_res(TPASS, "Time quantum %llis %llins",
69 tst_ts_get_sec(tp), tst_ts_get_nsec(tp));
70 } else {
71 tst_res(TFAIL, "Invalid time quantum %llis %llins",
72 tst_ts_get_sec(tp), tst_ts_get_nsec(tp));
73 }
74
75 if (proc_flag)
76 TST_ASSERT_INT(PROC_SCHED_RR_TIMESLICE_MS, tst_ts_to_ms(tp));
77 }
78
79 static struct tst_test test = {
80 .test_all = run,
81 .test_variants = ARRAY_SIZE(variants),
82 .setup = setup,
83 .needs_root = 1,
84 .tags = (const struct tst_tag[]) {
85 {"linux-git", "975e155ed873"},
86 {"linux-git", "c7fcb99877f9"},
87 {}
88 }
89 };
90