2003-09-05 03:14:32

by Dmitry Torokhov

[permalink] [raw]
Subject: Question: monolitic_clock, timer_{tsc,hpet} and CPUFREQ

I noticed that although timer_tsc registers cpufreq notifier to detect
frequency changes and adjust cpu_khz it does not set cyc2ns_scale. Is
monotonic clocks supposed to be also accurate?

Will something like this suffice for timer_tsc (compiled, not yet booted):

--- 2.6.0-test4/arch/i386/kernel/timers/timer_tsc.c 2003-08-26 21:56:19.000000000 -0500
+++ linux-2.6.0-test4/arch/i386/kernel/timers/timer_tsc.c 2003-09-04 22:08:27.000000000 -0500
@@ -315,6 +315,7 @@
if (use_tsc) {
fast_gettimeoffset_quotient = cpufreq_scale(fast_gettimeoffset_ref, freq->new, ref_freq);
cpu_khz = cpufreq_scale(cpu_khz_ref, ref_freq, freq->new);
+ set_cyc2ns_scale(cpu_khz/1000);
}
#endif
}


2003-09-05 08:13:35

by john stultz

[permalink] [raw]
Subject: Re: Question: monolitic_clock, timer_{tsc,hpet} and CPUFREQ

On Thu, 2003-09-04 at 20:14, Dmitry Torokhov wrote:
> I noticed that although timer_tsc registers cpufreq notifier to detect
> frequency changes and adjust cpu_khz it does not set cyc2ns_scale. Is
> monotonic clocks supposed to be also accurate?

You are correct, without adjusting the cyc2ns_scale value
monotonic_clock() will not be accurate on freq changing hardware.


> Will something like this suffice for timer_tsc (compiled, not yet booted):
>
> --- 2.6.0-test4/arch/i386/kernel/timers/timer_tsc.c 2003-08-26 21:56:19.000000000 -0500
> +++ linux-2.6.0-test4/arch/i386/kernel/timers/timer_tsc.c 2003-09-04 22:08:27.000000000 -0500
> @@ -315,6 +315,7 @@
> if (use_tsc) {
> fast_gettimeoffset_quotient = cpufreq_scale(fast_gettimeoffset_ref, freq->new, ref_freq);
> cpu_khz = cpufreq_scale(cpu_khz_ref, ref_freq, freq->new);
> + set_cyc2ns_scale(cpu_khz/1000);
> }
> #endif
> }

Looks fine to me. Although I don't have any cpufreq enabled hardware, so
I'm unable to test this (main cause I never added it myself).

thanks
-john


2003-09-07 19:30:30

by Dominik Brodowski

[permalink] [raw]
Subject: Re: Question: monolitic_clock, timer_{tsc,hpet} and CPUFREQ

On Fri, Sep 05, 2003 at 01:13:14AM -0700, john stultz wrote:
> On Thu, 2003-09-04 at 20:14, Dmitry Torokhov wrote:
> > I noticed that although timer_tsc registers cpufreq notifier to detect
> > frequency changes and adjust cpu_khz it does not set cyc2ns_scale. Is
> > monotonic clocks supposed to be also accurate?
>
> You are correct, without adjusting the cyc2ns_scale value
> monotonic_clock() will not be accurate on freq changing hardware.

Seems to be a necessary update. Thanks for noting this.


> Looks fine to me. Although I don't have any cpufreq enabled hardware, so
> I'm unable to test this (main cause I never added it myself).

/me has cpufreq enabled hardware -- but how can I accurately debug
monotonic_ticks()?

Dominik

2003-09-08 17:37:33

by john stultz

[permalink] [raw]
Subject: Re: Question: monolitic_clock, timer_{tsc,hpet} and CPUFREQ

On Sun, 2003-09-07 at 11:57, Dominik Brodowski wrote:
> On Fri, Sep 05, 2003 at 01:13:14AM -0700, john stultz wrote:
> > Looks fine to me. Although I don't have any cpufreq enabled hardware, so
> > I'm unable to test this (main cause I never added it myself).
>
> /me has cpufreq enabled hardware -- but how can I accurately debug
> monotonic_ticks()?

Usually I hack up the hangcheck-timer module to be more verbose to
verify monotonic_clock() works. Also Oracle has a hangcheck-delay module
you can use to hang the system for a defined length of time. You can
then check the delta between gettimeofday and monotonic_clock to verify
its working as it should.

thanks
-john