sched/rt: Reset sysctl_sched_rr_timeslice when it non-positive

Message ID 20230314031323.3638994-1-yajun.deng@linux.dev
State New
Headers
Series sched/rt: Reset sysctl_sched_rr_timeslice when it non-positive |

Commit Message

Yajun Deng March 14, 2023, 3:13 a.m. UTC
  When sysctl_sched_rr_timeslice was set a non-positive number, only
sched_rr_timeslice was reset to default, This behavior should let
users know.

So reset sysctl_sched_rr_timeslice at the same time when it
non-positive.

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 kernel/sched/rt.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
  

Patch

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 0a11f44adee5..0723a6297f96 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -3036,9 +3036,12 @@  static int sched_rr_handler(struct ctl_table *table, int write, void *buffer,
 	 * Also, writing zero resets the timeslice to default:
 	 */
 	if (!ret && write) {
-		sched_rr_timeslice =
-			sysctl_sched_rr_timeslice <= 0 ? RR_TIMESLICE :
-			msecs_to_jiffies(sysctl_sched_rr_timeslice);
+		if (sysctl_sched_rr_timeslice > 0)
+			sched_rr_timeslice = msecs_to_jiffies(sysctl_sched_rr_timeslice);
+		else {
+			sched_rr_timeslice = RR_TIMESLICE;
+			sysctl_sched_rr_timeslice = (MSEC_PER_SEC / HZ) * RR_TIMESLICE;
+		}
 	}
 	mutex_unlock(&mutex);