Skip to contentSkip to conversation

clocksource: improve sh_cmt clocksource overflow handling

PATCH Applied Magnus Damm 2 participants 2 messages Apr 28, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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;
Applied
#1 lore raw
Quoted 6 lines · Magnus Damm

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.

Quoted 8 lines · Magnus Damm

This patch moves the SuperH timer setup code from time_init() to late_time_init(). Good things about this change:
- interrupts: they are enabled at late_time_init()
- mm: regular kmalloc() can be used at late_time_init()

Together with moving to late_time_init() this patch changes the sh_cmt driver to always allocate with kmalloc(). This simplifies the code a bit and also fixes section mismatches.

Applied to the sh-2.6.31 queue.