tools/rtla: Add for_each_monitored_cpu() helper
The rtla tools have many instances of iterating over CPUs while checking if they are monitored. Add a for_each_monitored_cpu() helper macro to make the code more readable and reduce code duplication. Signed-off-by: Costa Shulyupin <costa.shul@redhat.com> Reviewed-by: Tomas Glozar <tglozar@redhat.com> Link: https://lore.kernel.org/r/20251002123553.389467-1-costa.shul@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>pull/1354/merge
parent
0d5077c73a
commit
04fa6bf373
|
|
@ -107,6 +107,10 @@ struct common_params {
|
||||||
struct timerlat_u_params user;
|
struct timerlat_u_params user;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define for_each_monitored_cpu(cpu, nr_cpus, common) \
|
||||||
|
for (cpu = 0; cpu < nr_cpus; cpu++) \
|
||||||
|
if (!(common)->cpus || CPU_ISSET(cpu, &(common)->monitored_cpus))
|
||||||
|
|
||||||
struct tool_ops;
|
struct tool_ops;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -247,9 +247,7 @@ static void osnoise_hist_header(struct osnoise_tool *tool)
|
||||||
if (!params->common.hist.no_index)
|
if (!params->common.hist.no_index)
|
||||||
trace_seq_printf(s, "Index");
|
trace_seq_printf(s, "Index");
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].count)
|
if (!data->hist[cpu].count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -278,9 +276,7 @@ osnoise_print_summary(struct osnoise_params *params,
|
||||||
if (!params->common.hist.no_index)
|
if (!params->common.hist.no_index)
|
||||||
trace_seq_printf(trace->seq, "count:");
|
trace_seq_printf(trace->seq, "count:");
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].count)
|
if (!data->hist[cpu].count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -292,9 +288,7 @@ osnoise_print_summary(struct osnoise_params *params,
|
||||||
if (!params->common.hist.no_index)
|
if (!params->common.hist.no_index)
|
||||||
trace_seq_printf(trace->seq, "min: ");
|
trace_seq_printf(trace->seq, "min: ");
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].count)
|
if (!data->hist[cpu].count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -307,9 +301,7 @@ osnoise_print_summary(struct osnoise_params *params,
|
||||||
if (!params->common.hist.no_index)
|
if (!params->common.hist.no_index)
|
||||||
trace_seq_printf(trace->seq, "avg: ");
|
trace_seq_printf(trace->seq, "avg: ");
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].count)
|
if (!data->hist[cpu].count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -325,9 +317,7 @@ osnoise_print_summary(struct osnoise_params *params,
|
||||||
if (!params->common.hist.no_index)
|
if (!params->common.hist.no_index)
|
||||||
trace_seq_printf(trace->seq, "max: ");
|
trace_seq_printf(trace->seq, "max: ");
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].count)
|
if (!data->hist[cpu].count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -362,9 +352,7 @@ osnoise_print_stats(struct osnoise_tool *tool)
|
||||||
trace_seq_printf(trace->seq, "%-6d",
|
trace_seq_printf(trace->seq, "%-6d",
|
||||||
bucket * data->bucket_size);
|
bucket * data->bucket_size);
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].count)
|
if (!data->hist[cpu].count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -400,9 +388,7 @@ osnoise_print_stats(struct osnoise_tool *tool)
|
||||||
if (!params->common.hist.no_index)
|
if (!params->common.hist.no_index)
|
||||||
trace_seq_printf(trace->seq, "over: ");
|
trace_seq_printf(trace->seq, "over: ");
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].count)
|
if (!data->hist[cpu].count)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -243,9 +243,7 @@ osnoise_print_stats(struct osnoise_tool *top)
|
||||||
|
|
||||||
osnoise_top_header(top);
|
osnoise_top_header(top);
|
||||||
|
|
||||||
for (i = 0; i < nr_cpus; i++) {
|
for_each_monitored_cpu(i, nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(i, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
osnoise_top_print(top, i);
|
osnoise_top_print(top, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,9 +126,7 @@ int timerlat_enable(struct osnoise_tool *tool)
|
||||||
|
|
||||||
nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
|
nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
|
||||||
|
|
||||||
for (i = 0; i < nr_cpus; i++) {
|
for_each_monitored_cpu(i, nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(i, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
if (save_cpu_idle_disable_state(i) < 0) {
|
if (save_cpu_idle_disable_state(i) < 0) {
|
||||||
err_msg("Could not save cpu idle state.\n");
|
err_msg("Could not save cpu idle state.\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -221,10 +219,7 @@ void timerlat_free(struct osnoise_tool *tool)
|
||||||
if (dma_latency_fd >= 0)
|
if (dma_latency_fd >= 0)
|
||||||
close(dma_latency_fd);
|
close(dma_latency_fd);
|
||||||
if (params->deepest_idle_state >= -1) {
|
if (params->deepest_idle_state >= -1) {
|
||||||
for (i = 0; i < nr_cpus; i++) {
|
for_each_monitored_cpu(i, nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus &&
|
|
||||||
!CPU_ISSET(i, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
restore_cpu_idle_disable_state(i);
|
restore_cpu_idle_disable_state(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -305,9 +305,7 @@ static void timerlat_hist_header(struct osnoise_tool *tool)
|
||||||
if (!params->common.hist.no_index)
|
if (!params->common.hist.no_index)
|
||||||
trace_seq_printf(s, "Index");
|
trace_seq_printf(s, "Index");
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -359,9 +357,7 @@ timerlat_print_summary(struct timerlat_params *params,
|
||||||
if (!params->common.hist.no_index)
|
if (!params->common.hist.no_index)
|
||||||
trace_seq_printf(trace->seq, "count:");
|
trace_seq_printf(trace->seq, "count:");
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -383,9 +379,7 @@ timerlat_print_summary(struct timerlat_params *params,
|
||||||
if (!params->common.hist.no_index)
|
if (!params->common.hist.no_index)
|
||||||
trace_seq_printf(trace->seq, "min: ");
|
trace_seq_printf(trace->seq, "min: ");
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -413,9 +407,7 @@ timerlat_print_summary(struct timerlat_params *params,
|
||||||
if (!params->common.hist.no_index)
|
if (!params->common.hist.no_index)
|
||||||
trace_seq_printf(trace->seq, "avg: ");
|
trace_seq_printf(trace->seq, "avg: ");
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -443,9 +435,7 @@ timerlat_print_summary(struct timerlat_params *params,
|
||||||
if (!params->common.hist.no_index)
|
if (!params->common.hist.no_index)
|
||||||
trace_seq_printf(trace->seq, "max: ");
|
trace_seq_printf(trace->seq, "max: ");
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -490,9 +480,7 @@ timerlat_print_stats_all(struct timerlat_params *params,
|
||||||
sum.min_thread = ~0;
|
sum.min_thread = ~0;
|
||||||
sum.min_user = ~0;
|
sum.min_user = ~0;
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -639,9 +627,7 @@ timerlat_print_stats(struct osnoise_tool *tool)
|
||||||
trace_seq_printf(trace->seq, "%-6d",
|
trace_seq_printf(trace->seq, "%-6d",
|
||||||
bucket * data->bucket_size);
|
bucket * data->bucket_size);
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -679,9 +665,7 @@ timerlat_print_stats(struct osnoise_tool *tool)
|
||||||
if (!params->common.hist.no_index)
|
if (!params->common.hist.no_index)
|
||||||
trace_seq_printf(trace->seq, "over: ");
|
trace_seq_printf(trace->seq, "over: ");
|
||||||
|
|
||||||
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
|
for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -459,9 +459,7 @@ timerlat_print_stats(struct osnoise_tool *top)
|
||||||
|
|
||||||
timerlat_top_header(params, top);
|
timerlat_top_header(params, top);
|
||||||
|
|
||||||
for (i = 0; i < nr_cpus; i++) {
|
for_each_monitored_cpu(i, nr_cpus, ¶ms->common) {
|
||||||
if (params->common.cpus && !CPU_ISSET(i, ¶ms->common.monitored_cpus))
|
|
||||||
continue;
|
|
||||||
timerlat_top_print(top, i);
|
timerlat_top_print(top, i);
|
||||||
timerlat_top_update_sum(top, i, &summary);
|
timerlat_top_update_sum(top, i, &summary);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue