public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: use unified time type for comparison
@ 2023-07-31  2:24 Bibo Mao
  2023-08-02 19:30 ` Sean Christopherson
  2023-08-02 21:11 ` Sean Christopherson
  0 siblings, 2 replies; 4+ messages in thread
From: Bibo Mao @ 2023-07-31  2:24 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini
  Cc: Shuah Khan, kvm, linux-kselftest, linux-kernel

With test case kvm_page_table_test, start time is acquired with
time type CLOCK_MONOTONIC_RAW, however end time in function timespec_elapsed
is acquired with time type CLOCK_MONOTONIC. This will cause
inaccurate elapsed time calculation on some platform such as LoongArch.

This patch modified test case kvm_page_table_test, and uses unified
time type CLOCK_MONOTONIC for start time.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 tools/testing/selftests/kvm/kvm_page_table_test.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c b/tools/testing/selftests/kvm/kvm_page_table_test.c
index b3b00be1ef82..69f26d80c821 100644
--- a/tools/testing/selftests/kvm/kvm_page_table_test.c
+++ b/tools/testing/selftests/kvm/kvm_page_table_test.c
@@ -200,7 +200,7 @@ static void *vcpu_worker(void *data)
 		if (READ_ONCE(host_quit))
 			return NULL;
 
-		clock_gettime(CLOCK_MONOTONIC_RAW, &start);
+		clock_gettime(CLOCK_MONOTONIC, &start);
 		ret = _vcpu_run(vcpu);
 		ts_diff = timespec_elapsed(start);
 
@@ -367,7 +367,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	/* Test the stage of KVM creating mappings */
 	*current_stage = KVM_CREATE_MAPPINGS;
 
-	clock_gettime(CLOCK_MONOTONIC_RAW, &start);
+	clock_gettime(CLOCK_MONOTONIC, &start);
 	vcpus_complete_new_stage(*current_stage);
 	ts_diff = timespec_elapsed(start);
 
@@ -380,7 +380,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 
 	*current_stage = KVM_UPDATE_MAPPINGS;
 
-	clock_gettime(CLOCK_MONOTONIC_RAW, &start);
+	clock_gettime(CLOCK_MONOTONIC, &start);
 	vcpus_complete_new_stage(*current_stage);
 	ts_diff = timespec_elapsed(start);
 
@@ -392,7 +392,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 
 	*current_stage = KVM_ADJUST_MAPPINGS;
 
-	clock_gettime(CLOCK_MONOTONIC_RAW, &start);
+	clock_gettime(CLOCK_MONOTONIC, &start);
 	vcpus_complete_new_stage(*current_stage);
 	ts_diff = timespec_elapsed(start);
 
-- 
2.27.0


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

* Re: [PATCH] KVM: selftests: use unified time type for comparison
  2023-07-31  2:24 [PATCH] KVM: selftests: use unified time type for comparison Bibo Mao
@ 2023-08-02 19:30 ` Sean Christopherson
  2023-08-02 19:52   ` Oliver Upton
  2023-08-02 21:11 ` Sean Christopherson
  1 sibling, 1 reply; 4+ messages in thread
From: Sean Christopherson @ 2023-08-02 19:30 UTC (permalink / raw)
  To: Bibo Mao
  Cc: Paolo Bonzini, Shuah Khan, kvm, linux-kselftest, linux-kernel,
	Oliver Upton

+Oliver to get input on something beyond non-x86, and because I hate anything
clock related :-)

On Mon, Jul 31, 2023, Bibo Mao wrote:
> With test case kvm_page_table_test, start time is acquired with
> time type CLOCK_MONOTONIC_RAW, however end time in function timespec_elapsed
> is acquired with time type CLOCK_MONOTONIC. This will cause
> inaccurate elapsed time calculation on some platform such as LoongArch.
> 
> This patch modified test case kvm_page_table_test, and uses unified
> time type CLOCK_MONOTONIC for start time.

AFAICT, there's zero reason to use CLOCK_MONOTONIC_RAW instead of CLOCK_MONOTONIC.
If there are no objections, I'll take this through kvm-x86/selftests for 6.6.

> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>  tools/testing/selftests/kvm/kvm_page_table_test.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c b/tools/testing/selftests/kvm/kvm_page_table_test.c
> index b3b00be1ef82..69f26d80c821 100644
> --- a/tools/testing/selftests/kvm/kvm_page_table_test.c
> +++ b/tools/testing/selftests/kvm/kvm_page_table_test.c
> @@ -200,7 +200,7 @@ static void *vcpu_worker(void *data)
>  		if (READ_ONCE(host_quit))
>  			return NULL;
>  
> -		clock_gettime(CLOCK_MONOTONIC_RAW, &start);
> +		clock_gettime(CLOCK_MONOTONIC, &start);
>  		ret = _vcpu_run(vcpu);
>  		ts_diff = timespec_elapsed(start);
>  
> @@ -367,7 +367,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>  	/* Test the stage of KVM creating mappings */
>  	*current_stage = KVM_CREATE_MAPPINGS;
>  
> -	clock_gettime(CLOCK_MONOTONIC_RAW, &start);
> +	clock_gettime(CLOCK_MONOTONIC, &start);
>  	vcpus_complete_new_stage(*current_stage);
>  	ts_diff = timespec_elapsed(start);
>  
> @@ -380,7 +380,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>  
>  	*current_stage = KVM_UPDATE_MAPPINGS;
>  
> -	clock_gettime(CLOCK_MONOTONIC_RAW, &start);
> +	clock_gettime(CLOCK_MONOTONIC, &start);
>  	vcpus_complete_new_stage(*current_stage);
>  	ts_diff = timespec_elapsed(start);
>  
> @@ -392,7 +392,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>  
>  	*current_stage = KVM_ADJUST_MAPPINGS;
>  
> -	clock_gettime(CLOCK_MONOTONIC_RAW, &start);
> +	clock_gettime(CLOCK_MONOTONIC, &start);
>  	vcpus_complete_new_stage(*current_stage);
>  	ts_diff = timespec_elapsed(start);
>  
> -- 
> 2.27.0
> 

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

* Re: [PATCH] KVM: selftests: use unified time type for comparison
  2023-08-02 19:30 ` Sean Christopherson
@ 2023-08-02 19:52   ` Oliver Upton
  0 siblings, 0 replies; 4+ messages in thread
From: Oliver Upton @ 2023-08-02 19:52 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Bibo Mao, Paolo Bonzini, Shuah Khan, kvm, linux-kselftest,
	linux-kernel

Howdy,

On Wed, Aug 02, 2023 at 12:30:43PM -0700, Sean Christopherson wrote:
> On Mon, Jul 31, 2023, Bibo Mao wrote:
> > With test case kvm_page_table_test, start time is acquired with
> > time type CLOCK_MONOTONIC_RAW, however end time in function timespec_elapsed
> > is acquired with time type CLOCK_MONOTONIC. This will cause
> > inaccurate elapsed time calculation on some platform such as LoongArch.

Well, there's the fundamental issue of mixing to timebases, so this
really isn't platform specific. One is subject to NTP frequency
adjustments and the other is not.

> > This patch modified test case kvm_page_table_test, and uses unified
> > time type CLOCK_MONOTONIC for start time.
> 
> AFAICT, there's zero reason to use CLOCK_MONOTONIC_RAW instead of CLOCK_MONOTONIC.
> If there are no objections, I'll take this through kvm-x86/selftests for 6.6.

CLOCK_MONOTONIC is objectively the better choice if you want something
that accurately tracks wall time, which we certainly do. So yeah, fine
by me to take this through the x86 tree:

Reviewed-by: Oliver Upton <oliver.upton@linux.dev>

-- 
Thanks,
Oliver

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

* Re: [PATCH] KVM: selftests: use unified time type for comparison
  2023-07-31  2:24 [PATCH] KVM: selftests: use unified time type for comparison Bibo Mao
  2023-08-02 19:30 ` Sean Christopherson
@ 2023-08-02 21:11 ` Sean Christopherson
  1 sibling, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2023-08-02 21:11 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Bibo Mao
  Cc: Shuah Khan, kvm, linux-kselftest, linux-kernel

On Mon, 31 Jul 2023 10:24:05 +0800, Bibo Mao wrote:
> With test case kvm_page_table_test, start time is acquired with
> time type CLOCK_MONOTONIC_RAW, however end time in function timespec_elapsed
> is acquired with time type CLOCK_MONOTONIC. This will cause
> inaccurate elapsed time calculation on some platform such as LoongArch.
> 
> This patch modified test case kvm_page_table_test, and uses unified
> time type CLOCK_MONOTONIC for start time.
> 
> [...]

Applied to kvm-x86 selftests, thanks!

[1/1] KVM: selftests: use unified time type for comparison
      https://github.com/kvm-x86/linux/commit/b859b018aadf

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes

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

end of thread, other threads:[~2023-08-02 21:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-31  2:24 [PATCH] KVM: selftests: use unified time type for comparison Bibo Mao
2023-08-02 19:30 ` Sean Christopherson
2023-08-02 19:52   ` Oliver Upton
2023-08-02 21:11 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox