From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
Cc: olsajiri@gmail.com, irogers@google.com,
linux-perf-users@vger.kernel.org, Jiri Olsa <jolsa@kernel.org>
Subject: Re: [PATCH] libperf: Fix read_size calculations
Date: Wed, 23 Feb 2022 10:59:03 -0300 [thread overview]
Message-ID: <YhY9p9wsYgXtdYnt@kernel.org> (raw)
In-Reply-To: <20220223131349.134897-1-tz.stoyanov@gmail.com>
Em Wed, Feb 23, 2022 at 03:13:49PM +0200, Tzvetomir Stoyanov (VMware) escreveu:
> Reading the counters from perf descriptor fails because of size
> mismatch when PERF_FORMAT_GROUP is set. The group count must include the
> parent and the count of siblings.
Yeah, it should match the calculation done in the kernel, in
__perf_event_read_size(), that has...
static void __perf_event_read_size(struct perf_event *event, int nr_siblings)
{
int entry = sizeof(u64); /* value */
int size = 0;
int nr = 1;
if (event->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
size += sizeof(u64);
if (event->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
size += sizeof(u64);
if (event->attr.read_format & PERF_FORMAT_ID)
entry += sizeof(u64);
if (event->attr.read_format & PERF_FORMAT_GROUP) {
nr += nr_siblings;
size += sizeof(u64);
}
size += entry * nr;
event->read_size = size;
}
So this bug has been with us since forever (well, 2017), so we need:
Fixes: 5c30af92f2b1e9d8 ("libperf: Adopt perf_evsel__read() function from tools/perf")
To fix it in libperf and probably:
Fixes: de63403bfd14ae8d ("perf tools: Add perf_evsel__read_size function")
To get this to stable kernels versions predating the move of this
function to libperf.
Jiri?
- Arnaldo
> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
> ---
> tools/lib/perf/evsel.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
> index 210ea7c06ce8..4597a53c0152 100644
> --- a/tools/lib/perf/evsel.c
> +++ b/tools/lib/perf/evsel.c
> @@ -299,7 +299,7 @@ int perf_evsel__read_size(struct perf_evsel *evsel)
> entry += sizeof(u64);
>
> if (read_format & PERF_FORMAT_GROUP) {
> - nr = evsel->nr_members;
> + nr += evsel->nr_members;
> size += sizeof(u64);
> }
>
> --
> 2.34.1
--
- Arnaldo
next prev parent reply other threads:[~2022-02-23 13:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-23 13:13 [PATCH] libperf: Fix read_size calculations Tzvetomir Stoyanov (VMware)
2022-02-23 13:59 ` Arnaldo Carvalho de Melo [this message]
2022-02-23 18:20 ` Jiri Olsa
2022-02-24 9:10 ` Tzvetomir Stoyanov
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=YhY9p9wsYgXtdYnt@kernel.org \
--to=acme@kernel.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=olsajiri@gmail.com \
--cc=tz.stoyanov@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).