All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/hyper-v: enable TSC page clocksource on 32bit
@ 2019-08-21  9:56 Vitaly Kuznetsov
  2019-08-21 21:16 ` Michael Kelley
  2019-08-21 21:17 ` Thomas Gleixner
  0 siblings, 2 replies; 5+ messages in thread
From: Vitaly Kuznetsov @ 2019-08-21  9:56 UTC (permalink / raw)
  To: linux-hyperv
  Cc: linux-kernel, x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, K. Y. Srinivasan, Haiyang Zhang,
	Stephen Hemminger, Sasha Levin, Daniel Lezcano, Michael Kelley,
	Tianyu Lan, Peter Zijlstra

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.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 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(-)

diff --git a/arch/x86/include/asm/vdso/gettimeofday.h b/arch/x86/include/asm/vdso/gettimeofday.h
index ba71a63cdac4..e9ee139cf29e 100644
--- a/arch/x86/include/asm/vdso/gettimeofday.h
+++ b/arch/x86/include/asm/vdso/gettimeofday.h
@@ -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();
diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
index ba2c79e6a0ee..b6083faab540 100644
--- a/drivers/clocksource/hyperv_timer.c
+++ b/drivers/clocksource/hyperv_timer.c
@@ -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)
 {
diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig
index 9a59957922d4..79e5356a737a 100644
--- a/drivers/hv/Kconfig
+++ b/drivers/hv/Kconfig
@@ -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
diff --git a/include/clocksource/hyperv_timer.h b/include/clocksource/hyperv_timer.h
index a821deb8ecb2..f72e4619d0a7 100644
--- a/include/clocksource/hyperv_timer.h
+++ b/include/clocksource/hyperv_timer.h
@@ -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
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [PATCH] x86/hyper-v: enable TSC page clocksource on 32bit
  2019-08-21  9:56 [PATCH] x86/hyper-v: enable TSC page clocksource on 32bit Vitaly Kuznetsov
@ 2019-08-21 21:16 ` Michael Kelley
  2019-08-21 21:17 ` Thomas Gleixner
  1 sibling, 0 replies; 5+ messages in thread
From: Michael Kelley @ 2019-08-21 21:16 UTC (permalink / raw)
  To: vkuznets, linux-hyperv
  Cc: linux-kernel, x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Sasha Levin, Daniel Lezcano, Tianyu Lan, Peter Zijlstra

From: Vitaly Kuznetsov <vkuznets@redhat.com> Sent: Wednesday, August 21, 2019 2:57 AM
> 
> 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/

>   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.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  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(-)
> 
> diff --git a/arch/x86/include/asm/vdso/gettimeofday.h
> b/arch/x86/include/asm/vdso/gettimeofday.h
> index ba71a63cdac4..e9ee139cf29e 100644
> --- a/arch/x86/include/asm/vdso/gettimeofday.h
> +++ b/arch/x86/include/asm/vdso/gettimeofday.h
> @@ -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();
> diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
> index ba2c79e6a0ee..b6083faab540 100644
> --- a/drivers/clocksource/hyperv_timer.c
> +++ b/drivers/clocksource/hyperv_timer.c
> @@ -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)
>  {
> diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig
> index 9a59957922d4..79e5356a737a 100644
> --- a/drivers/hv/Kconfig
> +++ b/drivers/hv/Kconfig
> @@ -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
> diff --git a/include/clocksource/hyperv_timer.h b/include/clocksource/hyperv_timer.h
> index a821deb8ecb2..f72e4619d0a7 100644
> --- a/include/clocksource/hyperv_timer.h
> +++ b/include/clocksource/hyperv_timer.h
> @@ -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 */

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

> 
>  #endif
> --
> 2.20.1

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

Reviewed-by: Michael Kelley <mikelley@microsoft.com>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86/hyper-v: enable TSC page clocksource on 32bit
  2019-08-21  9:56 [PATCH] x86/hyper-v: enable TSC page clocksource on 32bit Vitaly Kuznetsov
  2019-08-21 21:16 ` Michael Kelley
@ 2019-08-21 21:17 ` Thomas Gleixner
  2019-08-21 21:23   ` Thomas Gleixner
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas Gleixner @ 2019-08-21 21:17 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: linux-hyperv, linux-kernel, x86, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, K. Y. Srinivasan, Haiyang Zhang,
	Stephen Hemminger, Sasha Levin, Daniel Lezcano, Michael Kelley,
	Tianyu Lan, Peter Zijlstra

On Wed, 21 Aug 2019, Vitaly Kuznetsov wrote:

> 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

s/allows us/allows/

> as it is now not any different from CONFIG_HYPERV_TIMER.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86/hyper-v: enable TSC page clocksource on 32bit
  2019-08-21 21:17 ` Thomas Gleixner
@ 2019-08-21 21:23   ` Thomas Gleixner
  2019-08-22  7:52     ` Vitaly Kuznetsov
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Gleixner @ 2019-08-21 21:23 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: linux-hyperv, linux-kernel, x86, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, K. Y. Srinivasan, Haiyang Zhang,
	Stephen Hemminger, Sasha Levin, Daniel Lezcano, Michael Kelley,
	Tianyu Lan, Peter Zijlstra

On Wed, 21 Aug 2019, Thomas Gleixner wrote:

> On Wed, 21 Aug 2019, Vitaly Kuznetsov wrote:
> 
> > 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
> 
> s/allows us/allows/
> 
> > as it is now not any different from CONFIG_HYPERV_TIMER.
> > 
> > Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> > ---
> >  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.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86/hyper-v: enable TSC page clocksource on 32bit
  2019-08-21 21:23   ` Thomas Gleixner
@ 2019-08-22  7:52     ` Vitaly Kuznetsov
  0 siblings, 0 replies; 5+ messages in thread
From: Vitaly Kuznetsov @ 2019-08-22  7:52 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-hyperv, linux-kernel, x86, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, K. Y. Srinivasan, Haiyang Zhang,
	Stephen Hemminger, Sasha Levin, Daniel Lezcano, Michael Kelley,
	Tianyu Lan, Peter Zijlstra

Thomas Gleixner <tglx@linutronix.de> writes:

> On Wed, 21 Aug 2019, Thomas Gleixner wrote:
>
>> On Wed, 21 Aug 2019, Vitaly Kuznetsov wrote:
>> 
>> > 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
>> 
>> s/allows us/allows/
>> 
>> > as it is now not any different from CONFIG_HYPERV_TIMER.
>> > 
>> > Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>> > ---
>> >  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.
>
> 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!

-- 
Vitaly

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-22  7:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-21  9:56 [PATCH] x86/hyper-v: enable TSC page clocksource on 32bit Vitaly Kuznetsov
2019-08-21 21:16 ` Michael Kelley
2019-08-21 21:17 ` Thomas Gleixner
2019-08-21 21:23   ` Thomas Gleixner
2019-08-22  7:52     ` Vitaly Kuznetsov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.