Commit c80ed4e
sched/core: Make finish_task_switch() and its subfunctions always inline
finish_task_switch() is not inlined even in the O2 level optimization,
performance testing indicates that this could lead to a significant
performance degradation when certain Spectre vulnerability mitigations
are enabled.
In switch_mm_irq_off(), some mitigations may clear branch prediction
history, or the instruction cache, like arm64_apply_bp_hardening() on
arm64, BPIALL/ICIALLU on arm, and indirect_branch_prediction_barrier()
on x86. finish_task_switch() is right after switch_mm_irqs_off(), the
performance is greatly affected by function calls and branch jumps.
__schedule() has a __sched attribute, which makes it be placed in
'.sched.text' section, while finish_task_switch() does not. This makes
they "far away from each other" in vmlinux, which aggravating the
performance degradation.
Make finish_task_switch() and its subfunctions always inline to optimize
the performance.
Performance test data - time spent on calling finish_task_switch():
1. x86-64: Intel i5-8300h@4Ghz, DDR4@2666mhz; unit: x86's tsc
| test scenario | old | new | delta |
| gcc 15.2 | 27.50 | 25.45 | -2.05 ( -7.5%) |
| gcc 15.2 + spectre_v2_user=on | 46.75 | 25.96 | -20.79 (-44.5%) |
| clang 21.1.7 | 27.25 | 25.45 | -1.80 ( -6.6%) |
| clang 21.1.7 + spectre_v2_user=on | 39.50 | 26.00 | -13.50 (-34.2%) |
2. x86-64: AMD 9600x@5.45Ghz, DDR5@4800mhz; unit: x86's tsc
| test scenario | old | new | delta |
| gcc 15.2 | 27.51 | 27.51 | 0 ( 0%) |
| gcc 15.2 + spectre_v2_user=on | 105.21 | 67.89 | -37.32 (-35.5%) |
| clang 21.1.7 | 27.51 | 27.51 | 0 ( 0%) |
| clang 21.1.7 + spectre_v2_user=on | 104.15 | 67.52 | -36.63 (-35.2%) |
3. arm64: Raspberry Pi 3b Rev 1.2, Cortex-A53@1.2Ghz; unit: cntvct_el0
| test scenario | old | new | delta |
| gcc 15.2 | 1.453 | 1.115 | -0.338 (-23.3%) |
| clang 21.1.7 | 1.532 | 1.123 | -0.409 (-26.7%) |
4. arm32: Raspberry Pi 3b Rev 1.2, Cortex-A53@1.2Ghz; unit: cntvct_el0
| test scenario | old | new | delta |
| gcc 15.2 | 1.421 | 1.187 | -0.234 (-16.5%) |
| clang 21.1.7 | 1.437 | 1.200 | -0.237 (-16.5%) |
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: Segher Boessenkool <segher@kernel.crashing.org>
Cc: David Hildenbrand (Red Hat) <david@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: H. Peter Anvin (Intel) <hpa@zytor.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Xie Yuanbin <qq570070308@gmail.com>1 parent 7d6c90b commit c80ed4e
11 files changed
Lines changed: 35 additions & 35 deletions
File tree
- arch
- arm/include/asm
- riscv/include/asm
- s390/include/asm
- sparc/include/asm
- x86/include/asm
- include/linux
- sched
- kernel/sched
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1632 | 1632 | | |
1633 | 1633 | | |
1634 | 1634 | | |
1635 | | - | |
| 1635 | + | |
1636 | 1636 | | |
1637 | 1637 | | |
1638 | 1638 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
532 | 532 | | |
533 | 533 | | |
534 | 534 | | |
535 | | - | |
| 535 | + | |
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | | - | |
| 180 | + | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
304 | | - | |
| 304 | + | |
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4891 | 4891 | | |
4892 | 4892 | | |
4893 | 4893 | | |
4894 | | - | |
| 4894 | + | |
4895 | 4895 | | |
4896 | 4896 | | |
4897 | 4897 | | |
| |||
4907 | 4907 | | |
4908 | 4908 | | |
4909 | 4909 | | |
4910 | | - | |
| 4910 | + | |
4911 | 4911 | | |
4912 | 4912 | | |
4913 | 4913 | | |
| |||
4942 | 4942 | | |
4943 | 4943 | | |
4944 | 4944 | | |
4945 | | - | |
| 4945 | + | |
4946 | 4946 | | |
4947 | 4947 | | |
4948 | 4948 | | |
| |||
5016 | 5016 | | |
5017 | 5017 | | |
5018 | 5018 | | |
5019 | | - | |
| 5019 | + | |
5020 | 5020 | | |
5021 | 5021 | | |
5022 | 5022 | | |
| |||
5049 | 5049 | | |
5050 | 5050 | | |
5051 | 5051 | | |
5052 | | - | |
| 5052 | + | |
5053 | 5053 | | |
5054 | 5054 | | |
5055 | 5055 | | |
| |||
5103 | 5103 | | |
5104 | 5104 | | |
5105 | 5105 | | |
5106 | | - | |
| 5106 | + | |
5107 | 5107 | | |
5108 | 5108 | | |
5109 | 5109 | | |
| |||
0 commit comments