Skip to contentSkip to conversation

perf intel-pt: Fix system_wide dummy event for hybrid

PATCH Applied Adrian Hunter 3 participants 6 messages Oct 12, 2022 – Oct 14, 2022 perf events

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

cover perf intel-pt: Fix system_wide dummy event for hybrid

Hi

Here are a couple of minor Intel PT fixes.

Adrian Hunter (2):
perf intel-pt: Fix segfault in intel_pt_print_info() with uClibc perf intel-pt: Fix system_wide dummy event for hybrid

 tools/perf/arch/x86/util/intel-pt.c | 2 +-
 tools/perf/util/intel-pt.c          | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

Regards
Adrian

author reviewer
#1 lore raw

PATCH 1/2 perf intel-pt: Fix segfault in intel_pt_print_info() with uClibc

uClibc segfaulted because NULL was passed as the format to fprintf().

That happened because one of the format strings was missing and intel_pt_print_info() didn't check that before calling fprintf().

Add the missing format string, and check format is not NULL before calling fprintf().

Fixes 11fa7cb86b56 ("perf tools: Pass Intel PT information for decoding MTC and CYC")
---
 tools/perf/util/intel-pt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/util/intel-pt.c +7 -2
index b34cb3dec1aa..e3548ddef254 100644
@@ -4046,6 +4046,7 @@ static const char * const intel_pt_info_fmts[] = {
 	[INTEL_PT_SNAPSHOT_MODE]	= "  Snapshot mode       %"PRId64"\n",
 	[INTEL_PT_PER_CPU_MMAPS]	= "  Per-cpu maps        %"PRId64"\n",
 	[INTEL_PT_MTC_BIT]		= "  MTC bit             %#"PRIx64"\n",
+	[INTEL_PT_MTC_FREQ_BITS]	= "  MTC freq bits       %#"PRIx64"\n",
 	[INTEL_PT_TSC_CTC_N]		= "  TSC:CTC numerator   %"PRIu64"\n",
 	[INTEL_PT_TSC_CTC_D]		= "  TSC:CTC denominator %"PRIu64"\n",
 	[INTEL_PT_CYC_BIT]		= "  CYC bit             %#"PRIx64"\n",
@@ -4060,8 +4061,12 @@ static void intel_pt_print_info(__u64 *arr, int start, int finish)
 	if (!dump_trace)
 		return;
 
-	for (i = start; i <= finish; i++)
-		fprintf(stdout, intel_pt_info_fmts[i], arr[i]);
+	for (i = start; i <= finish; i++) {
+		const char *fmt = intel_pt_info_fmts[i];
+
+		if (fmt)
+			fprintf(stdout, fmt, arr[i]);
+	}
 }
 
 static void intel_pt_print_info_str(const char *name, const char *str)
Signature · 1 line
2.25.1
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] perf intel-pt: Fix segfault in intel_pt_print_info() with uClibc

Hi Adrian,

Quoted 2 lines · Adrian Hunter

uClibc segfaulted because NULL was passed as the format to fprintf().

Sounds like glibc has a NULL check in fprintf().

Quoted 10 lines

That happened because one of the format strings was missing and intel_pt_print_info() didn't check that before calling fprintf().

Add the missing format string, and check format is not NULL before calling fprintf().

Fixes 11fa7cb86b56 ("perf tools: Pass Intel PT information for decoding MTC and CYC")

Thanks,
Namhyung

Quoted 34 lines
---
 tools/perf/util/intel-pt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/util/intel-pt.c +7 -3
index b34cb3dec1aa..e3548ddef254 100644
@@ -4046,6 +4046,7 @@ static const char * const intel_pt_info_fmts[] = {
        [INTEL_PT_SNAPSHOT_MODE]        = "  Snapshot mode       %"PRId64"\n",
        [INTEL_PT_PER_CPU_MMAPS]        = "  Per-cpu maps        %"PRId64"\n",
        [INTEL_PT_MTC_BIT]              = "  MTC bit             %#"PRIx64"\n",
+       [INTEL_PT_MTC_FREQ_BITS]        = "  MTC freq bits       %#"PRIx64"\n",
        [INTEL_PT_TSC_CTC_N]            = "  TSC:CTC numerator   %"PRIu64"\n",
        [INTEL_PT_TSC_CTC_D]            = "  TSC:CTC denominator %"PRIu64"\n",
        [INTEL_PT_CYC_BIT]              = "  CYC bit             %#"PRIx64"\n",
@@ -4060,8 +4061,12 @@ static void intel_pt_print_info(__u64 *arr, int start, int finish)
        if (!dump_trace)
                return;
 
-       for (i = start; i <= finish; i++)
-               fprintf(stdout, intel_pt_info_fmts[i], arr[i]);
+       for (i = start; i <= finish; i++) {
+               const char *fmt = intel_pt_info_fmts[i];
+
+               if (fmt)
+                       fprintf(stdout, fmt, arr[i]);
+       }
 }
 
 static void intel_pt_print_info_str(const char *name, const char *str)
--

2.25.1

author reviewer
#3 lore raw

PATCH 2/2 perf intel-pt: Fix system_wide dummy event for hybrid

In reply to Adrian Hunter

User space tasks can migrate between CPUs, so when tracing selected CPUs, system-wide sideband is still needed, however evlist->core.has_user_cpus is not set in the hybrid case, so check the target cpu_list instead.

Fixes 7d189cadbeeb ("perf intel-pt: Track sideband system-wide when needed")
---
 tools/perf/arch/x86/util/intel-pt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/arch/x86/util/intel-pt.c +1 -1
index 793b35f2221a..af102f471e9f 100644
@@ -866,7 +866,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
 		 * User space tasks can migrate between CPUs, so when tracing
 		 * selected CPUs, sideband for all CPUs is still needed.
 		 */
-		need_system_wide_tracking = evlist->core.has_user_cpus &&
+		need_system_wide_tracking = opts->target.cpu_list &&
 					    !intel_pt_evsel->core.attr.exclude_user;
 
 		tracking_evsel = evlist__add_aux_dummy(evlist, need_system_wide_tracking);
Signature · 1 line
2.25.1
maintainer Acked-by on v1 2/2
#4 lore raw
Quoted 8 lines · Adrian Hunter

User space tasks can migrate between CPUs, so when tracing selected CPUs, system-wide sideband is still needed, however evlist->core.has_user_cpus is not set in the hybrid case, so check the target cpu_list instead.

Fixes 7d189cadbeeb ("perf intel-pt: Track sideband system-wide when needed")

Thanks,
Namhyung

Quoted 20 lines
---
 tools/perf/arch/x86/util/intel-pt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/arch/x86/util/intel-pt.c +1 -2
index 793b35f2221a..af102f471e9f 100644
@@ -866,7 +866,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
                 * User space tasks can migrate between CPUs, so when tracing
                 * selected CPUs, sideband for all CPUs is still needed.
                 */
-               need_system_wide_tracking = evlist->core.has_user_cpus &&
+               need_system_wide_tracking = opts->target.cpu_list &&
                                            !intel_pt_evsel->core.attr.exclude_user;
 
                tracking_evsel = evlist__add_aux_dummy(evlist, need_system_wide_tracking);
--

2.25.1

maintainer Applied
#5 lore raw

Em Wed, Oct 12, 2022 at 09:25:14AM -0700, Namhyung Kim escreveu:

Quoted 11 lines · Adrian Hunter
Quoted 8 lines

User space tasks can migrate between CPUs, so when tracing selected CPUs, system-wide sideband is still needed, however evlist->core.has_user_cpus is not set in the hybrid case, so check the target cpu_list instead.

Fixes 7d189cadbeeb ("perf intel-pt: Track sideband system-wide when needed")

Thanks, applied both fixes.

- Arnaldo

Quoted 24 lines

Thanks,
Namhyung

Quoted 20 lines
---
 tools/perf/arch/x86/util/intel-pt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/arch/x86/util/intel-pt.c +1 -2
index 793b35f2221a..af102f471e9f 100644
@@ -866,7 +866,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
                 * User space tasks can migrate between CPUs, so when tracing
                 * selected CPUs, sideband for all CPUs is still needed.
                 */
-               need_system_wide_tracking = evlist->core.has_user_cpus &&
+               need_system_wide_tracking = opts->target.cpu_list &&
                                            !intel_pt_evsel->core.attr.exclude_user;
 
                tracking_evsel = evlist__add_aux_dummy(evlist, need_system_wide_tracking);
--

2.25.1

Signature · 1 line
- Arnaldo