Skip to contentSkip to conversation

sched/clock: Remove pointless test in cpu_clock/local_clock

PATCH Superseded Daniel Lezcano 2 participants 3 messages Apr 1, 2016 Scheduler

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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. We can assume gcc is smart enough to inline cpu_clock()/local_clock() to sched_clock_cpu().

---
 kernel/sched/clock.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
kernel/sched/clock.c +2 -8
index fedb967..30c4b20 100644
@@ -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
maintainer
#1 lore raw
Quoted 3 lines · Daniel Lezcano

Remove the duplicate test by directly calling sched_clock_cpu() and let the static key act in this function instead. We can assume gcc is smart enough to inline cpu_clock()/local_clock() to sched_clock_cpu().

Why assume if you can easily check; so does it indeed inline?

#2 lore raw
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Daniel Lezcano

Remove the duplicate test by directly calling sched_clock_cpu() and let the static key act in this function instead. We can assume gcc is smart enough to inline cpu_clock()/local_clock() to sched_clock_cpu().

Why assume if you can easily check; so does it indeed inline?

Actually, no. They are not inlined.

With this patch we end up with one line functions:

#ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK

u64 cpu_clock(int cpu)

{
	return sched_clock_cpu(cpu);
}

u64 local_clock(void)

{
	return sched_clock_cpu(raw_smp_processor_id());
}

#else

u64 cpu_clock(int cpu)

{
	return sched_clock();
}

u64 local_clock(void)

{
	return sched_clock();
}

#endif

is it worth to convert them to static inline function ?

(static inline does effectively inline those functions).

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