public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yajun Deng <yajun.deng@linux.dev>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	bristot@redhat.com, vschneid@redhat.com
Cc: linux-kernel@vger.kernel.org, Yajun Deng <yajun.deng@linux.dev>
Subject: [PATCH] sched/rt: Redefine RR_TIMESLICE to 100 msecs
Date: Wed, 18 Oct 2023 16:17:09 +0800	[thread overview]
Message-ID: <20231018081709.2289264-1-yajun.deng@linux.dev> (raw)

The RR_TIMESLICE is currently defined as the jiffies corresponding to
100 msecs. And then sysctl_sched_rr_timeslice will convert RR_TIMESLICE
to 100 msecs. These are opposite calculations.

There are msecs_to_jiffies and jiffies_to_msecs in sched_rr_handler.
These are also opposite calculations.

Redefine RR_TIMESLICE to 100 msecs, only sched_rr_timeslice needs to
convert RR_TIMESLICE to jiffies.

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 include/linux/sched/rt.h |  2 +-
 init/init_task.c         |  2 +-
 kernel/sched/rt.c        | 12 +++++-------
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/include/linux/sched/rt.h b/include/linux/sched/rt.h
index b2b9e6eb9683..74f8f456a804 100644
--- a/include/linux/sched/rt.h
+++ b/include/linux/sched/rt.h
@@ -58,6 +58,6 @@ extern void normalize_rt_tasks(void);
  * default timeslice is 100 msecs (used only for SCHED_RR tasks).
  * Timeslices get refilled after they expire.
  */
-#define RR_TIMESLICE		(100 * HZ / 1000)
+#define RR_TIMESLICE		(100)
 
 #endif /* _LINUX_SCHED_RT_H */
diff --git a/init/init_task.c b/init/init_task.c
index 5727d42149c3..86619a425342 100644
--- a/init/init_task.c
+++ b/init/init_task.c
@@ -94,7 +94,7 @@ struct task_struct init_task
 	},
 	.rt		= {
 		.run_list	= LIST_HEAD_INIT(init_task.rt.run_list),
-		.time_slice	= RR_TIMESLICE,
+		.time_slice	= (RR_TIMESLICE * HZ) / MSEC_PER_SEC,
 	},
 	.tasks		= LIST_HEAD_INIT(init_task.tasks),
 #ifdef CONFIG_SMP
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 6aaf0a3d6081..7c0e912094a9 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -4,7 +4,7 @@
  * policies)
  */
 
-int sched_rr_timeslice = RR_TIMESLICE;
+int sched_rr_timeslice = (RR_TIMESLICE * HZ) / MSEC_PER_SEC;
 /* More than 4 hours if BW_SHIFT equals 20. */
 static const u64 max_rt_runtime = MAX_BW;
 
@@ -25,7 +25,7 @@ int sysctl_sched_rt_period = 1000000;
 int sysctl_sched_rt_runtime = 950000;
 
 #ifdef CONFIG_SYSCTL
-static int sysctl_sched_rr_timeslice = (MSEC_PER_SEC * RR_TIMESLICE) / HZ;
+static int sysctl_sched_rr_timeslice = RR_TIMESLICE;
 static int sched_rt_handler(struct ctl_table *table, int write, void *buffer,
 		size_t *lenp, loff_t *ppos);
 static int sched_rr_handler(struct ctl_table *table, int write, void *buffer,
@@ -3014,12 +3014,10 @@ 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)
-			sysctl_sched_rr_timeslice = jiffies_to_msecs(RR_TIMESLICE);
+			sysctl_sched_rr_timeslice = RR_TIMESLICE;
+
+		sched_rr_timeslice = msecs_to_jiffies(sysctl_sched_rr_timeslice);
 	}
 	mutex_unlock(&mutex);
 
-- 
2.25.1


             reply	other threads:[~2023-10-18  8:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18  8:17 Yajun Deng [this message]
2023-11-08 11:02 ` [PATCH] sched/rt: Redefine RR_TIMESLICE to 100 msecs Yajun Deng
2023-11-08 16:55 ` Steven Rostedt
2023-11-09  2:11   ` Yajun Deng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231018081709.2289264-1-yajun.deng@linux.dev \
    --to=yajun.deng@linux.dev \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox