Commit c6338ce4 authored by Tiejun Chen's avatar Tiejun Chen Committed by Paolo Bonzini

kvm: kvmclock: use get_cpu() and put_cpu()

We can use get_cpu() and put_cpu() to replace
preempt_disable()/cpu = smp_processor_id() and
preempt_enable() for slightly better code.
Signed-off-by: default avatarTiejun Chen <tiejun.chen@intel.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent f30ebc31
...@@ -59,13 +59,12 @@ static void kvm_get_wallclock(struct timespec *now) ...@@ -59,13 +59,12 @@ static void kvm_get_wallclock(struct timespec *now)
native_write_msr(msr_kvm_wall_clock, low, high); native_write_msr(msr_kvm_wall_clock, low, high);
preempt_disable(); cpu = get_cpu();
cpu = smp_processor_id();
vcpu_time = &hv_clock[cpu].pvti; vcpu_time = &hv_clock[cpu].pvti;
pvclock_read_wallclock(&wall_clock, vcpu_time, now); pvclock_read_wallclock(&wall_clock, vcpu_time, now);
preempt_enable(); put_cpu();
} }
static int kvm_set_wallclock(const struct timespec *now) static int kvm_set_wallclock(const struct timespec *now)
...@@ -107,11 +106,10 @@ static unsigned long kvm_get_tsc_khz(void) ...@@ -107,11 +106,10 @@ static unsigned long kvm_get_tsc_khz(void)
int cpu; int cpu;
unsigned long tsc_khz; unsigned long tsc_khz;
preempt_disable(); cpu = get_cpu();
cpu = smp_processor_id();
src = &hv_clock[cpu].pvti; src = &hv_clock[cpu].pvti;
tsc_khz = pvclock_tsc_khz(src); tsc_khz = pvclock_tsc_khz(src);
preempt_enable(); put_cpu();
return tsc_khz; return tsc_khz;
} }
...@@ -284,23 +282,22 @@ int __init kvm_setup_vsyscall_timeinfo(void) ...@@ -284,23 +282,22 @@ int __init kvm_setup_vsyscall_timeinfo(void)
size = PAGE_ALIGN(sizeof(struct pvclock_vsyscall_time_info)*NR_CPUS); size = PAGE_ALIGN(sizeof(struct pvclock_vsyscall_time_info)*NR_CPUS);
preempt_disable(); cpu = get_cpu();
cpu = smp_processor_id();
vcpu_time = &hv_clock[cpu].pvti; vcpu_time = &hv_clock[cpu].pvti;
flags = pvclock_read_flags(vcpu_time); flags = pvclock_read_flags(vcpu_time);
if (!(flags & PVCLOCK_TSC_STABLE_BIT)) { if (!(flags & PVCLOCK_TSC_STABLE_BIT)) {
preempt_enable(); put_cpu();
return 1; return 1;
} }
if ((ret = pvclock_init_vsyscall(hv_clock, size))) { if ((ret = pvclock_init_vsyscall(hv_clock, size))) {
preempt_enable(); put_cpu();
return ret; return ret;
} }
preempt_enable(); put_cpu();
kvm_clock.archdata.vclock_mode = VCLOCK_PVCLOCK; kvm_clock.archdata.vclock_mode = VCLOCK_PVCLOCK;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment