2021-02-09 15:16:21

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [patch] preempt: select PREEMPT_DYNAMIC under PREEMPTION instead of PREEMPT

On Tue, Feb 09, 2021 at 02:45:37PM +0100, Mike Galbraith wrote:
>
> 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?


2021-02-09 16:09:08

by Mike Galbraith

[permalink] [raw]
Subject: Re: [patch] preempt: select PREEMPT_DYNAMIC under PREEMPTION instead of PREEMPT

On Tue, 2021-02-09 at 16:13 +0100, Peter Zijlstra wrote:
> On Tue, Feb 09, 2021 at 02:45:37PM +0100, Mike Galbraith wrote:
> >
> > 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'
...


2021-02-09 16:18:36

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [patch] preempt: select PREEMPT_DYNAMIC under PREEMPTION instead of PREEMPT

On Tue, Feb 09, 2021 at 05:05:14PM +0100, Mike Galbraith wrote:

> 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.


2021-02-09 16:25:56

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [patch] preempt: select PREEMPT_DYNAMIC under PREEMPTION instead of PREEMPT

On Tue, Feb 09, 2021 at 05:13:15PM +0100, Peter Zijlstra wrote:
> On Tue, Feb 09, 2021 at 05:05:14PM +0100, Mike Galbraith wrote:
>
> > 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?

---
diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
index 0aa96f824af1..f8cb8af4de5c 100644
--- a/arch/x86/include/asm/preempt.h
+++ b/arch/x86/include/asm/preempt.h
@@ -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 */

2021-02-09 16:53:49

by Mike Galbraith

[permalink] [raw]
Subject: Re: [patch] preempt: select PREEMPT_DYNAMIC under PREEMPTION instead of PREEMPT

On Tue, 2021-02-09 at 17:19 +0100, Peter Zijlstra wrote:
> On Tue, Feb 09, 2021 at 05:13:15PM +0100, Peter Zijlstra wrote:
> > On Tue, Feb 09, 2021 at 05:05:14PM +0100, Mike Galbraith wrote:
> >
> > > 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

2021-02-10 07:29:49

by Mike Galbraith

[permalink] [raw]
Subject: Re: [patch] preempt: select PREEMPT_DYNAMIC under PREEMPTION instead of PREEMPT

On Tue, 2021-02-09 at 17:13 +0100, Peter Zijlstra wrote:
> On Tue, Feb 09, 2021 at 05:05:14PM +0100, Mike Galbraith wrote:
>
> > 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

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

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")
Reported-by: Mike Galbraith <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Tested-by: Mike Galbraith <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
arch/x86/include/asm/preempt.h | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
index 0aa96f8..f8cb8af 100644
--- a/arch/x86/include/asm/preempt.h
+++ b/arch/x86/include/asm/preempt.h
@@ -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 */

2021-02-10 14:22:53

by Frederic Weisbecker

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

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.
>
> Fixes: 8c98e8cf723c ("preempt/dynamic: Provide preempt_schedule[_notrace]() static calls")
> Reported-by: Mike Galbraith <[email protected]>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> Tested-by: Mike Galbraith <[email protected]>
> Link: https://lkml.kernel.org/r/[email protected]

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.

Signed-off-by: Frederic Weisbecker <[email protected]>
---
kernel/Kconfig.preempt | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/kernel/Kconfig.preempt b/kernel/Kconfig.preempt
index 416017301660..1fe759677907 100644
--- a/kernel/Kconfig.preempt
+++ b/kernel/Kconfig.preempt
@@ -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.
--
2.25.1

2021-02-16 10:42:47

by Peter Zijlstra

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

On Wed, Feb 10, 2021 at 03:18:38PM +0100, Frederic Weisbecker wrote:
> 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.

> 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.
>
> Signed-off-by: Frederic Weisbecker <[email protected]>
> ---
> kernel/Kconfig.preempt | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/Kconfig.preempt b/kernel/Kconfig.preempt
> index 416017301660..1fe759677907 100644
> --- a/kernel/Kconfig.preempt
> +++ b/kernel/Kconfig.preempt
> @@ -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.
> --
> 2.25.1
>

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

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")
Reported-by: Mike Galbraith <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Tested-by: Mike Galbraith <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
arch/x86/include/asm/preempt.h | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
index 0aa96f8..f8cb8af 100644
--- a/arch/x86/include/asm/preempt.h
+++ b/arch/x86/include/asm/preempt.h
@@ -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 */