On Sat, 2009-11-21 at 22:49 +0800, Wu Zhangjin wrote: > From: Wu Zhangjin <wuzhangjin@xxxxxxxxx> > > This patch adds a cnt32_to_63() and MIPS c0 count based sched_clock(), > which can provide high resolution. and also, two new kernel options are > added. the HR_SCHED_CLOCK is used to enable/disable this sched_clock(), > and the HT_SCHED_CLOCK_UPDATE is used to allow whether update the > sched_clock() automatically or not. > > Without it, the Ftrace for MIPS will give useless timestamp information. > > (Because cnt32_to_63() needs to be called at least once per half period > to work properly, Differ from the old version, this v1 revision set up a > kernel timer to ensure the requirement of some MIPSs which have short c0 > count period.) [...] > > diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c > index e95a3cd..5048989 100644 > --- a/arch/mips/kernel/csrc-r4k.c > +++ b/arch/mips/kernel/csrc-r4k.c > @@ -6,10 +6,62 @@ > * Copyright (C) 2007 by Ralf Baechle > */ > #include <linux/clocksource.h> > +#include <linux/cnt32_to_63.h> > +#include <linux/timer.h> > #include <linux/init.h> > > #include <asm/time.h> > > +/* > + * MIPS' sched_clock implementation. > + * > + * because cnt32_to_63() needs to be called at least once per half period to > + * work properly, and some of the MIPS' frequency is very low, perhaps a kernel > + * timer is needed to be set up to ensure this requirement is always met. > + * please refer to arch/arm/plat-orion/time.c and include/linux/cnt32_to_63.h > + */ > +static unsigned long __maybe_unused tclk2ns_scale; > +static unsigned long __maybe_unused tclk2ns_scale_factor; > + need to be: #ifdef CONFIG_HR_SCHED_CLOCK > +unsigned long long notrace sched_clock(void) > +{ > + unsigned long long v = cnt32_to_63(read_c0_count()); > + return (v * tclk2ns_scale) >> tclk2ns_scale_factor; > +} > + #endif Regards, Wu Zhangjin