From: Jiri Olsa <olsajiri@gmail.com>
To: Andrew Nisbet <Andy.Nisbet@manchester.ac.uk>
Cc: "bpf@vger.kernel.org " <bpf@vger.kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Subject: Re: EBPF/libpbf initialising/reading raw (hardware) performance counters BPF_PERF_ARRAY
Date: Thu, 6 Apr 2023 15:24:24 +0200 [thread overview]
Message-ID: <ZC7ICD/vAKdtvopd@krava> (raw)
In-Reply-To: <CWLP265MB326715B58C33134FB24B913FC1919@CWLP265MB3267.GBRP265.PROD.OUTLOOK.COM>
On Thu, Apr 06, 2023 at 10:41:35AM +0000, Andrew Nisbet wrote:
> Hi,
> apologies in advance if I have missed an obvious information resource.
>
> I've used BCC/eBPF before to generate a tool that attached to sched_switch with performance counters and that traces the per-scheduling thread quanta changes in counters for threads of interest.
> I'd like to use libbbpf to create similar functionality to something like ...
>
> perf stat -e LLC-loads,LLC-load-misses,LLC-stores,LLC-prefetches -p PID --per-thread
> The actual counters are immaterial - except that I expect to be sometimes using RAW performance counters, and I typically extract the perf_event_attr information such as event/config etc using
> perf stat -vvv -e counter-name /bin/ls
>
> I can see from the libbpf examples how to catch the pid of the command as it enters the runqueue, but I dont see how to initialise the raw hardware performance counters to only count the pid and its threads (is this even possible or does one just accumulate counters for each relevant thread in sched_switch - this is what we do currently). I understand how to put these values into a map.
yes, you need to agregate counts yourself for more pids
you can create perf counter for single entities like pid/tid/cpu/task/cgroup,
so if you want to meassure more pids you need to create counter for each and
aggregate their counts, that's what perf tool does
>
> I'm looking for (if possible) example code or information pointers on how to initialise and read the counters, not using sampling - presumably using a BPF_PERF_ARRAY map and a call to the perf_counter_read or the older perf_read on the map.
there's 'bpftool prog profile' that creates perf counters,
but I think there's no aggregation, still nice example:
(see do_profile function)
https://github.com/torvalds/linux/blob/master/tools/bpf/bpftool/prog.c
also there's libperf if you need the abstraction to create more
counters and read from them:
https://github.com/torvalds/linux/tree/master/tools/lib/perf/
https://github.com/torvalds/linux/tree/master/tools/lib/perf/Documentation/examples
jirka
>
> I'm only just getting up to speed with libbpf, so apologies if I've misunderstood and presented BCC ways that do not apply.
>
> Thanks,
> Andy
prev parent reply other threads:[~2023-04-06 13:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-06 10:41 EBPF/libpbf initialising/reading raw (hardware) performance counters BPF_PERF_ARRAY Andrew Nisbet
2023-04-06 13:24 ` Jiri Olsa [this message]
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=ZC7ICD/vAKdtvopd@krava \
--to=olsajiri@gmail.com \
--cc=Andy.Nisbet@manchester.ac.uk \
--cc=acme@kernel.org \
--cc=bpf@vger.kernel.org \
/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