* [PATCH v4 1/4] tools/rtla: Consolidate nr_cpus usage across all tools
2026-03-06 19:49 [PATCH v4 0/4] tools/rtla: Consolidate nr_cpus usage Costa Shulyupin
@ 2026-03-06 19:49 ` Costa Shulyupin
2026-03-06 19:49 ` [PATCH v4 2/4] tools/rtla: Remove unneeded nr_cpus arguments Costa Shulyupin
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Costa Shulyupin @ 2026-03-06 19:49 UTC (permalink / raw)
To: Steven Rostedt, Tomas Glozar, Costa Shulyupin, Crystal Wood,
Wander Lairson Costa, John Kacur, Ivan Pravdin, Tiezhu Yang,
linux-trace-kernel, linux-kernel, bpf
sysconf(_SC_NPROCESSORS_CONF) (via get_nprocs_conf) reflects
cpu_possible_mask, which is fixed at boot time, so querying it
repeatedly is unnecessary.
Replace multiple calls to sysconf(_SC_NPROCESSORS_CONF) with a single
global nr_cpus variable initialized once at startup.
`#pragma once` in timerlat_u.h is needed for pre-C23 compilers to avoid
redefinition errors.
Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
---
tools/tracing/rtla/src/common.c | 7 +++-
tools/tracing/rtla/src/common.h | 2 +
tools/tracing/rtla/src/osnoise_hist.c | 3 --
tools/tracing/rtla/src/osnoise_top.c | 7 ----
tools/tracing/rtla/src/timerlat.c | 5 +--
tools/tracing/rtla/src/timerlat_aa.c | 1 -
tools/tracing/rtla/src/timerlat_hist.c | 3 --
tools/tracing/rtla/src/timerlat_top.c | 7 ----
tools/tracing/rtla/src/timerlat_u.c | 3 +-
tools/tracing/rtla/src/timerlat_u.h | 1 +
tools/tracing/rtla/src/utils.c | 10 +----
tools/tracing/rtla/tests/unit/unit_tests.c | 44 ++++++++++------------
12 files changed, 31 insertions(+), 62 deletions(-)
diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/common.c
index f310b0d59ad3..a31fbaea5da6 100644
--- a/tools/tracing/rtla/src/common.c
+++ b/tools/tracing/rtla/src/common.c
@@ -5,12 +5,14 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <getopt.h>
+#include <sys/sysinfo.h>
+
#include "common.h"
struct trace_instance *trace_inst;
volatile int stop_tracing;
+int nr_cpus;
static void stop_trace(int sig)
{
@@ -165,7 +167,7 @@ common_apply_config(struct osnoise_tool *tool, struct common_params *params)
}
if (!params->cpus) {
- for (i = 0; i < sysconf(_SC_NPROCESSORS_CONF); i++)
+ for (i = 0; i < nr_cpus; i++)
CPU_SET(i, ¶ms->monitored_cpus);
}
@@ -213,6 +215,7 @@ int run_tool(struct tool_ops *ops, int argc, char *argv[])
bool stopped;
int retval;
+ nr_cpus = get_nprocs_conf();
params = ops->parse_args(argc, argv);
if (!params)
exit(1);
diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/common.h
index d4b3715700be..90a3c0d1dbf3 100644
--- a/tools/tracing/rtla/src/common.h
+++ b/tools/tracing/rtla/src/common.h
@@ -108,6 +108,8 @@ struct common_params {
struct timerlat_u_params user;
};
+extern int nr_cpus;
+
#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))
diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c
index 5c863e7aad28..00b8c95cbf85 100644
--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -646,9 +646,6 @@ static struct osnoise_tool
*osnoise_init_hist(struct common_params *params)
{
struct osnoise_tool *tool;
- int nr_cpus;
-
- nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
tool = osnoise_init_tool("osnoise_hist");
if (!tool)
diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c
index b7aed40fd216..9a6cd9a2470a 100644
--- a/tools/tracing/rtla/src/osnoise_top.c
+++ b/tools/tracing/rtla/src/osnoise_top.c
@@ -232,12 +232,8 @@ osnoise_print_stats(struct osnoise_tool *top)
{
struct osnoise_params *params = to_osnoise_params(top->params);
struct trace_instance *trace = &top->trace;
- static int nr_cpus = -1;
int i;
- if (nr_cpus == -1)
- nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
-
if (!params->common.quiet)
clear_terminal(trace->seq);
@@ -494,9 +490,6 @@ osnoise_top_apply_config(struct osnoise_tool *tool)
struct osnoise_tool *osnoise_init_top(struct common_params *params)
{
struct osnoise_tool *tool;
- int nr_cpus;
-
- nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
tool = osnoise_init_tool("osnoise_top");
if (!tool)
diff --git a/tools/tracing/rtla/src/timerlat.c b/tools/tracing/rtla/src/timerlat.c
index 9e4daed0aafc..31c921efa7c1 100644
--- a/tools/tracing/rtla/src/timerlat.c
+++ b/tools/tracing/rtla/src/timerlat.c
@@ -99,7 +99,7 @@ timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params)
int timerlat_enable(struct osnoise_tool *tool)
{
struct timerlat_params *params = to_timerlat_params(tool->params);
- int retval, nr_cpus, i;
+ int retval, i;
if (params->dma_latency >= 0) {
dma_latency_fd = set_cpu_dma_latency(params->dma_latency);
@@ -115,8 +115,6 @@ int timerlat_enable(struct osnoise_tool *tool)
return -1;
}
- nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
-
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");
@@ -214,7 +212,6 @@ void timerlat_analyze(struct osnoise_tool *tool, bool stopped)
void timerlat_free(struct osnoise_tool *tool)
{
struct timerlat_params *params = to_timerlat_params(tool->params);
- int nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
int i;
timerlat_aa_destroy();
diff --git a/tools/tracing/rtla/src/timerlat_aa.c b/tools/tracing/rtla/src/timerlat_aa.c
index 178de60dcef9..095483375823 100644
--- a/tools/tracing/rtla/src/timerlat_aa.c
+++ b/tools/tracing/rtla/src/timerlat_aa.c
@@ -1043,7 +1043,6 @@ void timerlat_aa_destroy(void)
*/
int timerlat_aa_init(struct osnoise_tool *tool, int dump_tasks, enum stack_format stack_format)
{
- int nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
struct timerlat_aa_context *taa_ctx;
int retval;
diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c
index 88211e54bc9d..3ebe41eed9f6 100644
--- a/tools/tracing/rtla/src/timerlat_hist.c
+++ b/tools/tracing/rtla/src/timerlat_hist.c
@@ -1040,9 +1040,6 @@ static struct osnoise_tool
*timerlat_init_hist(struct common_params *params)
{
struct osnoise_tool *tool;
- int nr_cpus;
-
- nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
tool = osnoise_init_tool("timerlat_hist");
if (!tool)
diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c
index 7a00f3844f56..4105638f45c4 100644
--- a/tools/tracing/rtla/src/timerlat_top.c
+++ b/tools/tracing/rtla/src/timerlat_top.c
@@ -442,15 +442,11 @@ timerlat_print_stats(struct osnoise_tool *top)
struct timerlat_params *params = to_timerlat_params(top->params);
struct trace_instance *trace = &top->trace;
struct timerlat_top_cpu summary;
- static int nr_cpus = -1;
int i;
if (params->common.aa_only)
return;
- if (nr_cpus == -1)
- nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
-
if (!params->common.quiet)
clear_terminal(trace->seq);
@@ -790,9 +786,6 @@ static struct osnoise_tool
*timerlat_init_top(struct common_params *params)
{
struct osnoise_tool *top;
- int nr_cpus;
-
- nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
top = osnoise_init_tool("timerlat_top");
if (!top)
diff --git a/tools/tracing/rtla/src/timerlat_u.c b/tools/tracing/rtla/src/timerlat_u.c
index ce68e39d25fd..a569fe7f93aa 100644
--- a/tools/tracing/rtla/src/timerlat_u.c
+++ b/tools/tracing/rtla/src/timerlat_u.c
@@ -16,7 +16,7 @@
#include <sys/wait.h>
#include <sys/prctl.h>
-#include "utils.h"
+#include "common.h"
#include "timerlat_u.h"
/*
@@ -131,7 +131,6 @@ static int timerlat_u_send_kill(pid_t *procs, int nr_cpus)
*/
void *timerlat_u_dispatcher(void *data)
{
- int nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
struct timerlat_u_params *params = data;
char proc_name[128];
int procs_count = 0;
diff --git a/tools/tracing/rtla/src/timerlat_u.h b/tools/tracing/rtla/src/timerlat_u.h
index 661511908957..a692331bd1c7 100644
--- a/tools/tracing/rtla/src/timerlat_u.h
+++ b/tools/tracing/rtla/src/timerlat_u.h
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
+#pragma once
/*
* Copyright (C) 2023 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
*/
diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
index d979159f6b70..77593718766a 100644
--- a/tools/tracing/rtla/src/utils.c
+++ b/tools/tracing/rtla/src/utils.c
@@ -19,7 +19,7 @@
#include <stdio.h>
#include <limits.h>
-#include "utils.h"
+#include "common.h"
#define MAX_MSG_LENGTH 1024
int config_debug;
@@ -119,14 +119,11 @@ int parse_cpu_set(char *cpu_list, cpu_set_t *set)
{
const char *p;
int end_cpu;
- int nr_cpus;
int cpu;
int i;
CPU_ZERO(set);
- nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
-
for (p = cpu_list; *p; ) {
cpu = atoi(p);
if (cpu < 0 || (!cpu && *p != '0') || cpu >= nr_cpus)
@@ -577,7 +574,6 @@ int save_cpu_idle_disable_state(unsigned int cpu)
unsigned int nr_states;
unsigned int state;
int disabled;
- int nr_cpus;
nr_states = cpuidle_state_count(cpu);
@@ -585,7 +581,6 @@ int save_cpu_idle_disable_state(unsigned int cpu)
return 0;
if (saved_cpu_idle_disable_state == NULL) {
- nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
saved_cpu_idle_disable_state = calloc(nr_cpus, sizeof(unsigned int *));
if (!saved_cpu_idle_disable_state)
return -1;
@@ -662,13 +657,10 @@ int restore_cpu_idle_disable_state(unsigned int cpu)
void free_cpu_idle_disable_states(void)
{
int cpu;
- int nr_cpus;
if (!saved_cpu_idle_disable_state)
return;
- nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
-
for (cpu = 0; cpu < nr_cpus; cpu++) {
free(saved_cpu_idle_disable_state[cpu]);
saved_cpu_idle_disable_state[cpu] = NULL;
diff --git a/tools/tracing/rtla/tests/unit/unit_tests.c b/tools/tracing/rtla/tests/unit/unit_tests.c
index aa53f8605e36..f3c6d89e3300 100644
--- a/tools/tracing/rtla/tests/unit/unit_tests.c
+++ b/tools/tracing/rtla/tests/unit/unit_tests.c
@@ -7,8 +7,10 @@
#include <sched.h>
#include <limits.h>
#include <unistd.h>
+#include <sys/sysinfo.h>
#include "../../src/utils.h"
+int nr_cpus;
START_TEST(test_strtoi)
{
@@ -34,35 +36,29 @@ END_TEST
START_TEST(test_parse_cpu_set)
{
cpu_set_t set;
- int nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
+ nr_cpus = 8;
ck_assert_int_eq(parse_cpu_set("0", &set), 0);
ck_assert(CPU_ISSET(0, &set));
ck_assert(!CPU_ISSET(1, &set));
- if (nr_cpus > 2) {
- ck_assert_int_eq(parse_cpu_set("0,2", &set), 0);
- ck_assert(CPU_ISSET(0, &set));
- ck_assert(CPU_ISSET(2, &set));
- }
-
- if (nr_cpus > 3) {
- ck_assert_int_eq(parse_cpu_set("0-3", &set), 0);
- ck_assert(CPU_ISSET(0, &set));
- ck_assert(CPU_ISSET(1, &set));
- ck_assert(CPU_ISSET(2, &set));
- ck_assert(CPU_ISSET(3, &set));
- }
-
- if (nr_cpus > 5) {
- ck_assert_int_eq(parse_cpu_set("1-3,5", &set), 0);
- ck_assert(!CPU_ISSET(0, &set));
- ck_assert(CPU_ISSET(1, &set));
- ck_assert(CPU_ISSET(2, &set));
- ck_assert(CPU_ISSET(3, &set));
- ck_assert(!CPU_ISSET(4, &set));
- ck_assert(CPU_ISSET(5, &set));
- }
+ ck_assert_int_eq(parse_cpu_set("0,2", &set), 0);
+ ck_assert(CPU_ISSET(0, &set));
+ ck_assert(CPU_ISSET(2, &set));
+
+ ck_assert_int_eq(parse_cpu_set("0-3", &set), 0);
+ ck_assert(CPU_ISSET(0, &set));
+ ck_assert(CPU_ISSET(1, &set));
+ ck_assert(CPU_ISSET(2, &set));
+ ck_assert(CPU_ISSET(3, &set));
+
+ ck_assert_int_eq(parse_cpu_set("1-3,5", &set), 0);
+ ck_assert(!CPU_ISSET(0, &set));
+ ck_assert(CPU_ISSET(1, &set));
+ ck_assert(CPU_ISSET(2, &set));
+ ck_assert(CPU_ISSET(3, &set));
+ ck_assert(!CPU_ISSET(4, &set));
+ ck_assert(CPU_ISSET(5, &set));
ck_assert_int_eq(parse_cpu_set("-1", &set), 1);
ck_assert_int_eq(parse_cpu_set("abc", &set), 1);
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v4 2/4] tools/rtla: Remove unneeded nr_cpus arguments
2026-03-06 19:49 [PATCH v4 0/4] tools/rtla: Consolidate nr_cpus usage Costa Shulyupin
2026-03-06 19:49 ` [PATCH v4 1/4] tools/rtla: Consolidate nr_cpus usage across all tools Costa Shulyupin
@ 2026-03-06 19:49 ` Costa Shulyupin
2026-03-06 19:49 ` [PATCH v4 3/4] tools/rtla: Remove unneeded nr_cpus members Costa Shulyupin
2026-03-06 19:49 ` [PATCH v4 4/4] tools/rtla: Remove unneeded nr_cpus from for_each_monitored_cpu Costa Shulyupin
3 siblings, 0 replies; 5+ messages in thread
From: Costa Shulyupin @ 2026-03-06 19:49 UTC (permalink / raw)
To: Steven Rostedt, Tomas Glozar, Costa Shulyupin, Crystal Wood,
Wander Lairson Costa, John Kacur, Ivan Pravdin, Tiezhu Yang,
linux-trace-kernel, linux-kernel, bpf
nr_cpus does not change at runtime, so passing it through function
arguments is unnecessary.
Use the global nr_cpus instead of propagating it via parameters.
Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
---
tools/tracing/rtla/src/osnoise_hist.c | 4 ++--
tools/tracing/rtla/src/osnoise_top.c | 4 ++--
tools/tracing/rtla/src/timerlat_bpf.c | 19 ++++++++-----------
tools/tracing/rtla/src/timerlat_bpf.h | 12 ++++--------
tools/tracing/rtla/src/timerlat_hist.c | 21 ++++++++-------------
tools/tracing/rtla/src/timerlat_top.c | 19 +++++++------------
tools/tracing/rtla/src/timerlat_u.c | 6 +++---
7 files changed, 34 insertions(+), 51 deletions(-)
diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c
index 00b8c95cbf85..f39f60d3b00e 100644
--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -62,7 +62,7 @@ static void osnoise_free_hist_tool(struct osnoise_tool *tool)
* osnoise_alloc_histogram - alloc runtime data
*/
static struct osnoise_hist_data
-*osnoise_alloc_histogram(int nr_cpus, int entries, int bucket_size)
+*osnoise_alloc_histogram(int entries, int bucket_size)
{
struct osnoise_hist_data *data;
int cpu;
@@ -651,7 +651,7 @@ static struct osnoise_tool
if (!tool)
return NULL;
- tool->data = osnoise_alloc_histogram(nr_cpus, params->hist.entries,
+ tool->data = osnoise_alloc_histogram(params->hist.entries,
params->hist.bucket_size);
if (!tool->data)
goto out_err;
diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c
index 9a6cd9a2470a..3a241b69f622 100644
--- a/tools/tracing/rtla/src/osnoise_top.c
+++ b/tools/tracing/rtla/src/osnoise_top.c
@@ -51,7 +51,7 @@ static void osnoise_free_top_tool(struct osnoise_tool *tool)
/*
* osnoise_alloc_histogram - alloc runtime data
*/
-static struct osnoise_top_data *osnoise_alloc_top(int nr_cpus)
+static struct osnoise_top_data *osnoise_alloc_top(void)
{
struct osnoise_top_data *data;
@@ -495,7 +495,7 @@ struct osnoise_tool *osnoise_init_top(struct common_params *params)
if (!tool)
return NULL;
- tool->data = osnoise_alloc_top(nr_cpus);
+ tool->data = osnoise_alloc_top();
if (!tool->data) {
osnoise_destroy_tool(tool);
return NULL;
diff --git a/tools/tracing/rtla/src/timerlat_bpf.c b/tools/tracing/rtla/src/timerlat_bpf.c
index 05adf18303df..dd3cf71d74e5 100644
--- a/tools/tracing/rtla/src/timerlat_bpf.c
+++ b/tools/tracing/rtla/src/timerlat_bpf.c
@@ -147,24 +147,23 @@ static int get_value(struct bpf_map *map_irq,
int key,
long long *value_irq,
long long *value_thread,
- long long *value_user,
- int cpus)
+ long long *value_user)
{
int err;
err = bpf_map__lookup_elem(map_irq, &key,
sizeof(unsigned int), value_irq,
- sizeof(long long) * cpus, 0);
+ sizeof(long long) * nr_cpus, 0);
if (err)
return err;
err = bpf_map__lookup_elem(map_thread, &key,
sizeof(unsigned int), value_thread,
- sizeof(long long) * cpus, 0);
+ sizeof(long long) * nr_cpus, 0);
if (err)
return err;
err = bpf_map__lookup_elem(map_user, &key,
sizeof(unsigned int), value_user,
- sizeof(long long) * cpus, 0);
+ sizeof(long long) * nr_cpus, 0);
if (err)
return err;
return 0;
@@ -176,13 +175,12 @@ static int get_value(struct bpf_map *map_irq,
int timerlat_bpf_get_hist_value(int key,
long long *value_irq,
long long *value_thread,
- long long *value_user,
- int cpus)
+ long long *value_user)
{
return get_value(bpf->maps.hist_irq,
bpf->maps.hist_thread,
bpf->maps.hist_user,
- key, value_irq, value_thread, value_user, cpus);
+ key, value_irq, value_thread, value_user);
}
/*
@@ -191,13 +189,12 @@ int timerlat_bpf_get_hist_value(int key,
int timerlat_bpf_get_summary_value(enum summary_field key,
long long *value_irq,
long long *value_thread,
- long long *value_user,
- int cpus)
+ long long *value_user)
{
return get_value(bpf->maps.summary_irq,
bpf->maps.summary_thread,
bpf->maps.summary_user,
- key, value_irq, value_thread, value_user, cpus);
+ key, value_irq, value_thread, value_user);
}
/*
diff --git a/tools/tracing/rtla/src/timerlat_bpf.h b/tools/tracing/rtla/src/timerlat_bpf.h
index 169abeaf4363..531c9ef16f51 100644
--- a/tools/tracing/rtla/src/timerlat_bpf.h
+++ b/tools/tracing/rtla/src/timerlat_bpf.h
@@ -23,13 +23,11 @@ int timerlat_bpf_restart_tracing(void);
int timerlat_bpf_get_hist_value(int key,
long long *value_irq,
long long *value_thread,
- long long *value_user,
- int cpus);
+ long long *value_user);
int timerlat_bpf_get_summary_value(enum summary_field key,
long long *value_irq,
long long *value_thread,
- long long *value_user,
- int cpus);
+ long long *value_user);
int timerlat_load_bpf_action_program(const char *program_path);
static inline int have_libbpf_support(void) { return 1; }
#else
@@ -45,16 +43,14 @@ static inline int timerlat_bpf_restart_tracing(void) { return -1; };
static inline int timerlat_bpf_get_hist_value(int key,
long long *value_irq,
long long *value_thread,
- long long *value_user,
- int cpus)
+ long long *value_user)
{
return -1;
}
static inline int timerlat_bpf_get_summary_value(enum summary_field key,
long long *value_irq,
long long *value_thread,
- long long *value_user,
- int cpus)
+ long long *value_user)
{
return -1;
}
diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c
index 3ebe41eed9f6..7e735b62488c 100644
--- a/tools/tracing/rtla/src/timerlat_hist.c
+++ b/tools/tracing/rtla/src/timerlat_hist.c
@@ -83,7 +83,7 @@ static void timerlat_free_histogram_tool(struct osnoise_tool *tool)
* timerlat_alloc_histogram - alloc runtime data
*/
static struct timerlat_hist_data
-*timerlat_alloc_histogram(int nr_cpus, int entries, int bucket_size)
+*timerlat_alloc_histogram(int entries, int bucket_size)
{
struct timerlat_hist_data *data;
int cpu;
@@ -211,7 +211,7 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
/* Pull histogram */
for (i = 0; i < data->entries; i++) {
err = timerlat_bpf_get_hist_value(i, value_irq, value_thread,
- value_user, data->nr_cpus);
+ value_user);
if (err)
return err;
for (j = 0; j < data->nr_cpus; j++) {
@@ -223,8 +223,7 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
/* Pull summary */
err = timerlat_bpf_get_summary_value(SUMMARY_COUNT,
- value_irq, value_thread, value_user,
- data->nr_cpus);
+ value_irq, value_thread, value_user);
if (err)
return err;
for (i = 0; i < data->nr_cpus; i++) {
@@ -234,8 +233,7 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
}
err = timerlat_bpf_get_summary_value(SUMMARY_MIN,
- value_irq, value_thread, value_user,
- data->nr_cpus);
+ value_irq, value_thread, value_user);
if (err)
return err;
for (i = 0; i < data->nr_cpus; i++) {
@@ -245,8 +243,7 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
}
err = timerlat_bpf_get_summary_value(SUMMARY_MAX,
- value_irq, value_thread, value_user,
- data->nr_cpus);
+ value_irq, value_thread, value_user);
if (err)
return err;
for (i = 0; i < data->nr_cpus; i++) {
@@ -256,8 +253,7 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
}
err = timerlat_bpf_get_summary_value(SUMMARY_SUM,
- value_irq, value_thread, value_user,
- data->nr_cpus);
+ value_irq, value_thread, value_user);
if (err)
return err;
for (i = 0; i < data->nr_cpus; i++) {
@@ -267,8 +263,7 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
}
err = timerlat_bpf_get_summary_value(SUMMARY_OVERFLOW,
- value_irq, value_thread, value_user,
- data->nr_cpus);
+ value_irq, value_thread, value_user);
if (err)
return err;
for (i = 0; i < data->nr_cpus; i++) {
@@ -1045,7 +1040,7 @@ static struct osnoise_tool
if (!tool)
return NULL;
- tool->data = timerlat_alloc_histogram(nr_cpus, params->hist.entries,
+ tool->data = timerlat_alloc_histogram(params->hist.entries,
params->hist.bucket_size);
if (!tool->data)
goto out_err;
diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c
index 4105638f45c4..994e89a57cd3 100644
--- a/tools/tracing/rtla/src/timerlat_top.c
+++ b/tools/tracing/rtla/src/timerlat_top.c
@@ -62,7 +62,7 @@ static void timerlat_free_top_tool(struct osnoise_tool *tool)
/*
* timerlat_alloc_histogram - alloc runtime data
*/
-static struct timerlat_top_data *timerlat_alloc_top(int nr_cpus)
+static struct timerlat_top_data *timerlat_alloc_top(void)
{
struct timerlat_top_data *data;
int cpu;
@@ -196,8 +196,7 @@ static int timerlat_top_bpf_pull_data(struct osnoise_tool *tool)
/* Pull summary */
err = timerlat_bpf_get_summary_value(SUMMARY_CURRENT,
- value_irq, value_thread, value_user,
- data->nr_cpus);
+ value_irq, value_thread, value_user);
if (err)
return err;
for (i = 0; i < data->nr_cpus; i++) {
@@ -207,8 +206,7 @@ static int timerlat_top_bpf_pull_data(struct osnoise_tool *tool)
}
err = timerlat_bpf_get_summary_value(SUMMARY_COUNT,
- value_irq, value_thread, value_user,
- data->nr_cpus);
+ value_irq, value_thread, value_user);
if (err)
return err;
for (i = 0; i < data->nr_cpus; i++) {
@@ -218,8 +216,7 @@ static int timerlat_top_bpf_pull_data(struct osnoise_tool *tool)
}
err = timerlat_bpf_get_summary_value(SUMMARY_MIN,
- value_irq, value_thread, value_user,
- data->nr_cpus);
+ value_irq, value_thread, value_user);
if (err)
return err;
for (i = 0; i < data->nr_cpus; i++) {
@@ -229,8 +226,7 @@ static int timerlat_top_bpf_pull_data(struct osnoise_tool *tool)
}
err = timerlat_bpf_get_summary_value(SUMMARY_MAX,
- value_irq, value_thread, value_user,
- data->nr_cpus);
+ value_irq, value_thread, value_user);
if (err)
return err;
for (i = 0; i < data->nr_cpus; i++) {
@@ -240,8 +236,7 @@ static int timerlat_top_bpf_pull_data(struct osnoise_tool *tool)
}
err = timerlat_bpf_get_summary_value(SUMMARY_SUM,
- value_irq, value_thread, value_user,
- data->nr_cpus);
+ value_irq, value_thread, value_user);
if (err)
return err;
for (i = 0; i < data->nr_cpus; i++) {
@@ -791,7 +786,7 @@ static struct osnoise_tool
if (!top)
return NULL;
- top->data = timerlat_alloc_top(nr_cpus);
+ top->data = timerlat_alloc_top();
if (!top->data)
goto out_err;
diff --git a/tools/tracing/rtla/src/timerlat_u.c b/tools/tracing/rtla/src/timerlat_u.c
index a569fe7f93aa..03b4e68e8b1e 100644
--- a/tools/tracing/rtla/src/timerlat_u.c
+++ b/tools/tracing/rtla/src/timerlat_u.c
@@ -99,7 +99,7 @@ static int timerlat_u_main(int cpu, struct timerlat_u_params *params)
*
* Return the number of processes that received the kill.
*/
-static int timerlat_u_send_kill(pid_t *procs, int nr_cpus)
+static int timerlat_u_send_kill(pid_t *procs)
{
int killed = 0;
int i, retval;
@@ -169,7 +169,7 @@ void *timerlat_u_dispatcher(void *data)
/* parent */
if (pid == -1) {
- timerlat_u_send_kill(procs, nr_cpus);
+ timerlat_u_send_kill(procs);
debug_msg("Failed to create child processes");
pthread_exit(&retval);
}
@@ -196,7 +196,7 @@ void *timerlat_u_dispatcher(void *data)
sleep(1);
}
- timerlat_u_send_kill(procs, nr_cpus);
+ timerlat_u_send_kill(procs);
while (procs_count) {
pid = waitpid(-1, &wstatus, 0);
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v4 3/4] tools/rtla: Remove unneeded nr_cpus members
2026-03-06 19:49 [PATCH v4 0/4] tools/rtla: Consolidate nr_cpus usage Costa Shulyupin
2026-03-06 19:49 ` [PATCH v4 1/4] tools/rtla: Consolidate nr_cpus usage across all tools Costa Shulyupin
2026-03-06 19:49 ` [PATCH v4 2/4] tools/rtla: Remove unneeded nr_cpus arguments Costa Shulyupin
@ 2026-03-06 19:49 ` Costa Shulyupin
2026-03-06 19:49 ` [PATCH v4 4/4] tools/rtla: Remove unneeded nr_cpus from for_each_monitored_cpu Costa Shulyupin
3 siblings, 0 replies; 5+ messages in thread
From: Costa Shulyupin @ 2026-03-06 19:49 UTC (permalink / raw)
To: Steven Rostedt, Tomas Glozar, Costa Shulyupin, Crystal Wood,
Wander Lairson Costa, John Kacur, Ivan Pravdin, Tiezhu Yang,
linux-trace-kernel, linux-kernel, bpf
nr_cpus does not change at runtime, so keeping it in struct members is
unnecessary.
Use the global nr_cpus instead of struct members.
Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
---
tools/tracing/rtla/src/osnoise_hist.c | 18 ++++++------
tools/tracing/rtla/src/osnoise_top.c | 3 --
tools/tracing/rtla/src/timerlat_aa.c | 10 +++----
tools/tracing/rtla/src/timerlat_hist.c | 38 ++++++++++++--------------
tools/tracing/rtla/src/timerlat_top.c | 19 ++++++-------
5 files changed, 38 insertions(+), 50 deletions(-)
diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c
index f39f60d3b00e..5bbec27b46a7 100644
--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -29,7 +29,6 @@ struct osnoise_hist_data {
struct osnoise_hist_cpu *hist;
int entries;
int bucket_size;
- int nr_cpus;
};
/*
@@ -41,7 +40,7 @@ osnoise_free_histogram(struct osnoise_hist_data *data)
int cpu;
/* one histogram for IRQ and one for thread, per CPU */
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
+ for (cpu = 0; cpu < nr_cpus; cpu++) {
if (data->hist[cpu].samples)
free(data->hist[cpu].samples);
}
@@ -73,7 +72,6 @@ static struct osnoise_hist_data
data->entries = entries;
data->bucket_size = bucket_size;
- data->nr_cpus = nr_cpus;
data->hist = calloc(1, sizeof(*data->hist) * nr_cpus);
if (!data->hist)
@@ -246,7 +244,7 @@ static void osnoise_hist_header(struct osnoise_tool *tool)
if (!params->common.hist.no_index)
trace_seq_printf(s, "Index");
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -275,7 +273,7 @@ osnoise_print_summary(struct osnoise_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "count:");
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -287,7 +285,7 @@ osnoise_print_summary(struct osnoise_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "min: ");
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -300,7 +298,7 @@ osnoise_print_summary(struct osnoise_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "avg: ");
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -316,7 +314,7 @@ osnoise_print_summary(struct osnoise_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "max: ");
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -351,7 +349,7 @@ osnoise_print_stats(struct osnoise_tool *tool)
trace_seq_printf(trace->seq, "%-6d",
bucket * data->bucket_size);
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -387,7 +385,7 @@ osnoise_print_stats(struct osnoise_tool *tool)
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "over: ");
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, 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 3a241b69f622..672cdb254f4c 100644
--- a/tools/tracing/rtla/src/osnoise_top.c
+++ b/tools/tracing/rtla/src/osnoise_top.c
@@ -31,7 +31,6 @@ struct osnoise_top_cpu {
struct osnoise_top_data {
struct osnoise_top_cpu *cpu_data;
- int nr_cpus;
};
/*
@@ -59,8 +58,6 @@ static struct osnoise_top_data *osnoise_alloc_top(void)
if (!data)
return NULL;
- data->nr_cpus = nr_cpus;
-
/* one set of histograms per CPU */
data->cpu_data = calloc(1, sizeof(*data->cpu_data) * nr_cpus);
if (!data->cpu_data)
diff --git a/tools/tracing/rtla/src/timerlat_aa.c b/tools/tracing/rtla/src/timerlat_aa.c
index 095483375823..41d8d48c5b41 100644
--- a/tools/tracing/rtla/src/timerlat_aa.c
+++ b/tools/tracing/rtla/src/timerlat_aa.c
@@ -102,7 +102,6 @@ struct timerlat_aa_data {
* The analysis context and system wide view
*/
struct timerlat_aa_context {
- int nr_cpus;
int dump_tasks;
enum stack_format stack_format;
@@ -759,7 +758,7 @@ void timerlat_auto_analysis(int irq_thresh, int thread_thresh)
irq_thresh = irq_thresh * 1000;
thread_thresh = thread_thresh * 1000;
- for (cpu = 0; cpu < taa_ctx->nr_cpus; cpu++) {
+ for (cpu = 0; cpu < nr_cpus; cpu++) {
taa_data = timerlat_aa_get_data(taa_ctx, cpu);
if (irq_thresh && taa_data->tlat_irq_latency >= irq_thresh) {
@@ -787,7 +786,7 @@ void timerlat_auto_analysis(int irq_thresh, int thread_thresh)
printf("\n");
printf("Printing CPU tasks:\n");
- for (cpu = 0; cpu < taa_ctx->nr_cpus; cpu++) {
+ for (cpu = 0; cpu < nr_cpus; cpu++) {
taa_data = timerlat_aa_get_data(taa_ctx, cpu);
tep = taa_ctx->tool->trace.tep;
@@ -813,7 +812,7 @@ static void timerlat_aa_destroy_seqs(struct timerlat_aa_context *taa_ctx)
if (!taa_ctx->taa_data)
return;
- for (i = 0; i < taa_ctx->nr_cpus; i++) {
+ for (i = 0; i < nr_cpus; i++) {
taa_data = timerlat_aa_get_data(taa_ctx, i);
if (taa_data->prev_irqs_seq) {
@@ -863,7 +862,7 @@ static int timerlat_aa_init_seqs(struct timerlat_aa_context *taa_ctx)
struct timerlat_aa_data *taa_data;
int i;
- for (i = 0; i < taa_ctx->nr_cpus; i++) {
+ for (i = 0; i < nr_cpus; i++) {
taa_data = timerlat_aa_get_data(taa_ctx, i);
@@ -1052,7 +1051,6 @@ int timerlat_aa_init(struct osnoise_tool *tool, int dump_tasks, enum stack_forma
__timerlat_aa_ctx = taa_ctx;
- taa_ctx->nr_cpus = nr_cpus;
taa_ctx->tool = tool;
taa_ctx->dump_tasks = dump_tasks;
taa_ctx->stack_format = stack_format;
diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c
index 7e735b62488c..cfb745b75b8a 100644
--- a/tools/tracing/rtla/src/timerlat_hist.c
+++ b/tools/tracing/rtla/src/timerlat_hist.c
@@ -44,7 +44,6 @@ struct timerlat_hist_data {
struct timerlat_hist_cpu *hist;
int entries;
int bucket_size;
- int nr_cpus;
};
/*
@@ -56,7 +55,7 @@ timerlat_free_histogram(struct timerlat_hist_data *data)
int cpu;
/* one histogram for IRQ and one for thread, per CPU */
- for (cpu = 0; cpu < data->nr_cpus; cpu++) {
+ for (cpu = 0; cpu < nr_cpus; cpu++) {
if (data->hist[cpu].irq)
free(data->hist[cpu].irq);
@@ -94,7 +93,6 @@ static struct timerlat_hist_data
data->entries = entries;
data->bucket_size = bucket_size;
- data->nr_cpus = nr_cpus;
/* one set of histograms per CPU */
data->hist = calloc(1, sizeof(*data->hist) * nr_cpus);
@@ -204,9 +202,9 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
{
struct timerlat_hist_data *data = tool->data;
int i, j, err;
- long long value_irq[data->nr_cpus],
- value_thread[data->nr_cpus],
- value_user[data->nr_cpus];
+ long long value_irq[nr_cpus],
+ value_thread[nr_cpus],
+ value_user[nr_cpus];
/* Pull histogram */
for (i = 0; i < data->entries; i++) {
@@ -214,7 +212,7 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
value_user);
if (err)
return err;
- for (j = 0; j < data->nr_cpus; j++) {
+ for (j = 0; j < nr_cpus; j++) {
data->hist[j].irq[i] = value_irq[j];
data->hist[j].thread[i] = value_thread[j];
data->hist[j].user[i] = value_user[j];
@@ -226,7 +224,7 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
value_irq, value_thread, value_user);
if (err)
return err;
- for (i = 0; i < data->nr_cpus; i++) {
+ for (i = 0; i < nr_cpus; i++) {
data->hist[i].irq_count = value_irq[i];
data->hist[i].thread_count = value_thread[i];
data->hist[i].user_count = value_user[i];
@@ -236,7 +234,7 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
value_irq, value_thread, value_user);
if (err)
return err;
- for (i = 0; i < data->nr_cpus; i++) {
+ for (i = 0; i < nr_cpus; i++) {
data->hist[i].min_irq = value_irq[i];
data->hist[i].min_thread = value_thread[i];
data->hist[i].min_user = value_user[i];
@@ -246,7 +244,7 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
value_irq, value_thread, value_user);
if (err)
return err;
- for (i = 0; i < data->nr_cpus; i++) {
+ for (i = 0; i < nr_cpus; i++) {
data->hist[i].max_irq = value_irq[i];
data->hist[i].max_thread = value_thread[i];
data->hist[i].max_user = value_user[i];
@@ -256,7 +254,7 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
value_irq, value_thread, value_user);
if (err)
return err;
- for (i = 0; i < data->nr_cpus; i++) {
+ for (i = 0; i < nr_cpus; i++) {
data->hist[i].sum_irq = value_irq[i];
data->hist[i].sum_thread = value_thread[i];
data->hist[i].sum_user = value_user[i];
@@ -266,7 +264,7 @@ static int timerlat_hist_bpf_pull_data(struct osnoise_tool *tool)
value_irq, value_thread, value_user);
if (err)
return err;
- for (i = 0; i < data->nr_cpus; i++) {
+ for (i = 0; i < nr_cpus; i++) {
data->hist[i].irq[data->entries] = value_irq[i];
data->hist[i].thread[data->entries] = value_thread[i];
data->hist[i].user[data->entries] = value_user[i];
@@ -300,7 +298,7 @@ static void timerlat_hist_header(struct osnoise_tool *tool)
if (!params->common.hist.no_index)
trace_seq_printf(s, "Index");
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -352,7 +350,7 @@ timerlat_print_summary(struct timerlat_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "count:");
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -374,7 +372,7 @@ timerlat_print_summary(struct timerlat_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "min: ");
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -402,7 +400,7 @@ timerlat_print_summary(struct timerlat_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "avg: ");
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -430,7 +428,7 @@ timerlat_print_summary(struct timerlat_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "max: ");
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -475,7 +473,7 @@ timerlat_print_stats_all(struct timerlat_params *params,
sum.min_thread = ~0;
sum.min_user = ~0;
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -622,7 +620,7 @@ timerlat_print_stats(struct osnoise_tool *tool)
trace_seq_printf(trace->seq, "%-6d",
bucket * data->bucket_size);
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -660,7 +658,7 @@ timerlat_print_stats(struct osnoise_tool *tool)
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "over: ");
- for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, 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 994e89a57cd3..8fad4edb0d72 100644
--- a/tools/tracing/rtla/src/timerlat_top.c
+++ b/tools/tracing/rtla/src/timerlat_top.c
@@ -41,7 +41,6 @@ struct timerlat_top_cpu {
struct timerlat_top_data {
struct timerlat_top_cpu *cpu_data;
- int nr_cpus;
};
/*
@@ -71,8 +70,6 @@ static struct timerlat_top_data *timerlat_alloc_top(void)
if (!data)
return NULL;
- data->nr_cpus = nr_cpus;
-
/* one set of histograms per CPU */
data->cpu_data = calloc(1, sizeof(*data->cpu_data) * nr_cpus);
if (!data->cpu_data)
@@ -190,16 +187,16 @@ static int timerlat_top_bpf_pull_data(struct osnoise_tool *tool)
{
struct timerlat_top_data *data = tool->data;
int i, err;
- long long value_irq[data->nr_cpus],
- value_thread[data->nr_cpus],
- value_user[data->nr_cpus];
+ long long value_irq[nr_cpus],
+ value_thread[nr_cpus],
+ value_user[nr_cpus];
/* Pull summary */
err = timerlat_bpf_get_summary_value(SUMMARY_CURRENT,
value_irq, value_thread, value_user);
if (err)
return err;
- for (i = 0; i < data->nr_cpus; i++) {
+ for (i = 0; i < nr_cpus; i++) {
data->cpu_data[i].cur_irq = value_irq[i];
data->cpu_data[i].cur_thread = value_thread[i];
data->cpu_data[i].cur_user = value_user[i];
@@ -209,7 +206,7 @@ static int timerlat_top_bpf_pull_data(struct osnoise_tool *tool)
value_irq, value_thread, value_user);
if (err)
return err;
- for (i = 0; i < data->nr_cpus; i++) {
+ for (i = 0; i < nr_cpus; i++) {
data->cpu_data[i].irq_count = value_irq[i];
data->cpu_data[i].thread_count = value_thread[i];
data->cpu_data[i].user_count = value_user[i];
@@ -219,7 +216,7 @@ static int timerlat_top_bpf_pull_data(struct osnoise_tool *tool)
value_irq, value_thread, value_user);
if (err)
return err;
- for (i = 0; i < data->nr_cpus; i++) {
+ for (i = 0; i < nr_cpus; i++) {
data->cpu_data[i].min_irq = value_irq[i];
data->cpu_data[i].min_thread = value_thread[i];
data->cpu_data[i].min_user = value_user[i];
@@ -229,7 +226,7 @@ static int timerlat_top_bpf_pull_data(struct osnoise_tool *tool)
value_irq, value_thread, value_user);
if (err)
return err;
- for (i = 0; i < data->nr_cpus; i++) {
+ for (i = 0; i < nr_cpus; i++) {
data->cpu_data[i].max_irq = value_irq[i];
data->cpu_data[i].max_thread = value_thread[i];
data->cpu_data[i].max_user = value_user[i];
@@ -239,7 +236,7 @@ static int timerlat_top_bpf_pull_data(struct osnoise_tool *tool)
value_irq, value_thread, value_user);
if (err)
return err;
- for (i = 0; i < data->nr_cpus; i++) {
+ for (i = 0; i < nr_cpus; i++) {
data->cpu_data[i].sum_irq = value_irq[i];
data->cpu_data[i].sum_thread = value_thread[i];
data->cpu_data[i].sum_user = value_user[i];
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v4 4/4] tools/rtla: Remove unneeded nr_cpus from for_each_monitored_cpu
2026-03-06 19:49 [PATCH v4 0/4] tools/rtla: Consolidate nr_cpus usage Costa Shulyupin
` (2 preceding siblings ...)
2026-03-06 19:49 ` [PATCH v4 3/4] tools/rtla: Remove unneeded nr_cpus members Costa Shulyupin
@ 2026-03-06 19:49 ` Costa Shulyupin
3 siblings, 0 replies; 5+ messages in thread
From: Costa Shulyupin @ 2026-03-06 19:49 UTC (permalink / raw)
To: Steven Rostedt, Tomas Glozar, Costa Shulyupin, Crystal Wood,
Wander Lairson Costa, John Kacur, Ivan Pravdin, Tiezhu Yang,
linux-trace-kernel, linux-kernel, bpf
nr_cpus does not change at runtime, so passing it through the macro
argument is unnecessary.
Remove the argument and use the global nr_cpus instead.
Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
---
tools/tracing/rtla/src/common.h | 2 +-
tools/tracing/rtla/src/osnoise_hist.c | 15 +++++++--------
tools/tracing/rtla/src/osnoise_top.c | 2 +-
tools/tracing/rtla/src/timerlat.c | 4 ++--
tools/tracing/rtla/src/timerlat_hist.c | 16 ++++++++--------
tools/tracing/rtla/src/timerlat_top.c | 2 +-
6 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/common.h
index 90a3c0d1dbf3..22ec436a93cc 100644
--- a/tools/tracing/rtla/src/common.h
+++ b/tools/tracing/rtla/src/common.h
@@ -110,7 +110,7 @@ struct common_params {
extern int nr_cpus;
-#define for_each_monitored_cpu(cpu, nr_cpus, common) \
+#define for_each_monitored_cpu(cpu, common) \
for (cpu = 0; cpu < nr_cpus; cpu++) \
if (!(common)->cpus || CPU_ISSET(cpu, &(common)->monitored_cpus))
diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c
index 5bbec27b46a7..4181e025511a 100644
--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -244,7 +244,7 @@ static void osnoise_hist_header(struct osnoise_tool *tool)
if (!params->common.hist.no_index)
trace_seq_printf(s, "Index");
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -273,8 +273,7 @@ osnoise_print_summary(struct osnoise_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "count:");
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
-
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -285,7 +284,7 @@ osnoise_print_summary(struct osnoise_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "min: ");
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -298,7 +297,7 @@ osnoise_print_summary(struct osnoise_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "avg: ");
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -314,7 +313,7 @@ osnoise_print_summary(struct osnoise_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "max: ");
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -349,7 +348,7 @@ osnoise_print_stats(struct osnoise_tool *tool)
trace_seq_printf(trace->seq, "%-6d",
bucket * data->bucket_size);
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].count)
continue;
@@ -385,7 +384,7 @@ osnoise_print_stats(struct osnoise_tool *tool)
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "over: ");
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶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 672cdb254f4c..f92caea9f2e9 100644
--- a/tools/tracing/rtla/src/osnoise_top.c
+++ b/tools/tracing/rtla/src/osnoise_top.c
@@ -236,7 +236,7 @@ osnoise_print_stats(struct osnoise_tool *top)
osnoise_top_header(top);
- for_each_monitored_cpu(i, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(i, ¶ms->common) {
osnoise_top_print(top, i);
}
diff --git a/tools/tracing/rtla/src/timerlat.c b/tools/tracing/rtla/src/timerlat.c
index 31c921efa7c1..8a44537e25cb 100644
--- a/tools/tracing/rtla/src/timerlat.c
+++ b/tools/tracing/rtla/src/timerlat.c
@@ -115,7 +115,7 @@ int timerlat_enable(struct osnoise_tool *tool)
return -1;
}
- for_each_monitored_cpu(i, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(i, ¶ms->common) {
if (save_cpu_idle_disable_state(i) < 0) {
err_msg("Could not save cpu idle state.\n");
return -1;
@@ -218,7 +218,7 @@ void timerlat_free(struct osnoise_tool *tool)
if (dma_latency_fd >= 0)
close(dma_latency_fd);
if (params->deepest_idle_state >= -1) {
- for_each_monitored_cpu(i, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(i, ¶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 cfb745b75b8a..ee1af251c94d 100644
--- a/tools/tracing/rtla/src/timerlat_hist.c
+++ b/tools/tracing/rtla/src/timerlat_hist.c
@@ -298,7 +298,7 @@ static void timerlat_hist_header(struct osnoise_tool *tool)
if (!params->common.hist.no_index)
trace_seq_printf(s, "Index");
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -350,7 +350,7 @@ timerlat_print_summary(struct timerlat_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "count:");
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -372,7 +372,7 @@ timerlat_print_summary(struct timerlat_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "min: ");
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -400,7 +400,7 @@ timerlat_print_summary(struct timerlat_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "avg: ");
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -428,7 +428,7 @@ timerlat_print_summary(struct timerlat_params *params,
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "max: ");
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -473,7 +473,7 @@ timerlat_print_stats_all(struct timerlat_params *params,
sum.min_thread = ~0;
sum.min_user = ~0;
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -620,7 +620,7 @@ timerlat_print_stats(struct osnoise_tool *tool)
trace_seq_printf(trace->seq, "%-6d",
bucket * data->bucket_size);
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶ms->common) {
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
continue;
@@ -658,7 +658,7 @@ timerlat_print_stats(struct osnoise_tool *tool)
if (!params->common.hist.no_index)
trace_seq_printf(trace->seq, "over: ");
- for_each_monitored_cpu(cpu, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(cpu, ¶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 8fad4edb0d72..cc296c9d7fe7 100644
--- a/tools/tracing/rtla/src/timerlat_top.c
+++ b/tools/tracing/rtla/src/timerlat_top.c
@@ -446,7 +446,7 @@ timerlat_print_stats(struct osnoise_tool *top)
timerlat_top_header(params, top);
- for_each_monitored_cpu(i, nr_cpus, ¶ms->common) {
+ for_each_monitored_cpu(i, ¶ms->common) {
timerlat_top_print(top, i);
timerlat_top_update_sum(top, i, &summary);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread