Skip to content

Commit ef08f0f

Browse files
Peter Zijlstraingomolnar
authored andcommitted
sched/clock: Remove local_irq_disable() from the clocks
Now that x86 no longer requires IRQs disabled for sched_clock() and ia64 never had this requirement (it doesn't seem to do cpufreq at all), we can remove the requirement of disabling IRQs. MAINLINE PRE POST sched_clock_stable: 1 1 1 (cold) sched_clock: 329841 257223 221876 (cold) local_clock: 301773 309889 234692 (warm) sched_clock: 38375 25280 25602 (warm) local_clock: 100371 85268 33265 (warm) rdtsc: 27340 24247 24214 sched_clock_stable: 0 0 0 (cold) sched_clock: 382634 301224 235941 (cold) local_clock: 396890 399870 297017 (warm) sched_clock: 38194 25630 25233 (warm) local_clock: 143452 129629 71234 (warm) rdtsc: 27345 24307 24245 Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Link: http://lkml.kernel.org/n/tip-36e5kohiasnr106d077mgubp@git.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 20d1c86 commit ef08f0f

1 file changed

Lines changed: 6 additions & 28 deletions

File tree

‎kernel/sched/clock.c‎

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
* at 0 on boot (but people really shouldn't rely on that).
2727
*
2828
* cpu_clock(i) -- can be used from any context, including NMI.
29-
* sched_clock_cpu(i) -- must be used with local IRQs disabled (implied by NMI)
3029
* local_clock() -- is cpu_clock() on the current cpu.
3130
*
31+
* sched_clock_cpu(i)
32+
*
3233
* How:
3334
*
3435
* The implementation either uses sched_clock() when
@@ -50,15 +51,6 @@
5051
* Furthermore, explicit sleep and wakeup hooks allow us to account for time
5152
* that is otherwise invisible (TSC gets stopped).
5253
*
53-
*
54-
* Notes:
55-
*
56-
* The !IRQ-safetly of sched_clock() and sched_clock_cpu() comes from things
57-
* like cpufreq interrupts that can change the base clock (TSC) multiplier
58-
* and cause funny jumps in time -- although the filtering provided by
59-
* sched_clock_cpu() should mitigate serious artifacts we cannot rely on it
60-
* in general since for !CONFIG_HAVE_UNSTABLE_SCHED_CLOCK we fully rely on
61-
* sched_clock().
6254
*/
6355
#include <linux/spinlock.h>
6456
#include <linux/hardirq.h>
@@ -242,20 +234,20 @@ u64 sched_clock_cpu(int cpu)
242234
struct sched_clock_data *scd;
243235
u64 clock;
244236

245-
WARN_ON_ONCE(!irqs_disabled());
246-
247237
if (sched_clock_stable)
248238
return sched_clock();
249239

250240
if (unlikely(!sched_clock_running))
251241
return 0ull;
252242

243+
preempt_disable();
253244
scd = cpu_sdc(cpu);
254245

255246
if (cpu != smp_processor_id())
256247
clock = sched_clock_remote(scd);
257248
else
258249
clock = sched_clock_local(scd);
250+
preempt_enable();
259251

260252
return clock;
261253
}
@@ -316,14 +308,7 @@ EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event);
316308
*/
317309
u64 cpu_clock(int cpu)
318310
{
319-
u64 clock;
320-
unsigned long flags;
321-
322-
local_irq_save(flags);
323-
clock = sched_clock_cpu(cpu);
324-
local_irq_restore(flags);
325-
326-
return clock;
311+
return sched_clock_cpu(cpu);
327312
}
328313

329314
/*
@@ -335,14 +320,7 @@ u64 cpu_clock(int cpu)
335320
*/
336321
u64 local_clock(void)
337322
{
338-
u64 clock;
339-
unsigned long flags;
340-
341-
local_irq_save(flags);
342-
clock = sched_clock_cpu(smp_processor_id());
343-
local_irq_restore(flags);
344-
345-
return clock;
323+
return sched_clock_cpu(raw_smp_processor_id());
346324
}
347325

348326
#else /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */

0 commit comments

Comments
 (0)