Skip to contentSkip to conversation

Question: monolitic_clock, timer_{tsc,hpet} and CPUFREQ

PATCH Dmitry Torokhov 3 participants 4 messages Sep 5, 2003 – Sep 8, 2003

lore
Share & tools
lore
#0 lore raw

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):

arch/i386/kernel/timers/timer_tsc.c +1 -0
@@ -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
 	}
#1 lore raw
Quoted 3 lines · Dmitry Torokhov

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.

arch/i386/kernel/timers/timer_tsc.c line 321

Quoted 12 lines

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

arch/i386/kernel/timers/timer_tsc.c +1 -0
@@ -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

#2 lore raw
Quoted 7 lines · john stultz
Quoted 3 lines · Dmitry Torokhov

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.

Quoted 2 lines

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

#3 lore raw
Quoted 6 lines · Dominik Brodowski
Quoted 2 lines · john stultz

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