linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools/perf: Use perf_tool__init() to initialize default values in builtin trace
@ 2025-02-25 11:31 Athira Rajeev
  2025-02-27  0:38 ` Namhyung Kim
  2025-02-27 16:50 ` Namhyung Kim
  0 siblings, 2 replies; 4+ messages in thread
From: Athira Rajeev @ 2025-02-25 11:31 UTC (permalink / raw)
  To: acme, jolsa, adrian.hunter, irogers, namhyung
  Cc: linux-perf-users, linuxppc-dev, maddy, atrajeev, kjain, disgoel,
	hbathini, Aditya.Bodkhe1, Tejas.Manhas1

Perf trace on perf.data fails as below:

	./perf trace record -- sleep 1
	./perf trace -i perf.data
	perf: Segmentation fault
	Segmentation fault (core dumped)

Backtrace pointed to :
	?? ()
	perf_session.process_user_event ()
	reader.read_event ()
	perf_session.process_events ()
	cmd_trace ()
	run_builtin ()
	handle_internal_command ()
	main ()

Further debug pointed that, segmentation fault happens when
trying to access id_index. Code snippet:

	case PERF_RECORD_ID_INDEX:
		err = tool->id_index(session, event);

Since 'commit 15d4a6f41d72 ("perf tool: Remove
perf_tool__fill_defaults()")', perf_tool__fill_defaults is
removed. All tools are initialized using perf_tool__init()
prior to use. But in builtin-trace, perf_tool__init is not
used and hence the defaults are not initialized. Use
perf_tool__init() in perf trace to handle the initialization.

Reported-by: Tejas Manhas <Tejas.Manhas1@ibm.com>
Signed-off-by: Athira Rajeev <atrajeev@linux.ibm.com>
---
 tools/perf/builtin-trace.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index f55a8a6481f2..092c5f6404ba 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -4589,6 +4589,7 @@ static int trace__replay(struct trace *trace)
 	struct evsel *evsel;
 	int err = -1;
 
+	perf_tool__init(&trace->tool, /*ordered_events=*/true);
 	trace->tool.sample	  = trace__process_sample;
 	trace->tool.mmap	  = perf_event__process_mmap;
 	trace->tool.mmap2	  = perf_event__process_mmap2;
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tools/perf: Use perf_tool__init() to initialize default values in builtin trace
  2025-02-25 11:31 [PATCH] tools/perf: Use perf_tool__init() to initialize default values in builtin trace Athira Rajeev
@ 2025-02-27  0:38 ` Namhyung Kim
  2025-02-27  6:42   ` Athira Rajeev
  2025-02-27 16:50 ` Namhyung Kim
  1 sibling, 1 reply; 4+ messages in thread
From: Namhyung Kim @ 2025-02-27  0:38 UTC (permalink / raw)
  To: Athira Rajeev
  Cc: acme, jolsa, adrian.hunter, irogers, linux-perf-users,
	linuxppc-dev, maddy, kjain, disgoel, hbathini, Aditya.Bodkhe1,
	Tejas.Manhas1

On Tue, Feb 25, 2025 at 05:01:57PM +0530, Athira Rajeev wrote:
> Perf trace on perf.data fails as below:
> 
> 	./perf trace record -- sleep 1
> 	./perf trace -i perf.data
> 	perf: Segmentation fault
> 	Segmentation fault (core dumped)
> 
> Backtrace pointed to :
> 	?? ()
> 	perf_session.process_user_event ()
> 	reader.read_event ()
> 	perf_session.process_events ()
> 	cmd_trace ()
> 	run_builtin ()
> 	handle_internal_command ()
> 	main ()
> 
> Further debug pointed that, segmentation fault happens when
> trying to access id_index. Code snippet:
> 
> 	case PERF_RECORD_ID_INDEX:
> 		err = tool->id_index(session, event);
> 
> Since 'commit 15d4a6f41d72 ("perf tool: Remove
> perf_tool__fill_defaults()")', perf_tool__fill_defaults is
> removed. All tools are initialized using perf_tool__init()
> prior to use. But in builtin-trace, perf_tool__init is not
> used and hence the defaults are not initialized. Use
> perf_tool__init() in perf trace to handle the initialization.

Thanks for fixing this.  I can reproduce the problem and confirmed this
patch fixed it.

Thanks,
Namhyung

> 
> Reported-by: Tejas Manhas <Tejas.Manhas1@ibm.com>
> Signed-off-by: Athira Rajeev <atrajeev@linux.ibm.com>
> ---
>  tools/perf/builtin-trace.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index f55a8a6481f2..092c5f6404ba 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -4589,6 +4589,7 @@ static int trace__replay(struct trace *trace)
>  	struct evsel *evsel;
>  	int err = -1;
>  
> +	perf_tool__init(&trace->tool, /*ordered_events=*/true);
>  	trace->tool.sample	  = trace__process_sample;
>  	trace->tool.mmap	  = perf_event__process_mmap;
>  	trace->tool.mmap2	  = perf_event__process_mmap2;
> -- 
> 2.43.5
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tools/perf: Use perf_tool__init() to initialize default values in builtin trace
  2025-02-27  0:38 ` Namhyung Kim
@ 2025-02-27  6:42   ` Athira Rajeev
  0 siblings, 0 replies; 4+ messages in thread
From: Athira Rajeev @ 2025-02-27  6:42 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, Ian Rogers,
	open list:PERFORMANCE EVENTS SUBSYSTEM, linuxppc-dev,
	Madhavan Srinivasan, Kajol Jain, Disha Goel, hbathini,
	Aditya.Bodkhe1, Tejas Manhas



> On 27 Feb 2025, at 6:08 AM, Namhyung Kim <namhyung@kernel.org> wrote:
> 
> On Tue, Feb 25, 2025 at 05:01:57PM +0530, Athira Rajeev wrote:
>> Perf trace on perf.data fails as below:
>> 
>> ./perf trace record -- sleep 1
>> ./perf trace -i perf.data
>> perf: Segmentation fault
>> Segmentation fault (core dumped)
>> 
>> Backtrace pointed to :
>> ?? ()
>> perf_session.process_user_event ()
>> reader.read_event ()
>> perf_session.process_events ()
>> cmd_trace ()
>> run_builtin ()
>> handle_internal_command ()
>> main ()
>> 
>> Further debug pointed that, segmentation fault happens when
>> trying to access id_index. Code snippet:
>> 
>> case PERF_RECORD_ID_INDEX:
>> err = tool->id_index(session, event);
>> 
>> Since 'commit 15d4a6f41d72 ("perf tool: Remove
>> perf_tool__fill_defaults()")', perf_tool__fill_defaults is
>> removed. All tools are initialized using perf_tool__init()
>> prior to use. But in builtin-trace, perf_tool__init is not
>> used and hence the defaults are not initialized. Use
>> perf_tool__init() in perf trace to handle the initialization.
> 
> Thanks for fixing this.  I can reproduce the problem and confirmed this
> patch fixed it.
> 
> Thanks,
> Namhyung
Thanks Namhyung for checking the patch

Athira
> 
>> 
>> Reported-by: Tejas Manhas <Tejas.Manhas1@ibm.com>
>> Signed-off-by: Athira Rajeev <atrajeev@linux.ibm.com>
>> ---
>> tools/perf/builtin-trace.c | 1 +
>> 1 file changed, 1 insertion(+)
>> 
>> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
>> index f55a8a6481f2..092c5f6404ba 100644
>> --- a/tools/perf/builtin-trace.c
>> +++ b/tools/perf/builtin-trace.c
>> @@ -4589,6 +4589,7 @@ static int trace__replay(struct trace *trace)
>> struct evsel *evsel;
>> int err = -1;
>> 
>> + perf_tool__init(&trace->tool, /*ordered_events=*/true);
>> trace->tool.sample   = trace__process_sample;
>> trace->tool.mmap   = perf_event__process_mmap;
>> trace->tool.mmap2   = perf_event__process_mmap2;
>> -- 
>> 2.43.5



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tools/perf: Use perf_tool__init() to initialize default values in builtin trace
  2025-02-25 11:31 [PATCH] tools/perf: Use perf_tool__init() to initialize default values in builtin trace Athira Rajeev
  2025-02-27  0:38 ` Namhyung Kim
@ 2025-02-27 16:50 ` Namhyung Kim
  1 sibling, 0 replies; 4+ messages in thread
From: Namhyung Kim @ 2025-02-27 16:50 UTC (permalink / raw)
  To: acme, jolsa, adrian.hunter, irogers, Athira Rajeev
  Cc: linux-perf-users, linuxppc-dev, maddy, kjain, disgoel, hbathini,
	Aditya.Bodkhe1, Tejas.Manhas1

On Tue, 25 Feb 2025 17:01:57 +0530, Athira Rajeev wrote:
> Perf trace on perf.data fails as below:
> 
> 	./perf trace record -- sleep 1
> 	./perf trace -i perf.data
> 	perf: Segmentation fault
> 	Segmentation fault (core dumped)
> 
> [...]
Applied to perf-tools-next, thanks!

Best regards,
Namhyung



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-27 16:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-25 11:31 [PATCH] tools/perf: Use perf_tool__init() to initialize default values in builtin trace Athira Rajeev
2025-02-27  0:38 ` Namhyung Kim
2025-02-27  6:42   ` Athira Rajeev
2025-02-27 16:50 ` Namhyung Kim

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).