Skip to contentSkip to conversation

clocksource: use clocksource_freq2mult() helper

PATCH In review Alexander Kuleshov 2 participants 3 messages Mar 16, 2016 – Apr 8, 2016 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clocksource: use clocksource_freq2mult() helper

which is introduced in the 7aca0c072 commit to simplify calculation of the mult and shift in the clocks_calc_mult_shift().

---
 kernel/time/clocksource.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/time/clocksource.c +1 -3
index 56ece14..de57923 100644
@@ -80,9 +80,7 @@ clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 maxsec)
 	 * accuracy and fits the maxsec conversion range:
 	 */
 	for (sft = 32; sft > 0; sft--) {
-		tmp = (u64) to << sft;
-		tmp += from / 2;
-		do_div(tmp, from);
+		tmp = clocksource_freq2mult(from, sft, to);
 		if ((tmp >> sftacc) == 0)
 			break;
 	}
Signature · 1 line
2.8.0.rc2.216.g1477fb2.dirty
#2 lore raw
In reply to Alexander Kuleshov
Quoted 13 lines · Alexander Kuleshov

which is introduced in the 7aca0c072 commit to simplify calculation of the mult and shift in the clocks_calc_mult_shift().

---
 kernel/time/clocksource.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/time/clocksource.c +0 -0
index 56ece14..de57923 100644

kernel/time/clocksource.c clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 maxsec) · line 86

Quoted 10 lines
kernel/time/clocksource.c +1 -3
@@ -80,9 +80,7 @@ clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 maxsec)
         * accuracy and fits the maxsec conversion range:
         */
        for (sft = 32; sft > 0; sft--) {
-               tmp = (u64) to << sft;
-               tmp += from / 2;
-               do_div(tmp, from);
+               tmp = clocksource_freq2mult(from, sft, to);
                if ((tmp >> sftacc) == 0)
                        break;
        }

I'm worried you never tested this, as its clearly broken, and keeps my systems from booting.

clocksource_freq2mult returns a u32. In the code being removed, tmp is a u64. So this may truncate the high bits.

Since sftacc is often 32, this causes it to exit prematurely on the first pass through the loop.

Please do make sure to boot test what you send out. I spent some time thinking I had broken my qemu testing setup before I realized it was this simple looking patch.

thanks
-john