Skip to contentSkip to conversation

cycles_to_usecs rounding fix

PATCH New Daniel Walker 1 participant 1 message Dec 12, 2007 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cycles_to_usecs rounding fix

do_div() rounds down, so we add have the divisor to round up. This effected my change to preempt_max_latency. Each time you read preempt_max_latency it gets rounded lower.

---
 kernel/time/timekeeping.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/timekeeping.c +2 -1
Index: linux-2.6.23/kernel/time/timekeeping.c
===================================================================
@@ -144,7 +144,8 @@ unsigned long notrace cycles_to_usecs(cy
 {
 	u64 ret = cyc2ns(clock, cycles);
 
-	do_div(ret, 1000);
+	ret += NSEC_PER_USEC/2; /* For rounding in do_div() */
+	do_div(ret, NSEC_PER_USEC);
 
 	return ret;
 }
Signature · 1 line
--