Re: [RFC PATCH v18 8/8] perf test: Add test for Intel TPEBS counting mode

From: Arnaldo Carvalho de Melo
Date: Tue Aug 13 2024 - 14:27:50 EST


On Tue, Aug 13, 2024 at 10:48:21AM -0700, Ian Rogers wrote:
> On Tue, Aug 13, 2024 at 10:18 AM Wang, Weilin <weilin.wang@xxxxxxxxx> wrote:
> > I just checkout the code and tested it. The failure is caused by a seg fault on a
> > perf_tool struct that is not initialized correctly. I think this is related to the patches
> > on struct perf_tool in this branch that applied right before the tpebs patches.

> > I was able to fix the seg fault by adding the perf_tool__fill_defaults() back. Since
> > Ian updated the code to replace this function, I think I need some advice on how
> > to use the new code to initialize perf_tool correctly here. Should I call the
> > perf_tool__init()?

> Yep. If you've added or refactored a tool struct the intent now is
> that you call perf_tool__init then override the functions you want to
> override. I don't mind to rebase those changes over your changes,
> Arnaldo if you want to drop those changes.

So I'm adding the patch below, which should be enough, right?

Now:

root@x1:~# perf test tpebs
123: test Intel TPEBS counting mode : Ok
root@x1:~# set -o vi
root@x1:~# perf test tpebs
123: test Intel TPEBS counting mode : Ok
root@x1:~# perf test -v tpebs
123: test Intel TPEBS counting mode : Ok
root@x1:~# perf test -vvv tpebs
123: test Intel TPEBS counting mode:
--- start ---
test child forked, pid 16603
Testing without --record-tpebs
Testing with --record-tpebs
---- end(0) ----
123: test Intel TPEBS counting mode : Ok
root@x1:~#

diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c
index 3729caeba645a3e8..50a3c3e0716065f8 100644
--- a/tools/perf/util/intel-tpebs.c
+++ b/tools/perf/util/intel-tpebs.c
@@ -164,11 +164,12 @@ static void *__sample_reader(void *arg)
.path = PERF_DATA,
.file.fd = child->out,
};
- struct perf_tool tool = {
- .sample = process_sample_event,
- .feature = process_feature_event,
- .attr = perf_event__process_attr,
- };
+ struct perf_tool tool;
+
+ perf_tool__init(&tool, /*ordered_events=*/false);
+ tool.sample = process_sample_event;
+ tool.feature = process_feature_event;
+ tool.attr = perf_event__process_attr;

session = perf_session__new(&data, &tool);
if (IS_ERR(session))

Thanks for root causing, my mistake,

- Arnaldo