From: Ian Rogers <irogers@google.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Subject: Re: [PATCH perf/core] perf intel-pt: Fix clang build failure in intel_pt_synth_pebs_sample
Date: Thu, 14 May 2020 15:46:05 -0700 [thread overview]
Message-ID: <CAP-5=fV5URsHn+SpW8N4XjkKT1vt2T1Us5FsqaJsoOW0zn=OxQ@mail.gmail.com> (raw)
In-Reply-To: <20200514220934.GT4897@embeddedor>
On Thu, May 14, 2020 at 3:04 PM Gustavo A. R. Silva
<gustavoars@kernel.org> wrote:
>
> On Thu, May 14, 2020 at 12:06:48PM -0700, Ian Rogers wrote:
> > On Thu, May 14, 2020 at 8:01 AM Gustavo A. R. Silva
> > <gustavoars@kernel.org> wrote:
> > >
> > > On Thu, May 14, 2020 at 10:10:30AM -0300, Arnaldo Carvalho de Melo wrote:
> > > > Em Wed, May 13, 2020 at 06:47:38PM -0500, Gustavo A. R. Silva escreveu:
> > > > > Fix the following build failure generated with command
> > > > > $ make CC=clang HOSTCC=clang -C tools/ perf:
> > > > >
> > > > > util/intel-pt.c:1802:24: error: field 'br_stack' with variable sized type 'struct branch_stack' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
> > > > > struct branch_stack br_stack;
> > > > > ^
> > > > > 1 error generated.
> > > > >
> > > > > Fix this by reordering the members of struct br.
> > > >
> > > > Yeah, I noticed that as far back as with ubuntu 16.04's clang:
> > > >
> > > > clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
> > > >
> > > > util/intel-pt.c:1802:24: error: field 'br_stack' with variable sized type 'struct branch_stack' not at the end of a struct or class is a GNU
> > > > extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
> > > > struct branch_stack br_stack;
> > > > ^
> > > > 1 error generated.
> > > >
> > > >
> > > > Will fold this with the bug introducing the problem to avoid bisection
> > > > problems.
> > > >
> > >
> > > I agree. Also, the commit hash of the "Fixes" tag only applies to the
> > > perf/core branch and, I guess that might create confusion.
> >
> >
> > So while this fixes the warning I believe it breaks the intent of the code.
> >
> > tools/perf/util/branch.h:
> > struct branch_stack {
> > u64 nr;
> > u64 hw_idx;
> > struct branch_entry entries[];
> > };
> >
> > tools/perf/util/intel-pt.c:
> > struct {
> > struct branch_stack br_stack;
> > struct branch_entry entries[LBRS_MAX];
> > } br;
> >
> > The array in br is trying to extend branch_stack's entries array. You
> > might have to do something like:
> >
> > alignas(alignof(branch_stack)) char storage[sizeof(branch_stack) +
> > sizeof(branch_entry) * LBRS_MAX];
> > struct branch_stack *br = &storage;
> >
> > malloc/free may be nicer on the eyeballs.
> >
>
> Yep, I'd go for zalloc/free. There are a couple of places where dynamic
> memory is being allocated for struct branch_stack:
>
> tools/perf/util/cs-etm.c-256- if (etm->synth_opts.last_branch) {
> tools/perf/util/cs-etm.c:257: size_t sz = sizeof(struct branch_stack);
> tools/perf/util/cs-etm.c-258-
> tools/perf/util/cs-etm.c-259- sz += etm->synth_opts.last_branch_sz *
> tools/perf/util/cs-etm.c-260- sizeof(struct branch_entry);
> tools/perf/util/cs-etm.c-261- tidq->last_branch = zalloc(sz);
>
> tools/perf/util/thread-stack.c-148- if (br_stack_sz) {
> tools/perf/util/thread-stack.c:149: size_t sz = sizeof(struct branch_stack);
> tools/perf/util/thread-stack.c-150-
> tools/perf/util/thread-stack.c-151- sz += br_stack_sz * sizeof(struct branch_entry);
> tools/perf/util/thread-stack.c-152- ts->br_stack_rb = zalloc(sz);
>
> there is even function intel_pt_alloc_br_stack().
>
> Just out of curiosity, why the need of such a hack in this case (the
> on-stack extension of branch_stack's entries array)?
My guess would be that the lbr size is an architectural constant and
so avoiding malloc/free in what could be a hot loop was desirable.
As this is part of a larger patch set, is this the only place this
problem has been encountered? Perhaps a macro could perform the
complicated stack allocation I suggested. It may be nice to save
cycles if code this pattern is widespread and the code hot.
Thanks,
Ian
> Thanks
> --
> Gustavo
>
next prev parent reply other threads:[~2020-05-14 22:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-13 23:47 [PATCH perf/core] perf intel-pt: Fix clang build failure in intel_pt_synth_pebs_sample Gustavo A. R. Silva
2020-05-14 0:56 ` Ian Rogers
2020-05-14 13:10 ` Arnaldo Carvalho de Melo
2020-05-14 15:06 ` Gustavo A. R. Silva
2020-05-14 19:06 ` Ian Rogers
2020-05-14 22:09 ` Gustavo A. R. Silva
2020-05-14 22:46 ` Ian Rogers [this message]
2020-05-15 0:10 ` Gustavo A. R. Silva
2020-05-15 0:09 ` Ian Rogers
2020-05-15 0:29 ` Gustavo A. R. Silva
2020-05-15 16:41 ` Arnaldo Carvalho de Melo
2020-05-15 16:43 ` Arnaldo Carvalho de Melo
2020-05-15 17:09 ` Gustavo A. R. Silva
2020-05-16 12:35 ` Adrian Hunter
2020-05-19 19:12 ` Gustavo A. R. Silva
2020-05-20 1:42 ` Arnaldo Carvalho de Melo
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='CAP-5=fV5URsHn+SpW8N4XjkKT1vt2T1Us5FsqaJsoOW0zn=OxQ@mail.gmail.com' \
--to=irogers@google.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=arnaldo.melo@gmail.com \
--cc=gustavo@embeddedor.com \
--cc=gustavoars@kernel.org \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).