Skip to contentSkip to conversation

preempt: select PREEMPT_DYNAMIC under PREEMPTION instead of PREEMPT

PATCH Applied Mike Galbraith 4 participants 11 messages Feb 9, 2021 – Feb 17, 2021 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 preempt: select PREEMPT_DYNAMIC under PREEMPTION instead of PREEMPT

PREEMPT_RT and PREEMPT both needs PREEMPT_DYNAMIC to build, so move selection of PREEMPT_DYNAMIC to the common denominator, PREEMPTION.

---
 kernel/Kconfig.preempt |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/Kconfig.preempt +1 -1
@@ -40,7 +40,6 @@ config PREEMPT
 	depends on !ARCH_NO_PREEMPT
 	select PREEMPTION
 	select UNINLINE_SPIN_UNLOCK if !ARCH_INLINE_SPIN_UNLOCK
-	select PREEMPT_DYNAMIC if HAVE_PREEMPT_DYNAMIC
 	help
 	  This option reduces the latency of the kernel by making
 	  all kernel code (that is not executing in a critical section)
@@ -81,6 +80,7 @@ config PREEMPT_COUNT
 config PREEMPTION
        bool
        select PREEMPT_COUNT
+       select PREEMPT_DYNAMIC if HAVE_PREEMPT_DYNAMIC
 
 config PREEMPT_DYNAMIC
 	bool
#1 lore raw
Quoted 3 lines · Mike Galbraith

PREEMPT_RT and PREEMPT both needs PREEMPT_DYNAMIC to build, so move selection of PREEMPT_DYNAMIC to the common denominator, PREEMPTION.

I'm confused, why would you want PREEMPT_DYNAMIC for PREEMPT_RT ?

PREEMPT_RT without full preemption is just plain daft, no?

#2 lore raw
Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Mike Galbraith

PREEMPT_RT and PREEMPT both needs PREEMPT_DYNAMIC to build, so move selection of PREEMPT_DYNAMIC to the common denominator, PREEMPTION.

I'm confused, why would you want PREEMPT_DYNAMIC for PREEMPT_RT ?

PREEMPT_RT without full preemption is just plain daft, no?

If you turn on PREEMPT, PREEMPT_DYNAMIC is selected because HAVE_PREEMPT_DYNAMIC is true.

homer:..kernel/linux-tip # grep PREEMPT .config
# CONFIG_PREEMPT_NONE is not set
# CONFIG_PREEMPT_VOLUNTARY is not set
CONFIG_PREEMPT=y
CONFIG_PREEMPT_COUNT=y
CONFIG_PREEMPTION=y
CONFIG_PREEMPT_DYNAMIC=y
CONFIG_PREEMPT_RCU=y
CONFIG_HAVE_PREEMPT_DYNAMIC=y
CONFIG_PREEMPT_NOTIFIERS=y
CONFIG_DRM_I915_PREEMPT_TIMEOUT=640
CONFIG_DEBUG_PREEMPT=y
# CONFIG_PREEMPT_TRACER is not set
# CONFIG_PREEMPTIRQ_DELAY_TEST is not set

Now over to tip-rt, with patchlet...

homer:..kernel/linux-tip-rt # grep PREEMPT .config CONFIG_HAVE_PREEMPT_LAZY=y CONFIG_PREEMPT_LAZY=y
# CONFIG_PREEMPT_NONE is not set
# CONFIG_PREEMPT_VOLUNTARY is not set
# CONFIG_PREEMPT is not set CONFIG_PREEMPT_RT=y
CONFIG_PREEMPT_COUNT=y
CONFIG_PREEMPTION=y CONFIG_PREEMPT_DYNAMIC=y CONFIG_PREEMPT_RCU=y CONFIG_HAVE_PREEMPT_DYNAMIC=y CONFIG_PREEMPT_NOTIFIERS=y CONFIG_DRM_I915_PREEMPT_TIMEOUT=640 CONFIG_DEBUG_PREEMPT=y
# CONFIG_PREEMPT_TRACER is not set
# CONFIG_PREEMPTIRQ_DELAY_TEST is not set

...tree builds/runs. Pop patchlet, and...

LD vmlinux.o
MODPOST vmlinux.symvers
MODINFO modules.builtin.modinfo
GEN modules.builtin
LD .tmp_vmlinux.kallsyms1
ld: init/main.o: in function `trace_initcall_start':
/backup/usr/local/src/kernel/linux-tip-rt/./include/trace/events/initcall.h:27: undefined reference to `__SCT__preempt_schedule_notrace'
ld: init/main.o: in function `trace_initcall_finish':
/backup/usr/local/src/kernel/linux-tip-rt/./include/trace/events/initcall.h:48: undefined reference to `__SCT__preempt_schedule_notrace'
ld: init/main.o: in function `trace_initcall_level':
/backup/usr/local/src/kernel/linux-tip-rt/./include/trace/events/initcall.h:10: undefined reference to `__SCT__preempt_schedule_notrace'
ld: init/main.o:(.static_call_sites+0x4): undefined reference to `__SCK__preempt_schedule_notrace'
ld: init/main.o:(.static_call_sites+0x14): undefined reference to `__SCK__preempt_schedule_notrace'
ld: init/main.o:(.static_call_sites+0x24): undefined reference to `__SCK__preempt_schedule_notrace'
ld: arch/x86/entry/vsyscall/vsyscall_64.o: in function `trace_emulate_vsyscall':
/backup/usr/local/src/kernel/linux-tip-rt/arch/x86/entry/vsyscall/vsyscall_trace.h:10: undefined reference to `__SCT__preempt_schedule_notrace'
ld: arch/x86/entry/vsyscall/vsyscall_64.o:(.static_call_sites+0x4): undefined reference to `__SCK__preempt_schedule_notrace'
ld: arch/x86/events/amd/ibs.o: in function `ibs_eilvt_valid':
/backup/usr/local/src/kernel/linux-tip-rt/arch/x86/events/amd/ibs.c:865: undefined reference to `__SCT__preempt_schedule'
ld: arch/x86/events/amd/ibs.o: in function `force_ibs_eilvt_setup':
/backup/usr/local/src/kernel/linux-tip-rt/arch/x86/events/amd/ibs.c:923: undefined reference to `__SCT__preempt_schedule'
ld: /backup/usr/local/src/kernel/linux-tip-rt/arch/x86/events/amd/ibs.c:943: undefined reference to `__SCT__preempt_schedule'
ld: arch/x86/events/amd/ibs.o: in function `ibs_eilvt_valid':
/backup/usr/local/src/kernel/linux-tip-rt/arch/x86/events/amd/ibs.c:865: undefined reference to `__SCT__preempt_schedule'
...

#3 lore raw
Quoted 2 lines · Mike Galbraith

ld: init/main.o: in function `trace_initcall_start':
/backup/usr/local/src/kernel/linux-tip-rt/./include/trace/events/initcall.h:27: undefined reference to `__SCT__preempt_schedule_notrace'

Ooohh... this is because x86 can't build PREEMPT without PREEMPT_DYNAMIC anymore. Maybe I should fix that. Lemme see what that would take.

#4 lore raw
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Mike Galbraith

ld: init/main.o: in function `trace_initcall_start':
/backup/usr/local/src/kernel/linux-tip-rt/./include/trace/events/initcall.h:27: undefined reference to `__SCT__preempt_schedule_notrace'

Ooohh... this is because x86 can't build PREEMPT without PREEMPT_DYNAMIC anymore. Maybe I should fix that. Lemme see what that would take.

Does this work?

---

arch/x86/include/asm/preempt.h +18 -6
index 0aa96f824af1..f8cb8af4de5c 100644
@@ -110,6 +110,13 @@ extern asmlinkage void preempt_schedule_thunk(void);
 
 #define __preempt_schedule_func preempt_schedule_thunk
 
+extern asmlinkage void preempt_schedule_notrace(void);
+extern asmlinkage void preempt_schedule_notrace_thunk(void);
+
+#define __preempt_schedule_notrace_func preempt_schedule_notrace_thunk
+
+#ifdef CONFIG_PREEMPT_DYNAMIC
+
 DECLARE_STATIC_CALL(preempt_schedule, __preempt_schedule_func);
 
 #define __preempt_schedule() \
@@ -118,11 +125,6 @@ do { \
 	asm volatile ("call " STATIC_CALL_TRAMP_STR(preempt_schedule) : ASM_CALL_CONSTRAINT); \
 } while (0)
 
-extern asmlinkage void preempt_schedule_notrace(void);
-extern asmlinkage void preempt_schedule_notrace_thunk(void);
-
-#define __preempt_schedule_notrace_func preempt_schedule_notrace_thunk
-
 DECLARE_STATIC_CALL(preempt_schedule_notrace, __preempt_schedule_notrace_func);
 
 #define __preempt_schedule_notrace() \
@@ -131,6 +133,16 @@ do { \
 	asm volatile ("call " STATIC_CALL_TRAMP_STR(preempt_schedule_notrace) : ASM_CALL_CONSTRAINT); \
 } while (0)
 
-#endif
+#else /* PREEMPT_DYNAMIC */
+
+#define __preempt_schedule() \
+	asm volatile ("call preempt_schedule_thunk" : ASM_CALL_CONSTRAINT);
+
+#define __preempt_schedule_notrace() \
+	asm volatile ("call preempt_schedule_notrace_thunk" : ASM_CALL_CONSTRAINT);
+
+#endif /* PREEMPT_DYNAMIC */
+
+#endif /* PREEMPTION */
 
 #endif /* __ASM_PREEMPT_H */
#5 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Mike Galbraith

ld: init/main.o: in function `trace_initcall_start':
/backup/usr/local/src/kernel/linux-tip-rt/./include/trace/events/initcall.h:27: undefined reference to `__SCT__preempt_schedule_notrace'

Ooohh... this is because x86 can't build PREEMPT without PREEMPT_DYNAMIC anymore. Maybe I should fix that. Lemme see what that would take.

Does this work?

Yup, worked fine.

-Mike

merge bot Applied
#6 lore raw

[tip: sched/core] sched,x86: Allow !PREEMPT_DYNAMIC

In reply to Peter Zijlstra
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     82891be90f3c42dc964fd61b8b2a89de12940c9f
Gitweb:        https://git.kernel.org/tip/82891be90f3c42dc964fd61b8b2a89de12940c9f
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Tue, 09 Feb 2021 22:02:33 +01:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Wed, 10 Feb 2021 14:44:51 +01:00

sched,x86: Allow !PREEMPT_DYNAMIC

Allow building x86 with PREEMPT_DYNAMIC=n, this is needed for PREEMPT_RT as it makes no sense to not have full preemption on PREEMPT_RT.

Fixes 8c98e8cf723c ("preempt/dynamic: Provide preempt_schedule[_notrace]() static calls")
---
 arch/x86/include/asm/preempt.h | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
arch/x86/include/asm/preempt.h +18 -6
index 0aa96f8..f8cb8af 100644
@@ -110,6 +110,13 @@ extern asmlinkage void preempt_schedule_thunk(void);
 
 #define __preempt_schedule_func preempt_schedule_thunk
 
+extern asmlinkage void preempt_schedule_notrace(void);
+extern asmlinkage void preempt_schedule_notrace_thunk(void);
+
+#define __preempt_schedule_notrace_func preempt_schedule_notrace_thunk
+
+#ifdef CONFIG_PREEMPT_DYNAMIC
+
 DECLARE_STATIC_CALL(preempt_schedule, __preempt_schedule_func);
 
 #define __preempt_schedule() \
@@ -118,11 +125,6 @@ do { \
 	asm volatile ("call " STATIC_CALL_TRAMP_STR(preempt_schedule) : ASM_CALL_CONSTRAINT); \
 } while (0)
 
-extern asmlinkage void preempt_schedule_notrace(void);
-extern asmlinkage void preempt_schedule_notrace_thunk(void);
-
-#define __preempt_schedule_notrace_func preempt_schedule_notrace_thunk
-
 DECLARE_STATIC_CALL(preempt_schedule_notrace, __preempt_schedule_notrace_func);
 
 #define __preempt_schedule_notrace() \
@@ -131,6 +133,16 @@ do { \
 	asm volatile ("call " STATIC_CALL_TRAMP_STR(preempt_schedule_notrace) : ASM_CALL_CONSTRAINT); \
 } while (0)
 
-#endif
+#else /* PREEMPT_DYNAMIC */
+
+#define __preempt_schedule() \
+	asm volatile ("call preempt_schedule_thunk" : ASM_CALL_CONSTRAINT);
+
+#define __preempt_schedule_notrace() \
+	asm volatile ("call preempt_schedule_notrace_thunk" : ASM_CALL_CONSTRAINT);
+
+#endif /* PREEMPT_DYNAMIC */
+
+#endif /* PREEMPTION */
 
 #endif /* __ASM_PREEMPT_H */
#7 lore raw

Re: [tip: sched/core] sched,x86: Allow !PREEMPT_DYNAMIC

Quoted 15 lines · On Wed, Feb 10, 2021 at 01:53:31PM -0000, tip-bot2 for Peter Zijlstra wrote:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     82891be90f3c42dc964fd61b8b2a89de12940c9f
Gitweb:        https://git.kernel.org/tip/82891be90f3c42dc964fd61b8b2a89de12940c9f
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Tue, 09 Feb 2021 22:02:33 +01:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Wed, 10 Feb 2021 14:44:51 +01:00

sched,x86: Allow !PREEMPT_DYNAMIC

Allow building x86 with PREEMPT_DYNAMIC=n, this is needed for PREEMPT_RT as it makes no sense to not have full preemption on PREEMPT_RT.

Quoted 5 lines
Fixes 8c98e8cf723c ("preempt/dynamic: Provide preempt_schedule[_notrace]() static calls")

Also should we add something like this?

From 4e1de6d9d8804ea7edc6f8767abea37f5103799a Mon Sep 17 00:00:00 2001
From: Frederic Weisbecker <[email protected]>
Date: Wed, 10 Feb 2021 15:11:39 +0100
Subject: [PATCH] preempt/dynamic: Make PREEMPT_DYNAMIC optional

In order not to make the small trampoline overhead mandatory for archs that support HAVE_STATIC_CALL but not HAVE_STATIC_CALL_INLINE, make PREEMPT_DYNAMIC optional.

---
 kernel/Kconfig.preempt | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
kernel/Kconfig.preempt +7 -4
index 416017301660..1fe759677907 100644
@@ -40,7 +40,6 @@ config PREEMPT
 	depends on !ARCH_NO_PREEMPT
 	select PREEMPTION
 	select UNINLINE_SPIN_UNLOCK if !ARCH_INLINE_SPIN_UNLOCK
-	select PREEMPT_DYNAMIC if HAVE_PREEMPT_DYNAMIC
 	help
 	  This option reduces the latency of the kernel by making
 	  all kernel code (that is not executing in a critical section)
@@ -83,11 +82,13 @@ config PREEMPTION
        select PREEMPT_COUNT
 
 config PREEMPT_DYNAMIC
-	bool
+	bool "Override preemption flavour at boot time"
+	depends on HAVE_PREEMPT_DYNAMIC && PREEMPT
+	default HAVE_STATIC_CALL_INLINE
 	help
 	  This option allows to define the preemption model on the kernel
-	  command line parameter and thus override the default preemption
-	  model defined during compile time.
+	  command line parameter "preempt=" and thus override the default
+	  preemption model defined during compile time.
 
 	  The feature is primarily interesting for Linux distributions which
 	  provide a pre-built kernel binary to reduce the number of kernel
@@ -99,3 +100,5 @@ config PREEMPT_DYNAMIC
 
 	  Interesting if you want the same pre-built kernel should be used for
 	  both Server and Desktop workloads.
+
+	  Say Y if you have CONFIG_HAVE_STATIC_CALL_INLINE.
Signature · 1 line
2.25.1
#8 lore raw

Re: [tip: sched/core] sched,x86: Allow !PREEMPT_DYNAMIC

Quoted 1 line · Frederic Weisbecker

Also should we add something like this?

I suppose we can do that, but I'd rather have actual numbers to go with it, I don't think the trampolines are really that terrible.

Quoted 51 lines

From: Frederic Weisbecker <[email protected]>
Date: Wed, 10 Feb 2021 15:11:39 +0100
Subject: [PATCH] preempt/dynamic: Make PREEMPT_DYNAMIC optional

In order not to make the small trampoline overhead mandatory for archs that support HAVE_STATIC_CALL but not HAVE_STATIC_CALL_INLINE, make PREEMPT_DYNAMIC optional.

---
 kernel/Kconfig.preempt | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
kernel/Kconfig.preempt +7 -4
index 416017301660..1fe759677907 100644
@@ -40,7 +40,6 @@ config PREEMPT
 	depends on !ARCH_NO_PREEMPT
 	select PREEMPTION
 	select UNINLINE_SPIN_UNLOCK if !ARCH_INLINE_SPIN_UNLOCK
-	select PREEMPT_DYNAMIC if HAVE_PREEMPT_DYNAMIC
 	help
 	  This option reduces the latency of the kernel by making
 	  all kernel code (that is not executing in a critical section)
@@ -83,11 +82,13 @@ config PREEMPTION
        select PREEMPT_COUNT
 
 config PREEMPT_DYNAMIC
-	bool
+	bool "Override preemption flavour at boot time"
+	depends on HAVE_PREEMPT_DYNAMIC && PREEMPT
+	default HAVE_STATIC_CALL_INLINE
 	help
 	  This option allows to define the preemption model on the kernel
-	  command line parameter and thus override the default preemption
-	  model defined during compile time.
+	  command line parameter "preempt=" and thus override the default
+	  preemption model defined during compile time.
 
 	  The feature is primarily interesting for Linux distributions which
 	  provide a pre-built kernel binary to reduce the number of kernel
@@ -99,3 +100,5 @@ config PREEMPT_DYNAMIC
 
 	  Interesting if you want the same pre-built kernel should be used for
 	  both Server and Desktop workloads.
+
+	  Say Y if you have CONFIG_HAVE_STATIC_CALL_INLINE.
Signature · 1 line
2.25.1
merge bot Applied
#9 lore raw

[tip: sched/core] sched,x86: Allow !PREEMPT_DYNAMIC

In reply to Peter Zijlstra
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     c5e6fc08feb2b88dc5dac2f3c817e1c2a4cafda4
Gitweb:        https://git.kernel.org/tip/c5e6fc08feb2b88dc5dac2f3c817e1c2a4cafda4
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Tue, 09 Feb 2021 22:02:33 +01:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Wed, 17 Feb 2021 14:12:43 +01:00

sched,x86: Allow !PREEMPT_DYNAMIC

Allow building x86 with PREEMPT_DYNAMIC=n, this is needed for PREEMPT_RT as it makes no sense to not have full preemption on PREEMPT_RT.

Fixes 8c98e8cf723c ("preempt/dynamic: Provide preempt_schedule[_notrace]() static calls")
---
 arch/x86/include/asm/preempt.h | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
arch/x86/include/asm/preempt.h +18 -6
index 0aa96f8..f8cb8af 100644
@@ -110,6 +110,13 @@ extern asmlinkage void preempt_schedule_thunk(void);
 
 #define __preempt_schedule_func preempt_schedule_thunk
 
+extern asmlinkage void preempt_schedule_notrace(void);
+extern asmlinkage void preempt_schedule_notrace_thunk(void);
+
+#define __preempt_schedule_notrace_func preempt_schedule_notrace_thunk
+
+#ifdef CONFIG_PREEMPT_DYNAMIC
+
 DECLARE_STATIC_CALL(preempt_schedule, __preempt_schedule_func);
 
 #define __preempt_schedule() \
@@ -118,11 +125,6 @@ do { \
 	asm volatile ("call " STATIC_CALL_TRAMP_STR(preempt_schedule) : ASM_CALL_CONSTRAINT); \
 } while (0)
 
-extern asmlinkage void preempt_schedule_notrace(void);
-extern asmlinkage void preempt_schedule_notrace_thunk(void);
-
-#define __preempt_schedule_notrace_func preempt_schedule_notrace_thunk
-
 DECLARE_STATIC_CALL(preempt_schedule_notrace, __preempt_schedule_notrace_func);
 
 #define __preempt_schedule_notrace() \
@@ -131,6 +133,16 @@ do { \
 	asm volatile ("call " STATIC_CALL_TRAMP_STR(preempt_schedule_notrace) : ASM_CALL_CONSTRAINT); \
 } while (0)
 
-#endif
+#else /* PREEMPT_DYNAMIC */
+
+#define __preempt_schedule() \
+	asm volatile ("call preempt_schedule_thunk" : ASM_CALL_CONSTRAINT);
+
+#define __preempt_schedule_notrace() \
+	asm volatile ("call preempt_schedule_notrace_thunk" : ASM_CALL_CONSTRAINT);
+
+#endif /* PREEMPT_DYNAMIC */
+
+#endif /* PREEMPTION */
 
 #endif /* __ASM_PREEMPT_H */
#10 lore raw
In reply to Peter Zijlstra
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Mike Galbraith

ld: init/main.o: in function `trace_initcall_start':
/backup/usr/local/src/kernel/linux-tip-rt/./include/trace/events/initcall.h:27: undefined reference to `__SCT__preempt_schedule_notrace'

Ooohh... this is because x86 can't build PREEMPT without PREEMPT_DYNAMIC anymore. Maybe I should fix that. Lemme see what that would take.

Uhoh, looks like something a lot worse managed to sneak into master. While test-driving that tip-rt build, I couldn't help noticing that evolution is going mad, chewing cpu and being useless enough that I couldn't reply to you. Unfortunately, it ain't my tip-rt tree, nor is it virgin tip, the evilness is present in virgin master, but not in 5.10 stable. Hohum, a hunting I shall go I suppose.

-Mike