Skip to content

Commit

Permalink
time/sched_clock: Disable interrupts in sched_clock_register()
Browse files Browse the repository at this point in the history
Instead of issueing a warning if sched_clock_register() is called from a
context where IRQs are enabled, the code now ensures that IRQs are indeed
disabled.

Signed-off-by: Paul Cercueil <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Acked-by: Daniel Lezcano <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
pcercuei authored and KAGA-KOKO committed Jan 9, 2020
1 parent c79f46a commit 2707745
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions kernel/time/sched_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,15 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
{
u64 res, wrap, new_mask, new_epoch, cyc, ns;
u32 new_mult, new_shift;
unsigned long r;
unsigned long r, flags;
char r_unit;
struct clock_read_data rd;

if (cd.rate > rate)
return;

WARN_ON(!irqs_disabled());
/* Cannot register a sched_clock with interrupts on */
local_irq_save(flags);

/* Calculate the mult/shift to convert counter ticks to ns. */
clocks_calc_mult_shift(&new_mult, &new_shift, rate, NSEC_PER_SEC, 3600);
Expand Down Expand Up @@ -233,6 +234,8 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
if (irqtime > 0 || (irqtime == -1 && rate >= 1000000))
enable_sched_clock_irqtime();

local_irq_restore(flags);

pr_debug("Registered %pS as sched_clock source\n", read);
}

Expand Down

0 comments on commit 2707745

Please sign in to comment.