From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Tomas Glozar <tglozar@redhat.com>, John Kacur <jkacur@redhat.com>,
Costa Shulyupin <costa.shul@redhat.com>
Subject: [for-next][PATCH 01/16] tools/rtla: Add for_each_monitored_cpu() helper
Date: Thu, 20 Nov 2025 18:23:24 -0500 [thread overview]
Message-ID: <20251120232707.442753984@kernel.org> (raw)
In-Reply-To: 20251120232323.271532418@kernel.org
From: Costa Shulyupin <costa.shul@redhat.com>
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>
---
tools/tracing/rtla/src/common.h | 4 ++++
tools/tracing/rtla/src/osnoise_hist.c | 28 ++++++----------------
tools/tracing/rtla/src/osnoise_top.c | 4 +---
tools/tracing/rtla/src/timerlat.c | 9 ++------
tools/tracing/rtla/src/timerlat_hist.c | 32 +++++++-------------------
tools/tracing/rtla/src/timerlat_top.c | 4 +---
6 files changed, 23 insertions(+), 58 deletions(-)
diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/common.h
index 355f113a14a3..9ec2b7632c37 100644
--- a/tools/tracing/rtla/src/common.h
+++ b/tools/tracing/rtla/src/common.h
@@ -107,6 +107,10 @@ struct common_params {
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;
/*
diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c
index dffb6d0a98d7..844f0468953c 100644
--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -247,9 +247,7 @@ static void osnoise_hist_header(struct osnoise_tool *tool)
if (!params->common.hist.no_index)
trace_seq_printf(s, "Index");
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -278,9 +276,7 @@ osnoise_print_summary(struct osnoise_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "count:");
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -292,9 +288,7 @@ osnoise_print_summary(struct osnoise_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "min: ");
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -307,9 +301,7 @@ osnoise_print_summary(struct osnoise_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "avg: ");
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -325,9 +317,7 @@ osnoise_print_summary(struct osnoise_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "max: ");
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -362,9 +352,7 @@ osnoise_print_stats(struct osnoise_tool *tool)
trace_seq_printf(trace->seq, "%-6d",
bucket * data->bucket_size);
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -400,9 +388,7 @@ osnoise_print_stats(struct osnoise_tool *tool)
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "over: ");
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c
index 95418f7ecc96..defa1eb63bee 100644
--- a/tools/tracing/rtla/src/osnoise_top.c
+++ b/tools/tracing/rtla/src/osnoise_top.c
@@ -243,9 +243,7 @@ osnoise_print_stats(struct osnoise_tool *top)
osnoise_top_header(top);
- for (i = 0; i < nr_cpus; i++) {
- if (params->common.cpus && !CPU_ISSET(i, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(i, nr_cpus, ¶ms->common) {
osnoise_top_print(top, i);
}
diff --git a/tools/tracing/rtla/src/timerlat.c b/tools/tracing/rtla/src/timerlat.c
index b69212874127..28ea4f6710c1 100644
--- a/tools/tracing/rtla/src/timerlat.c
+++ b/tools/tracing/rtla/src/timerlat.c
@@ -126,9 +126,7 @@ int timerlat_enable(struct osnoise_tool *tool)
nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
- for (i = 0; i < nr_cpus; i++) {
- if (params->common.cpus && !CPU_ISSET(i, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(i, nr_cpus, ¶ms->common) {
if (save_cpu_idle_disable_state(i) < 0) {
err_msg("Could not save cpu idle state.\n");
return -1;
@@ -221,10 +219,7 @@ void timerlat_free(struct osnoise_tool *tool)
if (dma_latency_fd >= 0)
close(dma_latency_fd);
if (params->deepest_idle_state >= -1) {
- for (i = 0; i < nr_cpus; i++) {
- if (params->common.cpus &&
- !CPU_ISSET(i, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(i, nr_cpus, ¶ms->common) {
restore_cpu_idle_disable_state(i);
}
}
diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c
index 606c1688057b..02d3ffd2cf4b 100644
--- a/tools/tracing/rtla/src/timerlat_hist.c
+++ b/tools/tracing/rtla/src/timerlat_hist.c
@@ -305,9 +305,7 @@ static void timerlat_hist_header(struct osnoise_tool *tool)
if (!params->common.hist.no_index)
trace_seq_printf(s, "Index");
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -359,9 +357,7 @@ timerlat_print_summary(struct timerlat_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "count:");
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -383,9 +379,7 @@ timerlat_print_summary(struct timerlat_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "min: ");
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -413,9 +407,7 @@ timerlat_print_summary(struct timerlat_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "avg: ");
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -443,9 +435,7 @@ timerlat_print_summary(struct timerlat_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "max: ");
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -490,9 +480,7 @@ timerlat_print_stats_all(struct timerlat_params *params,
sum.min_thread = ~0;
sum.min_user = ~0;
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -639,9 +627,7 @@ timerlat_print_stats(struct osnoise_tool *tool)
trace_seq_printf(trace->seq, "%-6d",
bucket * data->bucket_size);
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -679,9 +665,7 @@ timerlat_print_stats(struct osnoise_tool *tool)
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "over: ");
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
- if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c
index fc479a0dcb59..607b57f2f231 100644
--- a/tools/tracing/rtla/src/timerlat_top.c
+++ b/tools/tracing/rtla/src/timerlat_top.c
@@ -459,9 +459,7 @@ timerlat_print_stats(struct osnoise_tool *top)
timerlat_top_header(params, top);
- for (i = 0; i < nr_cpus; i++) {
- if (params->common.cpus && !CPU_ISSET(i, ¶ms->common.monitored_cpus))
- continue;
+ for_each_monitored_cpu(i, nr_cpus, ¶ms->common) {
timerlat_top_print(top, i);
timerlat_top_update_sum(top, i, &summary);
}
--
2.51.0
next prev parent reply other threads:[~2025-11-20 23:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-20 23:23 [for-next][PATCH 00/16] rtla: Updates for v6.19 Steven Rostedt
2025-11-20 23:23 ` Steven Rostedt [this message]
2025-11-20 23:23 ` [for-next][PATCH 02/16] tools/rtla: Remove unused optional option_index Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 03/16] tools/rtla: Fix unassigned nr_cpus Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 04/16] rtla/timerlat_bpf: Stop tracing on user latency Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 05/16] tools/rtla: Fix --on-threshold always triggering Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 06/16] rtla/tests: Extend action tests to 5s Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 07/16] rtla/tests: Fix osnoise test calling timerlat Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 08/16] tools/rtla: Add fatal() and replace error handling pattern Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 09/16] tools/rtla: Replace timerlat_top_usage("...") with fatal("...") Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 10/16] tools/rtla: Replace timerlat_hist_usage("...") " Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 11/16] tools/rtla: Replace osnoise_top_usage("...") " Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 12/16] tools/rtla: Replace osnoise_hist_usage("...") " Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 13/16] rtla: Fix -C/--cgroup interface Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 14/16] rtla: Fix -a overriding -t argument Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 15/16] rtla/tests: Dont rely on matching ^1ALL Steven Rostedt
2025-11-20 23:23 ` [for-next][PATCH 16/16] rtla/timerlat: Exit top main loop on any non-zero wait_retval Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251120232707.442753984@kernel.org \
--to=rostedt@kernel.org \
--cc=costa.shul@redhat.com \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglozar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.