Skip to content

Commit 7d7de1a

Browse files
fancerdlezcano
authored andcommitted
clocksource: mips-gic-timer: Mark GIC timer as unstable if ref clock changes
Currently clocksource framework doesn't support the clocks with variable frequency. Since MIPS GIC timer ticks rate might be unstable on some platforms, we must make sure that it justifies the clocksource requirements. MIPS GIC timer is incremented with the CPU cluster reference clocks rate. So in case if CPU frequency changes, the MIPS GIC tick rate changes synchronously. Due to this the clocksource subsystem can't rely on the timer to measure system clocks anymore. This commit marks the MIPS GIC based clocksource as unstable if reference clock (normally it's a CPU reference clocks) rate changes. The clocksource will execute a watchdog thread, which lowers the MIPS GIC timer rating to zero and fallbacks to a new stable one. Note we don't need to set the CLOCK_SOURCE_MUST_VERIFY flag to the MIPS GIC clocksource since normally the timer is stable. The only reason why it gets unstable is due to the ref clock rate change, which event we detect here in the driver by means of the clocks event notifier. Signed-off-by: Serge Semin <[email protected]> Cc: Alexey Malahov <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Paul Burton <[email protected]> Cc: Ralf Baechle <[email protected]> Cc: Alessandro Zummo <[email protected]> Cc: Alexandre Belloni <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Rob Herring <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 48016e7 commit 7d7de1a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

drivers/clocksource/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ config CLKSRC_VERSATILE
570570
config CLKSRC_MIPS_GIC
571571
bool
572572
depends on MIPS_GIC
573+
select CLOCKSOURCE_WATCHDOG
573574
select TIMER_OF
574575

575576
config CLKSRC_TANGO_XTAL

drivers/clocksource/mips-gic-timer.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
static DEFINE_PER_CPU(struct clock_event_device, gic_clockevent_device);
2525
static int gic_timer_irq;
2626
static unsigned int gic_frequency;
27+
static bool __read_mostly gic_clock_unstable;
28+
29+
static void gic_clocksource_unstable(char *reason);
2730

2831
static u64 notrace gic_read_count_2x32(void)
2932
{
@@ -125,8 +128,10 @@ static int gic_clk_notifier(struct notifier_block *nb, unsigned long action,
125128
{
126129
struct clk_notifier_data *cnd = data;
127130

128-
if (action == POST_RATE_CHANGE)
131+
if (action == POST_RATE_CHANGE) {
132+
gic_clocksource_unstable("ref clock rate change");
129133
on_each_cpu(gic_update_frequency, (void *)cnd->new_rate, 1);
134+
}
130135

131136
return NOTIFY_OK;
132137
}
@@ -172,6 +177,18 @@ static struct clocksource gic_clocksource = {
172177
.vdso_clock_mode = VDSO_CLOCKMODE_GIC,
173178
};
174179

180+
static void gic_clocksource_unstable(char *reason)
181+
{
182+
if (gic_clock_unstable)
183+
return;
184+
185+
gic_clock_unstable = true;
186+
187+
pr_info("GIC timer is unstable due to %s\n", reason);
188+
189+
clocksource_mark_unstable(&gic_clocksource);
190+
}
191+
175192
static int __init __gic_clocksource_init(void)
176193
{
177194
unsigned int count_width;

0 commit comments

Comments
 (0)