Skip to contentSkip to conversation

Add a CPU KHZ calibration function to paravirt-ops

PATCH In review Zachary Amsden 2 participants 3 messages Feb 6, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 8/11 Add a CPU KHZ calibration function to paravirt-ops

Provide a paravirtualized way to get the CPU clock frequency; this allows much of the code in tsc.c to be shared between all paravirt implementations.

Subject: Add a CPU KHZ calibration function to paravirt-ops

arch/i386/kernel/vmi.c +1 -0
diff -r a08f195aa92a arch/i386/kernel/vmi.c
@@ -881,6 +881,7 @@ static int __init activate_vmi(void)
 		paravirt_ops.setup_secondary_clock = vmi_timer_setup_secondary_alarm;
 #endif
 		paravirt_ops.get_scheduled_cycles = vmi_get_sched_cycles;
+ 		paravirt_ops.get_cpu_khz = vmi_cpu_khz;
 	}
 
 	/*
arch/i386/kernel/vmitime.c +9 -1
diff -r a08f195aa92a arch/i386/kernel/vmitime.c
@@ -175,6 +175,15 @@ unsigned long long vmi_get_sched_cycles(
 	return read_available_cycles();
 }
 
+unsigned long vmi_cpu_khz(void)
+{
+	unsigned long long khz;
+
+	khz = vmi_timer_ops.get_cycle_frequency();
+	(void)do_div(khz, 1000);
+	return khz;
+}
+
 void __init vmi_time_init(void)
 {
 	unsigned long long cycles_per_sec, cycles_per_msec;
@@ -204,7 +213,6 @@ void __init vmi_time_init(void)
 	(void)do_div(cycles_per_alarm, alarm_hz);
 	cycles_per_msec = cycles_per_sec;
 	(void)do_div(cycles_per_msec, 1000);
-	cpu_khz = cycles_per_msec;
 
 	printk(KERN_WARNING "VMI timer cycles/sec = %llu ; cycles/jiffy = %llu ;"
 	       "cycles/alarm = %llu\n", cycles_per_sec, cycles_per_jiffy,
include/asm-i386/vmi_time.h +1 -0
diff -r a08f195aa92a include/asm-i386/vmi_time.h
@@ -50,6 +50,7 @@ extern unsigned long vmi_get_wallclock(v
 extern unsigned long vmi_get_wallclock(void);
 extern int vmi_set_wallclock(unsigned long now);
 extern unsigned long long vmi_get_sched_cycles(void);
+extern unsigned long vmi_cpu_khz(void);
 
 #ifdef CONFIG_X86_LOCAL_APIC
 extern void __init vmi_timer_setup_boot_alarm(void);
#1 lore raw
Quoted 2 lines · Zachary Amsden

Provide a paravirtualized way to get the CPU clock frequency; this allows much of the code in tsc.c to be shared between all paravirt implementations.

Is this really needed?

What worries me somewhat of your patches is that you seem to be quick at adding new hooks. But I would like to keep paravirtops as minimal as possible with new hooks only added when there is a very good justification.

I don't see it here.

-Andi

#2 lore raw
Quoted 8 lines · Andi Kleen
Quoted 3 lines · Zachary Amsden

Provide a paravirtualized way to get the CPU clock frequency; this allows much of the code in tsc.c to be shared between all paravirt implementations.

Is this really needed?

Honestly, no. But it is better and more accurate to do it.

Quoted 7 lines

What worries me somewhat of your patches is that you seem to be quick at adding new hooks. But I would like to keep paravirtops as minimal as possible with new hooks only added when there is a very good justification.

I don't see it here.

We can calibrate CPU frequency pretty accurately, despite being in a VM where time does not operate in the normal way. Many other hypervisors won't be able to do such a good job, or might not implement the required hardware.

Adding this hook allows everyone to just re-use all the frequency scaling / recalibration code in tsc.c.

The primary justification is allowing code re-use, which is why I allowed myself to add a hook. I also want paravirt-ops to be as minimal as possible.

Zach