From nobody Tue Dec 2 02:05:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B3A3F1E2614 for ; Thu, 20 Nov 2025 23:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763681194; cv=none; b=jBcX61UA3Syxy8krwEzhXkb+x+hWxVRGFJGCajrg0Co+qZJXhahwYn4q4eM04wGf5zud5NphTxEfAJH048Zaq1hGCKQd+U9cdAibgaozPsX/c6NRsvYNAjm+dFDLJ+Z/PB9fcCTyvVa/6RKRyNxpPVXHneU1CKMFRXwkujViGyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763681194; c=relaxed/simple; bh=pulV9Ic/vDOAOBhu9dt7BiWM/6WwB651W9QEZP1S9Lc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=X9/Cg0HTIIRQjoejw/73T4fO1E3RRZNQn4HwCrxminXp47FN7Hy3+n0jDwuAex+S3QQzaVUJKZPiDalC1IOgwDlYCis4DZsv0d03P1+4gyGbW0iDb+MrQ7RMls9sHhkN8MbbGY3g3umlcMyE1v4tTIZLtGs/Pe2aSQlYKOAcMNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LUuqy4f6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LUuqy4f6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86EF5C4CEF1; Thu, 20 Nov 2025 23:26:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763681194; bh=pulV9Ic/vDOAOBhu9dt7BiWM/6WwB651W9QEZP1S9Lc=; h=Date:From:To:Cc:Subject:References:From; b=LUuqy4f6yzkN865gwLOivE9oSNHCg0ELk2L3sgT0DuKq9OFneDr+oiMR65IB3S5Jl MRW6WMSeQqPhCgTzMCFOAJo/4KGlsLJEOBmAcH24TxRJJ9mo6ElYkkPhVVdAoiZkm7 +pW7KYiItPWpz3ssJwb9Eb5DmrwernfkvJoWaTc9I4Ku3gPX/ipv1NC7cDbgijc9y6 8YLLQtvpWqv3A8ljwKD7SkAWUssg/s4iruDCsCeyTyLNM7p0UL+dF87qtqkzH1Fzto JyZTrolJagnVyEU2eaAkTuT0eYedjDh9JE33FU4CbfDAqGJhq3+Z95wq+4rcMFHiIi LjQpNe5kQCfKg== Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1vME3P-000000041qj-2TOQ; Thu, 20 Nov 2025 18:27:07 -0500 Message-ID: <20251120232707.442753984@kernel.org> User-Agent: quilt/0.68 Date: Thu, 20 Nov 2025 18:23:24 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Tomas Glozar , John Kacur , Costa Shulyupin Subject: [for-next][PATCH 01/16] tools/rtla: Add for_each_monitored_cpu() helper References: <20251120232323.271532418@kernel.org> 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" From: Costa Shulyupin 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 Reviewed-by: Tomas Glozar Link: https://lore.kernel.org/r/20251002123553.389467-1-costa.shul@redhat.c= om Signed-off-by: Tomas Glozar --- 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/commo= n.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; }; =20 +#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)) + struct tool_ops; =20 /* 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 *to= ol) if (!params->common.hist.no_index) trace_seq_printf(s, "Index"); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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:"); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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: "); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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: "); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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: "); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cp= us)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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: "); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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) =20 osnoise_top_header(top); =20 - for (i =3D 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); } =20 diff --git a/tools/tracing/rtla/src/timerlat.c b/tools/tracing/rtla/src/tim= erlat.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) =20 nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); =20 - for (i =3D 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 >=3D 0) close(dma_latency_fd); if (params->deepest_idle_state >=3D -1) { - for (i =3D 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/sr= c/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 *t= ool) if (!params->common.hist.no_index) trace_seq_printf(s, "Index"); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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:"); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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: "); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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: "); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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: "); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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 =3D ~0; sum.min_user =3D ~0; =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cp= us)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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: "); =20 - for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) - continue; + for_each_monitored_cpu(cpu, data->nr_cpus, ¶ms->common) { =20 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) =20 timerlat_top_header(params, top); =20 - for (i =3D 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); } --=20 2.51.0