[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250401182347.3422199-33-irogers@google.com>
Date: Tue, 1 Apr 2025 11:23:30 -0700
From: Ian Rogers <irogers@...gle.com>
To: Yury Norov <yury.norov@...il.com>, Rasmus Villemoes <linux@...musvillemoes.dk>,
Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>, Namhyung Kim <namhyung@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>,
Ian Rogers <irogers@...gle.com>, Adrian Hunter <adrian.hunter@...el.com>,
Kan Liang <kan.liang@...ux.intel.com>, Thomas Gleixner <tglx@...utronix.de>,
Darren Hart <dvhart@...radead.org>, Davidlohr Bueso <dave@...olabs.net>,
"André Almeida" <andrealmeid@...lia.com>, John Garry <john.g.garry@...cle.com>,
Will Deacon <will@...nel.org>, James Clark <james.clark@...aro.org>,
Mike Leach <mike.leach@...aro.org>, Leo Yan <leo.yan@...ux.dev>,
Yicong Yang <yangyicong@...ilicon.com>, Jonathan Cameron <jonathan.cameron@...wei.com>,
Nathan Chancellor <nathan@...nel.org>, Bill Wendling <morbo@...gle.com>,
Justin Stitt <justinstitt@...gle.com>, Josh Poimboeuf <jpoimboe@...nel.org>,
Al Viro <viro@...iv.linux.org.uk>, Kyle Meyer <kyle.meyer@....com>,
Ben Gainey <ben.gainey@....com>, Athira Rajeev <atrajeev@...ux.vnet.ibm.com>,
Kajol Jain <kjain@...ux.ibm.com>, Aditya Gupta <adityag@...ux.ibm.com>,
Eder Zulian <ezulian@...hat.com>, Dapeng Mi <dapeng1.mi@...ux.intel.com>,
Kuan-Wei Chiu <visitorckw@...il.com>, He Zhe <zhe.he@...driver.com>,
Dirk Gouders <dirk@...ders.net>, Brian Geffon <bgeffon@...gle.com>,
Ravi Bangoria <ravi.bangoria@....com>, Howard Chu <howardchu95@...il.com>,
Charlie Jenkins <charlie@...osinc.com>, Colin Ian King <colin.i.king@...il.com>,
Dominique Martinet <asmadeus@...ewreck.org>, Jann Horn <jannh@...gle.com>,
Masahiro Yamada <masahiroy@...nel.org>, Arnd Bergmann <arnd@...db.de>,
Yang Jihong <yangjihong@...edance.com>, Dmitry Vyukov <dvyukov@...gle.com>,
Andi Kleen <ak@...ux.intel.com>, Graham Woodward <graham.woodward@....com>,
Ilkka Koskinen <ilkka@...amperecomputing.com>,
Anshuman Khandual <anshuman.khandual@....com>, Zhongqiu Han <quic_zhonhan@...cinc.com>,
Hao Ge <gehao@...inos.cn>, Tengda Wu <wutengda@...weicloud.com>,
Gabriele Monaco <gmonaco@...hat.com>, Chun-Tse Shao <ctshao@...gle.com>,
Casey Chen <cachen@...estorage.com>, "Dr. David Alan Gilbert" <linux@...blig.org>,
Li Huafei <lihuafei1@...wei.com>, "Steinar H. Gunderson" <sesse@...gle.com>, Levi Yun <yeoreum.yun@....com>,
Weilin Wang <weilin.wang@...el.com>, Thomas Falcon <thomas.falcon@...el.com>,
Thomas Richter <tmricht@...ux.ibm.com>, Andrew Kreimer <algonell@...il.com>,
"Krzysztof Łopatowski" <krzysztof.m.lopatowski@...il.com>,
Christophe Leroy <christophe.leroy@...roup.eu>,
Jean-Philippe Romain <jean-philippe.romain@...s.st.com>, Junhao He <hejunhao3@...wei.com>,
"Masami Hiramatsu (Google)" <mhiramat@...nel.org>, Xu Yang <xu.yang_2@....com>,
Steve Clevenger <scclevenger@...amperecomputing.com>, Zixian Cai <fzczx123@...il.com>,
Stephen Brennan <stephen.s.brennan@...cle.com>, Yujie Liu <yujie.liu@...el.com>,
linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, llvm@...ts.linux.dev
Subject: [PATCH v1 32/48] perf script: Silence -Wshorten-64-to-32 warnings
The clang warning -Wshorten-64-to-32 can be useful to catch
inadvertent truncation. In some instances this truncation can lead to
changing the sign of a result, for example, truncation to return an
int to fit a sort routine. Silence the warning by making the implicit
truncation explicit.
Signed-off-by: Ian Rogers <irogers@...gle.com>
---
tools/perf/builtin-script.c | 39 ++++++++++++++++++----------------
tools/perf/util/print_binary.c | 13 ++++++------
2 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 9b16df881af8..bb997f2ceb62 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -724,7 +724,7 @@ static int perf_session__check_output_opt(struct perf_session *session)
static int perf_sample__fprintf_regs(struct regs_dump *regs, uint64_t mask, const char *arch,
FILE *fp)
{
- unsigned i = 0, r;
+ size_t i = 0, r;
int printed = 0;
if (!regs || !regs->regs)
@@ -734,7 +734,7 @@ static int perf_sample__fprintf_regs(struct regs_dump *regs, uint64_t mask, cons
for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) {
u64 val = regs->regs[i++];
- printed += fprintf(fp, "%5s:0x%"PRIx64" ", perf_reg_name(r, arch), val);
+ printed += fprintf(fp, "%5s:0x%"PRIx64" ", perf_reg_name((int)r, arch), val);
}
return printed;
@@ -1150,7 +1150,7 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
if (len <= 0)
pr_debug("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n",
start, end);
- ret = len;
+ ret = (int)len;
out:
addr_location__exit(&al);
return ret;
@@ -1270,7 +1270,8 @@ static int ip__fprintf_jump(uint64_t ip, struct branch_entry *en,
if (PRINT_FIELD(BRCNTR)) {
struct evsel *pos = evsel__leader(evsel);
- unsigned int i = 0, j, num, mask, width;
+ unsigned int i = 0, width;
+ size_t mask, num;
perf_env__find_br_cntr_info(evsel__env(evsel), NULL, &width);
mask = (1L << width) - 1;
@@ -1283,10 +1284,11 @@ static int ip__fprintf_jump(uint64_t ip, struct branch_entry *en,
num = (br_cntr >> (i++ * width)) & mask;
if (!verbose) {
- for (j = 0; j < num; j++)
+ for (size_t j = 0; j < num; j++)
printed += fprintf(fp, "%s", pos->abbr_name);
- } else
- printed += fprintf(fp, "%s %d ", pos->name, num);
+ } else {
+ printed += fprintf(fp, "%s %zu ", pos->name, num);
+ }
}
printed += fprintf(fp, "\t");
}
@@ -1328,9 +1330,9 @@ static int ip__fprintf_sym(uint64_t addr, struct thread *thread,
goto out;
if (al.addr < al.sym->end)
- off = al.addr - al.sym->start;
+ off = (int)(al.addr - al.sym->start);
else
- off = al.addr - map__start(al.map) - al.sym->start;
+ off = (int)(al.addr - map__start(al.map) - al.sym->start);
printed += fprintf(fp, "\t%s", al.sym->name);
if (off)
printed += fprintf(fp, "%+d", off);
@@ -1365,7 +1367,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,
if (!(br && br->nr))
return 0;
- nr = br->nr;
+ nr = (int)br->nr;
if (max_blocks && nr > max_blocks + 1)
nr = max_blocks + 1;
@@ -1645,14 +1647,14 @@ static int perf_sample__fprintf_insn(struct perf_sample *sample,
static int perf_sample__fprintf_ipc(struct perf_sample *sample,
struct evsel *evsel, FILE *fp)
{
- unsigned int ipc;
+ u64 ipc;
if (!PRINT_FIELD(IPC) || !sample->cyc_cnt || !sample->insn_cnt)
return 0;
ipc = (sample->insn_cnt * 100) / sample->cyc_cnt;
- return fprintf(fp, " \t IPC: %u.%02u (%" PRIu64 "/%" PRIu64 ") ",
+ return fprintf(fp, " \t IPC: %" PRIu64 ".%02" PRIu64 " (%" PRIu64 "/%" PRIu64 ") ",
ipc / 100, ipc % 100, sample->insn_cnt, sample->cyc_cnt);
}
@@ -2036,7 +2038,7 @@ static int evlist__max_name_len(struct evlist *evlist)
int max = 0;
evlist__for_each_entry(evlist, evsel) {
- int len = strlen(evsel__name(evsel));
+ int len = (int)strlen(evsel__name(evsel));
max = MAX(len, max);
}
@@ -2147,7 +2149,7 @@ static bool show_event(struct perf_sample *sample,
struct addr_location *al,
struct addr_location *addr_al)
{
- int depth = thread_stack__depth(thread, sample->cpu);
+ int depth = (int)thread_stack__depth(thread, sample->cpu);
if (!symbol_conf.graph_function)
return true;
@@ -2163,13 +2165,14 @@ static bool show_event(struct perf_sample *sample,
u64 ip;
const char *name = resolve_branch_sym(sample, evsel, thread, al, addr_al,
&ip);
- unsigned nlen;
+ size_t nlen;
if (!name)
return false;
nlen = strlen(name);
while (*s) {
- unsigned len = strcspn(s, ",");
+ size_t len = strcspn(s, ",");
+
if (nlen == len && !strncmp(name, s, len)) {
thread__set_filter(thread, true);
thread__set_filter_entry_depth(thread, depth);
@@ -2952,7 +2955,7 @@ static int parse_scriptname(const struct option *opt __maybe_unused,
{
char spec[PATH_MAX];
const char *script, *ext;
- int len;
+ size_t len;
if (strcmp(str, "lang") == 0) {
list_available_languages();
@@ -4097,7 +4100,7 @@ int cmd_script(int argc, const char **argv)
script.tool.ordering_requires_timestamps = true;
session = perf_session__new(&data, &script.tool);
if (IS_ERR(session))
- return PTR_ERR(session);
+ return (int)PTR_ERR(session);
if (header || header_only) {
script.tool.show_feat_hdr = SHOW_FEAT_HEADER;
diff --git a/tools/perf/util/print_binary.c b/tools/perf/util/print_binary.c
index 13fdc51c61d9..6894fb5e7865 100644
--- a/tools/perf/util/print_binary.c
+++ b/tools/perf/util/print_binary.c
@@ -7,8 +7,7 @@ int binary__fprintf(unsigned char *data, size_t len,
size_t bytes_per_line, binary__fprintf_t printer,
void *extra, FILE *fp)
{
- size_t i, j, mask;
- int printed = 0;
+ size_t mask, printed = 0;
if (!printer)
return 0;
@@ -17,7 +16,7 @@ int binary__fprintf(unsigned char *data, size_t len,
mask = bytes_per_line - 1;
printed += printer(BINARY_PRINT_DATA_BEGIN, 0, extra, fp);
- for (i = 0; i < len; i++) {
+ for (unsigned int i = 0; i < len; i++) {
if ((i & mask) == 0) {
printed += printer(BINARY_PRINT_LINE_BEGIN, -1, extra, fp);
printed += printer(BINARY_PRINT_ADDR, i, extra, fp);
@@ -26,19 +25,19 @@ int binary__fprintf(unsigned char *data, size_t len,
printed += printer(BINARY_PRINT_NUM_DATA, data[i], extra, fp);
if (((i & mask) == mask) || i == len - 1) {
- for (j = 0; j < mask-(i & mask); j++)
+ for (unsigned int j = 0; j < mask-(i & mask); j++)
printed += printer(BINARY_PRINT_NUM_PAD, -1, extra, fp);
printer(BINARY_PRINT_SEP, i, extra, fp);
- for (j = i & ~mask; j <= i; j++)
+ for (unsigned int j = i & ~mask; j <= i; j++)
printed += printer(BINARY_PRINT_CHAR_DATA, data[j], extra, fp);
- for (j = 0; j < mask-(i & mask); j++)
+ for (unsigned int j = 0; j < mask-(i & mask); j++)
printed += printer(BINARY_PRINT_CHAR_PAD, i, extra, fp);
printed += printer(BINARY_PRINT_LINE_END, -1, extra, fp);
}
}
printed += printer(BINARY_PRINT_DATA_END, -1, extra, fp);
- return printed;
+ return (int)printed;
}
int is_printable_array(char *p, unsigned int len)
--
2.49.0.504.g3bcea36a83-goog
Powered by blists - more mailing lists