From: Marc Zyngier <maz@kernel.org>
To: Colton Lewis <coltonlewis@google.com>
Cc: pbonzini@redhat.com, shuah@kernel.org, seanjc@google.com,
dmatlack@google.com, vipinsh@google.com, andrew.jones@linux.dev,
bgardon@google.com, ricarkol@google.com, oliver.upton@linux.dev,
kvm@vger.kernel.org
Subject: Re: [PATCH v2 1/2] KVM: selftests: Provide generic way to read system counter
Date: Tue, 28 Mar 2023 11:09:46 +0100 [thread overview]
Message-ID: <86r0t9w5jp.wl-maz@kernel.org> (raw)
In-Reply-To: <gsntfs9xdipf.fsf@coltonlewis-kvm.c.googlers.com>
On Tue, 21 Mar 2023 19:10:04 +0000,
Colton Lewis <coltonlewis@google.com> wrote:
>
> Marc Zyngier <maz@kernel.org> writes:
>
> >> +#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 is built on another function timer_get_cntct which includes
> its own barriers. Stripped of some abstraction, the sequence is:
>
> timer_get_cntct (isb+read timer)
> whatever is being measured
> timer_get_cntct
>
> I hadn't looked at it too closely before but on review of the manual
> I think you are correct. Borrowing from example D7-2 in the manual, it
> should be:
>
> timer_get_cntct
> isb
> whatever is being measured
> dsb
> timer_get_cntct
That's better, but also very heavy handed. You'd be better off
constructing an address dependency from the timer value, and feed that
into a load-acquire/store-release pair wrapping your payload.
>
> >> + 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.
>
>
> In context, I'm trying to measure the time it takes to write to a buffer
> *with dirty memory logging enabled*. What do you mean by zero? I can
> confirm from running this code I am not measuring zero time.
See my earlier point: the counter tick is a few MHz, and the CPU
multiple GHz. So unless "whatever" is something that takes a
significant time (several thousands of CPU cycles), you'll measure
nothing using the counter. Page faults will probably show, but not a
normal access.
The right tool for this job is to use PMU events, as they count at the
CPU frequency.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2023-03-28 10:10 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
2023-03-21 19:10 ` Colton Lewis
2023-03-28 10:09 ` Marc Zyngier [this message]
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=86r0t9w5jp.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.