sched/clock: Make local_clock/cpu_clock inline
PATCH 1/1 sched/clock: Make local_clock/cpu_clock inline
The local_clock/cpu_clock functions were changed to prevent a double identical test with sched_clock_cpu() when HAVE_UNSTABLE_SCHED_CLOCK is set. That resulted in one line functions.
As these functions are in all the cases one line functions and in the hot path, it is useful to specify them as static inline in order to give a strong hint to the compiler.
After verification, it appears the compiler does not inline them without this hint. Change those functions to static inline.
--- include/linux/sched.h | 32 ++++++++++++++++++++++++++++++-- kernel/sched/clock.c | 41 ----------------------------------------- 2 files changed, 30 insertions(+), 43 deletions(-)
include/linux/sched.h +30 -2
@@ -2303,8 +2303,6 @@ extern unsigned long long notrace sched_clock(void);/* * See the comment in kernel/sched/clock.c */ -extern u64 cpu_clock (int cpu); -extern u64 local_clock (void );extern u64 running_clock (void );extern u64 sched_clock_cpu (int cpu);
@@ -2323,6 +2321,16 @@ static inline void sched_clock_idle_sleep_event(void)static inline void sched_clock_idle_wakeup_event (u64 delta_ns) { } + +static inline u64 cpu_clock (int cpu) +{ +return sched_clock (); +} + +static inline u64 local_clock (void ) +{ +return sched_clock (); +}#else /* * Architectures can set this to 1 if they have specified
@@ -2337,6 +2345,26 @@ extern void clear_sched_clock_stable(void);extern void sched_clock_tick (void );extern void sched_clock_idle_sleep_event (void );extern void sched_clock_idle_wakeup_event (u64 delta_ns); + +/* +* As outlined in clock.c, provides a fast, high resolution, nanosecond +* time source that is monotonic per cpu argument and has bounded drift +* between cpus. +* +* ######################### BIG FAT WARNING ########################## +* # when comparing cpu_clock(i) to cpu_clock(j) for i != j, time can # +* # go backwards !! # +* #################################################################### +*/ +static inline u64 cpu_clock (int cpu) +{ +return sched_clock_cpu (cpu); +} + +static inline u64 local_clock (void ) +{ +return sched_clock_cpu (raw_smp_processor_id ()); +}#endif #ifdef CONFIG_IRQ_TIME_ACCOUNTING
kernel/sched/clock.c +0 -41
55 lines not on this page · raw message
Signature · 1 line
1.9.1
Quoted 8 lines · Daniel Lezcano
The local_clock/cpu_clock functions were changed to prevent a double identical test with
sched_clock_cpu()whenHAVE_UNSTABLE_SCHED_CLOCKis set. That resulted in one line functions.As these functions are in all the cases one line functions and in the hot path, it is useful to specify them as static inline in order to give a strong hint to the compiler.
Quoted 8 lines
After verification, it appears the compiler does not inline them without this hint. Change those functions to static inline.
Signed-off-by Daniel Lezcano <[email protected]>--- include/linux/sched.h | 32 ++++++++++++++++++++++++++++++-- kernel/sched/clock.c | 41 ----------------------------------------- 2 files changed, 30 insertions(+), 43 deletions(-)
Hm, this does not seem to apply to v4.6-rc3 cleanly.
Thanks,
Ingo
Quoted 14 lines · Ingo Molnar
Quoted 11 lines · Daniel Lezcano
The local_clock/cpu_clock functions were changed to prevent a double identical test with
sched_clock_cpu()whenHAVE_UNSTABLE_SCHED_CLOCKis set. That resulted in one line functions.As these functions are in all the cases one line functions and in the hot path, it is useful to specify them as static inline in order to give a strong hint to the compiler.
After verification, it appears the compiler does not inline them without this hint. Change those functions to static inline.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Daniel Lezcano <[email protected]>--- include/linux/sched.h | 32 ++++++++++++++++++++++++++++++-- kernel/sched/clock.c | 41 ----------------------------------------- 2 files changed, 30 insertions(+), 43 deletions(-)Hm, this does not seem to apply to v4.6-rc3 cleanly.
Actually I based the patches on top of tip/sched/core.
Shall I rebase them against v4.6-rc3 ?
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Quoted 21 lines · Daniel Lezcano
Quoted 20 lines · Ingo Molnar
Quoted 16 lines · Daniel Lezcano
The local_clock/cpu_clock functions were changed to prevent a double identical test with
sched_clock_cpu()whenHAVE_UNSTABLE_SCHED_CLOCKis set. That resulted in one line functions.As these functions are in all the cases one line functions and in the hot path, it is useful to specify them as static inline in order to give a strong hint to the compiler.
After verification, it appears the compiler does not inline them without this hint. Change those functions to static inline.
Signed-off-by Daniel Lezcano <[email protected]>--- include/linux/sched.h | 32 ++++++++++++++++++++++++++++++-- kernel/sched/clock.c | 41 ----------------------------------------- 2 files changed, 30 insertions(+), 43 deletions(-)
Quoted 3 lines
Quoted 1 line
Hm, this does not seem to apply to v4.6-rc3 cleanly.
Actually I based the patches on top of tip/sched/core.
This patch does not seem to apply to tip/sched/core either (2b8c41daba32).
Thanks,
Ingo
Quoted 24 lines · Ingo Molnar
Quoted 21 lines · Daniel Lezcano
Quoted 20 lines · Ingo Molnar
Quoted 16 lines · Daniel Lezcano
The local_clock/cpu_clock functions were changed to prevent a double identical test with
sched_clock_cpu()whenHAVE_UNSTABLE_SCHED_CLOCKis set. That resulted in one line functions.As these functions are in all the cases one line functions and in the hot path, it is useful to specify them as static inline in order to give a strong hint to the compiler.
After verification, it appears the compiler does not inline them without this hint. Change those functions to static inline.
Signed-off-by Daniel Lezcano <[email protected]>--- include/linux/sched.h | 32 ++++++++++++++++++++++++++++++-- kernel/sched/clock.c | 41 ----------------------------------------- 2 files changed, 30 insertions(+), 43 deletions(-)
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Hm, this does not seem to apply to v4.6-rc3 cleanly.
Actually I based the patches on top of tip/sched/core.
This patch does not seem to apply to tip/sched/core either (
2b8c41daba32).
Ah, yes. I received a compilation error because of a missing EXPORT_SYMBOL_GPL for an inlined function call from kbuild test:
ERROR: "sched_clock_cpu" [kernel/torture.ko] undefined!
ERROR: "sched_clock_cpu" [drivers/gpu/drm/i915/i915.ko] undefined!
So I resent a fixed V2.
https://lkml.org/lkml/2016/4/11/603
https://lkml.org/lkml/2016/4/11/602
Sorry, I did not notice you were mentioning the first version which is outdated. The V2 is based on top of 2b8c41daba32.
-- Daniel
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog