[PATCH 1/3] hyperv: add define for time unit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hyper-V uses 100ns time units in all time-related places (clocks,
timers, etc.).  Define a constant for it and use it throughout the code.

Signed-off-by: Roman Kagan <rkagan@xxxxxxxxxxxxx>
---
 arch/x86/include/uapi/asm/hyperv.h |  3 +++
 arch/x86/kernel/cpu/mshyperv.c     |  3 ++-
 arch/x86/kvm/hyperv.c              | 12 ++++++++----
 drivers/hv/hv.c                    |  3 ++-
 drivers/hv/hv_util.c               |  2 +-
 5 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h
index 9b1a918..bd0d629 100644
--- a/arch/x86/include/uapi/asm/hyperv.h
+++ b/arch/x86/include/uapi/asm/hyperv.h
@@ -18,6 +18,9 @@
 #define HYPERV_CPUID_MIN			0x40000005
 #define HYPERV_CPUID_MAX			0x4000ffff
 
+/* time unit in Hyper-V clocks and timers */
+#define HV_NSEC_PER_TICK			100
+
 /*
  * Feature identification. EAX indicates which features are available
  * to the partition based upon the current partition privileges.
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 4e7c693..ae9421f 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -180,7 +180,8 @@ static void __init ms_hyperv_init_platform(void)
 #endif
 
 	if (ms_hyperv.features & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE)
-		clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100);
+		clocksource_register_hz(&hyperv_cs,
+					NSEC_PER_SEC / HV_NSEC_PER_TICK);
 
 #ifdef CONFIG_X86_IO_APIC
 	no_timer_check = 1;
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 01bd7b7..2641907 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -386,7 +386,8 @@ static void synic_init(struct kvm_vcpu_hv_synic *synic)
 
 static u64 get_time_ref_counter(struct kvm *kvm)
 {
-	return div_u64(get_kernel_ns() + kvm->arch.kvmclock_offset, 100);
+	return div_u64(get_kernel_ns() + kvm->arch.kvmclock_offset,
+		       HV_NSEC_PER_TICK);
 }
 
 static void stimer_mark_pending(struct kvm_vcpu_hv_stimer *stimer,
@@ -460,7 +461,8 @@ static int stimer_start(struct kvm_vcpu_hv_stimer *stimer)
 
 		hrtimer_start(&stimer->timer,
 			      ktime_add_ns(ktime_now,
-					   100 * (stimer->exp_time - time_now)),
+					   HV_NSEC_PER_TICK *
+					   (stimer->exp_time - time_now)),
 			      HRTIMER_MODE_ABS);
 		return 0;
 	}
@@ -481,7 +483,9 @@ static int stimer_start(struct kvm_vcpu_hv_stimer *stimer)
 					   time_now, stimer->count);
 
 	hrtimer_start(&stimer->timer,
-		      ktime_add_ns(ktime_now, 100 * (stimer->count - time_now)),
+		      ktime_add_ns(ktime_now,
+				   HV_NSEC_PER_TICK *
+				   (stimer->count - time_now)),
 		      HRTIMER_MODE_ABS);
 	return 0;
 }
@@ -836,7 +840,7 @@ static u64 current_task_runtime_100ns(void)
 	cputime_t utime, stime;
 
 	task_cputime_adjusted(current, &utime, &stime);
-	return div_u64(cputime_to_nsecs(utime + stime), 100);
+	return div_u64(cputime_to_nsecs(utime + stime), HV_NSEC_PER_TICK);
 }
 
 static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index a1c086b..46b5f8c 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -255,7 +255,8 @@ int hv_init(void)
 		tsc_msr.guest_physical_address = vmalloc_to_pfn(va_tsc);
 
 		wrmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
-		clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100);
+		clocksource_register_hz(&hyperv_cs_tsc,
+					NSEC_PER_SEC / HV_NSEC_PER_TICK);
 	}
 #endif
 	return 0;
diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c
index d5acaa2..fe19605 100644
--- a/drivers/hv/hv_util.c
+++ b/drivers/hv/hv_util.c
@@ -168,7 +168,7 @@ static inline void do_adj_guesttime(u64 hosttime)
 	s64 host_tns;
 	struct timespec host_ts;
 
-	host_tns = (hosttime - WLTIMEDELTA) * 100;
+	host_tns = (hosttime - WLTIMEDELTA) * HV_NSEC_PER_TICK;
 	host_ts = ns_to_timespec(host_tns);
 
 	do_settimeofday(&host_ts);
-- 
2.5.5

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux