sched/clock: Remove pointless test in cpu_clock/local_clock
PATCH v2 1/2 sched/clock: Remove pointless test in cpu_clock/local_clock
In case the HAVE_UNSTABLE_SCHED_CLOCK config is set, the cpu_clock() version checks if sched_clock_stable() is not set and calls sched_clock_cpu(), otherwise it calls sched_clock().
sched_clock_cpu() checks also if sched_clock_stable() is set and, if true, calls sched_clock().
sched_clock() will be called in sched_clock_cpu() if sched_clock_stable() is true.
Remove the duplicate test by directly calling sched_clock_cpu() and let the static key act in this function instead.
---
V2:
- Remove "assumption" comment about gcc inlining the functions
--- kernel/sched/clock.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
kernel/sched/clock.c +2 -8
@@ -375,10 +375,7 @@ EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event);*/ u64 cpu_clock (int cpu) { -if (!sched_clock_stable ()) -return sched_clock_cpu (cpu); - -return sched_clock (); +return sched_clock_cpu (cpu); }/*
@@ -390,10 +387,7 @@ u64 cpu_clock(int cpu)*/ u64 local_clock (void ) { -if (!sched_clock_stable ()) -return sched_clock_cpu (raw_smp_processor_id ()); - -return sched_clock (); +return sched_clock_cpu (raw_smp_processor_id ()); }#else /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */
Signature · 1 line
1.9.1
PATCH v2 2/2 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.
sched_clock_cpu() is called via the inlined local_clock()/cpu_clock() functions from sched.h. So any module code including sched.h will reference sched_clock_cpu(). Thus it must be exported with the EXPORT_SYMBOL_GPL macro.
---
V2
- Add EXPORT_SYMBOL_GPL(sched_clock_cpu) to fix the unresolved symbol errors:
>> ERROR: "sched_clock_cpu" [kernel/torture.ko] undefined! >> ERROR: "sched_clock_cpu" [drivers/gpu/drm/i915/i915.ko] undefined!
--- include/linux/sched.h | 32 ++++++++++++++++++++++++++++++-- kernel/sched/clock.c | 42 +----------------------------------------- 2 files changed, 31 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 +1 -41
62 lines not on this page · raw message
Signature · 1 line
1.9.1
tip-bot for Daniel Lezcano
merge bot[tip:sched/core] sched/clock: Make local_clock()/cpu_clock() inline
sched/clock: Make local_clock()/cpu_clock() inline
Commit-ID: 2c923e94cd9c6acff3b22f0ae29cfe65e2658b40 Gitweb: http://git.kernel.org/tip/2c923e94cd9c6acff3b22f0ae29cfe65e2658b40 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 11 Apr 2016 16:38:34 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 13 Apr 2016 12:25:22 +0200
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.
sched_clock_cpu() is called via the inlined local_clock()/cpu_clock() functions from sched.h. So any module code including sched.h will reference sched_clock_cpu(). Thus it must be exported with the EXPORT_SYMBOL_GPL macro.
--- include/linux/sched.h | 32 ++++++++++++++++++++++++++++++-- kernel/sched/clock.c | 42 +----------------------------------------- 2 files changed, 31 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 +1 -41
62 lines not on this page · raw message
tip-bot for Daniel Lezcano
merge botsched/clock: Remove pointless test in cpu_clock/local_clock
Commit-ID: c78b17e28cc2c2df74264afc408bdc6aaf3fbcc8 Gitweb: http://git.kernel.org/tip/c78b17e28cc2c2df74264afc408bdc6aaf3fbcc8 Author: Daniel Lezcano <[email protected]> AuthorDate: Mon, 11 Apr 2016 16:38:33 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 13 Apr 2016 12:25:22 +0200
sched/clock: Remove pointless test in cpu_clock/local_clock
In case the HAVE_UNSTABLE_SCHED_CLOCK config is set, the cpu_clock() version checks if sched_clock_stable() is not set and calls sched_clock_cpu(), otherwise it calls sched_clock().
sched_clock_cpu() checks also if sched_clock_stable() is set and, if true, calls sched_clock().
sched_clock() will be called in sched_clock_cpu() if sched_clock_stable() is true.
Remove the duplicate test by directly calling sched_clock_cpu() and let the static key act in this function instead.
--- kernel/sched/clock.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
kernel/sched/clock.c +2 -8
@@ -375,10 +375,7 @@ EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event);*/ u64 cpu_clock (int cpu) { -if (!sched_clock_stable ()) -return sched_clock_cpu (cpu); - -return sched_clock (); +return sched_clock_cpu (cpu); }/*
@@ -390,10 +387,7 @@ u64 cpu_clock(int cpu)*/ u64 local_clock (void ) { -if (!sched_clock_stable ()) -return sched_clock_cpu (raw_smp_processor_id ()); - -return sched_clock (); +return sched_clock_cpu (raw_smp_processor_id ()); }#else /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */