perf sched latency: Refine outputs, unit scaling, and histogram support
v3 cover perf sched latency: Refine outputs, unit scaling, and histogram support
This patch series improves 'perf sched latency' by fixing misleading empty table output, introducing dynamic unit auto-scaling for latency and runtime statistics, and adding latency histogram visualisation alongside time-span filtering.
Patch 1 fixes a bug where 'perf sched latency' would fall through and return success (0) when perf_session__has_traces() failed due to missing tracepoint events in perf.data. This resulted in empty header tables and zeroed summary statistics being printed. The fix ensures an early return of a suitable error code.
Patch 2 introduces dynamic auto-scaling for display columns (Runtime, Avg delay, Max delay). Previously, all values were unconditionally formatted in milliseconds (ms), making microsecond or second-scale latencies difficult to read. Columns are now scaled dynamically to the most appropriate unit (ns, us, ms, s) and headers are updated accordingly.
Patch 3 adds three new command-line options to 'perf sched latency':
--histogram (-H):
Displays an ASCII bar chart of CPU wait latencies between snapshots
--hist-mode:
Configures the bucketing scheme to either logarithmic (log) or 100 us equal-width linear (linear) mode
--time:
Filters event processing to a specified [start,stop] time span
Changes since v2:
- Ensured vertical pipe separators align across all latency table columns
- Excluded "swapper" (idle thread) latency samples from global_hist
- Preserved task state machine transitions across --time boundaries
- Suppressed empty table headers, total lines, and histogram graphs when no matching trace samples exist (e.g., when --time, --CPU, or --pids exclude all samples), outputting "No matching trace samples found." instead
- Linked to v2: https://lore.kernel.org/lkml/[email protected]/
Changes since v1:
- Fixed integer overflow in latency_bucket() (Ian Rogers)
- Linked to v1: https://lore.kernel.org/lkml/[email protected]/
Aaron Tomlin (3):
perf sched: Suppress latency table output when trace samples are
missing
perf sched latency: Auto-scale latency and runtime display units perf sched latency: Add histogram and time interval options
tools/perf/Documentation/perf-sched.txt | 6 + tools/perf/builtin-sched.c | 246 ++++++++++++++++++++++-- 2 files changed, 231 insertions(+), 21 deletions(-)
Signature · 1 line
2.54.0
PATCH v3 1/3 perf sched: Suppress latency table output when trace samples are missing
When 'perf sched latency' is executed on a perf.data file that lacks tracepoint samples (i.e., a file recorded without the -R flag or containing only non-tracepoint events), perf_session__has_traces() correctly outputs an error message. However, perf_sched__read_events() subsequently falls through and returns 0 (success).
Consequently, caller functions such as perf_sched__lat() assume event processing succeeded and proceed to render empty latency header tables and total summary statistics.
Fix this behaviour by ensuring perf_sched__read_events() aborts early and returns a suitable error code when perf_session__has_traces() evaluates to false. This prevents superfluous table output from being generated when no trace data is available.
--- tools/perf/builtin-sched.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
tools/perf/builtin-sched.c +11 -10
@@ -2001,7 +2001,7 @@ static int perf_sched__read_events(struct perf_sched *sched) .mode = PERF_DATA_MODE_READ, .force = sched->force, }; -int rc =-1 ; +int rc =-1 , err; session =perf_session__new (&data, &sched->tool);if (IS_ERR (session)) {
@@ -2018,18 +2018,19 @@ static int perf_sched__read_events(struct perf_sched *sched)if (perf_session__set_tracepoints_handlers (session, handlers)) goto out_delete; -if (perf_session__has_traces (session,"record -R" )) { -int err =perf_session__process_events (session); -if (err) { -pr_err ("Failed to process events, error %d" , err); - goto out_delete; - } +if (!perf_session__has_traces (session,"record -R" )) + goto out_delete; - sched->nr_events = session->evlist->stats.nr_events[0 ]; - sched->nr_lost_events = session->evlist->stats.total_lost; - sched->nr_lost_chunks = session->evlist->stats.nr_events[PERF_RECORD_LOST ]; + err =perf_session__process_events (session); +if (err) { +pr_err ("Failed to process events, error %d" , err); + goto out_delete; } + sched->nr_events = session->evlist->stats.nr_events[0 ]; + sched->nr_lost_events = session->evlist->stats.total_lost; + sched->nr_lost_chunks = session->evlist->stats.nr_events[PERF_RECORD_LOST ]; + rc =0 ; out_delete:perf_session__delete (session);
Signature · 1 line
2.54.0
PATCH v3 2/3 perf sched latency: Auto-scale latency and runtime display units
In reply to Aaron TomlinCurrently, 'perf sched latency' displays task runtime and delay values exclusively in milliseconds (ms). This can be hard to read when latencies are very small (in the microsecond or nanosecond range) or unusually large (seconds).
Introduce auto-scaling for latency and runtime display columns. Values are dynamically scaled and output with the most appropriate unit:
nanoseconds (ns), microseconds (us), milliseconds (ms), or seconds (s).
Additionally, rename column headers from "Runtime ms", "Avg delay ms", and "Max delay ms" to "Runtime", "Avg delay", and "Max delay" respectively, and adjust spacing to maintain column alignment.
--- tools/perf/builtin-sched.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
tools/perf/builtin-sched.c +26 -8
@@ -246,6 +246,17 @@ struct perf_sched {struct perf_data *data; }; +static int scnprintf_latency_unit (char *buf,size_t size,u64 nsecs) +{ +if (nsecs <1000 ) +return scnprintf (buf, size,"%6" PRIu64" ns" , nsecs); +if (nsecs <NSEC_PER_MSEC ) +return scnprintf (buf, size,"%6.3f us" , (double )nsecs /NSEC_PER_USEC ); +if (nsecs <NSEC_PER_SEC ) +return scnprintf (buf, size,"%6.3f ms" , (double )nsecs /NSEC_PER_MSEC ); +return scnprintf (buf, size,"%6.3f s " , (double )nsecs /NSEC_PER_SEC ); +} +/* per thread run time data */ struct thread_runtime {u64 last_time;/* time of previous sched in/out event */
@@ -1405,6 +1416,8 @@ static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_int i;int ret;u64 avg; +char runtime_lat[32 ]; +char avg_lat[32 ], max_lat[32 ];char max_lat_start[32 ], max_lat_end[32 ];if (!work_list->nb_atoms)
@@ -1430,14 +1443,17 @@ static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_printf (" " ); avg = work_list->total_lat / work_list->nb_atoms; +scnprintf_latency_unit (runtime_lat,sizeof (runtime_lat), work_list->total_runtime); +scnprintf_latency_unit (avg_lat,sizeof (avg_lat), avg); +scnprintf_latency_unit (max_lat,sizeof (max_lat), work_list->max_lat);timestamp__scnprintf_usec (work_list->max_lat_start, max_lat_start,sizeof (max_lat_start));timestamp__scnprintf_usec (work_list->max_lat_end, max_lat_end,sizeof (max_lat_end)); -printf ("|%11.3f ms |%9" PRIu64" | avg:%8.3f ms | max:%8.3f ms | max start: %12s s | max end: %12s s\n" , - (double )work_list->total_runtime /NSEC_PER_MSEC , - work_list->nb_atoms, (double )avg /NSEC_PER_MSEC , - (double )work_list->max_lat /NSEC_PER_MSEC , - max_lat_start, max_lat_end); +printf ("|%14s |%9" PRIu64" | avg:%11s | max:%11s | max start: %12s s | max end: %12s s\n" , + runtime_lat, + work_list->nb_atoms, avg_lat, max_lat, + max_lat_start, max_lat_end); + }static int pid_cmp (struct work_atoms *l,struct work_atoms *r)
@@ -3599,6 +3615,7 @@ static int perf_sched__lat(struct perf_sched *sched) {int rc =-1 ;struct rb_node *next; +char total_runtime_str[32 ];setup_pager ();
@@ -3612,7 +3629,7 @@ static int perf_sched__lat(struct perf_sched *sched)perf_sched__sort_lat (sched);printf ("\n -------------------------------------------------------------------------------------------------------------------------------------------\n" ); -printf (" Task | Runtime ms | Count | Avg delay ms | Max delay ms | Max delay start | Max delay end |\n" ); +printf (" Task | Runtime | Count | Avg delay | Max delay | Max delay start | Max delay end |\n" );printf (" -------------------------------------------------------------------------------------------------------------------------------------------\n" ); next =rb_first_cached (&sched->sorted_atom_root);
@@ -3626,8 +3643,9 @@ static int perf_sched__lat(struct perf_sched *sched) }printf (" -----------------------------------------------------------------------------------------------------------------\n" ); -printf (" TOTAL: |%11.3f ms |%9" PRIu64" |\n" , - (double )sched->all_runtime /NSEC_PER_MSEC , sched->all_count); +scnprintf_latency_unit (total_runtime_str,sizeof (total_runtime_str), sched->all_runtime); +printf (" TOTAL: |%14s |%9" PRIu64" |\n" , + total_runtime_str, sched->all_count);printf (" ---------------------------------------------------\n" );
Signature · 1 line
2.54.0
PATCH v3 3/3 perf sched latency: Add histogram and time interval options
In reply to Aaron TomlinWhile 'perf sched latency' reports task runtime and delay statistics (average and maximum delay), it does not provide a visual representation of how task wait times are distributed across latency ranges between snapshots (start and finish of the analysis window).
The --histogram option collects CPU wait latencies (time between when a task becomes runnable and when it gets scheduled onto a CPU) into 22 latency buckets, displaying an ASCII bar chart distribution.
The --hist-mode option configures the bucketing scheme:
- log (default). Logarithmic latency buckets ranging from sub-microsecond (< 1 us) up to >= 1.05 seconds
- linear. Equal-width linear latency buckets
(i.e., 100 us steps up to >= 2.1 ms)
The --time option allows filtering trace event processing to a specific time interval [start,stop].
Example histogram output excerpt:
❯ sudo perf sched latency --histogram --CPU 0
CPU Wait Latency Distribution Histogram (between snapshots) (total samples: 36114)
-------------------------------------------------------------------
Latency Range | Count | Pct | Histogram Graph
-------------------------------------------------------------------
< 1 us | 17 | 0.0% | #
2 - 4 us | 673 | 1.9% | #
4 - 8 us | 6237 | 17.3% | ######
8 - 16 us | 3224 | 8.9% | ###
16 - 32 us | 1388 | 3.8% | #
32 - 64 us | 709 | 2.0% | #
64 - 128 us | 690 | 1.9% | #
128 - 256 us | 789 | 2.2% | #
256 - 512 us | 541 | 1.5% | #
512 - 1024 us | 2256 | 6.2% | ##
1 - 2 ms | 3577 | 9.9% | ###
2 - 4 ms | 13259 | 36.7% | ##############
4 - 8 ms | 2523 | 7.0% | ##
8 - 16 ms | 222 | 0.6% | #
16 - 32 ms | 10 | 0.0% | #
>= 1.05 s | 3 | 0.0% | #
---------------------------------------------------------------------- tools/perf/Documentation/perf-sched.txt | 6 + tools/perf/builtin-sched.c | 191 +++++++++++++++++++++++- 2 files changed, 194 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-sched.txt +6 -0
@@ -40,6 +40,12 @@ There are several variants of 'perf sched': Tasks with the same command name are merged and the merge count is given within (), However if -p option is used, pid is mentioned. + If -H or --histogram option is passed, a CPU wait latency distribution + histogram is displayed illustrating how long tasks waited for CPU + runtime across latency buckets between snapshots. The --time + option (start,stop) limits analysis to a specific snapshot time interval. + The --hist-mode option (log or linear) configures the latency bucketing scheme. + 'perf sched script' to see a detailed trace of the workload that was recorded (aliased to 'perf script' for now).
tools/perf/builtin-sched.c +188 -3
291 lines not on this page · raw message
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v3 2/3] perf sched latency: Auto-scale latency and runtime display units
In reply to Aaron TomlinThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Column misalignment in the 'perf sched latency' output due to data rows being narrower than their…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Column misalignment in the 'perf sched latency' output due to data rows being narrower than their corresponding headers. --
--- Patch [2]: [PATCH v3 2/3] perf sched latency: Auto-scale latency and runtime display units --- commit 2e23c112768cacfb80cab8592bd0a0612fb05704
Author: Aaron Tomlin <[email protected]>
perf sched latency: Auto-scale latency and runtime display units
This commit introduces dynamic scaling for latency and runtime values in 'perf sched latency', outputting them in ns, us, ms, or s. It also renames the column headers to reflect the variable units.
Quoted 4 lines
tools/perf/builtin-sched.c +0
-0
[ ... ]
Quoted 1 line
tools/perf/builtin-sched.c +0
-0@@ -1430,14 +1443,17 @@ static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_
[ ... ]
tools/perf/builtin-sched.c static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_ · line 1455
Quoted 9 lines
tools/perf/builtin-sched.c +4
-5-printf ("|%11.3f ms |%9" PRIu64" | avg:%8.3f ms | max:%8.3f ms | max start: %12s s | max end: %12s s\n" , - (double )work_list->total_runtime /NSEC_PER_MSEC , - work_list->nb_atoms, (double )avg /NSEC_PER_MSEC , - (double )work_list->max_lat /NSEC_PER_MSEC , - max_lat_start, max_lat_end); +printf ("|%14s |%9" PRIu64" | avg:%11s | max:%11s | max start: %12s s | max end: %12s s\n" , + runtime_lat, + work_list->nb_atoms, avg_lat, max_lat, + max_lat_start, max_lat_end);
[Severity: Low]
Does this format change cause the data columns to misalign with the table headers during output?
The updated data row format specifiers " avg:%11s " and " max:%11s " expand to exactly 16 characters each (1 space, 4 chars for the prefix, and 11 chars for the string).
In the old format, " avg:%8.3f ms " expanded to 17 characters, which perfectly matched the 17-character width of the corresponding table headers shown below.
[ ... ]
Quoted 1 line
tools/perf/builtin-sched.c +0
-0@@ -3612,7 +3629,7 @@ static int perf_sched__lat(struct perf_sched *sched)
[ ... ]
tools/perf/builtin-sched.c static int perf_sched__lat(struct perf_sched *sched) · line 3632
Quoted 3 lines
tools/perf/builtin-sched.c +1
-1printf ("\n -------------------------------------------------------------------------------------------------------------------------------------------\n" ); -printf (" Task | Runtime ms | Count | Avg delay ms | Max delay ms | Max delay start | Max delay end |\n" ); +printf (" Task | Runtime | Count | Avg delay | Max delay | Max delay start | Max delay end |\n" );
Because the "Avg delay" and "Max delay" header columns are 17 characters
wide (" Avg delay " and " Max delay "), shrinking the data row
columns by 1 character each will shift the subsequent data columns leftward, breaking vertical alignment.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v3 1/3] perf sched: Suppress latency table output when trace samples are missing
In reply to Aaron TomlinThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing NULL pointer check after calling thread__get_runtime() in map_switch_event() could lead to a segmentation fault.
- [Medium] The default sched.tool initialization for perf sched subcommands omits the .attr and .feature callbacks, preventing evlist population in pipe mode. --
--- Patch [1]: [PATCH v3 1/3] perf sched: Suppress latency table output when trace samples are missing --- commit 74145a7e4615a4aa12c0b60a699cc17c4a941dd7
Author: Aaron Tomlin <[email protected]>
perf sched: Suppress latency table output when trace samples are missing
This commit updates perf_sched__read_events() to abort early and return an error if perf_session__has_traces() evaluates to false. This suppresses empty latency table outputs when no tracepoint samples are present in the perf.data file.
Quoted 4 lines
tools/perf/builtin-sched.c +0
-0
[ ... ]
tools/perf/builtin-sched.c static int perf_sched__read_events(struct perf_sched *sched) · line 2022
Quoted 12 lines
tools/perf/builtin-sched.c +2
-6@@ -2018,18 +2018,19 @@ static int perf_sched__read_events(struct perf_sched *sched)if (perf_session__set_tracepoints_handlers (session, handlers)) goto out_delete; -if (perf_session__has_traces (session,"record -R" )) { -int err =perf_session__process_events (session); -if (err) { -pr_err ("Failed to process events, error %d" , err); - goto out_delete; - } +if (!perf_session__has_traces (session,"record -R" )) + goto out_delete;
[Severity: Medium]
This is a pre-existing issue, but does this patch now cause pipe mode to always fail and return an error code?
Because sched.tool is initialized in cmd_sched() without the mandatory .attr and .feature callbacks:
perf_tool__init(&sched.tool, /*ordered_events=*/true); sched.tool.sample = perf_sched__process_tracepoint_sample; sched.tool.comm = perf_sched__process_comm; sched.tool.namespaces = perf_event__process_namespaces; sched.tool.lost = perf_event__process_lost; sched.tool.fork = perf_sched__process_fork_event;
In pipe mode, PERF_RECORD_HEADER_ATTR events are silently dropped by the fallback stub handler, which prevents evlist population. As a result, perf_session__has_traces() always evaluates to false when reading from a pipe.
With this patch adding an early abort, does this mean commands like 'perf sched latency -i -' will now unconditionally fail instead of processing what they can?
[ ... ]
While reviewing the rest of the file, I noticed another pre-existing issue in map_switch_event() that might surface under memory pressure:
sched_out:
if (sched->map.task_name) {
tr = thread__get_runtime(sched->curr_out_thread[this_cpu.cpu]);
if (strcmp(tr->shortname, "") == 0)
goto out;[Severity: High]
This is a pre-existing issue, but could this lead to a segmentation fault?
If memory allocation fails inside thread__init_runtime(), thread__get_runtime() returns NULL. Unlike other places in map_switch_event() that verify the returned pointer, the tr pointer is immediately dereferenced by strcmp() here without a NULL check.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v3 2/3] perf sched latency: Auto-scale latency and runtime display units
In reply to [email protected]Quoted 32 lines · On Sun, Jul 26, 2026 at 03:33:42AM +0000, [email protected] wrote:
Quoted 4 lines
tools/perf/builtin-sched.c +0
-0[ ... ]
Quoted 1 line
tools/perf/builtin-sched.c +0
-0@@ -1430,14 +1443,17 @@ static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_[ ... ]
tools/perf/builtin-sched.c static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_ · line 1455
Quoted 9 lines
tools/perf/builtin-sched.c +4
-5-printf ("|%11.3f ms |%9" PRIu64" | avg:%8.3f ms | max:%8.3f ms | max start: %12s s | max end: %12s s\n" , - (double )work_list->total_runtime /NSEC_PER_MSEC , - work_list->nb_atoms, (double )avg /NSEC_PER_MSEC , - (double )work_list->max_lat /NSEC_PER_MSEC , - max_lat_start, max_lat_end); +printf ("|%14s |%9" PRIu64" | avg:%11s | max:%11s | max start: %12s s | max end: %12s s\n" , + runtime_lat, + work_list->nb_atoms, avg_lat, max_lat, + max_lat_start, max_lat_end);[Severity: Low]
Does this format change cause the data columns to misalign with the table headers during output?The updated data row format specifiers " avg:%11s " and " max:%11s " expand to exactly 16 characters each (1 space, 4 chars for the prefix, and 11 chars for the string).
In the old format, " avg:%8.3f ms " expanded to 17 characters, which perfectly matched the 17-character width of the corresponding table headers shown below.
[ ... ]
Quoted 1 line
tools/perf/builtin-sched.c +0
-0@@ -3612,7 +3629,7 @@ static int perf_sched__lat(struct perf_sched *sched)[ ... ]
Quoted 8 lines
tools/perf/builtin-sched.c static int perf_sched__lat(struct perf_sched *sched) · line 3632
Quoted 3 lines
tools/perf/builtin-sched.c +1
-1printf ("\n -------------------------------------------------------------------------------------------------------------------------------------------\n" ); -printf (" Task | Runtime ms | Count | Avg delay ms | Max delay ms | Max delay start | Max delay end |\n" ); +printf (" Task | Runtime | Count | Avg delay | Max delay | Max delay start | Max delay end |\n" );Because the "Avg delay" and "Max delay" header columns are 17 characters
wide (" Avg delay " and " Max delay "), shrinking the data row
columns by 1 character each will shift the subsequent data columns leftward, breaking vertical alignment.
Hi Ian, Namhyung, Arnaldo,
This is a minor concern. Nevertheless, to remain consistent, I will address it in v4.
Kind regards,
Signature · 1 line
Aaron Tomlin
Re: [PATCH v3 1/3] perf sched: Suppress latency table output when trace samples are missing
In reply to [email protected]Quoted 52 lines · On Sun, Jul 26, 2026 at 03:37:25AM +0000, [email protected] wrote:
Quoted 4 lines
tools/perf/builtin-sched.c +0
-0[ ... ]
tools/perf/builtin-sched.c static int perf_sched__read_events(struct perf_sched *sched) · line 2022
Quoted 12 lines
tools/perf/builtin-sched.c +2
-6@@ -2018,18 +2018,19 @@ static int perf_sched__read_events(struct perf_sched *sched)if (perf_session__set_tracepoints_handlers (session, handlers)) goto out_delete; -if (perf_session__has_traces (session,"record -R" )) { -int err =perf_session__process_events (session); -if (err) { -pr_err ("Failed to process events, error %d" , err); - goto out_delete; - } +if (!perf_session__has_traces (session,"record -R" )) + goto out_delete;[Severity: Medium]
This is a pre-existing issue, but does this patch now cause pipe mode to always fail and return an error code?Because sched.tool is initialized in
cmd_sched()without the mandatory .attr and .feature callbacks:perf_tool__init(&sched.tool, /*ordered_events=*/true); sched.tool.sample = perf_sched__process_tracepoint_sample; sched.tool.comm = perf_sched__process_comm; sched.tool.namespaces = perf_event__process_namespaces; sched.tool.lost = perf_event__process_lost; sched.tool.fork = perf_sched__process_fork_event;In pipe mode,
PERF_RECORD_HEADER_ATTRevents are silently dropped by the fallback stub handler, which prevents evlist population. As a result,perf_session__has_traces()always evaluates to false when reading from a pipe.With this patch adding an early abort, does this mean commands like 'perf sched latency -i -' will now unconditionally fail instead of processing what they can?
[ ... ]
While reviewing the rest of the file, I noticed another pre-existing issue in
map_switch_event()that might surface under memory pressure:sched_out: if (sched->map.task_name) { tr = thread__get_runtime(sched->curr_out_thread[this_cpu.cpu]); if (strcmp(tr->shortname, "") == 0) goto out;
Quoted 7 lines
[Severity: High]
This is a pre-existing issue, but could this lead to a segmentation fault?If memory allocation fails inside
thread__init_runtime(),thread__get_runtime()returns NULL. Unlike other places inmap_switch_event()that verify the returned pointer, the tr pointer is immediately dereferenced bystrcmp()here without a NULL check.
Hi Ian, Namhyung, Arnaldo,
These are pre-existing issues. However, do you mind if I resolve these valid concerns within this series?
Kind regards,
Signature · 1 line
Aaron Tomlin
Namhyung Kim
maintainerRe: [PATCH v3 1/3] perf sched: Suppress latency table output when trace samples are missing
Hello,
Quoted 61 lines · Aaron Tomlin
Quoted 52 lines · On Sun, Jul 26, 2026 at 03:37:25AM +0000, [email protected] wrote:
Quoted 4 lines
tools/perf/builtin-sched.c +0
-0[ ... ]
tools/perf/builtin-sched.c static int perf_sched__read_events(struct perf_sched *sched) · line 2022
Quoted 12 lines
tools/perf/builtin-sched.c +2
-6@@ -2018,18 +2018,19 @@ static int perf_sched__read_events(struct perf_sched *sched)if (perf_session__set_tracepoints_handlers (session, handlers)) goto out_delete; -if (perf_session__has_traces (session,"record -R" )) { -int err =perf_session__process_events (session); -if (err) { -pr_err ("Failed to process events, error %d" , err); - goto out_delete; - } +if (!perf_session__has_traces (session,"record -R" )) + goto out_delete;[Severity: Medium]
This is a pre-existing issue, but does this patch now cause pipe mode to always fail and return an error code?Because sched.tool is initialized in
cmd_sched()without the mandatory .attr and .feature callbacks:perf_tool__init(&sched.tool, /*ordered_events=*/true); sched.tool.sample = perf_sched__process_tracepoint_sample; sched.tool.comm = perf_sched__process_comm; sched.tool.namespaces = perf_event__process_namespaces; sched.tool.lost = perf_event__process_lost; sched.tool.fork = perf_sched__process_fork_event;In pipe mode,
PERF_RECORD_HEADER_ATTRevents are silently dropped by the fallback stub handler, which prevents evlist population. As a result,perf_session__has_traces()always evaluates to false when reading from a pipe.With this patch adding an early abort, does this mean commands like 'perf sched latency -i -' will now unconditionally fail instead of processing what they can?
[ ... ]
While reviewing the rest of the file, I noticed another pre-existing issue in
map_switch_event()that might surface under memory pressure:sched_out: if (sched->map.task_name) { tr = thread__get_runtime(sched->curr_out_thread[this_cpu.cpu]); if (strcmp(tr->shortname, "") == 0) goto out;Quoted 7 lines
[Severity: High]
This is a pre-existing issue, but could this lead to a segmentation fault?If memory allocation fails inside
thread__init_runtime(),thread__get_runtime()returns NULL. Unlike other places inmap_switch_event()that verify the returned pointer, the tr pointer is immediately dereferenced bystrcmp()here without a NULL check.
Quoted 4 lines
Hi Ian, Namhyung, Arnaldo,
These are pre-existing issues. However, do you mind if I resolve these valid concerns within this series?
I'm fine as long as you address them either in this series or a separate one.
Thanks,
Namhyung