]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
torture: Add torture_sched_set_normal() for user-specified nice values
authorPaul E. McKenney <paulmck@kernel.org>
Thu, 7 May 2026 16:57:16 +0000 (09:57 -0700)
committerUladzislau Rezki (Sony) <urezki@gmail.com>
Sun, 24 May 2026 07:38:47 +0000 (09:38 +0200)
This new torture_sched_set_normal() function clamps the nice value at
the MIN_NICE..MAX_NICE limits, splatting it these limits are exceeded.
It then invokes sched_set_normal() to set the new value.  This prevents
more difficult-to-debug failures within the scheduler.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
include/linux/torture.h
kernel/torture.c

index 1b59056c3b1822523d0225b35bde465a62eb49c7..c9b47d138302956f52e83ceab11491eb8f57f9bc 100644 (file)
@@ -129,6 +129,7 @@ void _torture_stop_kthread(char *m, struct task_struct **tp);
 #else
 #define torture_preempt_schedule()     do { } while (0)
 #endif
+void torture_sched_set_normal(struct task_struct *t, int nice);
 
 #if IS_ENABLED(CONFIG_RCU_TORTURE_TEST) || IS_MODULE(CONFIG_RCU_TORTURE_TEST) || IS_ENABLED(CONFIG_LOCK_TORTURE_TEST) || IS_MODULE(CONFIG_LOCK_TORTURE_TEST)
 long torture_sched_setaffinity(pid_t pid, const struct cpumask *in_mask, bool dowarn);
index 62c1ac77769424a515295994a8f0b5262a4e2066..77cb3589b19f9c9a034b21777d3fe0b5cf897af9 100644 (file)
@@ -972,3 +972,19 @@ void _torture_stop_kthread(char *m, struct task_struct **tp)
        *tp = NULL;
 }
 EXPORT_SYMBOL_GPL(_torture_stop_kthread);
+
+/*
+ * Set the specified task's niceness value, saturating at limits.
+ * Saturating noisily, but saturating.
+ */
+void torture_sched_set_normal(struct task_struct *t, int nice)
+{
+       int realnice = nice;
+
+       if (WARN_ON_ONCE(realnice > MAX_NICE))
+               realnice = MAX_NICE;
+       if (WARN_ON_ONCE(realnice < MIN_NICE))
+               realnice = MIN_NICE;
+       sched_set_normal(t, realnice);
+}
+EXPORT_SYMBOL_GPL(torture_sched_set_normal);