* [PATCH] x86/Hyper-V: Fix hv sched clock function return wrong time unit
@ 2020-03-24 15:19 Yubo Xie
2020-03-24 15:49 ` Vitaly Kuznetsov
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Yubo Xie @ 2020-03-24 15:19 UTC (permalink / raw)
To: kys, haiyangz, sthemmin, liuwe, daniel.lezcano, tglx, michael.h.kelley
Cc: Yubo Xie, linux-hyperv, linux-kernel, vkuznets, stable, Tianyu Lan
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 = {
--
2.14.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/Hyper-V: Fix hv sched clock function return wrong time unit
2020-03-24 15:19 [PATCH] x86/Hyper-V: Fix hv sched clock function return wrong time unit Yubo Xie
@ 2020-03-24 15:49 ` Vitaly Kuznetsov
2020-03-25 13:57 ` Tianyu Lan
2020-03-25 1:02 ` Sasha Levin
2020-03-25 18:46 ` Dexuan Cui
2 siblings, 1 reply; 7+ messages in thread
From: Vitaly Kuznetsov @ 2020-03-24 15:49 UTC (permalink / raw)
To: Yubo Xie
Cc: Yubo Xie, linux-hyperv, linux-kernel, stable, Tianyu Lan, kys,
haiyangz, sthemmin, liuwe, daniel.lezcano, tglx,
michael.h.kelley
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 = {
--
Vitaly
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/Hyper-V: Fix hv sched clock function return wrong time unit
2020-03-24 15:19 [PATCH] x86/Hyper-V: Fix hv sched clock function return wrong time unit Yubo Xie
2020-03-24 15:49 ` Vitaly Kuznetsov
@ 2020-03-25 1:02 ` Sasha Levin
2020-03-25 18:46 ` Dexuan Cui
2 siblings, 0 replies; 7+ messages in thread
From: Sasha Levin @ 2020-03-25 1:02 UTC (permalink / raw)
To: Sasha Levin, Yubo Xie, kys, haiyangz, sthemmin
Cc: Yubo Xie, linux-hyperv, stable, stable
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?
--
Thanks
Sasha
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/Hyper-V: Fix hv sched clock function return wrong time unit
2020-03-24 15:49 ` Vitaly Kuznetsov
@ 2020-03-25 13:57 ` Tianyu Lan
2020-03-25 14:28 ` Vitaly Kuznetsov
0 siblings, 1 reply; 7+ messages in thread
From: Tianyu Lan @ 2020-03-25 13:57 UTC (permalink / raw)
To: Vitaly Kuznetsov
Cc: Yubo Xie, linux-hyperv, linux-kernel, stable, Tianyu Lan, kys,
haiyangz, sthemmin, liuwe, daniel.lezcano, tglx,
michael.h.kelley
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 = {
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/Hyper-V: Fix hv sched clock function return wrong time unit
2020-03-25 13:57 ` Tianyu Lan
@ 2020-03-25 14:28 ` Vitaly Kuznetsov
0 siblings, 0 replies; 7+ messages in thread
From: Vitaly Kuznetsov @ 2020-03-25 14:28 UTC (permalink / raw)
To: Tianyu Lan
Cc: Yubo Xie, linux-hyperv, linux-kernel, stable, Tianyu Lan, kys,
haiyangz, sthemmin, liuwe, daniel.lezcano, tglx,
michael.h.kelley
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.
--
Vitaly
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH] x86/Hyper-V: Fix hv sched clock function return wrong time unit
2020-03-24 15:19 [PATCH] x86/Hyper-V: Fix hv sched clock function return wrong time unit Yubo Xie
2020-03-24 15:49 ` Vitaly Kuznetsov
2020-03-25 1:02 ` Sasha Levin
@ 2020-03-25 18:46 ` Dexuan Cui
2020-03-25 18:57 ` Yubo Xie
2 siblings, 1 reply; 7+ messages in thread
From: Dexuan Cui @ 2020-03-25 18:46 UTC (permalink / raw)
To: Yubo Xie, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
Wei Liu, daniel.lezcano, tglx, Michael Kelley
Cc: Yubo Xie, linux-hyperv, linux-kernel, vkuznets, stable, Tianyu Lan
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH] x86/Hyper-V: Fix hv sched clock function return wrong time unit
2020-03-25 18:46 ` Dexuan Cui
@ 2020-03-25 18:57 ` Yubo Xie
0 siblings, 0 replies; 7+ messages in thread
From: Yubo Xie @ 2020-03-25 18:57 UTC (permalink / raw)
To: Dexuan Cui, Yubo Xie, KY Srinivasan, Haiyang Zhang,
Stephen Hemminger, Wei Liu, daniel.lezcano, tglx, Michael Kelley
Cc: linux-hyperv, linux-kernel, vkuznets, stable, Tianyu Lan
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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-03-25 18:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-24 15:19 [PATCH] x86/Hyper-V: Fix hv sched clock function return wrong time unit Yubo Xie
2020-03-24 15:49 ` Vitaly Kuznetsov
2020-03-25 13:57 ` Tianyu Lan
2020-03-25 14:28 ` Vitaly Kuznetsov
2020-03-25 1:02 ` Sasha Levin
2020-03-25 18:46 ` Dexuan Cui
2020-03-25 18:57 ` Yubo Xie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).