From: Marc Zyngier <maz@kernel.org>
To: Colton Lewis <coltonlewis@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Shuah Khan <shuah@kernel.org>,
Sean Christopherson <seanjc@google.com>,
David Matlack <dmatlack@google.com>,
Vipin Sharma <vipinsh@google.com>,
Andrew Jones <andrew.jones@linux.dev>,
Ben Gardon <bgardon@google.com>,
Ricardo Koller <ricarkol@google.com>,
Oliver Upton <oliver.upton@linux.dev>,
kvm@vger.kernel.org
Subject: Re: [PATCH v2 1/2] KVM: selftests: Provide generic way to read system counter
Date: Fri, 17 Mar 2023 17:09:39 +0000 [thread overview]
Message-ID: <87y1nvgv8s.wl-maz@kernel.org> (raw)
In-Reply-To: <20230316222752.1911001-2-coltonlewis@google.com>
On Thu, 16 Mar 2023 22:27:51 +0000,
Colton Lewis <coltonlewis@google.com> wrote:
>
> Provide a generic function to read the system counter from the guest
> for timing purposes. A common and important way to measure guest
> performance is to measure the amount of time different actions take in
> the guest. Provide also a mathematical conversion from cycles to
> nanoseconds and a macro for timing individual statements.
>
> Substitute the previous custom implementation of a similar function in
> system_counter_offset_test with this new implementation.
>
> Signed-off-by: Colton Lewis <coltonlewis@google.com>
> ---
> .../testing/selftests/kvm/include/kvm_util.h | 15 ++++++++++
> tools/testing/selftests/kvm/lib/kvm_util.c | 30 +++++++++++++++++++
> .../kvm/system_counter_offset_test.c | 10 ++-----
> 3 files changed, 47 insertions(+), 8 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
> index c9286811a4cb..8b478eabee4c 100644
> --- a/tools/testing/selftests/kvm/include/kvm_util.h
> +++ b/tools/testing/selftests/kvm/include/kvm_util.h
> @@ -10,4 +10,19 @@
> #include "kvm_util_base.h"
> #include "ucall_common.h"
>
> +#if defined(__aarch64__) || defined(__x86_64__)
> +
> +uint64_t cycles_read(void);
> +double cycles_to_ns(struct kvm_vcpu *vcpu, double cycles);
> +
> +#define MEASURE_CYCLES(x) \
> + ({ \
> + uint64_t start; \
> + start = cycles_read(); \
> + x; \
You insert memory accesses inside a sequence that has no dependency
with it. On a weakly ordered memory system, there is absolutely no
reason why the memory access shouldn't be moved around. What do you
exactly measure in that case?
> + cycles_read() - start; \
I also question the usefulness of this exercise. You're comparing the
time it takes for a multi-GHz system to put a write in a store buffer
(assuming it didn't miss in the TLBs) vs a counter that gets updated
at a frequency of a few tens of MHz.
My guts feeling is that this results in a big fat zero most of the
time, but I'm happy to be explained otherwise.
> + })
> +
> +#endif
> +
> #endif /* SELFTEST_KVM_UTIL_H */
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 3ea24a5f4c43..780481a92efe 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -2135,3 +2135,34 @@ void __attribute((constructor)) kvm_selftest_init(void)
>
> kvm_selftest_arch_init();
> }
> +
> +#if defined(__aarch64__)
> +
> +#include "arch_timer.h"
> +
> +uint64_t cycles_read(void)
> +{
> + return timer_get_cntct(VIRTUAL);
> +}
> +
> +double cycles_to_ns(struct kvm_vcpu *vcpu, double cycles)
> +{
> + return cycles * (1e9 / timer_get_cntfrq());
We already have all the required code to deal with ns conversions
using a multiplier and a shift, avoiding floating point like the
plague it is. Please reuse the kernel code for this, as you're quite
likely to only measure the time it takes for KVM to trap the FP
registers and perform a FP/SIMD switch...
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2023-03-17 17:11 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-16 22:27 [PATCH v2 0/2] Calculate memory access latency stats Colton Lewis
2023-03-16 22:27 ` [PATCH v2 1/2] KVM: selftests: Provide generic way to read system counter Colton Lewis
2023-03-17 9:26 ` Andrew Jones
2023-03-21 19:08 ` Colton Lewis
2023-03-17 17:04 ` Vipin Sharma
2023-03-21 19:09 ` Colton Lewis
2023-03-17 17:09 ` Marc Zyngier [this message]
2023-03-21 19:10 ` Colton Lewis
2023-03-28 10:09 ` Marc Zyngier
2023-03-28 15:38 ` Sean Christopherson
2023-03-28 15:50 ` Marc Zyngier
2023-03-28 21:51 ` Colton Lewis
2023-03-16 22:27 ` [PATCH v2 2/2] KVM: selftests: Print summary stats of memory latency distribution Colton Lewis
2023-03-17 18:16 ` Vipin Sharma
2023-03-21 19:10 ` Colton Lewis
2023-03-21 21:21 ` Sean Christopherson
2023-03-24 16:26 ` Colton Lewis
-- strict thread matches above, loose matches on Subject: below --
2023-03-19 5:42 [PATCH v2 1/2] KVM: selftests: Provide generic way to read system counter kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y1nvgv8s.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=andrew.jones@linux.dev \
--cc=bgardon@google.com \
--cc=coltonlewis@google.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=oliver.upton@linux.dev \
--cc=pbonzini@redhat.com \
--cc=ricarkol@google.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=vipinsh@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.