You might find the attached header of some interest. It is part of the high-res-timers patch and is for i386, but I expect we will do the same for most archs before we are done. The notion is to use a power of two scale and to make it easy to access by keeping the asm out of your face (and in a neat little header file :) In the patch we use it to avoid div in all the places that it matters, i.e. we do a div to set up the conversion constants (e.g. TSC to nanosecond or TSC to microsecond) once and then use the "sc" mpy functions to do the conversions. Enjoy -g Yoann Vandoorselaere wrote: > > On Thu, 2002-08-22 at 17:23, Gabriel Paubert wrote: > > Benjamin Herrenschmidt wrote: > > >>Well, first on sane archs which have an easily accessible, fixed > > >>frequency time counter, loops_per_jiffy should never have existed :-) > > >> > > >>Second, putting this code there means that one day somebody will > > >>inevitably try to use it outside of its domain of operation (like it > > >>happened for div64 a few months ago when I pointed out that it would not > > >>work for divisors above 65535 or so). > > > > > > > > > Well... it's clearly located inside kernel/cpufreq.c, so there is > > > little risk, though it may be worth a big bold comment > > > > Hmm, in my experience people hardly ever read detailed comments even > > when they are well-written. Perhaps if you called the function > > imprecise_scale or coarse_scale, it might ring a bell. > > > > Besides that functions should do one thing and do that *well*[1]. Well, > > I'm usually not too dogmatic, but this function breaks the second rule > > beyond what I find acceptable. > > At least it report *correct* result (when the old one was returning BS > because of the 32 bits integer overflow). Doing it well require per > architecture support. > > > > >>In this case a generic scaling function, while not a standard libgcc/C > > >>library feature has potentially more applications than this simple > > >>cpufreq approximation. But I don't see very much the need for scaling a > > >>long (64 bit on 64 bit archs) value, 32 bit would be sufficient. > > > > > > > > > Well... if you can write one, go on then ;) In my case, I'm happy > > > with Yoann implementation for cpufreq right now. Though I agree that > > > could ultimately be moved to arch code. > > [...] > > > [1] Documentation/CodingStyle, which also claims that functions should > > be short and *sweet*. Well, I found the patch far too bitter ;-). > > No wonder why you're loosing contributor with such comportment. > > -- > Yoann Vandoorselaere, http://www.prelude-ids.org > > "Programming is a race between programmers, who try and make more and > more idiot-proof software, and universe, which produces more and more > remarkable idiots. Until now, universe leads the race" -- R. Cook > > - > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ -- George Anzinger george@mvista.com High-res-timers: http://sourceforge.net/projects/high-res-timers/ Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml