* [PATCH] sched/idle: fetch smp_processor_id out of the idle loop
@ 2017-10-25 11:28 Cheng Jian
2017-10-26 9:31 ` [tip:sched/core] sched/idle: Micro-optimize " tip-bot for Cheng Jian
0 siblings, 1 reply; 3+ messages in thread
From: Cheng Jian @ 2017-10-25 11:28 UTC (permalink / raw)
To: mingo, peterz; +Cc: linux-kernel, xiexiuqi, huawei.libin
The commit c1de45ca831a ("sched/idle: Add support for
tasks that inject idle") redesigns the code for idle
loop to support for tasks that inject idle.
it fetches the current CPU using smp_processor_id( )
every time when the idle task runs.
Now idle task is no longer limited to PID == 0,
but the current CPU is constant, so fetch the
smp_prcessor_id( ) out of the loop like the
commit df55f462b905 ("sched/idle: Optimize the
generic idle loop") do.
x86-64:
Before patch (execution in loop):
864: 0f ae e8 lfence
867: 65 8b 05 c2 38 f1 7e mov %gs:0x7ef138c2(%rip),%eax
86e: 89 c0 mov %eax,%eax
870: 48 0f a3 05 68 19 08 bt %rax,0x1081968(%rip)
877: 01
After patch (execution in loop):
872: 0f ae e8 lfence
875: 4c 0f a3 25 63 19 08 bt %r12,0x1081963(%rip)
87c: 01
ARM64:
Before patch (execution in loop):
c58: d5033d9f dsb ld
c5c: d538d080 mrs x0, tpidr_el1
c60: b8606a61 ldr w1, [x19,x0]
c64: 1100fc20 add w0, w1, #0x3f
c68: 7100003f cmp w1, #0x0
c6c: 1a81b000 csel w0, w0, w1, lt
c70: 13067c00 asr w0, w0, #6
c74: 93407c00 sxtw x0, w0
c78: f8607a80 ldr x0, [x20,x0,lsl #3]
c7c: 9ac12401 lsr x1, x0, x1
c80: 36000581 tbz w1, #0, d30 <do_idle+0x128>
After patch (execution in loop):
c84: d5033d9f dsb ld
c88: f9400260 ldr x0, [x19]
c8c: ea14001f tst x0, x20
c90: 54000580 b.eq d40 <do_idle+0x138>
Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
---
kernel/sched/idle.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 257f4f0..41f16b8 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -209,6 +209,7 @@ static void cpuidle_idle_call(void)
*/
static void do_idle(void)
{
+ int cpu = smp_processor_id();
/*
* If the arch has a polling bit, we maintain an invariant:
*
@@ -226,7 +227,7 @@ static void do_idle(void)
check_pgt_cache();
rmb();
- if (cpu_is_offline(smp_processor_id())) {
+ if (cpu_is_offline(cpu)) {
cpuhp_report_idle_dead();
arch_cpu_idle_dead();
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [tip:sched/core] sched/idle: Micro-optimize the idle loop
2017-10-25 11:28 [PATCH] sched/idle: fetch smp_processor_id out of the idle loop Cheng Jian
@ 2017-10-26 9:31 ` tip-bot for Cheng Jian
2017-10-26 13:41 ` Peter Zijlstra
0 siblings, 1 reply; 3+ messages in thread
From: tip-bot for Cheng Jian @ 2017-10-26 9:31 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, torvalds, mingo, peterz, cj.chengjian, tglx, hpa
Commit-ID: 54b933c6c954a8b7b0c2b40a1c4d3f7279d11e22
Gitweb: https://git.kernel.org/tip/54b933c6c954a8b7b0c2b40a1c4d3f7279d11e22
Author: Cheng Jian <cj.chengjian@huawei.com>
AuthorDate: Wed, 25 Oct 2017 19:28:27 +0800
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 26 Oct 2017 08:31:29 +0200
sched/idle: Micro-optimize the idle loop
Move the loop-invariant calculation of 'cpu' in do_idle() out of the loop body,
because the current CPU is always constant.
This improves the generated code both on x86-64 and ARM64:
x86-64:
Before patch (execution in loop):
864: 0f ae e8 lfence
867: 65 8b 05 c2 38 f1 7e mov %gs:0x7ef138c2(%rip),%eax
86e: 89 c0 mov %eax,%eax
870: 48 0f a3 05 68 19 08 bt %rax,0x1081968(%rip)
877: 01
After patch (execution in loop):
872: 0f ae e8 lfence
875: 4c 0f a3 25 63 19 08 bt %r12,0x1081963(%rip)
87c: 01
ARM64:
Before patch (execution in loop):
c58: d5033d9f dsb ld
c5c: d538d080 mrs x0, tpidr_el1
c60: b8606a61 ldr w1, [x19,x0]
c64: 1100fc20 add w0, w1, #0x3f
c68: 7100003f cmp w1, #0x0
c6c: 1a81b000 csel w0, w0, w1, lt
c70: 13067c00 asr w0, w0, #6
c74: 93407c00 sxtw x0, w0
c78: f8607a80 ldr x0, [x20,x0,lsl #3]
c7c: 9ac12401 lsr x1, x0, x1
c80: 36000581 tbz w1, #0, d30 <do_idle+0x128>
After patch (execution in loop):
c84: d5033d9f dsb ld
c88: f9400260 ldr x0, [x19]
c8c: ea14001f tst x0, x20
c90: 54000580 b.eq d40 <do_idle+0x138>
Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
[ Rewrote the title and the changelog. ]
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: huawei.libin@huawei.com
Cc: xiexiuqi@huawei.com
Link: http://lkml.kernel.org/r/1508930907-107755-1-git-send-email-cj.chengjian@huawei.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/sched/idle.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index b2e8f0a..7dae9eb 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -209,6 +209,7 @@ exit_idle:
*/
static void do_idle(void)
{
+ int cpu = smp_processor_id();
/*
* If the arch has a polling bit, we maintain an invariant:
*
@@ -225,7 +226,7 @@ static void do_idle(void)
check_pgt_cache();
rmb();
- if (cpu_is_offline(smp_processor_id())) {
+ if (cpu_is_offline(cpu)) {
cpuhp_report_idle_dead();
arch_cpu_idle_dead();
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [tip:sched/core] sched/idle: Micro-optimize the idle loop
2017-10-26 9:31 ` [tip:sched/core] sched/idle: Micro-optimize " tip-bot for Cheng Jian
@ 2017-10-26 13:41 ` Peter Zijlstra
0 siblings, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2017-10-26 13:41 UTC (permalink / raw)
To: cj.chengjian, tglx, hpa, linux-kernel, torvalds, mingo; +Cc: linux-tip-commits
On Thu, Oct 26, 2017 at 02:31:34AM -0700, tip-bot for Cheng Jian wrote:
> After patch (execution in loop):
> 872: 0f ae e8 lfence
> ARM64:
> After patch (execution in loop):
> c84: d5033d9f dsb ld
> @@ -225,7 +226,7 @@ static void do_idle(void)
> check_pgt_cache();
> rmb();
I never could find a reason for that rmb() to exist, it also lacks a
clarifying comment.
We should perhaps attempt removing that...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-26 13:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-25 11:28 [PATCH] sched/idle: fetch smp_processor_id out of the idle loop Cheng Jian
2017-10-26 9:31 ` [tip:sched/core] sched/idle: Micro-optimize " tip-bot for Cheng Jian
2017-10-26 13:41 ` Peter Zijlstra
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.