From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
James Clark <james.clark@linaro.org>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Clark Williams <williams@redhat.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Ankur Arora <ankur.a.arora@oracle.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Alexandre Ghiti <alex@ghiti.fr>,
Athira Rajeev <atrajeev@linux.vnet.ibm.com>,
Guo Ren <guoren@kernel.org>, Howard Chu <howardchu95@gmail.com>,
Ingo Molnar <mingo@redhat.com>, Leo Yan <leo.yan@arm.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Paul Walmsley <pjw@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Yujie Liu <yujie.liu@intel.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: Re: [PATCH 1/4] perf tools: Make more global variables static
Date: Tue, 7 Apr 2026 09:50:19 -0300 [thread overview]
Message-ID: <adT9iwnGImRtXLHa@x1> (raw)
In-Reply-To: <20260402001740.2220481-2-acme@kernel.org>
On Wed, Apr 01, 2026 at 09:17:37PM -0300, Arnaldo Carvalho de Melo wrote:
> From: Ian Rogers <irogers@google.com>
>
> `make check` will run sparse on the perf code base. A frequent warning
> is "warning: symbol '...' was not declared. Should it be static?" Go
> through and make global definitions without declarations static.
>
> In some cases it is deliberate due to dlsym accessing the symbol, this
> change doesn't clean up the missing declarations for perf test suites.
>
> Sometimes things can opportunistically be made const.
>
> Making somethings static exposed unused functions warnings, so
> restructuring of ifdefs was necessary for that.
>
> These changes reduce the size of the perf binary by 568 bytes.
>
> Committer notes:
>
> Refreshed the patch, the original one fell thru the cracks, updated the
> size reduction.
>
> Remove the trace-event-scripting.c changes, break the build, noticed
> with container builds and with sashiko:
>
> https://sashiko.dev/#/patchset/20260401215306.2152898-1-acme%40kernel.org
Addressing a Sashiko review comment:
---
Does moving this array into the function without the static keyword force
unnecessary stack allocation and runtime initialization?
Since top_callchain_help[] is no longer static, the compiler might allocate
space on the stack and copy the contents from .rodata every time the function
is called. Using a pointer (const char *top_callchain_help) or keeping it
static const would prevent this overhead.
---
⬢ [acme@toolbx perf-tools-next]$ cat before
text data bss dec hex filename
12249047 362081 40040 12651168 c10aa0 /home/acme/bin/perf
⬢ [acme@toolbx perf-tools-next]$ size ~/bin/perf
text data bss dec hex filename
12248983 362081 40040 12651104 c10a60 /home/acme/bin/perf
⬢ [acme@toolbx perf-tools-next]$ git diff
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 35ff2495e1ee5897..f6eb543de537a3d3 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1451,7 +1451,7 @@ parse_percent_limit(const struct option *opt, const char *arg,
int cmd_top(int argc, const char **argv)
{
- const char top_callchain_help[] = CALLCHAIN_RECORD_HELP CALLCHAIN_REPORT_HELP
+ static const char top_callchain_help[] = CALLCHAIN_RECORD_HELP CALLCHAIN_REPORT_HELP
"\n\t\t\t\tDefault: fp,graph,0.5,caller,function";
char errbuf[BUFSIZ];
struct perf_top top = {
⬢ [acme@toolbx perf-tools-next]$
The second suggestion didn't make a difference, but lets keep it static
as well to ensure that is the case.
---
Is this also creating a stack-allocated array that requires initialization on
every call? Making distro_dwarf_types[] static const would ensure it stays
entirely in .rodata with zero runtime overhead.
---
⬢ [acme@toolbx perf-tools-next]$ cat before
text data bss dec hex filename
12248983 362081 40040 12651104 c10a60 /home/acme/bin/perf
⬢ [acme@toolbx perf-tools-next]$ size ~/bin/perf
text data bss dec hex filename
12248983 362081 40040 12651104 c10a60 /home/acme/bin/perf
⬢ [acme@toolbx perf-tools-next]$ git diff
diff --git a/tools/perf/util/debuginfo.c b/tools/perf/util/debuginfo.c
index 8b819dea36ac1ef0..0e35c13abd041c46 100644
--- a/tools/perf/util/debuginfo.c
+++ b/tools/perf/util/debuginfo.c
@@ -90,7 +90,7 @@ static struct debuginfo *__debuginfo__new(const char *path)
struct debuginfo *debuginfo__new(const char *path)
{
- const enum dso_binary_type distro_dwarf_types[] = {
+ static const enum dso_binary_type distro_dwarf_types[] = {
DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
⬢ [acme@toolbx perf-tools-next]$
I'm adding these two changes and will resubmit, holler if you disagree.
:-)
- Arnaldo
next prev parent reply other threads:[~2026-04-07 12:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 0:17 [PATCHES v3 perf-tools-next 0/4] Cleanups and a fix Arnaldo Carvalho de Melo
2026-04-02 0:17 ` [PATCH 1/4] perf tools: Make more global variables static Arnaldo Carvalho de Melo
2026-04-07 12:50 ` Arnaldo Carvalho de Melo [this message]
2026-04-02 0:17 ` [PATCH 2/4] perf bench: Constify tables Arnaldo Carvalho de Melo
2026-04-02 0:17 ` [PATCH 3/4] perf tools: Use calloc() were applicable Arnaldo Carvalho de Melo
2026-04-02 0:17 ` [PATCH 4/4] perf symbol: Add missing libgen.h include to get basename() prototype Arnaldo Carvalho de Melo
2026-04-02 15:19 ` Ian Rogers
2026-04-02 15:48 ` Arnaldo Melo
2026-04-07 12:08 ` Arnaldo Carvalho de Melo
2026-04-07 15:44 ` Ian Rogers
-- strict thread matches above, loose matches on Subject: below --
2026-04-01 21:53 [PATCHES v2 perf-tools-next 0/4] Cleanups and a fix Arnaldo Carvalho de Melo
2026-04-01 21:53 ` [PATCH 1/4] perf tools: Make more global variables static Arnaldo Carvalho de Melo
2026-04-01 21:01 [PATCHES perf-tools-next 0/4] Cleanups and a fix Arnaldo Carvalho de Melo
2026-04-01 21:01 ` [PATCH 1/4] perf tools: Make more global variables static Arnaldo Carvalho de Melo
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=adT9iwnGImRtXLHa@x1 \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=alex@ghiti.fr \
--cc=alexander.shishkin@linux.intel.com \
--cc=ankur.a.arora@oracle.com \
--cc=aou@eecs.berkeley.edu \
--cc=atrajeev@linux.vnet.ibm.com \
--cc=guoren@kernel.org \
--cc=howardchu95@gmail.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=leo.yan@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=palmer@dabbelt.com \
--cc=peterz@infradead.org \
--cc=pjw@kernel.org \
--cc=tglx@linutronix.de \
--cc=williams@redhat.com \
--cc=yujie.liu@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox