From nobody Tue Feb 10 23:01:39 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCB63364022 for ; Mon, 9 Feb 2026 09:24:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770629097; cv=none; b=ZYWsXRofldxX40QOT4BydDNsSaYmsqrinpTAmthY/AZcOsC41oXu9tk1XhmPqo/QqwZj3WcVTFyo1DmI27QsPYibpk4SA5XyU+gXdIZ7sRTnJKQ8t5cCejpyrzuauG1vYZGRkDMmOGDQbSzSfX+L5pRZVc2cDFtLYjf2iK+PrPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770629097; c=relaxed/simple; bh=TS3My54+1+wB3igxyJXqNn57tpPk9g2oanX93lMf9nc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UbyLxPwoyp6wwmwlsBoM8BasUo4Yey0JwT39jvL1qhZ4Eh+KWWx7wkaNc16XqnunG10SSrOcDF2Lfw7ZoyQY9pS6IVpCumEvo6trBX4W3WSRwujDGJA6zSEZCCOLK5C3qqYyZFSqRrpCUVlFPjqKNBOtyUSzunq/+UBpA5yVJgc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CPGxZmNr; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=HZSKOJdz; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CPGxZmNr"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="HZSKOJdz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770629095; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=st11ylo4z/SO3tLN7S2b9c++GEqcWdO6dyVW8k4qC0Q=; b=CPGxZmNrgvC+sjoPfTKqcVIKJoRS7cj5xrx3VVBBgm0NxI37TKpOPVVZ7RZ9YmwXkAABCm WKlSCyiApAX50bFVOWJtSqgR0uun6z1OoKGfTTleaB0KTA838OB4s5aegtayyTNlX4T8ew 1m2BGtfp33/a5fUhKJqVAOGNKNYcbV8= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-374-GqPPrCzoN5ykglpXN-cbbA-1; Mon, 09 Feb 2026 04:24:54 -0500 X-MC-Unique: GqPPrCzoN5ykglpXN-cbbA-1 X-Mimecast-MFC-AGG-ID: GqPPrCzoN5ykglpXN-cbbA_1770629093 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4831192e66aso38099305e9.2 for ; Mon, 09 Feb 2026 01:24:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770629093; x=1771233893; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=st11ylo4z/SO3tLN7S2b9c++GEqcWdO6dyVW8k4qC0Q=; b=HZSKOJdzZ/idoYRx4/HZXz+lLCYBxtp891fHPSMJcnMNtpyRSrKb/Nv2WAREBrj8tU E6HJM2p4phHhh9UfZcxr02LlKx4clRQQbiC5OOb7GhrE4qZshFwipI1gO0B+YrYXC5Ni IN6Yuldgp6k+SSFaCR3Xl7VX5CC9ifHG6lEGjl2YQuKgIol8ZqBD7zWnteqvDFM4v74P +mUnIILbYzU9I2CL77EPX6nQ4psJGoECBE78wpH3v6alT+9K63+CQLAghyX9ppc9twGo 1d89zBoHZM391Cwqgz/kbI5scLeTKd6xDj4InpWfRoH1cwDJ7IqD6YVR8h+KJkyahD2p ThSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770629093; x=1771233893; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=st11ylo4z/SO3tLN7S2b9c++GEqcWdO6dyVW8k4qC0Q=; b=irJAJF/hPhO1K1YXYi+QVzwFjlna1zIaSCsWoJNGWzkCfk9voSyRWFqBa7s+6mplXp N1LUKXdBMNT1EtOaUWJyp2VIQHMQ2qXHy4lq7cXIJieAcdKHHJC/IJnObSZB8/SU60uT e/8g8KofpkpdvLSnhD5w+5cZzum7XP7B7u1VwSdKbHwaCNoo+wEwNuv/IgMEtAMcHCd2 28ESyc5WzS3684LlGxbhK5p6zJIw3VXYNphJWpWrbqiYf+BdzTNmKdFk1VWPAa9bRlUs QaN7RnFor+Nym3bVJDiRTg2ofXBlSVJNGu5pvc+6MQn0Au49m38vtFAKoDhdmfVVw1TI MWWw== X-Forwarded-Encrypted: i=1; AJvYcCW1Lzs/GjCwCDQhve38Dbb6trXwfN3zhS2iF0yLXxtLmgJi0wIPvd+rqNqxNWILO1UcU0ykY1QanjCnMUE=@vger.kernel.org X-Gm-Message-State: AOJu0YxiohQZwGyvPcg//ktT2NsDvHOtp0g6smym+OTdiQwM+hJh5ipN Gp6UnKosU5Vc9UrH97XTl08i7lRjKJtf5z4L1wcW7MZ4qkNQl06f0fFWpju+KoG2hvXskws0a0s DQFllWvc/B0Zixaeb0MIXMj4cwTOWJml+8QFykpWb/ApyUo8t0eqhJkz3AUqCpZROVw== X-Gm-Gg: AZuq6aKyhA8l5gwlgv050tg5eidBep4woOp6DiWMpeDaKOslNp9RF2rz2kO/lrGTQ/x xfDNwTCclEJ6kNi4BNrKAH6e2iM0CtzIhhOa7XlnwrdfZqddXnl7ML3f4qoI9rSo5NsUlhUhxZW nyMpmQkuGZGJ65R2dPtxSoSXBEv2sblN4E2Bzd5+gdrLGZpuN0FlSfYhj+X9HBimytWbsvoQno3 1wRFRRo/Q+UKDoieLl6/TE0Jf8QTKqKD0DIfLe1oG+DV47rqFjvodTIlOyQgAHYwFrP7UfnaFJS fzmXZAgVZvYkcg3hsy3wefdEu1700ex5c9M2/pehiNHCbXZQoQaZb87RseHek0D7tBkwEFxCvft mcUXfhwnylCEEgvg9Ctw//ifeOQ== X-Received: by 2002:a05:600c:4e86:b0:480:52fd:d2e4 with SMTP id 5b1f17b1804b1-483201710c7mr129388065e9.0.1770629093076; Mon, 09 Feb 2026 01:24:53 -0800 (PST) X-Received: by 2002:a05:600c:4e86:b0:480:52fd:d2e4 with SMTP id 5b1f17b1804b1-483201710c7mr129387715e9.0.1770629092614; Mon, 09 Feb 2026 01:24:52 -0800 (PST) Received: from costa-tp.redhat.com ([2a00:a041:e223:1b00:fe51:8bb:7986:c897]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48317d33f5fsm316310295e9.5.2026.02.09.01.24.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Feb 2026 01:24:52 -0800 (PST) From: Costa Shulyupin To: Steven Rostedt , Tomas Glozar , Costa Shulyupin , Crystal Wood , Wander Lairson Costa , Ivan Pravdin , John Kacur , Tiezhu Yang , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH v2 1/4] tools/rtla: Consolidate nr_cpus usage across all tools Date: Mon, 9 Feb 2026 11:24:33 +0200 Message-ID: <20260209092436.2899888-2-costa.shul@redhat.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260209092436.2899888-1-costa.shul@redhat.com> References: <20260209092436.2899888-1-costa.shul@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 +--------- 11 files changed, 11 insertions(+), 38 deletions(-) diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/commo= n.c index ceff76a62a30..e4cf30a65e82 100644 --- a/tools/tracing/rtla/src/common.c +++ b/tools/tracing/rtla/src/common.c @@ -5,12 +5,14 @@ #include #include #include -#include #include +#include + #include "common.h" =20 struct trace_instance *trace_inst; volatile int stop_tracing; +int nr_cpus; =20 static void stop_trace(int sig) { @@ -135,7 +137,7 @@ common_apply_config(struct osnoise_tool *tool, struct c= ommon_params *params) } =20 if (!params->cpus) { - for (i =3D 0; i < sysconf(_SC_NPROCESSORS_CONF); i++) + for (i =3D 0; i < nr_cpus; i++) CPU_SET(i, ¶ms->monitored_cpus); } =20 @@ -183,6 +185,7 @@ int run_tool(struct tool_ops *ops, int argc, char *argv= []) bool stopped; int retval; =20 + nr_cpus =3D get_nprocs_conf(); params =3D ops->parse_args(argc, argv); if (!params) exit(1); diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/commo= n.h index 7602c5593ef5..32f9c1351209 100644 --- a/tools/tracing/rtla/src/common.h +++ b/tools/tracing/rtla/src/common.h @@ -107,6 +107,8 @@ struct common_params { struct timerlat_u_params user; }; =20 +extern int nr_cpus; + #define for_each_monitored_cpu(cpu, nr_cpus, common) \ for (cpu =3D 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 9d70ea34807f..03ebff34fff4 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -647,9 +647,6 @@ static struct osnoise_tool *osnoise_init_hist(struct common_params *params) { struct osnoise_tool *tool; - int nr_cpus; - - nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); =20 tool =3D 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 d54d47947fb4..7dcd2e318205 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 =3D to_osnoise_params(top->params); struct trace_instance *trace =3D &top->trace; - static int nr_cpus =3D -1; int i; =20 - if (nr_cpus =3D=3D -1) - nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); - if (!params->common.quiet) clear_terminal(trace->seq); =20 @@ -495,9 +491,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 =3D sysconf(_SC_NPROCESSORS_CONF); =20 tool =3D osnoise_init_tool("osnoise_top"); if (!tool) diff --git a/tools/tracing/rtla/src/timerlat.c b/tools/tracing/rtla/src/tim= erlat.c index 8f8811f7a13b..69856f677fce 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 t= imerlat_params *params) int timerlat_enable(struct osnoise_tool *tool) { struct timerlat_params *params =3D to_timerlat_params(tool->params); - int retval, nr_cpus, i; + int retval, i; =20 if (params->dma_latency >=3D 0) { dma_latency_fd =3D set_cpu_dma_latency(params->dma_latency); @@ -115,8 +115,6 @@ int timerlat_enable(struct osnoise_tool *tool) return -1; } =20 - nr_cpus =3D 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 s= topped) void timerlat_free(struct osnoise_tool *tool) { struct timerlat_params *params =3D to_timerlat_params(tool->params); - int nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); int i; =20 timerlat_aa_destroy(); diff --git a/tools/tracing/rtla/src/timerlat_aa.c b/tools/tracing/rtla/src/= timerlat_aa.c index 31e66ea2b144..5766d58709eb 100644 --- a/tools/tracing/rtla/src/timerlat_aa.c +++ b/tools/tracing/rtla/src/timerlat_aa.c @@ -1022,7 +1022,6 @@ void timerlat_aa_destroy(void) */ int timerlat_aa_init(struct osnoise_tool *tool, int dump_tasks) { - int nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); struct timerlat_aa_context *taa_ctx; int retval; =20 diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index 4e8c38a61197..841118ed84f2 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -1031,9 +1031,6 @@ static struct osnoise_tool *timerlat_init_hist(struct common_params *params) { struct osnoise_tool *tool; - int nr_cpus; - - nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); =20 tool =3D 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 284b74773c2b..3e395ce4fa9f 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 =3D to_timerlat_params(top->params); struct trace_instance *trace =3D &top->trace; struct timerlat_top_cpu summary; - static int nr_cpus =3D -1; int i; =20 if (params->common.aa_only) return; =20 - if (nr_cpus =3D=3D -1) - nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); - if (!params->common.quiet) clear_terminal(trace->seq); =20 @@ -781,9 +777,6 @@ static struct osnoise_tool *timerlat_init_top(struct common_params *params) { struct osnoise_tool *top; - int nr_cpus; - - nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); =20 top =3D osnoise_init_tool("timerlat_top"); if (!top) diff --git a/tools/tracing/rtla/src/timerlat_u.c b/tools/tracing/rtla/src/t= imerlat_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 #include =20 -#include "utils.h" +#include "common.h" #include "timerlat_u.h" =20 /* @@ -131,7 +131,6 @@ static int timerlat_u_send_kill(pid_t *procs, int nr_cp= us) */ void *timerlat_u_dispatcher(void *data) { - int nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); struct timerlat_u_params *params =3D data; char proc_name[128]; int procs_count =3D 0; diff --git a/tools/tracing/rtla/src/timerlat_u.h b/tools/tracing/rtla/src/t= imerlat_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 */ diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index 0da3b2470c31..8cd1b374b035 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -19,7 +19,7 @@ #include #include =20 -#include "utils.h" +#include "common.h" =20 #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; =20 CPU_ZERO(set); =20 - nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); - for (p =3D cpu_list; *p; ) { cpu =3D atoi(p); if (cpu < 0 || (!cpu && *p !=3D '0') || cpu >=3D nr_cpus) @@ -559,7 +556,6 @@ int save_cpu_idle_disable_state(unsigned int cpu) unsigned int nr_states; unsigned int state; int disabled; - int nr_cpus; =20 nr_states =3D cpuidle_state_count(cpu); =20 @@ -567,7 +563,6 @@ int save_cpu_idle_disable_state(unsigned int cpu) return 0; =20 if (saved_cpu_idle_disable_state =3D=3D NULL) { - nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); saved_cpu_idle_disable_state =3D calloc(nr_cpus, sizeof(unsigned int *)); if (!saved_cpu_idle_disable_state) return -1; @@ -644,13 +639,10 @@ int restore_cpu_idle_disable_state(unsigned int cpu) void free_cpu_idle_disable_states(void) { int cpu; - int nr_cpus; =20 if (!saved_cpu_idle_disable_state) return; =20 - nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); - for (cpu =3D 0; cpu < nr_cpus; cpu++) { free(saved_cpu_idle_disable_state[cpu]); saved_cpu_idle_disable_state[cpu] =3D NULL; --=20 2.52.0