clocksource/drivers: Create new Hyper-V clocksource driver
v5 cover clocksource/drivers: Create new Hyper-V clocksource driver
This patch series moves Hyper-V clock/timer code to a separate Hyper-V clocksource driver. Previously, Hyper-V clock/timer code and data structures were mixed in with other Hyper-V code in the ISA independent drivers/hv code as well as in ISA dependent code. The new Hyper-V clocksource driver is ISA agnostic, with a just few dependencies on ISA specific functions. The patch series does not change any behavior or functionality -- it only reorganizes the existing code and fixes up the linkages. A few places outside of Hyper-V code are fixed up to use the new #include file structure.
This restructuring is in response to Marc Zyngier's review comments on supporting Hyper-V running on ARM64, and is a good idea in general. It increases the amount of code shared between the x86 and ARM64 architectures, and reduces the size of the new code for supporting Hyper-V on ARM64. A new version of the Hyper-V on ARM64 patches will follow once this clocksource restructuring is accepted.
The code is diff'ed against the upstream tip tree:git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/vdso
Changes in v5:
* Revised commit summaries [Thomas Gleixner]
* Removed call to clockevents_unbind_device() [Thomas Gleixner]
* Restructured hv_init_clocksource() [Thomas Gleixner]
* Various other small code cleanups [Thomas Gleixner]
Changes in v4:
* Revised commit messages
* Rebased to upstream tip tree
Changes in v3:
* Removed boolean argument to hv_init_clocksource(). Always call sched_clock_register, which is needed on ARM64 but a no-op on x86.
* Removed separate cpuhp setup in hv_stimer_alloc() and instead directly call hv_stimer_init() and hv_stimer_cleanup() from corresponding VMbus functions. This more closely matches original code and avoids clocksource stop/restart problems on ARM64 when VMbus code denies CPU offlining request.
Changes in v2:
* Revised commit short descriptions so the distinction between the first and second patches is clearer [GregKH]
* Renamed new clocksource driver files and functions to use existing "timer" and "stimer" names instead of introducing "syntimer". [Vitaly Kuznetsov]
* Introduced CONFIG_HYPER_TIMER to fix build problem when CONFIG_HYPERV=m [Vitaly Kuznetsov]
* Added "Suggested-by: Marc Zyngier"
Michael Kelley (2):
clocksource/drivers: Make Hyper-V clocksource ISA agnostic clocksource/drivers: Continue making Hyper-V clocksource ISA agnostic
MAINTAINERS | 2 + arch/x86/entry/vdso/vma.c | 2 +- arch/x86/hyperv/hv_init.c | 91 +-------- arch/x86/include/asm/hyperv-tlfs.h | 6 + arch/x86/include/asm/mshyperv.h | 81 +------- arch/x86/include/asm/vdso/gettimeofday.h | 2 +- arch/x86/kernel/cpu/mshyperv.c | 4 +- arch/x86/kvm/x86.c | 1 + drivers/clocksource/Makefile | 1 + drivers/clocksource/hyperv_timer.c | 339 +++++++++++++++++++++++++++++++ drivers/hv/Kconfig | 3 + drivers/hv/hv.c | 156 +------------- drivers/hv/hv_util.c | 1 + drivers/hv/hyperv_vmbus.h | 3 - drivers/hv/vmbus_drv.c | 42 ++-- include/clocksource/hyperv_timer.h | 105 ++++++++++ 16 files changed, 503 insertions(+), 336 deletions(-) create mode 100644 drivers/clocksource/hyperv_timer.c create mode 100644 include/clocksource/hyperv_timer.h
Signature · 1 line
1.8.3.1
PATCH v5 1/2 clocksource/drivers: Make Hyper-V clocksource ISA agnostic
Hyper-V clock/timer code and data structures are currently mixed in with other code in the ISA independent drivers/hv directory as well as the ISA dependent Hyper-V code under arch/x86. Consolidate this code and data structures into a Hyper-V clocksource driver to better follow the Linux model. In doing so, separate out the ISA dependent portions so the new clocksource driver works for x86 and for the in-process Hyper-V on ARM64 code.
To start, move the existing clockevents code to create the new clocksource driver. Update the VMbus driver to call initialization and cleanup routines since the Hyper-V synthetic timers are not independently enumerated in ACPI.
No behavior is changed and no new functionality is added.
--- MAINTAINERS | 2 + arch/x86/include/asm/hyperv-tlfs.h | 6 ++ arch/x86/kernel/cpu/mshyperv.c | 4 +- drivers/clocksource/Makefile | 1 + drivers/clocksource/hyperv_timer.c | 200 +++++++++++++++++++++++++++++++++++++ drivers/hv/Kconfig | 3 + drivers/hv/hv.c | 156 +---------------------------- drivers/hv/hyperv_vmbus.h | 3 - drivers/hv/vmbus_drv.c | 42 ++++---- include/clocksource/hyperv_timer.h | 27 +++++ 10 files changed, 268 insertions(+), 176 deletions(-) create mode 100644 drivers/clocksource/hyperv_timer.c create mode 100644 include/clocksource/hyperv_timer.h
MAINTAINERS +2 -0
@@ -7313,6 +7313,7 @@ F: arch/x86/include/asm/trace/hyperv.h F: arch/x86/include/asm/hyperv-tlfs.h F: arch/x86/kernel/cpu/mshyperv.c F: arch/x86/hyperv +F: drivers/clocksource/hyperv_timer.c F: drivers/hid/hid-hyperv.c F: drivers/hv/ F: drivers/input/serio/hyperv-keyboard.c
@@ -7323,6 +7324,7 @@ F: drivers/uio/uio_hv_generic.c F: drivers/video/fbdev/hyperv_fb.c F: drivers/iommu/hyperv_iommu.c F: net/vmw_vsock/hyperv_transport.c +F: include/clocksource/hyperv_timer.h F: include/linux/hyperv.h F: include/uapi/linux/hyperv.h F: tools/hv/
arch/x86/include/asm/hyperv-tlfs.h +6 -0
@@ -401,6 +401,12 @@ enum HV_GENERIC_SET_FORMAT {#define HV_STATUS_INVALID_CONNECTION_ID 18#define HV_STATUS_INSUFFICIENT_BUFFERS 19 +/* +* The Hyper-V TimeRefCount register and the TSC +* page provide a guest VM clock with 100ns tick rate +*/ +#define HV_CLOCK_HZ (NSEC_PER_SEC/100) + typedef struct _HV_REFERENCE_TSC_PAGE { __u32 tsc_sequence; __u32 res1;
arch/x86/kernel/cpu/mshyperv.c +3 -1
@@ -17,6 +17,7 @@#include <linux/irq.h> #include <linux/kexec.h> #include <linux/i8253.h> +#include <linux/random.h> #include <asm/processor.h> #include <asm/hypervisor.h> #include <asm/hyperv-tlfs.h>
@@ -80,6 +81,7 @@ __visible void __irq_entry hv_stimer0_vector_handler(struct pt_regs *regs)inc_irq_stat (hyperv_stimer0_count);if (hv_stimer0_handler)hv_stimer0_handler (); +add_interrupt_randomness (HYPERV_STIMER0_VECTOR ,0 );ack_APIC_irq ();exiting_irq ();
@@ -89,7 +91,7 @@ __visible void __irq_entry hv_stimer0_vector_handler(struct pt_regs *regs)int hv_setup_stimer0_irq (int *irq,int *vector,void (*handler)(void )) { *vector =HYPERV_STIMER0_VECTOR ; - *irq =0 ;/* Unused on x86/x64 */ + *irq =-1 ;/* Unused on x86/x64 */ hv_stimer0_handler = handler;return 0 ; }
drivers/clocksource/Makefile +1 -0
@@ -84,3 +84,4 @@ obj-$(CONFIG_ATCPIT100_TIMER) += timer-atcpit100.o obj-$(CONFIG_RISCV_TIMER) += timer-riscv.o obj-$(CONFIG_CSKY_MP_TIMER) += timer-mp-csky.o obj-$(CONFIG_GX6605S_TIMER) += timer-gx6605s.o +obj-$(CONFIG_HYPERV_TIMER) += hyperv_timer.o
drivers/clocksource/hyperv_timer.c new file +200 -0
200 lines not on this page · raw message
drivers/hv/Kconfig +3 -0
@@ -10,6 +10,9 @@ config HYPERV Select this option to run Linux as a Hyper-V client operating system. +config HYPERV_TIMER + def_bool HYPERV + config HYPERV_TSCPAGE def_bool HYPERV && X86_64
drivers/hv/hv.c +4 -152
211 lines not on this page · raw message
drivers/hv/hyperv_vmbus.h +0 -3
@@ -138,7 +138,6 @@ struct hv_per_cpu_context {* per-cpu list of the channels based on their CPU affinity. */ struct list_head chan_list; -struct clock_event_device *clk_evt; };struct hv_context {
@@ -176,8 +175,6 @@ extern int hv_post_message(union hv_connection_id connection_id,extern int hv_synic_cleanup (unsigned int cpu); -extern void hv_synic_clockevents_cleanup (void ); -/* Interface */ void hv_ringbuffer_pre_init (struct vmbus_channel *channel);
drivers/hv/vmbus_drv.c +22 -20
101 lines not on this page · raw message
include/clocksource/hyperv_timer.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Definitions for the clocksource provided by the Hyper-V +* hypervisor to guest VMs, as described in the Hyper-V Top +* Level Functional Spec (TLFS). +* +* Copyright (C) 2019, Microsoft, Inc. +* +* Author: Michael Kelley <[email protected]> +*/ + +#ifndef __CLKSOURCE_HYPERV_TIMER_H +#define __CLKSOURCE_HYPERV_TIMER_H + +#define HV_MAX_MAX_DELTA_TICKS 0xffffffff +#define HV_MIN_DELTA_TICKS 1 + +/* Routines called by the VMbus driver */ +extern int hv_stimer_alloc (int sint); +extern void hv_stimer_free (void ); +extern void hv_stimer_init (unsigned int cpu); +extern void hv_stimer_cleanup (unsigned int cpu); +extern void hv_stimer_global_cleanup (void ); +extern void hv_stimer0_isr (void ); + +#endif
Signature · 1 line
1.8.3.1
tip-bot for Michael Kelley
merge bot[tip:timers/core] clocksource/drivers: Make Hyper-V clocksource ISA agnostic
clocksource/drivers: Make Hyper-V clocksource ISA agnostic
Commit-ID: fd1fea6834d0f9f93062ae6685862908a9baed39 Gitweb: https://git.kernel.org/tip/fd1fea6834d0f9f93062ae6685862908a9baed39 Author: Michael Kelley <[email protected]> AuthorDate: Mon, 1 Jul 2019 04:25:56 +0000 Committer: Thomas Gleixner <[email protected]> CommitDate: Wed, 3 Jul 2019 11:00:59 +0200
clocksource/drivers: Make Hyper-V clocksource ISA agnostic
Hyper-V clock/timer code and data structures are currently mixed in with other code in the ISA independent drivers/hv directory as well as the ISA dependent Hyper-V code under arch/x86.
Consolidate this code and data structures into a Hyper-V clocksource driver to better follow the Linux model. In doing so, separate out the ISA dependent portions so the new clocksource driver works for x86 and for the in-process Hyper-V on ARM64 code.
To start, move the existing clockevents code to create the new clocksource driver. Update the VMbus driver to call initialization and cleanup routines since the Hyper-V synthetic timers are not independently enumerated in ACPI.
No behavior is changed and no new functionality is added.
--- MAINTAINERS | 2 + arch/x86/include/asm/hyperv-tlfs.h | 6 ++ arch/x86/kernel/cpu/mshyperv.c | 4 +- drivers/clocksource/Makefile | 1 + drivers/clocksource/hyperv_timer.c | 200 +++++++++++++++++++++++++++++++++++++ drivers/hv/Kconfig | 3 + drivers/hv/hv.c | 156 +---------------------------- drivers/hv/hyperv_vmbus.h | 3 - drivers/hv/vmbus_drv.c | 42 ++++---- include/clocksource/hyperv_timer.h | 27 +++++ 10 files changed, 268 insertions(+), 176 deletions(-)
MAINTAINERS +2 -0
@@ -7313,6 +7313,7 @@ F: arch/x86/include/asm/trace/hyperv.h F: arch/x86/include/asm/hyperv-tlfs.h F: arch/x86/kernel/cpu/mshyperv.c F: arch/x86/hyperv +F: drivers/clocksource/hyperv_timer.c F: drivers/hid/hid-hyperv.c F: drivers/hv/ F: drivers/input/serio/hyperv-keyboard.c
@@ -7323,6 +7324,7 @@ F: drivers/uio/uio_hv_generic.c F: drivers/video/fbdev/hyperv_fb.c F: drivers/iommu/hyperv_iommu.c F: net/vmw_vsock/hyperv_transport.c +F: include/clocksource/hyperv_timer.h F: include/linux/hyperv.h F: include/uapi/linux/hyperv.h F: tools/hv/
arch/x86/include/asm/hyperv-tlfs.h +6 -0
@@ -401,6 +401,12 @@ enum HV_GENERIC_SET_FORMAT {#define HV_STATUS_INVALID_CONNECTION_ID 18#define HV_STATUS_INSUFFICIENT_BUFFERS 19 +/* +* The Hyper-V TimeRefCount register and the TSC +* page provide a guest VM clock with 100ns tick rate +*/ +#define HV_CLOCK_HZ (NSEC_PER_SEC/100) + typedef struct _HV_REFERENCE_TSC_PAGE { __u32 tsc_sequence; __u32 res1;
arch/x86/kernel/cpu/mshyperv.c +3 -1
@@ -17,6 +17,7 @@#include <linux/irq.h> #include <linux/kexec.h> #include <linux/i8253.h> +#include <linux/random.h> #include <asm/processor.h> #include <asm/hypervisor.h> #include <asm/hyperv-tlfs.h>
@@ -80,6 +81,7 @@ __visible void __irq_entry hv_stimer0_vector_handler(struct pt_regs *regs)inc_irq_stat (hyperv_stimer0_count);if (hv_stimer0_handler)hv_stimer0_handler (); +add_interrupt_randomness (HYPERV_STIMER0_VECTOR ,0 );ack_APIC_irq ();exiting_irq ();
@@ -89,7 +91,7 @@ __visible void __irq_entry hv_stimer0_vector_handler(struct pt_regs *regs)int hv_setup_stimer0_irq (int *irq,int *vector,void (*handler)(void )) { *vector =HYPERV_STIMER0_VECTOR ; - *irq =0 ;/* Unused on x86/x64 */ + *irq =-1 ;/* Unused on x86/x64 */ hv_stimer0_handler = handler;return 0 ; }
drivers/clocksource/Makefile +1 -0
@@ -86,3 +86,4 @@ obj-$(CONFIG_ATCPIT100_TIMER) += timer-atcpit100.o obj-$(CONFIG_RISCV_TIMER) += timer-riscv.o obj-$(CONFIG_CSKY_MP_TIMER) += timer-mp-csky.o obj-$(CONFIG_GX6605S_TIMER) += timer-gx6605s.o +obj-$(CONFIG_HYPERV_TIMER) += hyperv_timer.o
drivers/clocksource/hyperv_timer.c new file +200 -0
200 lines not on this page · raw message
drivers/hv/Kconfig +3 -0
@@ -10,6 +10,9 @@ config HYPERV Select this option to run Linux as a Hyper-V client operating system. +config HYPERV_TIMER + def_bool HYPERV + config HYPERV_TSCPAGE def_bool HYPERV && X86_64
drivers/hv/hv.c +4 -152
211 lines not on this page · raw message
drivers/hv/hyperv_vmbus.h +0 -3
@@ -138,7 +138,6 @@ struct hv_per_cpu_context {* per-cpu list of the channels based on their CPU affinity. */ struct list_head chan_list; -struct clock_event_device *clk_evt; };struct hv_context {
@@ -176,8 +175,6 @@ extern int hv_synic_init(unsigned int cpu);extern int hv_synic_cleanup (unsigned int cpu); -extern void hv_synic_clockevents_cleanup (void ); -/* Interface */ void hv_ringbuffer_pre_init (struct vmbus_channel *channel);
drivers/hv/vmbus_drv.c +22 -20
101 lines not on this page · raw message
include/clocksource/hyperv_timer.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Definitions for the clocksource provided by the Hyper-V +* hypervisor to guest VMs, as described in the Hyper-V Top +* Level Functional Spec (TLFS). +* +* Copyright (C) 2019, Microsoft, Inc. +* +* Author: Michael Kelley <[email protected]> +*/ + +#ifndef __CLKSOURCE_HYPERV_TIMER_H +#define __CLKSOURCE_HYPERV_TIMER_H + +#define HV_MAX_MAX_DELTA_TICKS 0xffffffff +#define HV_MIN_DELTA_TICKS 1 + +/* Routines called by the VMbus driver */ +extern int hv_stimer_alloc (int sint); +extern void hv_stimer_free (void ); +extern void hv_stimer_init (unsigned int cpu); +extern void hv_stimer_cleanup (unsigned int cpu); +extern void hv_stimer_global_cleanup (void ); +extern void hv_stimer0_isr (void ); + +#endif
Dexuan Cui
maintainerRE: [tip:timers/core] clocksource/drivers: Make Hyper-V clocksource ISA agnostic
Quoted 21 lines
From: [email protected] <[email protected]> On Behalf Of tip-bot for Michael Kelley
Sent: Wednesday, July 3, 2019 2:07 AM
clocksource/drivers: Make Hyper-V clocksource ISA agnosticHyper-V clock/timer code and data structures are currently mixed in with other code in the ISA independent
drivers/hvdirectory as well as the ISA dependent Hyper-V code underarch/x86.Consolidate this code and data structures into a Hyper-V clocksource driver to better follow the Linux model. In doing so, separate out the ISA dependent portions so the new clocksource driver works for x86 and for the in-process Hyper-V on ARM64 code.
To start, move the existing clockevents code to create the new clocksource driver. Update the VMbus driver to call initialization and cleanup routines since the Hyper-V synthetic timers are not independently enumerated in ACPI.
No behavior is changed and no new functionality is added.
...
drivers/clocksource/hyperv_timer.c line 142
Quoted 10 lines
drivers/clocksource/hyperv_timer.c new file +10
-0+void hv_stimer_cleanup (unsigned int cpu) +{ +struct clock_event_device *ce; + +/* Turn off clockevent device */ +if (ms_hyperv.features &HV_MSR_SYNTIMER_AVAILABLE ) { + ce =per_cpu_ptr (hv_clock_event, cpu); +hv_ce_shutdown (ce); + } +}
Actually, there is a behavior change (see https://lkml.org/lkml/2019/7/1/9):
Removed call to clockevents_unbind_device() [Thomas Gleixner]
and this breaks my ongoing work of Linux guest hibernation on Hyper-V. :-(
I guess Thomas suggested we remove the call because the clockevent device can be automatically cleaned up in tick_cleanup_dead_cpu(), when a CPU is offlined? BTW, I didn't find Thomas's mail suggesting the change.
In the case of hibernation, this is not true for CPU0, because tick_cleanup_dead_cpu() is not called for CPU0. As a result, when the system resumes from hibernation, we add the same clock_event_device into the global list clockevent_devices twice in hv_stimer_init(0) -> clockevents_config_and_register() for CPU0, causing unexpected behaviors...
Should we call clockevents_unbind_device() or tick_cleanup_dead_cpu() somewher for CPU0, in the case of hibernation?
Or, in clockevents_config_and_register(), should we not add the event device, if it's already in the global list?
Thanks,
-- Dexuan
RE: [tip:timers/core] clocksource/drivers: Make Hyper-V clocksource ISA agnostic
Quoted 23 lines · Dexuan Cui
Quoted 4 lines
From: [email protected] <[email protected]> On Behalf Of tip-bot for Michael Kelley No behavior is changed and no new functionality is added.
...drivers/clocksource/hyperv_timer.c line 142
Quoted 10 lines
drivers/clocksource/hyperv_timer.c new file +10
-0+void hv_stimer_cleanup (unsigned int cpu) +{ +struct clock_event_device *ce; + +/* Turn off clockevent device */ +if (ms_hyperv.features &HV_MSR_SYNTIMER_AVAILABLE ) { + ce =per_cpu_ptr (hv_clock_event, cpu); +hv_ce_shutdown (ce); + } +}Actually, there is a behavior change (see https://lkml.org/lkml/2019/7/1/9):
Removed call toclockevents_unbind_device()[Thomas Gleixner]
and this breaks my ongoing work of Linux guest hibernation on Hyper-V. :-(I guess Thomas suggested we remove the call because the clockevent device can be automatically cleaned up in
tick_cleanup_dead_cpu(), when a CPU is offlined? BTW, I didn't find Thomas's mail suggesting the change.
Quoted 6 lines
In the case of hibernation, this is not true for CPU0, because
tick_cleanup_dead_cpu()is not called for CPU0. As a result, when the system resumes from hibernation, we add the sameclock_event_deviceinto the global listclockevent_devicestwice inhv_stimer_init(0)->clockevents_config_and_register()for CPU0, causing unexpected behaviors...
The way this is normally done is to suspend the clockevent device on hibernation and resume it when coming back. From a kernel POV resume is really different than boot.
But that needs probably more surgery. I'll add the unbind() call back for now.
Thanks,
tglx
RE: [tip:timers/core] clocksource/drivers: Make Hyper-V clocksource ISA agnostic
Quoted 31 lines · Thomas Gleixner
Quoted 23 lines · Dexuan Cui
Quoted 4 lines
From: [email protected] <[email protected]> On Behalf Of tip-bot for Michael Kelley No behavior is changed and no new functionality is added.
...drivers/clocksource/hyperv_timer.c line 142
Quoted 10 lines
drivers/clocksource/hyperv_timer.c new file +10
-0+void hv_stimer_cleanup (unsigned int cpu) +{ +struct clock_event_device *ce; + +/* Turn off clockevent device */ +if (ms_hyperv.features &HV_MSR_SYNTIMER_AVAILABLE ) { + ce =per_cpu_ptr (hv_clock_event, cpu); +hv_ce_shutdown (ce); + } +}Actually, there is a behavior change (see https://lkml.org/lkml/2019/7/1/9):
Removed call toclockevents_unbind_device()[Thomas Gleixner]
and this breaks my ongoing work of Linux guest hibernation on Hyper-V. :-(I guess Thomas suggested we remove the call because the clockevent device can be automatically cleaned up in
tick_cleanup_dead_cpu(), when a CPU is offlined? BTW, I didn't find Thomas's mail suggesting the change.Quoted 6 lines
In the case of hibernation, this is not true for CPU0, because
tick_cleanup_dead_cpu()is not called for CPU0. As a result, when the system resumes from hibernation, we add the sameclock_event_deviceinto the global listclockevent_devicestwice inhv_stimer_init(0)->clockevents_config_and_register()for CPU0, causing unexpected behaviors...
Quoted 6 lines
The way this is normally done is to suspend the clockevent device on hibernation and resume it when coming back. From a kernel POV resume is really different than boot.
But that needs probably more surgery. I'll add the
unbind()call back for now.
Second thoughts. As it was just on top of the branch, I dropped the two patches and we can sort it out for 5.4 without a hurry.
Thanks,
tglx
Dexuan Cui
maintainerRE: [tip:timers/core] clocksource/drivers: Make Hyper-V clocksource ISA agnostic
Quoted 26 lines
From: Thomas Gleixner <[email protected]>
Sent: Saturday, July 6, 2019 1:34 AMQuoted 3 lines · Thomas Gleixner
Quoted 2 lines · Dexuan Cui
Quoted 2 lines
From: [email protected] <[email protected]> On Behalf Of tip-bot for Michael
Kelley
Quoted 17 lines
Quoted 17 lines
drivers/clocksource/hyperv_timer.c line 142
Quoted 12 lines
No behavior is changed and no new functionality is added.
...drivers/clocksource/hyperv_timer.c new file +10
-0+void hv_stimer_cleanup (unsigned int cpu) +{ +struct clock_event_device *ce; + +/* Turn off clockevent device */ +if (ms_hyperv.features &HV_MSR_SYNTIMER_AVAILABLE ) { + ce =per_cpu_ptr (hv_clock_event, cpu); +hv_ce_shutdown (ce); + } +}Actually, there is a behavior change (see ...):
Removed call toclockevents_unbind_device()[Thomas Gleixner]
and this breaks my ongoing work of Linux guest hibernation on Hyper-V. :-(
Quoted 15 lines
Quoted 1 line
Quoted 1 line
I guess Thomas suggested we remove the call because the clockevent
device
Quoted 13 lines
Quoted 9 lines
can be automatically cleaned up in
tick_cleanup_dead_cpu(), when a CPU is offlined? BTW, I didn't find Thomas's mail suggesting the change.In the case of hibernation, this is not true for CPU0, because
tick_cleanup_dead_cpu()is not called for CPU0. As a result, when the system resumes from hibernation, we add the sameclock_event_deviceinto the global listclockevent_devicestwice inhv_stimer_init(0)->clockevents_config_and_register()for CPU0, causing unexpected behaviors...The way this is normally done is to suspend the clockevent device on hibernation and resume it when coming back. From a kernel POV resume is really different than boot.
Hi Thomas,
Thanks for the important reminder! I realized actually Michael's patches are good, and hibernation can not work because my own hibernation code is buggy:
in the resume path, on CPU0, I should NOT call hv_stimer_init() -> clockevents_config_and_register(): instead, I should use the event device's suspend/resume callbacks to save/restore the device's state.
With this kept in mind, I made some small changes to my code and hibernation can work fine for me now!
Quoted 2 lines
Quoted 2 lines
But that needs probably more surgery. I'll add the
unbind()call back for now.
Can you please drop the unbind() call again? :-)
I realized we don't really need it, and hibernation can work for me without it. I checked the related functions in detail: tick_cleanup_dead_cpu(), timekeeping_suspend() and timekeeping_resume(), and I think the unbind() call is indeed unnecessary.
I also checked the CPU offlining scenario, and I think the unbind() call is also unnecessary.
Quoted 4 lines
Second thoughts. As it was just on top of the branch, I dropped the two patches and we can sort it out for 5.4 without a hurry.
tglx
Hmm, I'm sorry for providing misleading info in my previous mail. IMHO I really think the 2 patches are good. They have been there quite a while and it's already the 5th version. I hope they can be in 5.3-rc1 so life would be a lot easier for everyone. :-) Especially, my hiberation work has been rebased onto the 2 patches; if they can not be in 5.3, I'll have to rebase my code again and once my code is accepted, it would make it harder to rebase the 2 patches.
May I know if there is any concern about the 2 patches? If yes, I definitely want to help sort it out now.
Thanks,
-- Dexuan
RE: [tip:timers/core] clocksource/drivers: Make Hyper-V clocksource ISA agnostic
Quoted 8 lines · Dexuan Cui
Quoted 1 line · Thomas Gleixner
Hi Thomas,
Thanks for the important reminder! I realized actually Michael's patches are good, and hibernation can not work because my own hibernation code is buggy:
in the resume path, on CPU0, I should NOT callhv_stimer_init()->clockevents_config_and_register(): instead, I should use the event device's suspend/resume callbacks to save/restore the device's state.
Quoted 7 lines
With this kept in mind, I made some small changes to my code and hibernation can work fine for me now!
Quoted 2 lines
Quoted 2 lines
But that needs probably more surgery. I'll add the
unbind()call back for now.Can you please drop the
unbind()call again? :-)
I restored the original commits without the unbind. All good now :)
PATCH v5 2/2 clocksource/drivers: Continue making Hyper-V clocksource ISA agnostic
In reply to Michael KelleyContinue consolidating Hyper-V clock and timer code into an ISA independent Hyper-V clocksource driver. Move the existing clocksource code under drivers/hv and arch/x86 to the new clocksource driver while separating out the ISA dependencies. Update Hyper-V initialization to call initialization and cleanup routines since the Hyper-V synthetic clock is not independently enumerated in ACPI. Update Hyper-V clocksource users in KVM and VDSO to get definitions from a new include file.
No behavior is changed and no new functionality is added.
--- arch/x86/entry/vdso/vma.c | 2 +- arch/x86/hyperv/hv_init.c | 91 +------------------- arch/x86/include/asm/mshyperv.h | 81 +++--------------- arch/x86/include/asm/vdso/gettimeofday.h | 2 +- arch/x86/kvm/x86.c | 1 + drivers/clocksource/hyperv_timer.c | 139 +++++++++++++++++++++++++++++++ drivers/hv/hv_util.c | 1 + include/clocksource/hyperv_timer.h | 78 +++++++++++++++++ 8 files changed, 235 insertions(+), 160 deletions(-)
arch/x86/entry/vdso/vma.c +1 -1
@@ -22,7 +22,7 @@#include <asm/page.h> #include <asm/desc.h> #include <asm/cpufeature.h> -#include <asm/mshyperv.h> +#include <clocksource/hyperv_timer.h> #if defined(CONFIG_X86_64 )unsigned int __read_mostly vdso64_enabled =1 ;
arch/x86/hyperv/hv_init.c +3 -88
109 lines not on this page · raw message
arch/x86/include/asm/mshyperv.h +11 -70
97 lines not on this page · raw message
arch/x86/include/asm/vdso/gettimeofday.h +1 -1
@@ -18,7 +18,7 @@#include <asm/unistd.h> #include <asm/msr.h> #include <asm/pvclock.h> -#include <asm/mshyperv.h> +#include <clocksource/hyperv_timer.h> #define __vdso_data (VVAR(_vdso_data))
arch/x86/kvm/x86.c +1 -0
@@ -67,6 +67,7 @@#include <asm/mshyperv.h> #include <asm/hypervisor.h> #include <asm/intel_pt.h> +#include <clocksource/hyperv_timer.h> #define CREATE_TRACE_POINTS #include "trace.h"
drivers/clocksource/hyperv_timer.c +139 -0
148 lines not on this page · raw message
drivers/hv/hv_util.c +1 -0
@@ -17,6 +17,7 @@#include <linux/hyperv.h> #include <linux/clockchips.h> #include <linux/ptp_clock_kernel.h> +#include <clocksource/hyperv_timer.h> #include <asm/mshyperv.h> #include "hyperv_vmbus.h"
include/clocksource/hyperv_timer.h +78 -0
88 lines not on this page · raw message
Signature · 1 line
1.8.3.1
tip-bot for Michael Kelley
merge bot[tip:timers/core] clocksource/drivers: Continue making Hyper-V clocksource ISA agnostic
clocksource/drivers: Continue making Hyper-V clocksource ISA agnostic
Commit-ID: dd2cb348613b44f9d948b068775e159aad298599 Gitweb: https://git.kernel.org/tip/dd2cb348613b44f9d948b068775e159aad298599 Author: Michael Kelley <[email protected]> AuthorDate: Mon, 1 Jul 2019 04:26:06 +0000 Committer: Thomas Gleixner <[email protected]> CommitDate: Wed, 3 Jul 2019 11:00:59 +0200
clocksource/drivers: Continue making Hyper-V clocksource ISA agnostic
Continue consolidating Hyper-V clock and timer code into an ISA independent Hyper-V clocksource driver.
Move the existing clocksource code under drivers/hv and arch/x86 to the new clocksource driver while separating out the ISA dependencies. Update Hyper-V initialization to call initialization and cleanup routines since the Hyper-V synthetic clock is not independently enumerated in ACPI.
Update Hyper-V clocksource users in KVM and VDSO to get definitions from the new include file.
No behavior is changed and no new functionality is added.
--- arch/x86/entry/vdso/vma.c | 2 +- arch/x86/hyperv/hv_init.c | 91 +------------------- arch/x86/include/asm/mshyperv.h | 81 +++--------------- arch/x86/include/asm/vdso/gettimeofday.h | 2 +- arch/x86/kvm/x86.c | 1 + drivers/clocksource/hyperv_timer.c | 139 +++++++++++++++++++++++++++++++ drivers/hv/hv_util.c | 1 + include/clocksource/hyperv_timer.h | 80 ++++++++++++++++++ 8 files changed, 237 insertions(+), 160 deletions(-)
arch/x86/entry/vdso/vma.c +1 -1
@@ -22,7 +22,7 @@#include <asm/page.h> #include <asm/desc.h> #include <asm/cpufeature.h> -#include <asm/mshyperv.h> +#include <clocksource/hyperv_timer.h> #if defined(CONFIG_X86_64 )unsigned int __read_mostly vdso64_enabled =1 ;
arch/x86/hyperv/hv_init.c +3 -88
109 lines not on this page · raw message
arch/x86/include/asm/mshyperv.h +11 -70
97 lines not on this page · raw message
arch/x86/include/asm/vdso/gettimeofday.h +1 -1
@@ -18,7 +18,7 @@#include <asm/unistd.h> #include <asm/msr.h> #include <asm/pvclock.h> -#include <asm/mshyperv.h> +#include <clocksource/hyperv_timer.h> #define __vdso_data (VVAR(_vdso_data))
arch/x86/kvm/x86.c +1 -0
@@ -67,6 +67,7 @@#include <asm/mshyperv.h> #include <asm/hypervisor.h> #include <asm/intel_pt.h> +#include <clocksource/hyperv_timer.h> #define CREATE_TRACE_POINTS #include "trace.h"
drivers/clocksource/hyperv_timer.c +139 -0
148 lines not on this page · raw message
drivers/hv/hv_util.c +1 -0
@@ -17,6 +17,7 @@#include <linux/hyperv.h> #include <linux/clockchips.h> #include <linux/ptp_clock_kernel.h> +#include <clocksource/hyperv_timer.h> #include <asm/mshyperv.h> #include "hyperv_vmbus.h"
include/clocksource/hyperv_timer.h +80 -0
90 lines not on this page · raw message