All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
Cc: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@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 19:20:23 +0100	[thread overview]
Message-ID: <YhZ651X4Fs9KJMa6@krava> (raw)
In-Reply-To: <YhY9p9wsYgXtdYnt@kernel.org>

On Wed, Feb 23, 2022 at 10:59:03AM -0300, Arnaldo Carvalho de Melo wrote:
> 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;

hum, I'll double check but AFAICS from tests/parse-events.c,
nr_members already includes both parent (leader) and members,
which is different from nr_siblings in kernel

can you please provide more details?

thanks,
jirka

> >  		size += sizeof(u64);
> >  	}
> >  
> > -- 
> > 2.34.1
> 
> -- 
> 
> - Arnaldo

  reply	other threads:[~2022-02-23 18:20 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
2022-02-23 18:20   ` Jiri Olsa [this message]
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=YhZ651X4Fs9KJMa6@krava \
    --to=olsajiri@gmail.com \
    --cc=arnaldo.melo@gmail.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --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 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.