From: Kirill Tkhai <ktkhai@virtuozzo.com>
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,
ktkhai@virtuozzo.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH RFC] sched: Micro optimization in pick_next_task() and in check_preempt_curr()
Date: Thu, 19 Dec 2019 15:39:14 +0300 [thread overview]
Message-ID: <157675913272.349305.8936736338884044103.stgit@localhost.localdomain> (raw)
In kernel/sched/Makefile files, describing different sched classes, already
go in the order from the lowest priority class to the highest priority class:
idle.o fair.o rt.o deadline.o stop_task.o
The documentation of GNU linker says, that section appears in the order
they are seen during link time (see [1]):
>Normally, the linker will place files and sections matched by wildcards
>in the order in which they are seen during the link. You can change this
>by using the SORT keyword, which appears before a wildcard pattern
>in parentheses (e.g., SORT(.text*)).
So, we may expect const variables from idle.o will go before ro variables
from fair.o in RO_DATA section, while ro variables from fair.o will go
before ro variables from rt.o, etc.
(Also, it looks like the linking order is already used in kernel, e.g.
in drivers/md/Makefile)
Thus, we may introduce an optimization based on xxx_sched_class addresses
in these two hot scheduler functions: pick_next_task() and check_preempt_curr().
One more result of the patch is that size of object file becomes a little
less (excluding added BUG_ON(), which goes in __init section):
$size kernel/sched/core.o
text data bss dec hex filename
before: 66446 18957 676 86079 1503f kernel/sched/core.o
after: 66398 18957 676 86031 1500f kernel/sched/core.o
[1] https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/sections.html
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
kernel/sched/Makefile | 2 ++
kernel/sched/core.c | 24 +++++++++---------------
2 files changed, 11 insertions(+), 15 deletions(-)
diff --git a/kernel/sched/Makefile b/kernel/sched/Makefile
index 5fc9c9b70862..f78f177c660a 100644
--- a/kernel/sched/Makefile
+++ b/kernel/sched/Makefile
@@ -23,6 +23,8 @@ CFLAGS_core.o := $(PROFILING) -fno-omit-frame-pointer
endif
obj-y += core.o loadavg.o clock.o cputime.o
+# Order is significant: a more priority class xxx is described by variable
+# xxx_sched_class with a bigger address. See BUG_ON() in sched_init().
obj-y += idle.o fair.o rt.o deadline.o
obj-y += wait.o wait_bit.o swait.o completion.o
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 15508c202bf5..befdd7158b27 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1416,20 +1416,10 @@ static inline void check_class_changed(struct rq *rq, struct task_struct *p,
void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags)
{
- const struct sched_class *class;
-
- if (p->sched_class == rq->curr->sched_class) {
+ if (p->sched_class == rq->curr->sched_class)
rq->curr->sched_class->check_preempt_curr(rq, p, flags);
- } else {
- for_each_class(class) {
- if (class == rq->curr->sched_class)
- break;
- if (class == p->sched_class) {
- resched_curr(rq);
- break;
- }
- }
- }
+ else if (p->sched_class > rq->curr->sched_class)
+ resched_curr(rq);
/*
* A queue event has occurred, and we're going to schedule. In
@@ -3914,8 +3904,7 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
* higher scheduling class, because otherwise those loose the
* opportunity to pull in more work from other CPUs.
*/
- if (likely((prev->sched_class == &idle_sched_class ||
- prev->sched_class == &fair_sched_class) &&
+ if (likely(prev->sched_class <= &fair_sched_class &&
rq->nr_running == rq->cfs.h_nr_running)) {
p = pick_next_task_fair(rq, prev, rf);
@@ -6569,6 +6558,11 @@ void __init sched_init(void)
unsigned long ptr = 0;
int i;
+ BUG_ON(&idle_sched_class > &fair_sched_class ||
+ &fair_sched_class > &rt_sched_class ||
+ &rt_sched_class > &dl_sched_class ||
+ &dl_sched_class > &stop_sched_class);
+
wait_bit_init();
#ifdef CONFIG_FAIR_GROUP_SCHED
next reply other threads:[~2019-12-19 12:39 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-19 12:39 Kirill Tkhai [this message]
2019-12-19 13:12 ` [PATCH RFC] sched: Micro optimization in pick_next_task() and in check_preempt_curr() Peter Zijlstra
2019-12-19 14:02 ` Peter Zijlstra
2019-12-19 14:25 ` Kirill Tkhai
2019-12-19 14:31 ` Kirill Tkhai
2019-12-19 14:43 ` Steven Rostedt
2019-12-19 14:46 ` Kirill Tkhai
2019-12-19 14:59 ` Steven Rostedt
2019-12-19 15:20 ` [PATCH v2] " Kirill Tkhai
2019-12-19 15:40 ` Steven Rostedt
2019-12-19 16:08 ` Kirill Tkhai
2019-12-19 16:22 ` Steven Rostedt
2019-12-19 20:16 ` Kirill Tkhai
2019-12-19 20:20 ` Steven Rostedt
2019-12-19 16:05 ` Steven Rostedt
2019-12-19 14:04 ` [Q] ld: Does LTO reorder ro variables in two files? Kirill Tkhai
2019-12-19 15:21 ` Jeff Law
2019-12-19 15:30 ` Kirill Tkhai
2019-12-19 15:45 ` Alexander Monakov
2019-12-19 16:08 ` Kirill Tkhai
2019-12-19 13:50 ` [PATCH RFC] sched: Micro optimization in pick_next_task() and in check_preempt_curr() Steven Rostedt
2019-12-19 13:53 ` Kirill Tkhai
2019-12-19 13:53 ` Peter Zijlstra
2020-06-25 11:53 ` [tip: sched/core] sched: Force the address order of each sched class descriptor tip-bot2 for Steven Rostedt (VMware)
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=157675913272.349305.8936736338884044103.stgit@localhost.localdomain \
--to=ktkhai@virtuozzo.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 \
/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