From: Peter Zijlstra <peterz@infradead.org>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Vadim Fedorenko <vadfed@meta.com>, Borislav Petkov <bp@alien8.de>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Yonghong Song <yonghong.song@linux.dev>,
Vadim Fedorenko <vadim.fedorenko@linux.dev>,
Mykola Lysenko <mykolal@fb.com>,
x86@kernel.org, bpf@vger.kernel.org,
Martin KaFai Lau <martin.lau@linux.dev>
Subject: Re: [PATCH bpf-next v8 0/4] bpf: add cpu cycles kfuncss
Date: Thu, 28 Nov 2024 12:27:34 +0100 [thread overview]
Message-ID: <20241128112734.GD35539@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <CAEf4BzYa5_jOhY3oDgJ-R4jhX7K+EmhcKQAt0VdDeNnpXicJ4g@mail.gmail.com>
On Tue, Nov 26, 2024 at 10:12:57AM -0800, Andrii Nakryiko wrote:
> On Fri, Nov 22, 2024 at 3:34 AM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Wed, Nov 20, 2024 at 04:08:10PM -0800, Vadim Fedorenko wrote:
> > > This patchset adds 2 kfuncs to provide a way to precisely measure the
> > > time spent running some code. The first patch provides a way to get cpu
> > > cycles counter which is used to feed CLOCK_MONOTONIC_RAW. On x86
> > > architecture it is effectively rdtsc_ordered() function while on other
> > > architectures it falls back to __arch_get_hw_counter(). The second patch
> > > adds a kfunc to convert cpu cycles to nanoseconds using shift/mult
> > > constants discovered by kernel. The main use-case for this kfunc is to
> > > convert deltas of timestamp counter values into nanoseconds. It is not
> > > supposed to get CLOCK_MONOTONIC_RAW values as offset part is skipped.
> > > JIT version is done for x86 for now, on other architectures it falls
> > > back to slightly simplified version of vdso_calc_ns.
> >
> > So having now read this. I'm still left wondering why you would want to
> > do this.
> >
> > Is this just debug stuff, for when you're doing a poor man's profile
> > run? If it is, why do we care about all the precision or the ns. And why
> > aren't you using perf?
>
> No, it's not debug stuff. It's meant to be used in production for
> measuring durations of whatever is needed. Like uprobe entry/exit
> duration, or time between scheduling switches, etc.
>
> Vadim emphasizes benchmarking at scale, but that's a bit misleading.
> It's not "benchmarking", it's measuring durations of relevant pairs of
> events. In production and at scale, so the unnecessary overhead all
> adds up. We'd like to have the minimal possible overhead for this time
> passage measurement. And some durations are very brief,
You might want to consider leaving out the LFENCE before the RDTSC on
some of those, LFENCE isn't exactly cheap.
> so precision
> matters as well. And given this is meant to be later used to do
> aggregation and comparison across large swaths of production hosts, we
> have to have comparable units, which is why nanoseconds and not some
> abstract "time cycles".
>
> Does this address your concerns?
Well, it's clearly useful for you guys, but I do worry about it. Even on
servers DVFS is starting to play a significant role. And the TSC is
unaffected by it.
Directly comparing these numbers, esp. across different systems makes no
sense to me. Yes putting them all in [ns] allows for comparison, but
you're still comparing fundamentally different things.
How does it make sense to measure uprobe entry/exit in wall-clock when
it can vary by at least a factor of 2 depending on DVFS. How does it
make sense to compare an x86-64 uprobe entry/exit to an aaargh64 one?
Or are you trying to estimate the fraction of overhead spend on
instrumentation instead of real work? Like, this machine spends 5% of
its wall-time in instrumentation, which is effectively not doing work?
The part I'm missing is how using wall-time for these things makes
sense.
I mean, if all you're doing is saying, hey, we appear to be spending X
on this action on this particular system Y doing workload Z (irrespecive
of you then having like a million Ys) and this patch reduces X by half
given the same Y and Z. So patch must be awesome.
Then you don't need the conversion to [ns], and the DVFS angle is more
or less mitigated by the whole 'same workload' thing.
next prev parent reply other threads:[~2024-11-28 11:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-21 0:08 [PATCH bpf-next v8 0/4] bpf: add cpu cycles kfuncss Vadim Fedorenko
2024-11-21 0:08 ` [PATCH bpf-next v8 1/4] bpf: add bpf_get_cpu_time_counter kfunc Vadim Fedorenko
2024-11-21 11:32 ` Peter Zijlstra
2024-11-21 14:35 ` Vadim Fedorenko
2024-11-21 15:33 ` Peter Zijlstra
2024-11-21 23:51 ` Andrii Nakryiko
2024-11-21 23:55 ` Vadim Fedorenko
2024-11-21 0:08 ` [PATCH bpf-next v8 2/4] bpf: add bpf_cpu_time_counter_to_ns helper Vadim Fedorenko
2024-11-21 11:31 ` Peter Zijlstra
2024-11-21 0:08 ` [PATCH bpf-next v8 3/4] selftests/bpf: add selftest to check rdtsc jit Vadim Fedorenko
2024-11-21 0:08 ` [PATCH bpf-next v8 4/4] selftests/bpf: add usage example for cpu cycles kfuncs Vadim Fedorenko
2024-11-22 11:34 ` [PATCH bpf-next v8 0/4] bpf: add cpu cycles kfuncss Peter Zijlstra
2024-11-22 15:40 ` Vadim Fedorenko
2024-11-26 18:12 ` Andrii Nakryiko
2024-11-28 11:27 ` Peter Zijlstra [this message]
2024-11-28 11:33 ` Peter Zijlstra
2024-11-28 14:30 ` Vadim Fedorenko
2024-11-28 14:28 ` Vadim Fedorenko
2024-12-02 19:15 ` Andrii Nakryiko
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=20241128112734.GD35539@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bp@alien8.de \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=tglx@linutronix.de \
--cc=vadfed@meta.com \
--cc=vadim.fedorenko@linux.dev \
--cc=x86@kernel.org \
--cc=yonghong.song@linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox