Skip to contentSkip to conversation

x86/hyper-v: enable TSC page clocksource on 32bit

PATCH Superseded Vitaly Kuznetsov 3 participants 5 messages Aug 21, 2019 – Aug 22, 2019

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hyper-v: enable TSC page clocksource on 32bit

There is no particular reason to not enable TSC page clocksource on 32-bit. mul_u64_u64_shr() is available and despite the increased computational complexity (compared to 64bit) TSC page is still a huge win compared to MSR-based clocksource.

In-kernel reads:
MSR based clocksource: 3361 cycles
TSC page clocksource: 49 cycles

Reads from userspace (unilizing vDSO in case of TSC page):
MSR based clocksource: 5664 cycles
TSC page clocksource: 131 cycles

Enabling TSC page on 32bits allows us to get rid of CONFIG_HYPERV_TSCPAGE as it is now not any different from CONFIG_HYPERV_TIMER.

---
 arch/x86/include/asm/vdso/gettimeofday.h |  6 +++---
 drivers/clocksource/hyperv_timer.c       | 11 -----------
 drivers/hv/Kconfig                       |  3 ---
 include/clocksource/hyperv_timer.h       |  6 ++----
 4 files changed, 5 insertions(+), 21 deletions(-)
arch/x86/include/asm/vdso/gettimeofday.h +3 -3
index ba71a63cdac4..e9ee139cf29e 100644
@@ -51,7 +51,7 @@ extern struct pvclock_vsyscall_time_info pvclock_page
 	__attribute__((visibility("hidden")));
 #endif
 
-#ifdef CONFIG_HYPERV_TSCPAGE
+#ifdef CONFIG_HYPERV_TIMER
 extern struct ms_hyperv_tsc_page hvclock_page
 	__attribute__((visibility("hidden")));
 #endif
@@ -228,7 +228,7 @@ static u64 vread_pvclock(void)
 }
 #endif
 
-#ifdef CONFIG_HYPERV_TSCPAGE
+#ifdef CONFIG_HYPERV_TIMER
 static u64 vread_hvclock(void)
 {
 	return hv_read_tsc_page(&hvclock_page);
@@ -251,7 +251,7 @@ static inline u64 __arch_get_hw_counter(s32 clock_mode)
 		return vread_pvclock();
 	}
 #endif
-#ifdef CONFIG_HYPERV_TSCPAGE
+#ifdef CONFIG_HYPERV_TIMER
 	if (clock_mode == VCLOCK_HVCLOCK) {
 		barrier();
 		return vread_hvclock();
drivers/clocksource/hyperv_timer.c +0 -11
index ba2c79e6a0ee..b6083faab540 100644
@@ -212,8 +212,6 @@ EXPORT_SYMBOL_GPL(hv_stimer_global_cleanup);
 struct clocksource *hyperv_cs;
 EXPORT_SYMBOL_GPL(hyperv_cs);
 
-#ifdef CONFIG_HYPERV_TSCPAGE
-
 static struct ms_hyperv_tsc_page *tsc_pg;
 
 struct ms_hyperv_tsc_page *hv_get_tsc_page(void)
@@ -244,7 +242,6 @@ static struct clocksource hyperv_cs_tsc = {
 	.mask	= CLOCKSOURCE_MASK(64),
 	.flags	= CLOCK_SOURCE_IS_CONTINUOUS,
 };
-#endif
 
 static u64 notrace read_hv_sched_clock_msr(void)
 {
@@ -271,7 +268,6 @@ static struct clocksource hyperv_cs_msr = {
 	.flags	= CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-#ifdef CONFIG_HYPERV_TSCPAGE
 static bool __init hv_init_tsc_clocksource(void)
 {
 	u64		tsc_msr;
@@ -306,13 +302,6 @@ static bool __init hv_init_tsc_clocksource(void)
 	sched_clock_register(read_hv_sched_clock_tsc, 64, HV_CLOCK_HZ);
 	return true;
 }
-#else
-static bool __init hv_init_tsc_clocksource(void)
-{
-	return false;
-}
-#endif
-
 
 void __init hv_init_clocksource(void)
 {
drivers/hv/Kconfig +0 -3
index 9a59957922d4..79e5356a737a 100644
@@ -14,9 +14,6 @@ config HYPERV
 config HYPERV_TIMER
 	def_bool HYPERV
 
-config HYPERV_TSCPAGE
-       def_bool HYPERV && X86_64
-
 config HYPERV_UTILS
 	tristate "Microsoft Hyper-V Utilities driver"
 	depends on HYPERV && CONNECTOR && NLS
include/clocksource/hyperv_timer.h +2 -4
index a821deb8ecb2..f72e4619d0a7 100644
@@ -28,12 +28,10 @@ extern void hv_stimer_cleanup(unsigned int cpu);
 extern void hv_stimer_global_cleanup(void);
 extern void hv_stimer0_isr(void);
 
-#if IS_ENABLED(CONFIG_HYPERV)
+#ifdef CONFIG_HYPERV_TIMER
 extern struct clocksource *hyperv_cs;
 extern void hv_init_clocksource(void);
-#endif /* CONFIG_HYPERV */
 
-#ifdef CONFIG_HYPERV_TSCPAGE
 extern struct ms_hyperv_tsc_page *hv_get_tsc_page(void);
 
 static inline notrace u64
@@ -102,6 +100,6 @@ static inline u64 hv_read_tsc_page_tsc(const struct ms_hyperv_tsc_page *tsc_pg,
 {
 	return U64_MAX;
 }
-#endif /* CONFIG_HYPERV_TSCPAGE */
+#endif /* CONFIG_HYPERV_TIMER */
 
 #endif
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw

From: Vitaly Kuznetsov <[email protected]> Sent: Wednesday, August 21, 2019 2:57 AM

Quoted 11 lines

There is no particular reason to not enable TSC page clocksource on 32-bit. mul_u64_u64_shr() is available and despite the increased computational complexity (compared to 64bit) TSC page is still a huge win compared to MSR-based clocksource.

In-kernel reads:
MSR based clocksource: 3361 cycles
TSC page clocksource: 49 cycles

Reads from userspace (unilizing vDSO in case of TSC page):

s/unilizing/utilizing/

Quoted 122 lines

MSR based clocksource: 5664 cycles
TSC page clocksource: 131 cycles

Enabling TSC page on 32bits allows us to get rid of CONFIG_HYPERV_TSCPAGE as it is now not any different from CONFIG_HYPERV_TIMER.

---
 arch/x86/include/asm/vdso/gettimeofday.h |  6 +++---
 drivers/clocksource/hyperv_timer.c       | 11 -----------
 drivers/hv/Kconfig                       |  3 ---
 include/clocksource/hyperv_timer.h       |  6 ++----
 4 files changed, 5 insertions(+), 21 deletions(-)
arch/x86/include/asm/vdso/gettimeofday.h +3 -3
index ba71a63cdac4..e9ee139cf29e 100644
@@ -51,7 +51,7 @@ extern struct pvclock_vsyscall_time_info pvclock_page
 	__attribute__((visibility("hidden")));
 #endif
 
-#ifdef CONFIG_HYPERV_TSCPAGE
+#ifdef CONFIG_HYPERV_TIMER
 extern struct ms_hyperv_tsc_page hvclock_page
 	__attribute__((visibility("hidden")));
 #endif
@@ -228,7 +228,7 @@ static u64 vread_pvclock(void)
 }
 #endif
 
-#ifdef CONFIG_HYPERV_TSCPAGE
+#ifdef CONFIG_HYPERV_TIMER
 static u64 vread_hvclock(void)
 {
 	return hv_read_tsc_page(&hvclock_page);
@@ -251,7 +251,7 @@ static inline u64 __arch_get_hw_counter(s32 clock_mode)
 		return vread_pvclock();
 	}
 #endif
-#ifdef CONFIG_HYPERV_TSCPAGE
+#ifdef CONFIG_HYPERV_TIMER
 	if (clock_mode == VCLOCK_HVCLOCK) {
 		barrier();
 		return vread_hvclock();
drivers/clocksource/hyperv_timer.c +0 -11
index ba2c79e6a0ee..b6083faab540 100644
@@ -212,8 +212,6 @@ EXPORT_SYMBOL_GPL(hv_stimer_global_cleanup);
 struct clocksource *hyperv_cs;
 EXPORT_SYMBOL_GPL(hyperv_cs);
 
-#ifdef CONFIG_HYPERV_TSCPAGE
-
 static struct ms_hyperv_tsc_page *tsc_pg;
 
 struct ms_hyperv_tsc_page *hv_get_tsc_page(void)
@@ -244,7 +242,6 @@ static struct clocksource hyperv_cs_tsc = {
 	.mask	= CLOCKSOURCE_MASK(64),
 	.flags	= CLOCK_SOURCE_IS_CONTINUOUS,
 };
-#endif
 
 static u64 notrace read_hv_sched_clock_msr(void)
 {
@@ -271,7 +268,6 @@ static struct clocksource hyperv_cs_msr = {
 	.flags	= CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-#ifdef CONFIG_HYPERV_TSCPAGE
 static bool __init hv_init_tsc_clocksource(void)
 {
 	u64		tsc_msr;
@@ -306,13 +302,6 @@ static bool __init hv_init_tsc_clocksource(void)
 	sched_clock_register(read_hv_sched_clock_tsc, 64, HV_CLOCK_HZ);
 	return true;
 }
-#else
-static bool __init hv_init_tsc_clocksource(void)
-{
-	return false;
-}
-#endif
-
 
 void __init hv_init_clocksource(void)
 {
drivers/hv/Kconfig +0 -3
index 9a59957922d4..79e5356a737a 100644
@@ -14,9 +14,6 @@ config HYPERV
 config HYPERV_TIMER
 	def_bool HYPERV
 
-config HYPERV_TSCPAGE
-       def_bool HYPERV && X86_64
-
 config HYPERV_UTILS
 	tristate "Microsoft Hyper-V Utilities driver"
 	depends on HYPERV && CONNECTOR && NLS
include/clocksource/hyperv_timer.h +1 -3
index a821deb8ecb2..f72e4619d0a7 100644
@@ -28,12 +28,10 @@ extern void hv_stimer_cleanup(unsigned int cpu);
 extern void hv_stimer_global_cleanup(void);
 extern void hv_stimer0_isr(void);
 
-#if IS_ENABLED(CONFIG_HYPERV)
+#ifdef CONFIG_HYPERV_TIMER
 extern struct clocksource *hyperv_cs;
 extern void hv_init_clocksource(void);
-#endif /* CONFIG_HYPERV */
 
-#ifdef CONFIG_HYPERV_TSCPAGE
 extern struct ms_hyperv_tsc_page *hv_get_tsc_page(void);
 
 static inline notrace u64

include/clocksource/hyperv_timer.h static inline u64 hv_read_tsc_page_tsc(const struct · line 104

Quoted 6 lines
include/clocksource/hyperv_timer.h +1 -1
@@ -102,6 +100,6 @@ static inline u64 hv_read_tsc_page_tsc(const struct
 ms_hyperv_tsc_page *tsc_pg,
 {
 	return U64_MAX;
 }
-#endif /* CONFIG_HYPERV_TSCPAGE */
+#endif /* CONFIG_HYPERV_TIMER */

There's a #else prior to the #endif that has TSCPAGE misspelled as TSC_PAGE in the comment. Should probably fix the comment ...

Quoted 4 lines
include/clocksource/hyperv_timer.h +0 -1
 #endif
--

2.20.1

Overall an excellent removal of unnecessary complexity. Thx. Two minor nits notwithstanding,

#2 lore raw
In reply to Vitaly Kuznetsov
Quoted 9 lines · Vitaly Kuznetsov

There is no particular reason to not enable TSC page clocksource on 32-bit. mul_u64_u64_shr() is available and despite the increased computational complexity (compared to 64bit) TSC page is still a huge win compared to MSR-based clocksource.

In-kernel reads:
MSR based clocksource: 3361 cycles
TSC page clocksource: 49 cycles

Quoted 5 lines

Reads from userspace (unilizing vDSO in case of TSC page):
MSR based clocksource: 5664 cycles
TSC page clocksource: 131 cycles

Enabling TSC page on 32bits allows us to get rid of CONFIG_HYPERV_TSCPAGE

s/allows us/allows/

Quoted 9 lines

as it is now not any different from CONFIG_HYPERV_TIMER.

---
 arch/x86/include/asm/vdso/gettimeofday.h |  6 +++---
 drivers/clocksource/hyperv_timer.c       | 11 -----------
 drivers/hv/Kconfig                       |  3 ---
 include/clocksource/hyperv_timer.h       |  6 ++----
 4 files changed, 5 insertions(+), 21 deletions(-)

Really nice cleanup as a side effect of adding functionality.

Thanks,

tglx

#3 lore raw
Quoted 29 lines · Thomas Gleixner
Quoted 9 lines · Vitaly Kuznetsov

There is no particular reason to not enable TSC page clocksource on 32-bit. mul_u64_u64_shr() is available and despite the increased computational complexity (compared to 64bit) TSC page is still a huge win compared to MSR-based clocksource.

In-kernel reads:
MSR based clocksource: 3361 cycles
TSC page clocksource: 49 cycles

Quoted 5 lines

Reads from userspace (unilizing vDSO in case of TSC page):
MSR based clocksource: 5664 cycles
TSC page clocksource: 131 cycles

Enabling TSC page on 32bits allows us to get rid of CONFIG_HYPERV_TSCPAGE

s/allows us/allows/

Quoted 9 lines

as it is now not any different from CONFIG_HYPERV_TIMER.

---
 arch/x86/include/asm/vdso/gettimeofday.h |  6 +++---
 drivers/clocksource/hyperv_timer.c       | 11 -----------
 drivers/hv/Kconfig                       |  3 ---
 include/clocksource/hyperv_timer.h       |  6 ++----
 4 files changed, 5 insertions(+), 21 deletions(-)
Quoted 1 line

Really nice cleanup as a side effect of adding functionality.

That said, could you please rebase that on

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/core

as I just applied the TSC page patches there and this conflicts left and right.

Thanks,

tglx

#4 lore raw
Quoted 31 lines · Thomas Gleixner
Quoted 29 lines · Thomas Gleixner
Quoted 9 lines · Vitaly Kuznetsov

There is no particular reason to not enable TSC page clocksource on 32-bit. mul_u64_u64_shr() is available and despite the increased computational complexity (compared to 64bit) TSC page is still a huge win compared to MSR-based clocksource.

In-kernel reads:
MSR based clocksource: 3361 cycles
TSC page clocksource: 49 cycles

Quoted 5 lines

Reads from userspace (unilizing vDSO in case of TSC page):
MSR based clocksource: 5664 cycles
TSC page clocksource: 131 cycles

Enabling TSC page on 32bits allows us to get rid of CONFIG_HYPERV_TSCPAGE

s/allows us/allows/

Quoted 9 lines

as it is now not any different from CONFIG_HYPERV_TIMER.

---
 arch/x86/include/asm/vdso/gettimeofday.h |  6 +++---
 drivers/clocksource/hyperv_timer.c       | 11 -----------
 drivers/hv/Kconfig                       |  3 ---
 include/clocksource/hyperv_timer.h       |  6 ++----
 4 files changed, 5 insertions(+), 21 deletions(-)
Quoted 8 lines
Quoted 1 line

Really nice cleanup as a side effect of adding functionality.

That said, could you please rebase that on

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/core

as I just applied the TSC page patches there and this conflicts left and right.

Sure, v2 is coming!

Signature · 1 line
Vitaly