sched clock callback should return time with nano second as unit but current hv callback returns time with 100ns. Fix it.
Cc: stable@vger.kernel.org Signed-off-by: Yubo Xie yuboxie@microsoft.com Signed-off-by: Tianyu Lan Tianyu.Lan@microsoft.com Fixes: adb87ff4f96c ("clocksource/drivers/hyperv: Allocate Hyper-V TSC page statically") --- drivers/clocksource/hyperv_timer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index 9d808d595ca8..662ed978fa24 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -343,7 +343,8 @@ static u64 notrace read_hv_clock_tsc_cs(struct clocksource *arg)
static u64 read_hv_sched_clock_tsc(void) { - return read_hv_clock_tsc() - hv_sched_clock_offset; + return (read_hv_clock_tsc() - hv_sched_clock_offset) + * (NSEC_PER_SEC / HV_CLOCK_HZ); }
static void suspend_hv_clock_tsc(struct clocksource *arg) @@ -398,7 +399,8 @@ static u64 notrace read_hv_clock_msr_cs(struct clocksource *arg)
static u64 read_hv_sched_clock_msr(void) { - return read_hv_clock_msr() - hv_sched_clock_offset; + return (read_hv_clock_msr() - hv_sched_clock_offset) + * (NSEC_PER_SEC / HV_CLOCK_HZ); }
static struct clocksource hyperv_cs_msr = {
Yubo Xie ltykernel@gmail.com writes:
sched clock callback should return time with nano second as unit but current hv callback returns time with 100ns. Fix it.
Cc: stable@vger.kernel.org Signed-off-by: Yubo Xie yuboxie@microsoft.com Signed-off-by: Tianyu Lan Tianyu.Lan@microsoft.com Fixes: adb87ff4f96c ("clocksource/drivers/hyperv: Allocate Hyper-V TSC page statically")
I don't think this is the right commit to reference,
commit bd00cd52d5be655a2f217e2ed74b91a71cb2b14f Author: Tianyu Lan Tianyu.Lan@microsoft.com Date: Wed Aug 14 20:32:16 2019 +0800
clocksource/drivers/hyperv: Add Hyper-V specific sched clock function
looks like the one.
drivers/clocksource/hyperv_timer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index 9d808d595ca8..662ed978fa24 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -343,7 +343,8 @@ static u64 notrace read_hv_clock_tsc_cs(struct clocksource *arg) static u64 read_hv_sched_clock_tsc(void) {
- return read_hv_clock_tsc() - hv_sched_clock_offset;
- return (read_hv_clock_tsc() - hv_sched_clock_offset)
* (NSEC_PER_SEC / HV_CLOCK_HZ);
} static void suspend_hv_clock_tsc(struct clocksource *arg) @@ -398,7 +399,8 @@ static u64 notrace read_hv_clock_msr_cs(struct clocksource *arg) static u64 read_hv_sched_clock_msr(void) {
- return read_hv_clock_msr() - hv_sched_clock_offset;
- return (read_hv_clock_msr() - hv_sched_clock_offset)
* (NSEC_PER_SEC / HV_CLOCK_HZ);
}
kvmclock seems to have the same (pre-patch) code ...
static struct clocksource hyperv_cs_msr = {
Hi Vitaly: Thanks for your review.
On 3/24/2020 11:49 PM, Vitaly Kuznetsov wrote:
Yubo Xie ltykernel@gmail.com writes:
sched clock callback should return time with nano second as unit but current hv callback returns time with 100ns. Fix it.
Cc: stable@vger.kernel.org Signed-off-by: Yubo Xie yuboxie@microsoft.com Signed-off-by: Tianyu Lan Tianyu.Lan@microsoft.com Fixes: adb87ff4f96c ("clocksource/drivers/hyperv: Allocate Hyper-V TSC page statically")
I don't think this is the right commit to reference,
commit bd00cd52d5be655a2f217e2ed74b91a71cb2b14f Author: Tianyu Lan Tianyu.Lan@microsoft.com Date: Wed Aug 14 20:32:16 2019 +0800
clocksource/drivers/hyperv: Add Hyper-V specific sched clock function
looks like the one.
Sorry. You are right. Will update in the next version.
drivers/clocksource/hyperv_timer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index 9d808d595ca8..662ed978fa24 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -343,7 +343,8 @@ static u64 notrace read_hv_clock_tsc_cs(struct clocksource *arg) static u64 read_hv_sched_clock_tsc(void) {
- return read_hv_clock_tsc() - hv_sched_clock_offset;
- return (read_hv_clock_tsc() - hv_sched_clock_offset)
}* (NSEC_PER_SEC / HV_CLOCK_HZ);
static void suspend_hv_clock_tsc(struct clocksource *arg) @@ -398,7 +399,8 @@ static u64 notrace read_hv_clock_msr_cs(struct clocksource *arg) static u64 read_hv_sched_clock_msr(void) {
- return read_hv_clock_msr() - hv_sched_clock_offset;
- return (read_hv_clock_msr() - hv_sched_clock_offset)
}* (NSEC_PER_SEC / HV_CLOCK_HZ);
kvmclock seems to have the same (pre-patch) code ...
kvm sched clock gets time from pvclock_clocksource_read() and the time unit is nanosecond. So there is such issue in KVM code.
static struct clocksource hyperv_cs_msr = {
Tianyu Lan ltykernel@gmail.com writes:
@@ -398,7 +399,8 @@ static u64 notrace read_hv_clock_msr_cs(struct clocksource *arg) static u64 read_hv_sched_clock_msr(void) {
- return read_hv_clock_msr() - hv_sched_clock_offset;
- return (read_hv_clock_msr() - hv_sched_clock_offset)
}* (NSEC_PER_SEC / HV_CLOCK_HZ);
kvmclock seems to have the same (pre-patch) code ...
kvm sched clock gets time from pvclock_clocksource_read() and the time unit is nanosecond. So there is such issue in KVM code.
Ah, true, kvmclock is always 1Ghz so it's reading 'naturally' converts to ns.
Hi
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag fixing commit: adb87ff4f96c ("clocksource/drivers/hyperv: Allocate Hyper-V TSC page statically").
The bot has tested the following trees: v5.5.11, v5.4.27.
v5.5.11: Failed to apply! Possible dependencies: 0af3e137c144 ("clocksource/drivers/hyper-v: Untangle stimers and timesync from clocksources") ddc61bbc4501 ("clocksource/drivers/hyper-v: Reserve PAGE_SIZE space for tsc page")
v5.4.27: Failed to apply! Possible dependencies: 0af3e137c144 ("clocksource/drivers/hyper-v: Untangle stimers and timesync from clocksources") ddc61bbc4501 ("clocksource/drivers/hyper-v: Reserve PAGE_SIZE space for tsc page")
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
From: linux-hyperv-owner@vger.kernel.org linux-hyperv-owner@vger.kernel.org On Behalf Of Yubo Xie Sent: Tuesday, March 24, 2020 8:20 AM ... sched clock callback should return time with nano second as unit but current hv callback returns time with 100ns. Fix it.
Hi Yubo, I'm curious how you found the bug? :-) Did you notice some kind of symtom?
Thanks, -- Dexuan
I use "time" to run some performance tests in our project under WSL2, but the result looks weird: the value of "real" is far from the sum of "user" + "sys".
-----Original Message----- From: Dexuan Cui decui@microsoft.com Sent: Wednesday, March 25, 2020 11:46 AM To: Yubo Xie ltykernel@gmail.com; KY Srinivasan kys@microsoft.com; Haiyang Zhang haiyangz@microsoft.com; Stephen Hemminger sthemmin@microsoft.com; Wei Liu liuwe@microsoft.com; daniel.lezcano@linaro.org; tglx@linutronix.de; Michael Kelley mikelley@microsoft.com Cc: Yubo Xie yuboxie@microsoft.com; linux-hyperv@vger.kernel.org; linux-kernel@vger.kernel.org; vkuznets vkuznets@redhat.com; stable@vger.kernel.org; Tianyu Lan Tianyu.Lan@microsoft.com Subject: RE: [PATCH] x86/Hyper-V: Fix hv sched clock function return wrong time unit
From: linux-hyperv-owner@vger.kernel.org linux-hyperv-owner@vger.kernel.org On Behalf Of Yubo Xie Sent: Tuesday, March 24, 2020 8:20 AM ... sched clock callback should return time with nano second as unit but current hv callback returns time with 100ns. Fix it.
Hi Yubo, I'm curious how you found the bug? :-) Did you notice some kind of symtom?
Thanks, -- Dexuan
linux-stable-mirror@lists.linaro.org