* Different definition in div_sc and clocksource_cyc2ns
@ 2010-03-05 21:14 Lin Mac
2010-03-05 21:29 ` john stultz
0 siblings, 1 reply; 2+ messages in thread
From: Lin Mac @ 2010-03-05 21:14 UTC (permalink / raw)
To: linux-arm-kernel
hi,
While working with the clocksource, I found that the relation of cycle
and nanosecond of div_sc and clocksource_cyc2ns is different.
linux-2.6.33
div_sc in include/linux/clockchips.h suggests that clock_ticks =
(nanoseconds * factor) >> shift.
98/*
99 * Calculate a multiplication factor for scaled math, which is
used to convert
100 * nanoseconds based values to clock ticks:
101 *
102 * clock_ticks = (nanoseconds * factor) >> shift.
103 *
104 * div_sc is the rearranged equation to calculate a factor from a
given clock
105 * ticks / nanoseconds ratio:
106 *
107 * factor = (clock_ticks << shift) / nanoseconds
108 */
109static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec,
110 int shift)
111{
112 uint64_t tmp = ((uint64_t)ticks) << shift;
113
114 do_div(tmp, nsec);
115 return (unsigned long) tmp;
116}
However, clocksource_cyc2ns in include/linux/clocksource.h suggest
nanoseconds=(cycles*mult)>>shift.
268static inline s64 clocksource_cyc2ns(cycle_t cycles, u32 mult, u32 shift)
269{
270 return ((u64) cycles * mult) >> shift;
271}
But there are many others using div_sc, I don't think they got issues
with it. So what am I missing?
Best Regards,
Mac Lin
^ permalink raw reply [flat|nested] 2+ messages in thread
* Different definition in div_sc and clocksource_cyc2ns
2010-03-05 21:14 Different definition in div_sc and clocksource_cyc2ns Lin Mac
@ 2010-03-05 21:29 ` john stultz
0 siblings, 0 replies; 2+ messages in thread
From: john stultz @ 2010-03-05 21:29 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Mar 5, 2010 at 1:14 PM, Lin Mac <mkl0301@gmail.com> wrote:
> While working with the clocksource, I found that the relation of cycle
> and nanosecond of div_sc and clocksource_cyc2ns is different.
>
> linux-2.6.33
> div_sc in include/linux/clockchips.h suggests that clock_ticks =
> (nanoseconds * factor) >> shift.
> However, clocksource_cyc2ns in include/linux/clocksource.h suggest
> nanoseconds=(cycles*mult)>>shift.
You're comparing similar helper conversion functions from two
different subsystems.
Both use similar shifted math, but the div_sc() is for clockchips.h,
which is used by the clockevents code to trigger interrupts at a
specified time, while clocksource_cyc2ns() is for the clocksource
code, which converts clockosurce cycles into nanoseconds for
timekeeping.
thanks
-john
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-03-05 21:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-05 21:14 Different definition in div_sc and clocksource_cyc2ns Lin Mac
2010-03-05 21:29 ` john stultz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).