clocksource: improve sh_cmt clocksource overflow handling
Subsystems (2)
PATCH 1/1 clocksource: improve sh_cmt clocksource overflow handling
From: Magnus Damm <[email protected]>
This patch improves the sh_cmt clocksource handling.
Currently the counter value is ignored in the case of overflow. With this patch the overflow flag is read before and after reading the counter, removing any counter value and overflow flag mismatch issues.
---
drivers/clocksource/sh_cmt.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/clocksource/sh_cmt.c +9 -4
@@ -111,16 +111,21 @@ static unsigned long sh_cmt_get_counter( int *has_wrapped) {unsigned long v1, v2, v3; +int o1, o2; + + o1 =sh_cmt_read (p,CMCSR ) & p->overflow_bit;/* Make sure the timer value is stable. Stolen from acpi_pm.c */ do { + o2 = o1; v1 =sh_cmt_read (p,CMCNT ); v2 =sh_cmt_read (p,CMCNT ); v3 =sh_cmt_read (p,CMCNT ); - }while (unlikely ((v1 > v2 && v1 < v3) || (v2 > v3 && v2 < v1) - || (v3 > v1 && v3 < v2))); + o1 =sh_cmt_read (p,CMCSR ) & p->overflow_bit; + }while (unlikely ((o1 != o2) || (v1 > v2 && v1 < v3) + || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2))); - *has_wrapped =sh_cmt_read (p,CMCSR ) & p->overflow_bit; + *has_wrapped = o1;return v2; }
@@ -394,7 +399,7 @@ static cycle_t sh_cmt_clocksource_read(s raw =sh_cmt_get_counter (p, &has_wrapped);if (unlikely (has_wrapped)) - raw = p->match_value; + raw += p->match_value;spin_unlock_irqrestore (&p->lock, flags);return value + raw;
Paul Mundt
AppliedQuoted 6 lines · Magnus Damm
This patch improves the
sh_cmtclocksource handling.Currently the counter value is ignored in the case of overflow. With this patch the overflow flag is read before and after reading the counter, removing any counter value and overflow flag mismatch issues.
Quoted 8 lines · Magnus Damm
This patch moves the SuperH timer setup code from
time_init()tolate_time_init(). Good things about this change:
- interrupts: they are enabled atlate_time_init()
- mm: regularkmalloc()can be used atlate_time_init()Together with moving to
late_time_init()this patch changes thesh_cmtdriver to always allocate withkmalloc(). This simplifies the code a bit and also fixes section mismatches.
Applied to the sh-2.6.31 queue.