Different definition in div_sc and clocksource_cyc2ns
mkl0301 at gmail.com
Fri Mar 5 16:14:38 EST 2010
While working with the clocksource, I found that the relation of cycle
and nanosecond of div_sc and clocksource_cyc2ns is different.
div_sc in include/linux/clockchips.h suggests that clock_ticks =
(nanoseconds * factor) >> shift.
99 * Calculate a multiplication factor for scaled math, which is
used to convert
100 * nanoseconds based values to clock ticks:
102 * clock_ticks = (nanoseconds * factor) >> shift.
104 * div_sc is the rearranged equation to calculate a factor from a
105 * ticks / nanoseconds ratio:
107 * factor = (clock_ticks << shift) / nanoseconds
109static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec,
110 int shift)
112 uint64_t tmp = ((uint64_t)ticks) << shift;
114 do_div(tmp, nsec);
115 return (unsigned long) tmp;
However, clocksource_cyc2ns in include/linux/clocksource.h suggest
268static inline s64 clocksource_cyc2ns(cycle_t cycles, u32 mult, u32 shift)
270 return ((u64) cycles * mult) >> shift;
But there are many others using div_sc, I don't think they got issues
with it. So what am I missing?
More information about the linux-arm-kernel