rtla/timerlat: Fix histogram ALL for zero samples

rtla timerlat hist currently computers the minimum, maximum and average
latency even in cases when there are zero samples. This leads to
nonsensical values being calculated for maximum and minimum, and to
divide by zero for average.

A similar bug is fixed by 01b05fc0e5 ("rtla/timerlat: Fix histogram
report when a cpu count is 0") but the bug still remains for printing
the sum over all CPUs in timerlat_print_stats_all.

The issue can be reproduced with this command:

$ rtla timerlat hist -U -d 1s
Index
over:
count:
min:
avg:
max:
Floating point exception (core dumped)

(There are always no samples with -U unless the user workload is
created.)

Fix the bug by omitting max/min/avg when sample count is zero,
displaying a dash instead, just like we already do for the individual
CPUs. The logic is moved into a new function called
format_summary_value, which is used for both the individual CPUs
and for the overall summary.

Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/20241127134130.51171-1-tglozar@redhat.com
Fixes: 1462501c7a ("rtla/timerlat: Add a summary for hist mode")
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
This commit is contained in:
Tomas Glozar 2024-11-27 14:41:30 +01:00 committed by Steven Rostedt (Google)
parent 4bbf9020be
commit 6cc45f8c1f

View File

@ -281,6 +281,21 @@ static void timerlat_hist_header(struct osnoise_tool *tool)
trace_seq_reset(s); trace_seq_reset(s);
} }
/*
* format_summary_value - format a line of summary value (min, max or avg)
* of hist data
*/
static void format_summary_value(struct trace_seq *seq,
int count,
unsigned long long val,
bool avg)
{
if (count)
trace_seq_printf(seq, "%9llu ", avg ? val / count : val);
else
trace_seq_printf(seq, "%9c ", '-');
}
/* /*
* timerlat_print_summary - print the summary of the hist data to the output * timerlat_print_summary - print the summary of the hist data to the output
*/ */
@ -328,29 +343,23 @@ timerlat_print_summary(struct timerlat_hist_params *params,
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count) if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue; continue;
if (!params->no_irq) { if (!params->no_irq)
if (data->hist[cpu].irq_count) format_summary_value(trace->seq,
trace_seq_printf(trace->seq, "%9llu ", data->hist[cpu].irq_count,
data->hist[cpu].min_irq); data->hist[cpu].min_irq,
else false);
trace_seq_printf(trace->seq, " - ");
}
if (!params->no_thread) { if (!params->no_thread)
if (data->hist[cpu].thread_count) format_summary_value(trace->seq,
trace_seq_printf(trace->seq, "%9llu ", data->hist[cpu].thread_count,
data->hist[cpu].min_thread); data->hist[cpu].min_thread,
else false);
trace_seq_printf(trace->seq, " - ");
}
if (params->user_hist) { if (params->user_hist)
if (data->hist[cpu].user_count) format_summary_value(trace->seq,
trace_seq_printf(trace->seq, "%9llu ", data->hist[cpu].user_count,
data->hist[cpu].min_user); data->hist[cpu].min_user,
else false);
trace_seq_printf(trace->seq, " - ");
}
} }
trace_seq_printf(trace->seq, "\n"); trace_seq_printf(trace->seq, "\n");
@ -364,29 +373,23 @@ timerlat_print_summary(struct timerlat_hist_params *params,
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count) if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue; continue;
if (!params->no_irq) { if (!params->no_irq)
if (data->hist[cpu].irq_count) format_summary_value(trace->seq,
trace_seq_printf(trace->seq, "%9llu ", data->hist[cpu].irq_count,
data->hist[cpu].sum_irq / data->hist[cpu].irq_count); data->hist[cpu].sum_irq,
else true);
trace_seq_printf(trace->seq, " - ");
}
if (!params->no_thread) { if (!params->no_thread)
if (data->hist[cpu].thread_count) format_summary_value(trace->seq,
trace_seq_printf(trace->seq, "%9llu ", data->hist[cpu].thread_count,
data->hist[cpu].sum_thread / data->hist[cpu].thread_count); data->hist[cpu].sum_thread,
else true);
trace_seq_printf(trace->seq, " - ");
}
if (params->user_hist) { if (params->user_hist)
if (data->hist[cpu].user_count) format_summary_value(trace->seq,
trace_seq_printf(trace->seq, "%9llu ", data->hist[cpu].user_count,
data->hist[cpu].sum_user / data->hist[cpu].user_count); data->hist[cpu].sum_user,
else true);
trace_seq_printf(trace->seq, " - ");
}
} }
trace_seq_printf(trace->seq, "\n"); trace_seq_printf(trace->seq, "\n");
@ -400,29 +403,23 @@ timerlat_print_summary(struct timerlat_hist_params *params,
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count) if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue; continue;
if (!params->no_irq) { if (!params->no_irq)
if (data->hist[cpu].irq_count) format_summary_value(trace->seq,
trace_seq_printf(trace->seq, "%9llu ", data->hist[cpu].irq_count,
data->hist[cpu].max_irq); data->hist[cpu].max_irq,
else false);
trace_seq_printf(trace->seq, " - ");
}
if (!params->no_thread) { if (!params->no_thread)
if (data->hist[cpu].thread_count) format_summary_value(trace->seq,
trace_seq_printf(trace->seq, "%9llu ", data->hist[cpu].thread_count,
data->hist[cpu].max_thread); data->hist[cpu].max_thread,
else false);
trace_seq_printf(trace->seq, " - ");
}
if (params->user_hist) { if (params->user_hist)
if (data->hist[cpu].user_count) format_summary_value(trace->seq,
trace_seq_printf(trace->seq, "%9llu ", data->hist[cpu].user_count,
data->hist[cpu].max_user); data->hist[cpu].max_user,
else false);
trace_seq_printf(trace->seq, " - ");
}
} }
trace_seq_printf(trace->seq, "\n"); trace_seq_printf(trace->seq, "\n");
trace_seq_do_printf(trace->seq); trace_seq_do_printf(trace->seq);
@ -506,16 +503,22 @@ timerlat_print_stats_all(struct timerlat_hist_params *params,
trace_seq_printf(trace->seq, "min: "); trace_seq_printf(trace->seq, "min: ");
if (!params->no_irq) if (!params->no_irq)
trace_seq_printf(trace->seq, "%9llu ", format_summary_value(trace->seq,
sum.min_irq); sum.irq_count,
sum.min_irq,
false);
if (!params->no_thread) if (!params->no_thread)
trace_seq_printf(trace->seq, "%9llu ", format_summary_value(trace->seq,
sum.min_thread); sum.thread_count,
sum.min_thread,
false);
if (params->user_hist) if (params->user_hist)
trace_seq_printf(trace->seq, "%9llu ", format_summary_value(trace->seq,
sum.min_user); sum.user_count,
sum.min_user,
false);
trace_seq_printf(trace->seq, "\n"); trace_seq_printf(trace->seq, "\n");
@ -523,16 +526,22 @@ timerlat_print_stats_all(struct timerlat_hist_params *params,
trace_seq_printf(trace->seq, "avg: "); trace_seq_printf(trace->seq, "avg: ");
if (!params->no_irq) if (!params->no_irq)
trace_seq_printf(trace->seq, "%9llu ", format_summary_value(trace->seq,
sum.sum_irq / sum.irq_count); sum.irq_count,
sum.sum_irq,
true);
if (!params->no_thread) if (!params->no_thread)
trace_seq_printf(trace->seq, "%9llu ", format_summary_value(trace->seq,
sum.sum_thread / sum.thread_count); sum.thread_count,
sum.sum_thread,
true);
if (params->user_hist) if (params->user_hist)
trace_seq_printf(trace->seq, "%9llu ", format_summary_value(trace->seq,
sum.sum_user / sum.user_count); sum.user_count,
sum.sum_user,
true);
trace_seq_printf(trace->seq, "\n"); trace_seq_printf(trace->seq, "\n");
@ -540,16 +549,22 @@ timerlat_print_stats_all(struct timerlat_hist_params *params,
trace_seq_printf(trace->seq, "max: "); trace_seq_printf(trace->seq, "max: ");
if (!params->no_irq) if (!params->no_irq)
trace_seq_printf(trace->seq, "%9llu ", format_summary_value(trace->seq,
sum.max_irq); sum.irq_count,
sum.max_irq,
false);
if (!params->no_thread) if (!params->no_thread)
trace_seq_printf(trace->seq, "%9llu ", format_summary_value(trace->seq,
sum.max_thread); sum.thread_count,
sum.max_thread,
false);
if (params->user_hist) if (params->user_hist)
trace_seq_printf(trace->seq, "%9llu ", format_summary_value(trace->seq,
sum.max_user); sum.user_count,
sum.max_user,
false);
trace_seq_printf(trace->seq, "\n"); trace_seq_printf(trace->seq, "\n");
trace_seq_do_printf(trace->seq); trace_seq_do_printf(trace->seq);