2007-02-06 03:54:44

by Zachary Amsden

[permalink] [raw]
Subject: [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
Signed-off-by: Zachary Amsden <[email protected]>

diff -r a08f195aa92a arch/i386/kernel/vmi.c
--- a/arch/i386/kernel/vmi.c Fri Feb 02 16:30:59 2007 -0800
+++ b/arch/i386/kernel/vmi.c Fri Feb 02 16:31:45 2007 -0800
@@ -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;
}

/*
diff -r a08f195aa92a arch/i386/kernel/vmitime.c
--- a/arch/i386/kernel/vmitime.c Fri Feb 02 16:30:59 2007 -0800
+++ b/arch/i386/kernel/vmitime.c Fri Feb 02 16:30:59 2007 -0800
@@ -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,
diff -r a08f195aa92a include/asm-i386/vmi_time.h
--- a/include/asm-i386/vmi_time.h Fri Feb 02 16:30:59 2007 -0800
+++ b/include/asm-i386/vmi_time.h Fri Feb 02 16:31:24 2007 -0800
@@ -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);


2007-02-06 12:26:31

by Andi Kleen

[permalink] [raw]
Subject: Re: [PATCH 8/11] Add a CPU KHZ calibration function to paravirt-ops

On Mon, Feb 05, 2007 at 07:53:23PM -0800, Zachary Amsden wrote:
> 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

2007-02-06 21:54:56

by Zachary Amsden

[permalink] [raw]
Subject: Re: [PATCH 8/11] Add a CPU KHZ calibration function to paravirt-ops

Andi Kleen wrote:
> On Mon, Feb 05, 2007 at 07:53:23PM -0800, Zachary Amsden wrote:
>
>> 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.

> 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