Skip to content

Commit a68becd

Browse files
Linus WalleijRussell King
authored andcommitted
ARM: 7563/1: SMP_TWD: make setup()/stop() reentrant
It has been brought to my knowledge that the .setup()/.stop() function pair in the SMP TWD is going to be called from atomic contexts for CPUs coming and going, and then the clk_prepare()/clk_unprepare() calls cannot be called on subsequent .setup()/.stop() iterations. This is however just the tip of an iceberg as the function pair is not designed to be reentrant at all. This change makes the SMP_TWD clock .setup()/.stop() pair reentrant by splitting the .setup() function in three parts: - One COMMON part that is executed the first time the first CPU in the TWD cluster is initialized. This will fetch the TWD clk for the cluster and prepare+enable it. If no clk is available it will calibrate the rate instead. - One part that is executed the FIRST TIME a certain CPU is brought on-line. This initializes and sets up the clock event for a certain CPU. - One part that is executed on every subsequent .setup() call. This will re-initialize the clock event. This is augmented to call the clk_enable()/clk_disable() pair properly. Cc: Shawn Guo <shawn.guo@linaro.org> Reported-by: Peter Chen <peter.chen@freescale.com> Reviewed-by: Santosh Shilimkar <santosh.shilimkar@ti.com> Tested-by: Shawn Guo <shawn.guo@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 2577cf2 commit a68becd

1 file changed

Lines changed: 37 additions & 5 deletions

File tree

‎arch/arm/kernel/smp_twd.c‎

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ static void __iomem *twd_base;
3131

3232
static struct clk *twd_clk;
3333
static unsigned long twd_timer_rate;
34+
static bool common_setup_called;
35+
static DEFINE_PER_CPU(bool, percpu_setup_called);
3436

3537
static struct clock_event_device __percpu **twd_evt;
3638
static int twd_ppi;
@@ -264,15 +266,45 @@ static struct clk *twd_get_clock(void)
264266
static int __cpuinit twd_timer_setup(struct clock_event_device *clk)
265267
{
266268
struct clock_event_device **this_cpu_clk;
269+
int cpu = smp_processor_id();
267270

268-
if (!twd_clk)
271+
/*
272+
* If the basic setup for this CPU has been done before don't
273+
* bother with the below.
274+
*/
275+
if (per_cpu(percpu_setup_called, cpu)) {
276+
__raw_writel(0, twd_base + TWD_TIMER_CONTROL);
277+
clockevents_register_device(*__this_cpu_ptr(twd_evt));
278+
enable_percpu_irq(clk->irq, 0);
279+
return 0;
280+
}
281+
per_cpu(percpu_setup_called, cpu) = true;
282+
283+
/*
284+
* This stuff only need to be done once for the entire TWD cluster
285+
* during the runtime of the system.
286+
*/
287+
if (!common_setup_called) {
269288
twd_clk = twd_get_clock();
270289

271-
if (!IS_ERR_OR_NULL(twd_clk))
272-
twd_timer_rate = clk_get_rate(twd_clk);
273-
else
274-
twd_calibrate_rate();
290+
/*
291+
* We use IS_ERR_OR_NULL() here, because if the clock stubs
292+
* are active we will get a valid clk reference which is
293+
* however NULL and will return the rate 0. In that case we
294+
* need to calibrate the rate instead.
295+
*/
296+
if (!IS_ERR_OR_NULL(twd_clk))
297+
twd_timer_rate = clk_get_rate(twd_clk);
298+
else
299+
twd_calibrate_rate();
300+
301+
common_setup_called = true;
302+
}
275303

304+
/*
305+
* The following is done once per CPU the first time .setup() is
306+
* called.
307+
*/
276308
__raw_writel(0, twd_base + TWD_TIMER_CONTROL);
277309

278310
clk->name = "local_timer";

0 commit comments

Comments
 (0)