Skip to contentSkip to conversation

Accessing host TSC from a guest kernel

DISCUSSION Julien Desfossez 3 participants 3 messages Sep 24, 2010 – Sep 26, 2010 KVM

lore
Share & tools
lore
#0 lore raw

Hello,

I'd like to access the host TSC from the inside of a guest kernel and I don't really know if it's possible.

I'm working with kvm_clock and I have been playing with the pvclock_vcpu_time_info structure, but I'm not sure if I'm in the right direction.

So could you tell me if there is an efficient way to access to access the host TSC (or at least the TSC_OFFSET) from a module inside a guest kernel ?

I did it with an hypercall, but it's for tracing purpose and doing an hypercall every time I want to record an event, is way too costly.

Thanks,

Julien

#1 lore raw
Quoted 9 lines · Julien Desfossez

Hello,

I'd like to access the host TSC from the inside of a guest kernel and I don't really know if it's possible.

I'm working with kvm_clock and I have been playing with the pvclock_vcpu_time_info structure, but I'm not sure if I'm in the right direction.

Quoted 8 lines

So could you tell me if there is an efficient way to access to access the host TSC (or at least the TSC_OFFSET) from a module inside a guest kernel ?

I did it with an hypercall, but it's for tracing purpose and doing an hypercall every time I want to record an event, is way too costly.

It isn't possible. If you need a coherent host/guest timestamp, I suggest using ktime_get().

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 14 lines · Avi Kivity
Quoted 13 lines · Julien Desfossez

Hello,

I'd like to access the host TSC from the inside of a guest kernel and I don't really know if it's possible.

I'm working with kvm_clock and I have been playing with the pvclock_vcpu_time_info structure, but I'm not sure if I'm in the right direction.

So could you tell me if there is an efficient way to access to access the host TSC (or at least the TSC_OFFSET) from a module inside a guest kernel ?

Quoted 6 lines
Quoted 3 lines

I did it with an hypercall, but it's for tracing purpose and doing an hypercall every time I want to record an event, is way too costly.

It isn't possible. If you need a coherent host/guest timestamp, I suggest using ktime_get().

I think Avi meant that it isn't possible with stock KVM. If you hack KVM to run the guest with 'RDTSC exiting' set to 0 and either disable 'use TSC offseting' or communicate the TSC offset to the guest out of band, you should have efficient & consistent guest/host timestamps.

Cheers,
Muli