Different definition in div_sc and clocksource_cyc2ns
From: Lin Mac
Date: Fri Mar 05 2010 - 16:21:59 EST
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?
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/