linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32
@ 2025-04-30 17:49 Ian Rogers
  2025-04-30 17:49 ` [PATCH v2 01/47] perf build: Avoid building libbpf/bpftool with LIBBPF_DYNAMIC Ian Rogers
                   ` (46 more replies)
  0 siblings, 47 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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. Leo Yan found an issue here:
https://lore.kernel.org/lkml/20250331172759.115604-1-leo.yan@arm.com/
and so it is worthwhile doing a round to clean up all these warnings.

So that libbpf and bpftool aren't also cleaned up the first patch
makes these more optional within the build. The rest of the patches
try to do the right thing in silencing the warning, generally making
the implicit casts explicit. Some issues similar to Leo's were
discovered in this process.

v2: Move the truncation error fixes to patches 2 and 3 in the series
    (Leo Yan). Rebase and fix issues with the changed files. Drop the
    linux header patches that are now their own series (Yury Norov)
    and we can pick those fixes up when the kernel changes land.
    https://lore.kernel.org/lkml/20250430171534.132774-1-irogers@google.com/

Ian Rogers (47):
  perf build: Avoid building libbpf/bpftool with LIBBPF_DYNAMIC
  perf tests: Silence -Wshorten-64-to-32 warnings
  perf ui: Silence -Wshorten-64-to-32 warnings
  perf bench: Silence -Wshorten-64-to-32 warnings
  arm64: cputype: Silence -Wshorten-64-to-32 warnings
  x86/insn: Silence -Wshorten-64-to-32 warnings
  tools lib: Silence -Wshorten-64-to-32 warnings
  libperf: Silence -Wshorten-64-to-32 warnings
  tools subcmd: Silence -Wshorten-64-to-32 warnings
  perf arch x86: Silence -Wshorten-64-to-32 warnings
  perf arm-spe: Silence -Wshorten-64-to-32 warnings
  perf trace: Silence -Wshorten-64-to-32 warnings
  perf trace-event: Silence -Wshorten-64-to-32 warnings
  perf jvmti: Silence -Wshorten-64-to-32 warnings
  perf pmu: Silence -Wshorten-64-to-32 warnings
  perf annotate powerpc: Silence -Wshorten-64-to-32 warnings
  perf s390: Silence -Wshorten-64-to-32 warnings
  perf cs-etm: Silence -Wshorten-64-to-32 warnings
  perf stat: Silence -Wshorten-64-to-32 warnings
  perf dlfilter: Silence -Wshorten-64-to-32 warnings
  perf demangle: Silence -Wshorten-64-to-32 warnings
  perf annotate: Silence -Wshorten-64-to-32 warnings
  perf report: Silence -Wshorten-64-to-32 warnings
  perf help: Silence -Wshorten-64-to-32 warnings
  perf hisi-ptt: Silence -Wshorten-64-to-32 warnings
  perf probe: Silence -Wshorten-64-to-32 warnings
  perf kwork: Silence -Wshorten-64-to-32 warnings
  perf buildid: Silence -Wshorten-64-to-32 warnings
  perf lock: Silence -Wshorten-64-to-32 warnings
  perf mem: Silence -Wshorten-64-to-32 warnings
  perf script: Silence -Wshorten-64-to-32 warnings
  perf evlist: Silence -Wshorten-64-to-32 warnings
  perf bpf_counter: Silence -Wshorten-64-to-32 warnings
  perf ftrace: Silence -Wshorten-64-to-32 warnings
  perf record: Silence -Wshorten-64-to-32 warnings
  perf inject: Silence -Wshorten-64-to-32 warnings
  perf sched: Silence -Wshorten-64-to-32 warnings
  perf timechart: Silence -Wshorten-64-to-32 warnings
  perf list: Silence -Wshorten-64-to-32 warnings
  perf kvm: Silence -Wshorten-64-to-32 warnings
  perf diff: Silence -Wshorten-64-to-32 warnings
  perf daemon: Silence -Wshorten-64-to-32 warnings
  perf zlib: Silence -Wshorten-64-to-32 warnings
  perf symbol: Silence -Wshorten-64-to-32 warnings
  perf util: Silence -Wshorten-64-to-32 warnings
  perf hashmap: Silence -Wshorten-64-to-32 warnings
  perf: Silence -Wshorten-64-to-32 warnings

 tools/arch/arm64/include/asm/cputype.h        |  2 +-
 tools/arch/x86/lib/insn.c                     |  2 +-
 tools/lib/api/fs/fs.c                         |  4 +-
 tools/lib/bitmap.c                            |  2 +-
 tools/lib/perf/cpumap.c                       | 18 ++--
 tools/lib/perf/evsel.c                        | 40 +++-----
 tools/lib/perf/include/internal/cpumap.h      |  2 +-
 tools/lib/perf/include/internal/evsel.h       |  2 +-
 tools/lib/perf/include/internal/lib.h         |  2 +-
 tools/lib/perf/include/internal/mmap.h        |  4 +-
 tools/lib/perf/include/internal/threadmap.h   |  2 +-
 tools/lib/perf/include/internal/xyarray.h     |  8 +-
 tools/lib/perf/include/perf/cpumap.h          |  3 +-
 tools/lib/perf/lib.c                          |  2 +-
 tools/lib/perf/mmap.c                         | 13 ++-
 tools/lib/perf/threadmap.c                    |  4 +-
 tools/lib/perf/xyarray.c                      |  2 +-
 tools/lib/string.c                            |  6 +-
 tools/lib/subcmd/help.c                       | 28 +++---
 tools/lib/subcmd/help.h                       |  6 --
 tools/lib/subcmd/parse-options.c              | 16 +--
 tools/lib/vsprintf.c                          |  6 +-
 tools/perf/Makefile.perf                      | 13 ++-
 .../perf/arch/powerpc/annotate/instructions.c |  2 +-
 tools/perf/arch/x86/tests/bp-modify.c         |  2 +-
 tools/perf/arch/x86/util/intel-bts.c          |  4 +-
 tools/perf/arch/x86/util/intel-pt.c           | 10 +-
 tools/perf/arch/x86/util/iostat.c             |  2 +-
 tools/perf/arch/x86/util/kvm-stat.c           |  6 +-
 tools/perf/arch/x86/util/perf_regs.c          |  3 +-
 tools/perf/arch/x86/util/topdown.c            |  2 +-
 tools/perf/bench/breakpoint.c                 |  8 +-
 tools/perf/bench/epoll-wait.c                 |  3 +-
 tools/perf/bench/evlist-open-close.c          |  8 +-
 tools/perf/bench/find-bit-bench.c             |  5 +-
 tools/perf/bench/futex.h                      |  4 +-
 tools/perf/bench/inject-buildid.c             |  8 +-
 tools/perf/bench/mem-functions.c              |  2 +-
 tools/perf/bench/pmu-scan.c                   | 12 +--
 tools/perf/bench/sched-messaging.c            |  4 +-
 tools/perf/bench/sched-pipe.c                 | 15 +--
 tools/perf/bench/sched-seccomp-notify.c       |  2 +-
 tools/perf/bench/synthesize.c                 |  6 +-
 tools/perf/builtin-annotate.c                 |  4 +-
 tools/perf/builtin-bench.c                    |  2 +-
 tools/perf/builtin-buildid-cache.c            |  2 +-
 tools/perf/builtin-buildid-list.c             |  2 +-
 tools/perf/builtin-c2c.c                      | 21 ++--
 tools/perf/builtin-daemon.c                   |  5 +-
 tools/perf/builtin-diff.c                     | 10 +-
 tools/perf/builtin-evlist.c                   |  2 +-
 tools/perf/builtin-ftrace.c                   | 17 ++--
 tools/perf/builtin-help.c                     |  4 +-
 tools/perf/builtin-inject.c                   | 28 +++---
 tools/perf/builtin-kmem.c                     | 39 ++++----
 tools/perf/builtin-kvm.c                      |  8 +-
 tools/perf/builtin-kwork.c                    | 11 +--
 tools/perf/builtin-list.c                     |  4 +-
 tools/perf/builtin-lock.c                     | 16 +--
 tools/perf/builtin-mem.c                      |  2 +-
 tools/perf/builtin-record.c                   | 66 +++++++------
 tools/perf/builtin-report.c                   |  4 +-
 tools/perf/builtin-sched.c                    | 56 +++++------
 tools/perf/builtin-script.c                   | 39 ++++----
 tools/perf/builtin-stat.c                     |  6 +-
 tools/perf/builtin-timechart.c                | 60 ++++++------
 tools/perf/builtin-top.c                      |  4 +-
 tools/perf/builtin-trace.c                    | 98 ++++++++++---------
 tools/perf/dlfilters/dlfilter-test-api-v0.c   |  4 +-
 tools/perf/jvmti/jvmti_agent.c                |  6 +-
 tools/perf/perf-sys.h                         |  3 +-
 tools/perf/perf.c                             |  2 +-
 tools/perf/tests/api-io.c                     |  2 +-
 tools/perf/tests/bp_signal.c                  |  6 +-
 tools/perf/tests/bp_signal_overflow.c         |  6 +-
 tools/perf/tests/builtin-test.c               |  9 +-
 tools/perf/tests/code-reading.c               |  4 +-
 tools/perf/tests/dso-data.c                   | 10 +-
 tools/perf/tests/mmap-thread-lookup.c         |  2 +-
 tools/perf/tests/openat-syscall-tp-fields.c   |  2 +-
 tools/perf/tests/pmu-events.c                 |  2 +-
 tools/perf/tests/sigtrap.c                    |  4 +-
 tools/perf/tests/switch-tracking.c            | 11 ++-
 tools/perf/tests/vmlinux-kallsyms.c           |  4 +-
 tools/perf/tests/wp.c                         |  4 +-
 tools/perf/trace/beauty/arch_prctl.c          |  2 +-
 tools/perf/trace/beauty/eventfd.c             |  2 +-
 tools/perf/trace/beauty/fcntl.c               |  5 +-
 tools/perf/trace/beauty/flock.c               |  2 +-
 tools/perf/trace/beauty/fs_at_flags.c         |  4 +-
 tools/perf/trace/beauty/futex_op.c            |  2 +-
 tools/perf/trace/beauty/futex_val3.c          |  2 +-
 tools/perf/trace/beauty/ioctl.c               |  2 +-
 tools/perf/trace/beauty/kcmp.c                |  8 +-
 tools/perf/trace/beauty/mmap.c                |  2 +-
 tools/perf/trace/beauty/mode_t.c              |  2 +-
 tools/perf/trace/beauty/msg_flags.c           |  2 +-
 tools/perf/trace/beauty/open_flags.c          |  2 +-
 tools/perf/trace/beauty/perf_event_open.c     |  4 +-
 tools/perf/trace/beauty/pid.c                 |  2 +-
 tools/perf/trace/beauty/pkey_alloc.c          |  2 +-
 tools/perf/trace/beauty/prctl.c               | 10 +-
 tools/perf/trace/beauty/sched_policy.c        |  2 +-
 tools/perf/trace/beauty/seccomp.c             |  4 +-
 tools/perf/trace/beauty/signum.c              |  2 +-
 tools/perf/trace/beauty/socket.c              |  6 +-
 tools/perf/trace/beauty/socket_type.c         |  2 +-
 tools/perf/trace/beauty/statx.c               |  2 +-
 .../beauty/tracepoints/x86_irq_vectors.c      |  3 +-
 tools/perf/trace/beauty/tracepoints/x86_msr.c |  3 +-
 tools/perf/trace/beauty/waitid_options.c      |  2 +-
 tools/perf/ui/hist.c                          | 18 ++--
 tools/perf/ui/stdio/hist.c                    |  5 +-
 tools/perf/util/annotate.c                    | 22 ++---
 .../util/arm-spe-decoder/arm-spe-decoder.c    |  4 +-
 .../arm-spe-decoder/arm-spe-pkt-decoder.c     |  2 +-
 tools/perf/util/arm-spe.c                     | 24 ++---
 tools/perf/util/auxtrace.c                    |  8 +-
 tools/perf/util/bpf-event.c                   |  2 +-
 tools/perf/util/bpf-filter.c                  | 20 ++--
 tools/perf/util/bpf_counter.c                 |  6 +-
 tools/perf/util/bpf_counter_cgroup.c          |  2 +-
 tools/perf/util/bpf_ftrace.c                  |  4 +-
 tools/perf/util/bpf_kwork_top.c               |  2 +-
 tools/perf/util/bpf_lock_contention.c         | 17 ++--
 tools/perf/util/bpf_off_cpu.c                 |  4 +-
 tools/perf/util/build-id.c                    |  2 +-
 tools/perf/util/cacheline.c                   |  5 +-
 tools/perf/util/callchain.c                   | 12 +--
 tools/perf/util/callchain.h                   |  2 +-
 tools/perf/util/cgroup.c                      |  4 +-
 tools/perf/util/comm.c                        |  2 +-
 tools/perf/util/config.c                      |  6 +-
 tools/perf/util/cpumap.c                      |  4 +-
 tools/perf/util/cs-etm-base.c                 |  4 +-
 tools/perf/util/debug.c                       |  7 +-
 tools/perf/util/demangle-java.c               |  4 +-
 tools/perf/util/demangle-ocaml.c              |  3 +-
 tools/perf/util/disasm.c                      | 11 ++-
 tools/perf/util/dlfilter.c                    | 10 +-
 tools/perf/util/env.c                         |  2 +-
 tools/perf/util/event.c                       |  4 +-
 tools/perf/util/evlist.c                      | 29 +++---
 tools/perf/util/evsel.c                       | 35 +++----
 tools/perf/util/genelf.c                      |  2 +-
 tools/perf/util/hashmap.c                     | 10 +-
 tools/perf/util/header.c                      | 54 +++++-----
 tools/perf/util/help-unknown-cmd.c            | 14 +--
 tools/perf/util/hisi-ptt.c                    |  8 +-
 tools/perf/util/hist.c                        |  7 +-
 tools/perf/util/hwmon_pmu.c                   |  8 +-
 tools/perf/util/intel-bts.c                   |  4 +-
 .../util/intel-pt-decoder/intel-pt-decoder.c  | 30 +++---
 .../intel-pt-decoder/intel-pt-insn-decoder.c  |  2 +-
 .../perf/util/intel-pt-decoder/intel-pt-log.c |  2 +-
 .../intel-pt-decoder/intel-pt-pkt-decoder.c   |  2 +-
 tools/perf/util/intel-pt.c                    | 38 +++----
 tools/perf/util/jitdump.c                     | 24 ++---
 tools/perf/util/levenshtein.c                 | 18 ++--
 tools/perf/util/machine.c                     | 14 +--
 tools/perf/util/map.c                         |  4 +-
 tools/perf/util/maps.c                        |  6 +-
 tools/perf/util/mem-events.c                  | 12 +--
 tools/perf/util/mem2node.c                    |  2 +-
 tools/perf/util/memswap.c                     |  4 +-
 tools/perf/util/memswap.h                     |  4 +-
 tools/perf/util/metricgroup.c                 | 15 ++-
 tools/perf/util/mmap.c                        |  6 +-
 tools/perf/util/parse-events.c                | 16 +--
 tools/perf/util/pmu.c                         |  9 +-
 tools/perf/util/pmus.c                        | 16 +--
 tools/perf/util/print_binary.c                | 13 ++-
 tools/perf/util/probe-event.c                 | 13 +--
 tools/perf/util/probe-file.c                  | 12 ++-
 tools/perf/util/python.c                      |  4 +-
 tools/perf/util/s390-sample-raw.c             |  4 +-
 .../scripting-engines/trace-event-python.c    | 13 +--
 tools/perf/util/session.c                     | 29 +++---
 tools/perf/util/sort.c                        | 20 ++--
 tools/perf/util/srccode.c                     |  6 +-
 tools/perf/util/srcline.c                     |  2 +-
 tools/perf/util/stat-display.c                | 10 +-
 tools/perf/util/strfilter.c                   |  2 +-
 tools/perf/util/string.c                      | 11 ++-
 tools/perf/util/svghelper.c                   | 23 ++---
 tools/perf/util/symbol-elf.c                  | 33 ++++---
 tools/perf/util/symbol.c                      | 10 +-
 tools/perf/util/synthetic-events.c            | 22 ++---
 tools/perf/util/target.c                      |  2 +-
 tools/perf/util/thread-stack.c                |  2 +-
 tools/perf/util/thread.c                      |  4 +-
 tools/perf/util/thread_map.c                  |  6 +-
 tools/perf/util/time-utils.c                  |  9 +-
 tools/perf/util/tool.c                        |  2 +-
 tools/perf/util/tool_pmu.c                    |  2 +-
 tools/perf/util/trace-event-info.c            |  3 +-
 tools/perf/util/trace-event-parse.c           |  2 +-
 tools/perf/util/trace-event-read.c            | 23 +++--
 tools/perf/util/trace-event-scripting.c       |  2 +-
 tools/perf/util/util.c                        |  9 +-
 tools/perf/util/util.h                        |  2 +-
 tools/perf/util/values.c                      |  4 +-
 tools/perf/util/zlib.c                        |  2 +-
 203 files changed, 963 insertions(+), 922 deletions(-)

-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply	[flat|nested] 58+ messages in thread

* [PATCH v2 01/47] perf build: Avoid building libbpf/bpftool with LIBBPF_DYNAMIC
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
@ 2025-04-30 17:49 ` Ian Rogers
  2025-04-30 17:49 ` [PATCH v2 02/47] perf tests: Silence -Wshorten-64-to-32 warnings Ian Rogers
                   ` (45 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

Building with LIBBPF_DYNAMIC still requires building libbpf as part of
bpftool, but the build also still accidentally builds it. Make the
parts of the build bringing in libbpf conditional. Don't build bpftool
is a bpftool exists from the which command.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/Makefile.perf | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 5438d1111f3b..296c00e224a0 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -960,10 +960,12 @@ $(LIBAPI)-clean:
 	$(call QUIET_CLEAN, libapi)
 	$(Q)$(RM) -r -- $(LIBAPI_OUTPUT)
 
+ifndef LIBBPF_DYNAMIC
 $(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
 	$(Q)$(MAKE) -C $(LIBBPF_DIR) FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) \
 		O= OUTPUT=$(LIBBPF_OUTPUT)/ DESTDIR=$(LIBBPF_DESTDIR) prefix= subdir= \
 		EXTRA_CFLAGS="-fPIC" $@ install_headers
+endif
 
 $(LIBBPF)-clean:
 	$(call QUIET_CLEAN, libbpf)
@@ -1183,7 +1185,11 @@ $(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_
 	$(Q)$(MKDIR) -p $@
 
 ifeq ($(CONFIG_PERF_BPF_SKEL),y)
+BPFTOOL := $(shell which bpftool)
+ifeq ($(BPFTOOL),)
 BPFTOOL := $(SKEL_TMP_OUT)/bootstrap/bpftool
+BUILD_BPFTOOL := y
+endif
 # Get Clang's default includes on this system, as opposed to those seen by
 # '--target=bpf'. This fixes "missing" files on some architectures/distros,
 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
@@ -1202,16 +1208,21 @@ endif
 
 CLANG_OPTIONS = -Wall
 CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
-BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES)
+BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. $(CLANG_SYS_INCLUDES)
+ifneq ($(LIBBPF_INCLUDE),)
+  BPF_INCLUDE += -I$(LIBBPF_INCLUDE)
+endif
 TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi
 
 ifneq ($(WERROR),0)
   CLANG_OPTIONS += -Werror
 endif
 
+ifneq ($(BUILD_BPFTOOL),)
 $(BPFTOOL): | $(SKEL_TMP_OUT)
 	$(Q)CFLAGS= $(MAKE) -C ../bpf/bpftool \
 		OUTPUT=$(SKEL_TMP_OUT)/ bootstrap
+endif
 
 # Paths to search for a kernel to generate vmlinux.h from.
 VMLINUX_BTF_ELF_PATHS ?= $(if $(O),$(O)/vmlinux)			\
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 02/47] perf tests: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
  2025-04-30 17:49 ` [PATCH v2 01/47] perf build: Avoid building libbpf/bpftool with LIBBPF_DYNAMIC Ian Rogers
@ 2025-04-30 17:49 ` Ian Rogers
  2025-04-30 17:49 ` [PATCH v2 03/47] perf ui: " Ian Rogers
                   ` (44 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/tests/api-io.c                   |  2 +-
 tools/perf/tests/bp_signal.c                |  6 +++---
 tools/perf/tests/bp_signal_overflow.c       |  6 +++---
 tools/perf/tests/builtin-test.c             |  9 +++++----
 tools/perf/tests/code-reading.c             |  4 ++--
 tools/perf/tests/dso-data.c                 | 10 +++++-----
 tools/perf/tests/mmap-thread-lookup.c       |  2 +-
 tools/perf/tests/openat-syscall-tp-fields.c |  2 +-
 tools/perf/tests/pmu-events.c               |  2 +-
 tools/perf/tests/sigtrap.c                  |  4 ++--
 tools/perf/tests/switch-tracking.c          | 11 ++++++-----
 tools/perf/tests/vmlinux-kallsyms.c         |  4 ++--
 tools/perf/tests/wp.c                       |  4 ++--
 13 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/tools/perf/tests/api-io.c b/tools/perf/tests/api-io.c
index 0ba3d5ccebcf..4aee1cff062e 100644
--- a/tools/perf/tests/api-io.c
+++ b/tools/perf/tests/api-io.c
@@ -74,7 +74,7 @@ static int setup_test(char path[PATH_MAX], const char *contents,
 		unlink(path);
 		return -1;
 	}
-	io__init(io, io->fd, io->buf, buf_size);
+	io__init(io, io->fd, io->buf, (unsigned int)buf_size);
 	return 0;
 }
 
diff --git a/tools/perf/tests/bp_signal.c b/tools/perf/tests/bp_signal.c
index 3faeb5b6fe0b..5ecac6c2d8b6 100644
--- a/tools/perf/tests/bp_signal.c
+++ b/tools/perf/tests/bp_signal.c
@@ -64,7 +64,7 @@ static noinline int test_function(void)
 {
 	__test_function(&the_var);
 	the_var++;
-	return time(NULL);
+	return (int)time(NULL);
 }
 
 static void sig_handler_2(int signum __maybe_unused,
@@ -151,11 +151,11 @@ static int wp_event(void *addr, int sig)
 static long long bp_count(int fd)
 {
 	long long count;
-	int ret;
+	ssize_t ret;
 
 	ret = read(fd, &count, sizeof(long long));
 	if (ret != sizeof(long long)) {
-		pr_debug("failed to read: %d\n", ret);
+		pr_debug("failed to read: %zd\n", ret);
 		return TEST_FAIL;
 	}
 
diff --git a/tools/perf/tests/bp_signal_overflow.c b/tools/perf/tests/bp_signal_overflow.c
index ee560e156be6..eb9021ad8177 100644
--- a/tools/perf/tests/bp_signal_overflow.c
+++ b/tools/perf/tests/bp_signal_overflow.c
@@ -33,7 +33,7 @@ static int overflows;
 
 static noinline int test_function(void)
 {
-	return time(NULL);
+	return (int)time(NULL);
 }
 
 static void sig_handler(int signum __maybe_unused,
@@ -46,11 +46,11 @@ static void sig_handler(int signum __maybe_unused,
 static long long bp_count(int fd)
 {
 	long long count;
-	int ret;
+	ssize_t ret;
 
 	ret = read(fd, &count, sizeof(long long));
 	if (ret != sizeof(long long)) {
-		pr_debug("failed to read: %d\n", ret);
+		pr_debug("failed to read: %zd\n", ret);
 		return TEST_FAIL;
 	}
 
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 14d30a5053be..4ea840580876 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -301,7 +301,7 @@ static int print_test_result(struct test_suite *t, int curr_suite, int curr_test
 	return 0;
 }
 
-static void finish_test(struct child_test **child_tests, int running_test, int child_test_num,
+static void finish_test(struct child_test **child_tests, size_t running_test, size_t child_test_num,
 		int width)
 {
 	struct child_test *child_test = child_tests[running_test];
@@ -349,7 +349,7 @@ static void finish_test(struct child_test **child_tests, int running_test, int c
 		if (perf_use_color_default) {
 			int running = 0;
 
-			for (int y = running_test; y < child_test_num; y++) {
+			for (size_t y = running_test; y < child_test_num; y++) {
 				if (child_tests[y] == NULL)
 					continue;
 				if (check_if_command_finished(&child_tests[y]->process) == 0)
@@ -478,13 +478,14 @@ static int __cmd_test(struct test_suite **suites, int argc, const char *argv[],
 	int err = 0;
 
 	for (struct test_suite **t = suites; *t; t++) {
-		int i, len = strlen(test_description(*t, -1));
+		int i;
+		int len = (int)strlen(test_description(*t, -1));
 
 		if (width < len)
 			width = len;
 
 		test_suite__for_each_test_case(*t, i) {
-			len = strlen(test_description(*t, i));
+			len = (int)strlen(test_description(*t, i));
 			if (width < len)
 				width = len;
 			num_tests += runs_per_test;
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index cf6edbe697b2..0c31d5ff77e2 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -188,7 +188,7 @@ static int objdump_version(void)
 	char *line = NULL;
 	const char *fmt;
 	FILE *f;
-	int ret;
+	ssize_t ret;
 
 	int version_tmp, version_num = 0;
 	char *version = 0, *token;
@@ -295,7 +295,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
 	if (len) {
 		pr_debug("objdump read too few bytes: %zd\n", len);
 		if (!ret)
-			ret = len;
+			ret = (int)len;
 	}
 
 	pclose(f);
diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c
index a1fff4203b75..2954e06ae5b3 100644
--- a/tools/perf/tests/dso-data.c
+++ b/tools/perf/tests/dso-data.c
@@ -233,14 +233,14 @@ static int dsos__create(int cnt, int size, struct dsos *dsos)
 	return 0;
 }
 
-static int set_fd_limit(int n)
+static int set_fd_limit(long n)
 {
 	struct rlimit rlim;
 
 	if (getrlimit(RLIMIT_NOFILE, &rlim))
 		return -1;
 
-	pr_debug("file limit %ld, new %d\n", (long) rlim.rlim_cur, n);
+	pr_debug("file limit %ld, new %ld\n", (long) rlim.rlim_cur, n);
 
 	rlim.rlim_cur = n;
 	return setrlimit(RLIMIT_NOFILE, &rlim);
@@ -249,8 +249,8 @@ static int set_fd_limit(int n)
 static int test__dso_data_cache(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
 {
 	struct machine machine;
-	long nr_end, nr = open_files_cnt();
-	int dso_cnt, limit, i, fd;
+	long dso_cnt, limit, nr_end, nr = open_files_cnt();
+	int i, fd;
 
 	/* Rest the internal dso open counter limit. */
 	reset_fd_limit();
@@ -264,7 +264,7 @@ static int test__dso_data_cache(struct test_suite *test __maybe_unused, int subt
 	/* and this is now our dso open FDs limit */
 	dso_cnt = limit / 2;
 	TEST_ASSERT_VAL("failed to create dsos\n",
-			!dsos__create(dso_cnt, TEST_FILE_SIZE, &machine.dsos));
+			!dsos__create((int)dso_cnt, TEST_FILE_SIZE, &machine.dsos));
 
 	for (i = 0; i < (dso_cnt - 1); i++) {
 		struct dso *dso = machine.dsos.dsos[i];
diff --git a/tools/perf/tests/mmap-thread-lookup.c b/tools/perf/tests/mmap-thread-lookup.c
index 446a3615d720..b328ad6973a3 100644
--- a/tools/perf/tests/mmap-thread-lookup.c
+++ b/tools/perf/tests/mmap-thread-lookup.c
@@ -45,7 +45,7 @@ static int thread_init(struct thread_data *td)
 	}
 
 	td->map = map;
-	td->tid = syscall(SYS_gettid);
+	td->tid = (pid_t)syscall(SYS_gettid);
 
 	pr_debug("tid = %d, map = %p\n", td->tid, map);
 	return 0;
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index 0ef4ba7c1571..68f1498d0a47 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -119,7 +119,7 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused
 					goto out_delete_evlist;
 				}
 
-				tp_flags = evsel__intval(evsel, &sample, "flags");
+				tp_flags = (int)evsel__intval(evsel, &sample, "flags");
 				perf_sample__exit(&sample);
 				if (flags != tp_flags) {
 					pr_debug("%s: Expected flags=%#x, got %#x\n",
diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c
index db004d26fcb0..2762794827ce 100644
--- a/tools/perf/tests/pmu-events.c
+++ b/tools/perf/tests/pmu-events.c
@@ -609,7 +609,7 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu)
 	pmu_add_sys_aliases(pmu);
 
 	/* Count how many aliases we generated */
-	alias_count = perf_pmu__num_events(pmu);
+	alias_count = (int)perf_pmu__num_events(pmu);
 
 	/* Count how many aliases we expect from the known table */
 	for (table = &test_pmu->aliases[0]; *table; table++)
diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c
index a67c756f90b8..b7d7735f8a72 100644
--- a/tools/perf/tests/sigtrap.c
+++ b/tools/perf/tests/sigtrap.c
@@ -154,13 +154,13 @@ sigtrap_handler(int signum __maybe_unused, siginfo_t *info, void *ucontext __may
 {
 	if (!__atomic_fetch_add(&ctx.signal_count, 1, __ATOMIC_RELAXED))
 		ctx.first_siginfo = *info;
-	__atomic_fetch_sub(&ctx.tids_want_signal, syscall(SYS_gettid), __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&ctx.tids_want_signal, (pid_t)syscall(SYS_gettid), __ATOMIC_RELAXED);
 }
 
 static void *test_thread(void *arg)
 {
 	pthread_barrier_t *barrier = (pthread_barrier_t *)arg;
-	pid_t tid = syscall(SYS_gettid);
+	pid_t tid = (pid_t)syscall(SYS_gettid);
 	int i;
 
 	pthread_barrier_wait(barrier);
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 8df3f9d9ffd2..1f0f8321ae40 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -140,8 +140,8 @@ static int process_sample_event(struct evlist *evlist,
 
 	evsel = evlist__id2evsel(evlist, sample.id);
 	if (evsel == switch_tracking->switch_evsel) {
-		next_tid = evsel__intval(evsel, &sample, "next_pid");
-		prev_tid = evsel__intval(evsel, &sample, "prev_pid");
+		next_tid = (int)evsel__intval(evsel, &sample, "next_pid");
+		prev_tid = (int)evsel__intval(evsel, &sample, "prev_pid");
 		cpu = sample.cpu;
 		pr_debug3("sched_switch: cpu: %d prev_tid %d next_tid %d\n",
 			  cpu, prev_tid, next_tid);
@@ -262,9 +262,10 @@ static int compar(const void *a, const void *b)
 {
 	const struct event_node *nodea = a;
 	const struct event_node *nodeb = b;
-	s64 cmp = nodea->event_time - nodeb->event_time;
 
-	return cmp;
+	if (nodea->event_time == nodeb->event_time)
+		return 0;
+	return nodea->event_time < nodeb->event_time ? -1 : 1;
 }
 
 static int process_events(struct evlist *evlist,
@@ -398,7 +399,7 @@ static int test__switch_tracking(struct test_suite *test __maybe_unused, int sub
 
 	switch_evsel = evlist__add_sched_switch(evlist, true);
 	if (IS_ERR(switch_evsel)) {
-		err = PTR_ERR(switch_evsel);
+		err = (int)PTR_ERR(switch_evsel);
 		pr_debug("Failed to create event %s\n", sched_switch);
 		goto out_err;
 	}
diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c
index 74cdbd2ce9d0..fbdb463e965d 100644
--- a/tools/perf/tests/vmlinux-kallsyms.c
+++ b/tools/perf/tests/vmlinux-kallsyms.c
@@ -82,7 +82,7 @@ static bool is_ignored_symbol(const char *name, char type)
 			return true;
 
 	for (p = ignored_suffixes; *p; p++) {
-		int l = strlen(name) - strlen(*p);
+		ssize_t l = strlen(name) - strlen(*p);
 
 		if (l >= 0 && !strcmp(name + l, *p))
 			return true;
@@ -313,7 +313,7 @@ static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused
 				 * _really_ have a problem.
 				 */
 				s64 skew = mem_end - UM(pair->end);
-				if (llabs(skew) >= page_size)
+				if (llabs(skew) >= (s64)page_size)
 					pr_debug("WARN: %#" PRIx64 ": diff end addr for %s v: %#" PRIx64 " k: %#" PRIx64 "\n",
 						 mem_start, sym->name, mem_end,
 						 UM(pair->end));
diff --git a/tools/perf/tests/wp.c b/tools/perf/tests/wp.c
index 6c178985e37f..d5dd17eb5c05 100644
--- a/tools/perf/tests/wp.c
+++ b/tools/perf/tests/wp.c
@@ -31,10 +31,10 @@ volatile u8 data2[3];
 #ifndef __s390x__
 static int wp_read(int fd, long long *count, int size)
 {
-	int ret = read(fd, count, size);
+	ssize_t ret = read(fd, count, size);
 
 	if (ret != size) {
-		pr_debug("failed to read: %d\n", ret);
+		pr_debug("failed to read: %zd\n", ret);
 		return -1;
 	}
 	return 0;
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 03/47] perf ui: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
  2025-04-30 17:49 ` [PATCH v2 01/47] perf build: Avoid building libbpf/bpftool with LIBBPF_DYNAMIC Ian Rogers
  2025-04-30 17:49 ` [PATCH v2 02/47] perf tests: Silence -Wshorten-64-to-32 warnings Ian Rogers
@ 2025-04-30 17:49 ` Ian Rogers
  2025-04-30 17:49 ` [PATCH v2 04/47] perf bench: " Ian Rogers
                   ` (43 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/ui/hist.c       | 18 ++++++++----------
 tools/perf/ui/stdio/hist.c |  5 ++---
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 3ffce69fc823..fcbfa6700464 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -233,7 +233,7 @@ static int __hpp__group_sort_idx(struct hist_entry *a, struct hist_entry *b,
 static int __hpp__sort(struct hist_entry *a, struct hist_entry *b,
 		       hpp_field_fn get_field)
 {
-	s64 ret;
+	int ret;
 	int i, nr_members;
 	struct evsel *evsel;
 	u64 *fields_a, *fields_b;
@@ -272,7 +272,7 @@ static int __hpp__sort(struct hist_entry *a, struct hist_entry *b,
 static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b,
 			   hpp_field_fn get_field)
 {
-	s64 ret = 0;
+	int ret = 0;
 
 	if (symbol_conf.cumulate_callchain) {
 		/*
@@ -287,7 +287,7 @@ static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b,
 		    !hist_entry__has_callchains(a) || !symbol_conf.use_callchain)
 			return 0;
 
-		ret = b->callchain->max_depth - a->callchain->max_depth;
+		ret = field_cmp(b->callchain->max_depth, a->callchain->max_depth);
 		if (callchain_param.order == ORDER_CALLER)
 			ret = -ret;
 	}
@@ -299,6 +299,7 @@ static int hpp__width_fn(struct perf_hpp_fmt *fmt,
 			 struct hists *hists)
 {
 	int len = fmt->user_len ?: fmt->len;
+	int fmt_len = (int)strlen(fmt->name);
 	struct evsel *evsel = hists_to_evsel(hists);
 
 	if (symbol_conf.event_group) {
@@ -314,10 +315,7 @@ static int hpp__width_fn(struct perf_hpp_fmt *fmt,
 		len = max(len, nr * fmt->len);
 	}
 
-	if (len < (int)strlen(fmt->name))
-		len = strlen(fmt->name);
-
-	return len;
+	return len < fmt_len ? fmt_len : len;
 }
 
 static int hpp__header_fn(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
@@ -341,7 +339,7 @@ int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
 	ret = percent_color_len_snprintf(hpp->buf, hpp->size, fmt, len, percent);
 	va_end(args);
 
-	return (ret >= ssize) ? (ssize - 1) : ret;
+	return (ret >= ssize) ? (int)(ssize - 1) : ret;
 }
 
 static int hpp_entry_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
@@ -354,7 +352,7 @@ static int hpp_entry_scnprintf(struct perf_hpp *hpp, const char *fmt, ...)
 	ret = vsnprintf(hpp->buf, hpp->size, fmt, args);
 	va_end(args);
 
-	return (ret >= ssize) ? (ssize - 1) : ret;
+	return (ret >= ssize) ? (int)(ssize - 1) : ret;
 }
 
 #define __HPP_COLOR_PERCENT_FN(_type, _field, _fmttype)				\
@@ -945,7 +943,7 @@ void perf_hpp__set_user_width(const char *width_list_str)
 	perf_hpp_list__for_each_format(&perf_hpp_list, fmt) {
 		char *p;
 
-		int len = strtol(ptr, &p, 10);
+		int len = (int)strtol(ptr, &p, 10);
 		fmt->user_len = len;
 
 		if (*p == ',')
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 7ac4b98e28bc..6a981f95b4ec 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -450,7 +450,7 @@ int __hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp,
 		advance_hpp(hpp, ret);
 	}
 
-	return hpp->buf - start;
+	return (int)(hpp->buf - start);
 }
 
 static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp)
@@ -612,8 +612,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
 	ret = fprintf(fp, "%s\n", bf);
 
 	if (hist_entry__has_callchains(he) && !ignore_callchains)
-		callchain_ret = hist_entry_callchain__fprintf(he, total_period,
-							      0, fp);
+		callchain_ret = (int)hist_entry_callchain__fprintf(he, total_period, 0, fp);
 
 	ret += callchain_ret;
 
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 04/47] perf bench: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (2 preceding siblings ...)
  2025-04-30 17:49 ` [PATCH v2 03/47] perf ui: " Ian Rogers
@ 2025-04-30 17:49 ` Ian Rogers
  2025-04-30 20:23   ` Dirk Gouders
  2025-04-30 17:49 ` [PATCH v2 05/47] arm64: cputype: " Ian Rogers
                   ` (42 subsequent siblings)
  46 siblings, 1 reply; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/bench/breakpoint.c           |  8 +++++---
 tools/perf/bench/epoll-wait.c           |  3 ++-
 tools/perf/bench/evlist-open-close.c    |  8 ++++----
 tools/perf/bench/find-bit-bench.c       |  5 +++--
 tools/perf/bench/futex.h                |  4 ++--
 tools/perf/bench/inject-buildid.c       |  8 ++++----
 tools/perf/bench/mem-functions.c        |  2 +-
 tools/perf/bench/pmu-scan.c             | 12 ++++++------
 tools/perf/bench/sched-messaging.c      |  4 ++--
 tools/perf/bench/sched-pipe.c           | 15 +++++++++------
 tools/perf/bench/sched-seccomp-notify.c |  2 +-
 tools/perf/bench/synthesize.c           |  6 +++---
 tools/perf/builtin-bench.c              |  2 +-
 13 files changed, 43 insertions(+), 36 deletions(-)

diff --git a/tools/perf/bench/breakpoint.c b/tools/perf/bench/breakpoint.c
index dfd18f5db97d..72802b334eeb 100644
--- a/tools/perf/bench/breakpoint.c
+++ b/tools/perf/bench/breakpoint.c
@@ -57,7 +57,7 @@ static int breakpoint_setup(void *addr)
 	attr.bp_addr = (unsigned long)addr;
 	attr.bp_type = HW_BREAKPOINT_RW;
 	attr.bp_len = HW_BREAKPOINT_LEN_1;
-	fd = syscall(SYS_perf_event_open, &attr, 0, -1, -1, 0);
+	fd = (int)syscall(SYS_perf_event_open, &attr, 0, -1, -1, 0);
 
 	if (fd < 0)
 		fd = -errno;
@@ -111,7 +111,8 @@ static void *breakpoint_thread(void *arg)
 // then starts nparallel threads which create and join bench_repeat batches of nthreads threads.
 int bench_breakpoint_thread(int argc, const char **argv)
 {
-	unsigned int i, result_usec;
+	unsigned int i;
+	long result_usec;
 	int repeat = bench_repeat;
 	struct breakpoint *breakpoints;
 	pthread_t *parallel;
@@ -197,7 +198,8 @@ static const char * const enable_usage[] = {
 // and then disables and enables the breakpoint bench_repeat times.
 int bench_breakpoint_enable(int argc, const char **argv)
 {
-	unsigned int i, nthreads, result_usec, done = 0;
+	unsigned int i, nthreads, done = 0;
+	long result_usec;
 	char watched;
 	int fd;
 	pthread_t *threads;
diff --git a/tools/perf/bench/epoll-wait.c b/tools/perf/bench/epoll-wait.c
index 20fe4f72b4af..5ea3e0b2daf2 100644
--- a/tools/perf/bench/epoll-wait.c
+++ b/tools/perf/bench/epoll-wait.c
@@ -182,7 +182,8 @@ static void shuffle(void *array, size_t n, size_t size)
 
 static void *workerfn(void *arg)
 {
-	int fd, ret, r;
+	int fd, ret;
+	ssize_t r;
 	struct worker *w = (struct worker *) arg;
 	unsigned long ops = w->ops;
 	struct epoll_event ev;
diff --git a/tools/perf/bench/evlist-open-close.c b/tools/perf/bench/evlist-open-close.c
index 79cedcf94a39..6b75e2dc2fbf 100644
--- a/tools/perf/bench/evlist-open-close.c
+++ b/tools/perf/bench/evlist-open-close.c
@@ -173,16 +173,16 @@ static char *bench__repeat_event_string(const char *evstr, int n)
 {
 	char sbuf[STRERR_BUFSIZE];
 	struct strbuf buf;
-	int i, str_size = strlen(evstr),
-	    final_size = str_size * n + n,
-	    err = strbuf_init(&buf, final_size);
+	size_t str_size = strlen(evstr);
+	size_t final_size = str_size * n + n;
+	int err = strbuf_init(&buf, final_size);
 
 	if (err) {
 		pr_err("strbuf_init: %s\n", str_error_r(err, sbuf, sizeof(sbuf)));
 		goto out_error;
 	}
 
-	for (i = 0; i < n; i++) {
+	for (int i = 0; i < n; i++) {
 		err = strbuf_add(&buf, evstr, str_size);
 		if (err) {
 			pr_err("strbuf_add: %s\n", str_error_r(err, sbuf, sizeof(sbuf)));
diff --git a/tools/perf/bench/find-bit-bench.c b/tools/perf/bench/find-bit-bench.c
index 7e25b0e413f6..59b00e89f71b 100644
--- a/tools/perf/bench/find-bit-bench.c
+++ b/tools/perf/bench/find-bit-bench.c
@@ -31,7 +31,7 @@ static const char *const bench_usage[] = {
 static unsigned int accumulator;
 static unsigned int use_of_val;
 
-static noinline void workload(int val)
+static noinline void workload(unsigned long val)
 {
 	use_of_val += val;
 	accumulator++;
@@ -59,8 +59,9 @@ static int do_for_each_set_bit(unsigned int num_bits)
 	u64 runtime_us;
 	struct stats fb_time_stats, tb_time_stats;
 	double time_average, time_stddev;
-	unsigned int bit, i, j;
+	unsigned int i, j;
 	unsigned int set_bits, skip;
+	unsigned long bit;
 
 	init_stats(&fb_time_stats);
 	init_stats(&tb_time_stats);
diff --git a/tools/perf/bench/futex.h b/tools/perf/bench/futex.h
index ebdc2b032afc..6d9076e091eb 100644
--- a/tools/perf/bench/futex.h
+++ b/tools/perf/bench/futex.h
@@ -49,14 +49,14 @@ static inline int
 futex_syscall(volatile u_int32_t *uaddr, int op, u_int32_t val, struct timespec *timeout,
 	      volatile u_int32_t *uaddr2, int val3, int opflags)
 {
-	return syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3);
+	return (int)syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3);
 }
 
 static inline int
 futex_syscall_nr_requeue(volatile u_int32_t *uaddr, int op, u_int32_t val, int nr_requeue,
 			 volatile u_int32_t *uaddr2, int val3, int opflags)
 {
-	return syscall(SYS_futex, uaddr, op | opflags, val, nr_requeue, uaddr2, val3);
+	return (int)syscall(SYS_futex, uaddr, op | opflags, val, nr_requeue, uaddr2, val3);
 }
 
 /**
diff --git a/tools/perf/bench/inject-buildid.c b/tools/perf/bench/inject-buildid.c
index f55c07e4be94..b78de817e721 100644
--- a/tools/perf/bench/inject-buildid.c
+++ b/tools/perf/bench/inject-buildid.c
@@ -175,7 +175,7 @@ static ssize_t synthesize_mmap(struct bench_data *data, struct bench_dso *dso, u
 	union perf_event event;
 	size_t len = offsetof(struct perf_record_mmap2, filename);
 	u64 *id_hdr_ptr = (void *)&event;
-	int ts_idx;
+	size_t ts_idx;
 
 	len += roundup(strlen(dso->name) + 1, 8) + bench_id_hdr_size;
 
@@ -250,14 +250,14 @@ static void *data_reader(void *arg)
 	struct bench_data *data = arg;
 	char buf[8192];
 	int flag;
-	int n;
 
 	flag = fcntl(data->output_pipe[0], F_GETFL);
 	fcntl(data->output_pipe[0], F_SETFL, flag | O_NONBLOCK);
 
 	/* read out data from child */
 	while (true) {
-		n = read(data->output_pipe[0], buf, sizeof(buf));
+		ssize_t n = read(data->output_pipe[0], buf, sizeof(buf));
+
 		if (n > 0)
 			continue;
 		if (n == 0)
@@ -451,7 +451,7 @@ static void do_inject_loop(struct bench_data *data, bool build_id_all)
 static int do_inject_loops(struct bench_data *data)
 {
 
-	srand(time(NULL));
+	srand((int)time(NULL));
 	symbol__init(NULL);
 
 	bench_sample_type  = PERF_SAMPLE_IDENTIFIER | PERF_SAMPLE_IP;
diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c
index 19d45c377ac1..672b76eb8f99 100644
--- a/tools/perf/bench/mem-functions.c
+++ b/tools/perf/bench/mem-functions.c
@@ -82,7 +82,7 @@ static int init_cycles(void)
 
 static u64 get_cycles(void)
 {
-	int ret;
+	ssize_t ret;
 	u64 clk;
 
 	ret = read(cycles_fd, &clk, sizeof(u64));
diff --git a/tools/perf/bench/pmu-scan.c b/tools/perf/bench/pmu-scan.c
index 9e4d36486f62..4a885d4bd279 100644
--- a/tools/perf/bench/pmu-scan.c
+++ b/tools/perf/bench/pmu-scan.c
@@ -19,8 +19,8 @@ static unsigned int iterations = 100;
 
 struct pmu_scan_result {
 	char *name;
-	int nr_aliases;
-	int nr_formats;
+	size_t nr_aliases;
+	size_t nr_formats;
 	int nr_caps;
 	bool is_core;
 };
@@ -63,7 +63,7 @@ static int save_result(void)
 		list_for_each(list, &pmu->format)
 			r->nr_formats++;
 
-		pr_debug("pmu[%d] name=%s, nr_caps=%d, nr_aliases=%d, nr_formats=%d\n",
+		pr_debug("pmu[%d] name=%s, nr_caps=%d, nr_aliases=%zu, nr_formats=%zu\n",
 			nr_pmus, r->name, r->nr_caps, r->nr_aliases, r->nr_formats);
 		nr_pmus++;
 	}
@@ -77,7 +77,7 @@ static int check_result(bool core_only)
 	struct pmu_scan_result *r;
 	struct perf_pmu *pmu;
 	struct list_head *list;
-	int nr;
+	size_t nr;
 
 	for (int i = 0; i < nr_pmus; i++) {
 		r = &results[i];
@@ -98,7 +98,7 @@ static int check_result(bool core_only)
 
 		nr = perf_pmu__num_events(pmu);
 		if (nr != r->nr_aliases) {
-			pr_err("Unmatched number of event aliases in %s: expect %d vs got %d\n",
+			pr_err("Unmatched number of event aliases in %s: expect %zu vs got %zu\n",
 				pmu->name, r->nr_aliases, nr);
 			return -1;
 		}
@@ -107,7 +107,7 @@ static int check_result(bool core_only)
 		list_for_each(list, &pmu->format)
 			nr++;
 		if (nr != r->nr_formats) {
-			pr_err("Unmatched number of event formats in %s: expect %d vs got %d\n",
+			pr_err("Unmatched number of event formats in %s: expect %zu vs got %zu\n",
 				pmu->name, r->nr_formats, nr);
 			return -1;
 		}
diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c
index 93dcd9dba3d0..a2eb47944f44 100644
--- a/tools/perf/bench/sched-messaging.c
+++ b/tools/perf/bench/sched-messaging.c
@@ -102,7 +102,7 @@ static void *sender(struct sender_context *ctx)
 	/* Now pump to every receiver. */
 	for (i = 0; i < nr_loops; i++) {
 		for (j = 0; j < ctx->num_fds; j++) {
-			int ret, done = 0;
+			ssize_t ret, done = 0;
 
 again:
 			ret = write(ctx->out_fds[j], data + done,
@@ -133,7 +133,7 @@ static void *receiver(struct receiver_context* ctx)
 	/* Receive them all */
 	for (i = 0; i < ctx->num_packets; i++) {
 		char data[DATASIZE];
-		int ret, done = 0;
+		ssize_t ret, done = 0;
 
 again:
 		ret = read(ctx->in_fds[0], data + done, DATASIZE - done);
diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
index 70139036d68f..b847213fd616 100644
--- a/tools/perf/bench/sched-pipe.c
+++ b/tools/perf/bench/sched-pipe.c
@@ -102,7 +102,8 @@ static const char * const bench_sched_pipe_usage[] = {
 static int enter_cgroup(int nr)
 {
 	char buf[32];
-	int fd, len, ret;
+	int fd;
+	ssize_t ret, len;
 	int saved_errno;
 	struct cgroup *cgrp;
 	pid_t pid;
@@ -118,7 +119,7 @@ static int enter_cgroup(int nr)
 	cgrp = cgrps[nr];
 
 	if (threaded)
-		pid = syscall(__NR_gettid);
+		pid = (pid_t)syscall(__NR_gettid);
 	else
 		pid = getpid();
 
@@ -172,23 +173,25 @@ static void exit_cgroup(int nr)
 
 static inline int read_pipe(struct thread_data *td)
 {
-	int ret, m;
+	ssize_t ret;
+	int m;
 retry:
 	if (nonblocking) {
 		ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);
 		if (ret < 0)
-			return ret;
+			return (int)ret;
 	}
 	ret = read(td->pipe_read, &m, sizeof(int));
 	if (nonblocking && ret < 0 && errno == EWOULDBLOCK)
 		goto retry;
-	return ret;
+	return (int)ret;
 }
 
 static void *worker_thread(void *__tdata)
 {
 	struct thread_data *td = __tdata;
-	int i, ret, m = 0;
+	int i, m = 0;
+	ssize_t ret;
 
 	ret = enter_cgroup(td->nr);
 	if (ret < 0) {
diff --git a/tools/perf/bench/sched-seccomp-notify.c b/tools/perf/bench/sched-seccomp-notify.c
index 269c1f4a6852..4f0c68b366e3 100644
--- a/tools/perf/bench/sched-seccomp-notify.c
+++ b/tools/perf/bench/sched-seccomp-notify.c
@@ -43,7 +43,7 @@ static const char * const bench_seccomp_usage[] = {
 
 static int seccomp(unsigned int op, unsigned int flags, void *args)
 {
-	return syscall(__NR_seccomp, op, flags, args);
+	return (int)syscall(__NR_seccomp, op, flags, args);
 }
 
 static int user_notif_syscall(int nr, unsigned int flags)
diff --git a/tools/perf/bench/synthesize.c b/tools/perf/bench/synthesize.c
index 9b333276cbdb..484ba825fcf4 100644
--- a/tools/perf/bench/synthesize.c
+++ b/tools/perf/bench/synthesize.c
@@ -120,7 +120,7 @@ static int run_single_threaded(void)
 	session = perf_session__new(NULL, NULL);
 	if (IS_ERR(session)) {
 		pr_err("Session creation failed.\n");
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 	}
 	threads = thread_map__new_by_pid(getpid());
 	if (!threads) {
@@ -163,7 +163,7 @@ static int do_run_multi_threaded(struct target *target,
 	for (i = 0; i < multi_iterations; i++) {
 		session = perf_session__new(NULL, NULL);
 		if (IS_ERR(session))
-			return PTR_ERR(session);
+			return (int)PTR_ERR(session);
 
 		atomic_set(&event_count, 0);
 		gettimeofday(&start, NULL);
@@ -210,7 +210,7 @@ static int run_multi_threaded(void)
 	int err;
 
 	if (max_threads == UINT_MAX)
-		max_threads = sysconf(_SC_NPROCESSORS_ONLN);
+		max_threads = (int)sysconf(_SC_NPROCESSORS_ONLN);
 
 	puts(
 "Computing performance of multi threaded perf event synthesis by\n"
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index 2c1a9f3d847a..2f6a34908273 100644
--- a/tools/perf/builtin-bench.c
+++ b/tools/perf/builtin-bench.c
@@ -212,7 +212,7 @@ static int bench_str2int(const char *str)
 static int run_bench(const char *coll_name, const char *bench_name, bench_fn_t fn,
 		     int argc, const char **argv)
 {
-	int size;
+	size_t size;
 	char *name;
 	int ret;
 
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 05/47] arm64: cputype: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (3 preceding siblings ...)
  2025-04-30 17:49 ` [PATCH v2 04/47] perf bench: " Ian Rogers
@ 2025-04-30 17:49 ` Ian Rogers
  2025-05-09 12:56   ` Mark Rutland
  2025-04-30 17:49 ` [PATCH v2 06/47] x86/insn: " Ian Rogers
                   ` (41 subsequent siblings)
  46 siblings, 1 reply; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/arch/arm64/include/asm/cputype.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/arch/arm64/include/asm/cputype.h b/tools/arch/arm64/include/asm/cputype.h
index 488f8e751349..d7289b9d2758 100644
--- a/tools/arch/arm64/include/asm/cputype.h
+++ b/tools/arch/arm64/include/asm/cputype.h
@@ -227,7 +227,7 @@
 
 #include <asm/sysreg.h>
 
-#define read_cpuid(reg)			read_sysreg_s(SYS_ ## reg)
+#define read_cpuid(reg)			((u32)read_sysreg_s(SYS_ ## reg))
 
 /*
  * Represent a range of MIDR values for a given CPU model and a
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 06/47] x86/insn: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (4 preceding siblings ...)
  2025-04-30 17:49 ` [PATCH v2 05/47] arm64: cputype: " Ian Rogers
@ 2025-04-30 17:49 ` Ian Rogers
  2025-04-30 17:49 ` [PATCH v2 07/47] tools lib: " Ian Rogers
                   ` (40 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/arch/x86/lib/insn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/arch/x86/lib/insn.c b/tools/arch/x86/lib/insn.c
index e91d4c4e1c16..5fa8697498fe 100644
--- a/tools/arch/x86/lib/insn.c
+++ b/tools/arch/x86/lib/insn.c
@@ -92,7 +92,7 @@ static int __insn_get_emulate_prefix(struct insn *insn,
 			goto err_out;
 	}
 
-	insn->emulate_prefix_size = len;
+	insn->emulate_prefix_size = (int)len;
 	insn->next_byte += len;
 
 	return 1;
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 07/47] tools lib: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (5 preceding siblings ...)
  2025-04-30 17:49 ` [PATCH v2 06/47] x86/insn: " Ian Rogers
@ 2025-04-30 17:49 ` Ian Rogers
  2025-04-30 17:49 ` [PATCH v2 08/47] libperf: " Ian Rogers
                   ` (39 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/lib/api/fs/fs.c | 4 ++--
 tools/lib/bitmap.c    | 2 +-
 tools/lib/string.c    | 6 +++---
 tools/lib/vsprintf.c  | 6 +++---
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c
index edec23406dbc..2c4677901de9 100644
--- a/tools/lib/api/fs/fs.c
+++ b/tools/lib/api/fs/fs.c
@@ -349,7 +349,7 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep)
 {
 	struct io io;
 	char bf[128];
-	int err;
+	ssize_t err;
 
 	io.fd = open(filename, O_RDONLY);
 	if (io.fd < 0)
@@ -363,7 +363,7 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep)
 	} else
 		err = 0;
 	close(io.fd);
-	return err;
+	return (int)err;
 }
 
 int filename__write_int(const char *filename, int value)
diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c
index 51255c69754d..7491bf174e92 100644
--- a/tools/lib/bitmap.c
+++ b/tools/lib/bitmap.c
@@ -32,7 +32,7 @@ size_t bitmap_scnprintf(unsigned long *bitmap, unsigned int nbits,
 			char *buf, size_t size)
 {
 	/* current bit is 'cur', most recently seen range is [rbot, rtop] */
-	unsigned int cur, rbot, rtop;
+	size_t cur, rbot, rtop;
 	bool first = true;
 	size_t ret = 0;
 
diff --git a/tools/lib/string.c b/tools/lib/string.c
index 3126d2cff716..638e75b63538 100644
--- a/tools/lib/string.c
+++ b/tools/lib/string.c
@@ -182,7 +182,7 @@ char *strreplace(char *s, char old, char new)
 	return s;
 }
 
-static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
+static void *check_bytes8(const u8 *start, u8 value, size_t bytes)
 {
 	while (bytes) {
 		if (*start != value)
@@ -206,7 +206,7 @@ void *memchr_inv(const void *start, int c, size_t bytes)
 {
 	u8 value = c;
 	u64 value64;
-	unsigned int words, prefix;
+	size_t words, prefix;
 
 	if (bytes <= 16)
 		return check_bytes8(start, value, bytes);
@@ -216,7 +216,7 @@ void *memchr_inv(const void *start, int c, size_t bytes)
 	value64 |= value64 << 16;
 	value64 |= value64 << 32;
 
-	prefix = (unsigned long)start % 8;
+	prefix = (size_t)start % 8;
 	if (prefix) {
 		u8 *r;
 
diff --git a/tools/lib/vsprintf.c b/tools/lib/vsprintf.c
index 8780b4cdab21..62028a5eea7e 100644
--- a/tools/lib/vsprintf.c
+++ b/tools/lib/vsprintf.c
@@ -8,7 +8,7 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
        int i = vsnprintf(buf, size, fmt, args);
        ssize_t ssize = size;
 
-       return (i >= ssize) ? (ssize - 1) : i;
+       return (i >= ssize) ? (int)(ssize - 1) : i;
 }
 
 int scnprintf(char * buf, size_t size, const char * fmt, ...)
@@ -21,7 +21,7 @@ int scnprintf(char * buf, size_t size, const char * fmt, ...)
        i = vsnprintf(buf, size, fmt, args);
        va_end(args);
 
-       return (i >= ssize) ? (ssize - 1) : i;
+       return (i >= ssize) ? (int)(ssize - 1) : i;
 }
 
 int scnprintf_pad(char * buf, size_t size, const char * fmt, ...)
@@ -40,5 +40,5 @@ int scnprintf_pad(char * buf, size_t size, const char * fmt, ...)
 		buf[i] = 0x0;
 	}
 
-	return (i >= ssize) ? (ssize - 1) : i;
+	return (i >= ssize) ? (int)(ssize - 1) : i;
 }
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 08/47] libperf: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (6 preceding siblings ...)
  2025-04-30 17:49 ` [PATCH v2 07/47] tools lib: " Ian Rogers
@ 2025-04-30 17:49 ` Ian Rogers
  2025-04-30 17:49 ` [PATCH v2 09/47] tools subcmd: " Ian Rogers
                   ` (38 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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.

Note: this change avoids truncating size_t values to int by changing
the type to size_t, but this causes sign comparison warnings requiring
the -Wno-sign-compare EXTRA_CFLAGS option. This gets resolved by the
end of the series.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/lib/perf/cpumap.c                     | 18 +++++-----
 tools/lib/perf/evsel.c                      | 40 +++++++++------------
 tools/lib/perf/include/internal/cpumap.h    |  2 +-
 tools/lib/perf/include/internal/evsel.h     |  2 +-
 tools/lib/perf/include/internal/lib.h       |  2 +-
 tools/lib/perf/include/internal/mmap.h      |  4 +--
 tools/lib/perf/include/internal/threadmap.h |  2 +-
 tools/lib/perf/include/internal/xyarray.h   |  8 ++---
 tools/lib/perf/include/perf/cpumap.h        |  3 +-
 tools/lib/perf/lib.c                        |  2 +-
 tools/lib/perf/mmap.c                       | 13 ++++---
 tools/lib/perf/threadmap.c                  |  4 +--
 tools/lib/perf/xyarray.c                    |  2 +-
 13 files changed, 46 insertions(+), 56 deletions(-)

diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c
index 4454a5987570..37d94911449b 100644
--- a/tools/lib/perf/cpumap.c
+++ b/tools/lib/perf/cpumap.c
@@ -20,7 +20,7 @@ void perf_cpu_map__set_nr(struct perf_cpu_map *map, int nr_cpus)
 	RC_CHK_ACCESS(map)->nr = nr_cpus;
 }
 
-struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus)
+struct perf_cpu_map *perf_cpu_map__alloc(size_t nr_cpus)
 {
 	RC_STRUCT(perf_cpu_map) *cpus;
 	struct perf_cpu_map *result;
@@ -30,7 +30,7 @@ struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus)
 
 	cpus = malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus);
 	if (ADD_RC_CHK(result, cpus)) {
-		cpus->nr = nr_cpus;
+		cpus->nr = (int)nr_cpus;
 		refcount_set(&cpus->refcnt, 1);
 	}
 	return result;
@@ -78,7 +78,7 @@ void perf_cpu_map__put(struct perf_cpu_map *map)
 static struct perf_cpu_map *cpu_map__new_sysconf(void)
 {
 	struct perf_cpu_map *cpus;
-	int nr_cpus, nr_cpus_conf;
+	size_t nr_cpus, nr_cpus_conf;
 
 	nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 	if (nr_cpus < 0)
@@ -86,15 +86,13 @@ static struct perf_cpu_map *cpu_map__new_sysconf(void)
 
 	nr_cpus_conf = sysconf(_SC_NPROCESSORS_CONF);
 	if (nr_cpus != nr_cpus_conf) {
-		pr_warning("Number of online CPUs (%d) differs from the number configured (%d) the CPU map will only cover the first %d CPUs.",
+		pr_warning("Number of online CPUs (%zu) differs from the number configured (%zu) the CPU map will only cover the first %zu CPUs.",
 			nr_cpus, nr_cpus_conf, nr_cpus);
 	}
 
 	cpus = perf_cpu_map__alloc(nr_cpus);
 	if (cpus != NULL) {
-		int i;
-
-		for (i = 0; i < nr_cpus; ++i)
+		for (size_t i = 0; i < nr_cpus; ++i)
 			RC_CHK_ACCESS(cpus)->map[i].cpu = i;
 	}
 
@@ -132,7 +130,7 @@ static int cmp_cpu(const void *a, const void *b)
 	return cpu_a->cpu - cpu_b->cpu;
 }
 
-static struct perf_cpu __perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx)
+static struct perf_cpu __perf_cpu_map__cpu(const struct perf_cpu_map *cpus, size_t idx)
 {
 	return RC_CHK_ACCESS(cpus)->map[idx];
 }
@@ -247,13 +245,13 @@ static int __perf_cpu_map__nr(const struct perf_cpu_map *cpus)
 	return RC_CHK_ACCESS(cpus)->nr;
 }
 
-struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx)
+struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *cpus, size_t idx)
 {
 	struct perf_cpu result = {
 		.cpu = -1
 	};
 
-	if (cpus && idx < __perf_cpu_map__nr(cpus))
+	if (cpus && idx < (size_t)__perf_cpu_map__nr(cpus))
 		return __perf_cpu_map__cpu(cpus, idx);
 
 	return result;
diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
index c475319e2e41..d647ca25a6db 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -71,7 +71,7 @@ int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
 	return evsel->fd != NULL ? 0 : -ENOMEM;
 }
 
-static int perf_evsel__alloc_mmap(struct perf_evsel *evsel, int ncpus, int nthreads)
+static int perf_evsel__alloc_mmap(struct perf_evsel *evsel, size_t ncpus, size_t nthreads)
 {
 	evsel->mmap = xyarray__new(ncpus, nthreads, sizeof(struct perf_mmap));
 
@@ -83,7 +83,7 @@ sys_perf_event_open(struct perf_event_attr *attr,
 		    pid_t pid, struct perf_cpu cpu, int group_fd,
 		    unsigned long flags)
 {
-	return syscall(__NR_perf_event_open, attr, pid, cpu.cpu, group_fd, flags);
+	return (int)syscall(__NR_perf_event_open, attr, pid, cpu.cpu, group_fd, flags);
 }
 
 static int get_group_fd(struct perf_evsel *evsel, int cpu_map_idx, int thread, int *group_fd)
@@ -179,11 +179,9 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
 	return err;
 }
 
-static void perf_evsel__close_fd_cpu(struct perf_evsel *evsel, int cpu_map_idx)
+static void perf_evsel__close_fd_cpu(struct perf_evsel *evsel, size_t cpu_map_idx)
 {
-	int thread;
-
-	for (thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) {
+	for (size_t thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) {
 		int *fd = FD(evsel, cpu_map_idx, thread);
 
 		if (fd && *fd >= 0) {
@@ -195,7 +193,7 @@ static void perf_evsel__close_fd_cpu(struct perf_evsel *evsel, int cpu_map_idx)
 
 void perf_evsel__close_fd(struct perf_evsel *evsel)
 {
-	for (int idx = 0; idx < xyarray__max_x(evsel->fd); idx++)
+	for (size_t idx = 0; idx < xyarray__max_x(evsel->fd); idx++)
 		perf_evsel__close_fd_cpu(evsel, idx);
 }
 
@@ -224,13 +222,11 @@ void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu_map_idx)
 
 void perf_evsel__munmap(struct perf_evsel *evsel)
 {
-	int idx, thread;
-
 	if (evsel->fd == NULL || evsel->mmap == NULL)
 		return;
 
-	for (idx = 0; idx < xyarray__max_x(evsel->fd); idx++) {
-		for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) {
+	for (size_t idx = 0; idx < xyarray__max_x(evsel->fd); idx++) {
+		for (size_t thread = 0; thread < xyarray__max_y(evsel->fd); thread++) {
 			int *fd = FD(evsel, idx, thread);
 
 			if (fd == NULL || *fd < 0)
@@ -246,7 +242,7 @@ void perf_evsel__munmap(struct perf_evsel *evsel)
 
 int perf_evsel__mmap(struct perf_evsel *evsel, int pages)
 {
-	int ret, idx, thread;
+	int ret;
 	struct perf_mmap_param mp = {
 		.prot = PROT_READ | PROT_WRITE,
 		.mask = (pages * page_size) - 1,
@@ -258,8 +254,8 @@ int perf_evsel__mmap(struct perf_evsel *evsel, int pages)
 	if (perf_evsel__alloc_mmap(evsel, xyarray__max_x(evsel->fd), xyarray__max_y(evsel->fd)) < 0)
 		return -ENOMEM;
 
-	for (idx = 0; idx < xyarray__max_x(evsel->fd); idx++) {
-		for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) {
+	for (size_t idx = 0; idx < xyarray__max_x(evsel->fd); idx++) {
+		for (size_t thread = 0; thread < xyarray__max_y(evsel->fd); thread++) {
 			int *fd = FD(evsel, idx, thread);
 			struct perf_mmap *map;
 			struct perf_cpu cpu = perf_cpu_map__cpu(evsel->cpus, idx);
@@ -415,7 +411,7 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu_map_idx, int thread,
 }
 
 static int perf_evsel__ioctl(struct perf_evsel *evsel, int ioc, void *arg,
-			     int cpu_map_idx, int thread)
+			     size_t cpu_map_idx, size_t thread)
 {
 	int *fd = FD(evsel, cpu_map_idx, thread);
 
@@ -427,11 +423,9 @@ static int perf_evsel__ioctl(struct perf_evsel *evsel, int ioc, void *arg,
 
 static int perf_evsel__run_ioctl(struct perf_evsel *evsel,
 				 int ioc,  void *arg,
-				 int cpu_map_idx)
+				 size_t cpu_map_idx)
 {
-	int thread;
-
-	for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) {
+	for (size_t thread = 0; thread < xyarray__max_y(evsel->fd); thread++) {
 		int err = perf_evsel__ioctl(evsel, ioc, arg, cpu_map_idx, thread);
 
 		if (err)
@@ -463,10 +457,9 @@ int perf_evsel__enable_thread(struct perf_evsel *evsel, int thread)
 
 int perf_evsel__enable(struct perf_evsel *evsel)
 {
-	int i;
 	int err = 0;
 
-	for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
+	for (size_t i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
 		err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, i);
 	return err;
 }
@@ -478,10 +471,9 @@ int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx)
 
 int perf_evsel__disable(struct perf_evsel *evsel)
 {
-	int i;
 	int err = 0;
 
-	for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
+	for (size_t i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
 		err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, i);
 	return err;
 }
@@ -512,7 +504,7 @@ struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel)
 	return &evsel->attr;
 }
 
-int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads)
+int perf_evsel__alloc_id(struct perf_evsel *evsel, size_t ncpus, size_t nthreads)
 {
 	if (ncpus == 0 || nthreads == 0)
 		return 0;
diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/include/internal/cpumap.h
index e2be2d17c32b..624c8163cc84 100644
--- a/tools/lib/perf/include/internal/cpumap.h
+++ b/tools/lib/perf/include/internal/cpumap.h
@@ -21,7 +21,7 @@ DECLARE_RC_STRUCT(perf_cpu_map) {
 	struct perf_cpu	map[];
 };
 
-struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus);
+struct perf_cpu_map *perf_cpu_map__alloc(size_t nr_cpus);
 int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu);
 bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct perf_cpu_map *b);
 
diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/include/internal/evsel.h
index ea78defa77d0..ed04a5d4b032 100644
--- a/tools/lib/perf/include/internal/evsel.h
+++ b/tools/lib/perf/include/internal/evsel.h
@@ -139,7 +139,7 @@ void perf_evsel__free_fd(struct perf_evsel *evsel);
 int perf_evsel__read_size(struct perf_evsel *evsel);
 int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter);
 
-int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
+int perf_evsel__alloc_id(struct perf_evsel *evsel, size_t ncpus, size_t nthreads);
 void perf_evsel__free_id(struct perf_evsel *evsel);
 
 bool perf_evsel__attr_has_per_thread_sample_period(struct perf_evsel *evsel);
diff --git a/tools/lib/perf/include/internal/lib.h b/tools/lib/perf/include/internal/lib.h
index 85471a4b900f..60253b81699f 100644
--- a/tools/lib/perf/include/internal/lib.h
+++ b/tools/lib/perf/include/internal/lib.h
@@ -4,7 +4,7 @@
 
 #include <sys/types.h>
 
-extern unsigned int page_size;
+extern size_t page_size;
 
 ssize_t readn(int fd, void *buf, size_t n);
 ssize_t writen(int fd, const void *buf, size_t n);
diff --git a/tools/lib/perf/include/internal/mmap.h b/tools/lib/perf/include/internal/mmap.h
index 5f08cab61ece..4780691c65f3 100644
--- a/tools/lib/perf/include/internal/mmap.h
+++ b/tools/lib/perf/include/internal/mmap.h
@@ -23,7 +23,7 @@ typedef void (*libperf_unmap_cb_t)(struct perf_mmap *map);
  */
 struct perf_mmap {
 	void			*base;
-	int			 mask;
+	size_t			 mask;
 	int			 fd;
 	struct perf_cpu		 cpu;
 	refcount_t		 refcnt;
@@ -40,7 +40,7 @@ struct perf_mmap {
 
 struct perf_mmap_param {
 	int	prot;
-	int	mask;
+	size_t	mask;
 };
 
 size_t perf_mmap__mmap_len(struct perf_mmap *map);
diff --git a/tools/lib/perf/include/internal/threadmap.h b/tools/lib/perf/include/internal/threadmap.h
index df748baf9eda..c223432be7a5 100644
--- a/tools/lib/perf/include/internal/threadmap.h
+++ b/tools/lib/perf/include/internal/threadmap.h
@@ -18,6 +18,6 @@ struct perf_thread_map {
 	struct thread_map_data map[];
 };
 
-struct perf_thread_map *perf_thread_map__realloc(struct perf_thread_map *map, int nr);
+struct perf_thread_map *perf_thread_map__realloc(struct perf_thread_map *map, size_t nr);
 
 #endif /* __LIBPERF_INTERNAL_THREADMAP_H */
diff --git a/tools/lib/perf/include/internal/xyarray.h b/tools/lib/perf/include/internal/xyarray.h
index f10af3da7b21..f8f6e1facf91 100644
--- a/tools/lib/perf/include/internal/xyarray.h
+++ b/tools/lib/perf/include/internal/xyarray.h
@@ -14,11 +14,11 @@ struct xyarray {
 	char contents[] __aligned(8);
 };
 
-struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size);
+struct xyarray *xyarray__new(size_t xlen, size_t ylen, size_t entry_size);
 void xyarray__delete(struct xyarray *xy);
 void xyarray__reset(struct xyarray *xy);
 
-static inline void *__xyarray__entry(struct xyarray *xy, int x, int y)
+static inline void *__xyarray__entry(struct xyarray *xy, size_t x, size_t y)
 {
 	return &xy->contents[x * xy->row_size + y * xy->entry_size];
 }
@@ -30,12 +30,12 @@ static inline void *xyarray__entry(struct xyarray *xy, size_t x, size_t y)
 	return __xyarray__entry(xy, x, y);
 }
 
-static inline int xyarray__max_y(struct xyarray *xy)
+static inline size_t xyarray__max_y(struct xyarray *xy)
 {
 	return xy->max_y;
 }
 
-static inline int xyarray__max_x(struct xyarray *xy)
+static inline size_t xyarray__max_x(struct xyarray *xy)
 {
 	return xy->max_x;
 }
diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h
index 8c1ab0f9194e..51bf70f639ad 100644
--- a/tools/lib/perf/include/perf/cpumap.h
+++ b/tools/lib/perf/include/perf/cpumap.h
@@ -5,6 +5,7 @@
 #include <perf/core.h>
 #include <stdbool.h>
 #include <stdint.h>
+#include <stdlib.h>
 
 /** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
 struct perf_cpu {
@@ -47,7 +48,7 @@ LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map);
  * perf_cpu_map__cpu - get the CPU value at the given index. Returns -1 if index
  *                     is invalid.
  */
-LIBPERF_API struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx);
+LIBPERF_API struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *cpus, size_t idx);
 /**
  * perf_cpu_map__nr - for an empty map returns 1, as perf_cpu_map__cpu returns a
  *                    cpu of -1 for an invalid index, this makes an empty map
diff --git a/tools/lib/perf/lib.c b/tools/lib/perf/lib.c
index 696fb0ea67c6..b759f9caee7a 100644
--- a/tools/lib/perf/lib.c
+++ b/tools/lib/perf/lib.c
@@ -5,7 +5,7 @@
 #include <linux/kernel.h>
 #include <internal/lib.h>
 
-unsigned int page_size;
+size_t page_size;
 
 static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
 {
diff --git a/tools/lib/perf/mmap.c b/tools/lib/perf/mmap.c
index c1a51d925e0e..3af5150f6ccf 100644
--- a/tools/lib/perf/mmap.c
+++ b/tools/lib/perf/mmap.c
@@ -109,11 +109,11 @@ void perf_mmap__consume(struct perf_mmap *map)
 		perf_mmap__put(map);
 }
 
-static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
+static int overwrite_rb_find_range(void *buf, size_t mask, u64 *start, u64 *end)
 {
 	struct perf_event_header *pheader;
 	u64 evt_head = *start;
-	int size = mask + 1;
+	size_t size = mask + 1;
 
 	pr_debug2("%s: buf=%p, start=%"PRIx64"\n", __func__, buf, *start);
 	pheader = (struct perf_event_header *)(buf + (*start & mask));
@@ -157,7 +157,7 @@ static int __perf_mmap__read_init(struct perf_mmap *md)
 	if ((md->end - md->start) < md->flush)
 		return -EAGAIN;
 
-	size = md->end - md->start;
+	size = (unsigned long)(md->end - md->start);
 	if (size > (unsigned long)(md->mask) + 1) {
 		if (!md->overwrite) {
 			WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
@@ -212,7 +212,7 @@ static union perf_event *perf_mmap__read(struct perf_mmap *map,
 {
 	unsigned char *data = map->base + page_size;
 	union perf_event *event = NULL;
-	int diff = end - *startp;
+	s64 diff = end - *startp;
 
 	if (diff >= (int)sizeof(event->header)) {
 		size_t size;
@@ -228,8 +228,7 @@ static union perf_event *perf_mmap__read(struct perf_mmap *map,
 		 * be inside due to u64 alignment of output.
 		 */
 		if ((*startp & map->mask) + size != ((*startp + size) & map->mask)) {
-			unsigned int offset = *startp;
-			unsigned int len = size, cpy;
+			u64 offset = *startp, len = size, cpy;
 			void *dst = map->event_copy;
 
 			if (size > map->event_copy_sz) {
@@ -242,7 +241,7 @@ static union perf_event *perf_mmap__read(struct perf_mmap *map,
 
 			do {
 				cpy = min(map->mask + 1 - (offset & map->mask), len);
-				memcpy(dst, &data[offset & map->mask], cpy);
+				memcpy(dst, &data[offset & map->mask], (size_t)cpy);
 				offset += cpy;
 				dst += cpy;
 				len -= cpy;
diff --git a/tools/lib/perf/threadmap.c b/tools/lib/perf/threadmap.c
index 07968f3ea093..21c50737bbc2 100644
--- a/tools/lib/perf/threadmap.c
+++ b/tools/lib/perf/threadmap.c
@@ -7,7 +7,7 @@
 #include <asm/bug.h>
 #include <stdio.h>
 
-static void perf_thread_map__reset(struct perf_thread_map *map, int start, int nr)
+static void perf_thread_map__reset(struct perf_thread_map *map, size_t start, size_t nr)
 {
 	size_t size = (nr - start) * sizeof(map->map[0]);
 
@@ -15,7 +15,7 @@ static void perf_thread_map__reset(struct perf_thread_map *map, int start, int n
 	map->err_thread = -1;
 }
 
-struct perf_thread_map *perf_thread_map__realloc(struct perf_thread_map *map, int nr)
+struct perf_thread_map *perf_thread_map__realloc(struct perf_thread_map *map, size_t nr)
 {
 	size_t size = sizeof(*map) + sizeof(map->map[0]) * nr;
 	int start = map ? map->nr : 0;
diff --git a/tools/lib/perf/xyarray.c b/tools/lib/perf/xyarray.c
index dcd901d154bb..35b2088da9c4 100644
--- a/tools/lib/perf/xyarray.c
+++ b/tools/lib/perf/xyarray.c
@@ -4,7 +4,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
+struct xyarray *xyarray__new(size_t xlen, size_t ylen, size_t entry_size)
 {
 	size_t row_size = ylen * entry_size;
 	struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size);
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 09/47] tools subcmd: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (7 preceding siblings ...)
  2025-04-30 17:49 ` [PATCH v2 08/47] libperf: " Ian Rogers
@ 2025-04-30 17:49 ` Ian Rogers
  2025-04-30 17:49 ` [PATCH v2 10/47] perf arch x86: " Ian Rogers
                   ` (37 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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.

Move mput_char out of header file to its only use in help.c, while
changing its argument types.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/lib/subcmd/help.c          | 28 ++++++++++++++++------------
 tools/lib/subcmd/help.h          |  6 ------
 tools/lib/subcmd/parse-options.c | 16 ++++++++--------
 3 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/tools/lib/subcmd/help.c b/tools/lib/subcmd/help.c
index 8561b0f01a24..555b91ada0f9 100644
--- a/tools/lib/subcmd/help.c
+++ b/tools/lib/subcmd/help.c
@@ -125,13 +125,11 @@ static void get_term_dimensions(struct winsize *ws)
 	ws->ws_col = 80;
 }
 
-static void pretty_print_string_list(struct cmdnames *cmds, int longest)
+static void pretty_print_string_list(struct cmdnames *cmds, size_t longest)
 {
-	int cols = 1, rows;
-	int space = longest + 1; /* min 1 SP between words */
+	size_t cols = 1, rows, max_cols;
+	size_t space = longest + 1; /* min 1 SP between words */
 	struct winsize win;
-	int max_cols;
-	int i, j;
 
 	get_term_dimensions(&win);
 	max_cols = win.ws_col - 1; /* don't print *on* the edge */
@@ -140,12 +138,12 @@ static void pretty_print_string_list(struct cmdnames *cmds, int longest)
 		cols = max_cols / space;
 	rows = (cmds->cnt + cols - 1) / cols;
 
-	for (i = 0; i < rows; i++) {
+	for (size_t i = 0; i < rows; i++) {
 		printf("  ");
 
-		for (j = 0; j < cols; j++) {
-			unsigned int n = j * rows + i;
-			unsigned int size = space;
+		for (size_t j = 0; j < cols; j++) {
+			size_t n = j * rows + i;
+			int size = (int)space;
 
 			if (n >= cmds->cnt)
 				break;
@@ -180,7 +178,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 					 const char *path,
 					 const char *prefix)
 {
-	int prefix_len;
+	size_t prefix_len;
 	DIR *dir = opendir(path);
 	struct dirent *de;
 	char *buf = NULL;
@@ -194,7 +192,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
 	astrcatf(&buf, "%s/", path);
 
 	while ((de = readdir(dir)) != NULL) {
-		int entlen;
+		size_t entlen;
 
 		if (!strstarts(de->d_name, prefix))
 			continue;
@@ -250,10 +248,16 @@ void load_command_list(const char *prefix,
 	exclude_cmds(other_cmds, main_cmds);
 }
 
+static void mput_char(char c, size_t num)
+{
+	while (num--)
+		putchar(c);
+}
+
 void list_commands(const char *title, struct cmdnames *main_cmds,
 		   struct cmdnames *other_cmds)
 {
-	unsigned int i, longest = 0;
+	size_t i, longest = 0;
 
 	for (i = 0; i < main_cmds->cnt; i++)
 		if (longest < main_cmds->names[i]->len)
diff --git a/tools/lib/subcmd/help.h b/tools/lib/subcmd/help.h
index 355c066c8d49..258b3a143cbc 100644
--- a/tools/lib/subcmd/help.h
+++ b/tools/lib/subcmd/help.h
@@ -14,12 +14,6 @@ struct cmdnames {
 	} **names;
 };
 
-static inline void mput_char(char c, unsigned int num)
-{
-	while(num--)
-		putchar(c);
-}
-
 void load_command_list(const char *prefix,
 		struct cmdnames *main_cmds,
 		struct cmdnames *other_cmds);
diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
index 555d617c1f50..add46b81a131 100644
--- a/tools/lib/subcmd/parse-options.c
+++ b/tools/lib/subcmd/parse-options.c
@@ -201,7 +201,7 @@ static int get_value(struct parse_opt_ctx_t *p,
 		return 0;
 
 	case OPTION_SET_UINT:
-		*(unsigned int *)opt->value = unset ? 0 : opt->defval;
+		*(unsigned int *)opt->value = unset ? 0 : (unsigned int)opt->defval;
 		return 0;
 
 	case OPTION_SET_PTR:
@@ -256,12 +256,12 @@ static int get_value(struct parse_opt_ctx_t *p,
 			return 0;
 		}
 		if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
-			*(int *)opt->value = opt->defval;
+			*(int *)opt->value = (int)opt->defval;
 			return 0;
 		}
 		if (get_arg(p, opt, flags, &arg))
 			return -1;
-		*(int *)opt->value = strtol(arg, (char **)&s, 10);
+		*(int *)opt->value = (int)strtol(arg, (char **)&s, 10);
 		if (*s)
 			return opterror(opt, "expects a numerical value", flags);
 		return 0;
@@ -272,14 +272,14 @@ static int get_value(struct parse_opt_ctx_t *p,
 			return 0;
 		}
 		if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
-			*(unsigned int *)opt->value = opt->defval;
+			*(unsigned int *)opt->value = (unsigned int)opt->defval;
 			return 0;
 		}
 		if (get_arg(p, opt, flags, &arg))
 			return -1;
 		if (arg[0] == '-')
 			return opterror(opt, "expects an unsigned numerical value", flags);
-		*(unsigned int *)opt->value = strtol(arg, (char **)&s, 10);
+		*(unsigned int *)opt->value = (unsigned int)strtol(arg, (char **)&s, 10);
 		if (*s)
 			return opterror(opt, "expects a numerical value", flags);
 		return 0;
@@ -770,9 +770,9 @@ static void print_option_help(const struct option *opts, int full)
 		break;
 	}
 
-	if (pos <= USAGE_OPTS_WIDTH)
-		pad = USAGE_OPTS_WIDTH - pos;
-	else {
+	if (pos <= USAGE_OPTS_WIDTH) {
+		pad = (int)(USAGE_OPTS_WIDTH - pos);
+	} else {
 		fputc('\n', stderr);
 		pad = USAGE_OPTS_WIDTH;
 	}
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 10/47] perf arch x86: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (8 preceding siblings ...)
  2025-04-30 17:49 ` [PATCH v2 09/47] tools subcmd: " Ian Rogers
@ 2025-04-30 17:49 ` Ian Rogers
  2025-04-30 17:49 ` [PATCH v2 11/47] perf arm-spe: " Ian Rogers
                   ` (36 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/arch/x86/tests/bp-modify.c         |  2 +-
 tools/perf/arch/x86/util/intel-bts.c          |  4 +-
 tools/perf/arch/x86/util/intel-pt.c           | 10 ++---
 tools/perf/arch/x86/util/iostat.c             |  2 +-
 tools/perf/arch/x86/util/kvm-stat.c           |  6 +--
 tools/perf/arch/x86/util/perf_regs.c          |  3 +-
 tools/perf/arch/x86/util/topdown.c            |  2 +-
 tools/perf/util/intel-bts.c                   |  4 +-
 .../util/intel-pt-decoder/intel-pt-decoder.c  | 30 +++++++--------
 .../intel-pt-decoder/intel-pt-insn-decoder.c  |  2 +-
 .../perf/util/intel-pt-decoder/intel-pt-log.c |  2 +-
 .../intel-pt-decoder/intel-pt-pkt-decoder.c   |  2 +-
 tools/perf/util/intel-pt.c                    | 38 +++++++++----------
 13 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/tools/perf/arch/x86/tests/bp-modify.c b/tools/perf/arch/x86/tests/bp-modify.c
index 0924ccd9e36d..0bbc81fe9b1d 100644
--- a/tools/perf/arch/x86/tests/bp-modify.c
+++ b/tools/perf/arch/x86/tests/bp-modify.c
@@ -37,7 +37,7 @@ static int spawn_child(void)
 		 * waits in signal for parent to trace it,
 		 * then it calls bp_1 and quits.
 		 */
-		int err = ptrace(PTRACE_TRACEME, 0, NULL, NULL);
+		int err = (int)ptrace(PTRACE_TRACEME, 0, NULL, NULL);
 
 		if (err) {
 			pr_debug("failed to PTRACE_TRACEME\n");
diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index 85c8186300c8..1692ee735109 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -169,7 +169,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr,
 			size_t sz = opts->auxtrace_snapshot_size;
 
 			sz = round_up(sz, page_size) / page_size;
-			opts->auxtrace_mmap_pages = roundup_pow_of_two(sz);
+			opts->auxtrace_mmap_pages = (unsigned int)roundup_pow_of_two(sz);
 		}
 		if (opts->auxtrace_snapshot_size >
 				opts->auxtrace_mmap_pages * (size_t)page_size) {
@@ -347,7 +347,7 @@ static int intel_bts_snapshot_finish(struct auxtrace_record *itr)
 
 static bool intel_bts_first_wrap(u64 *data, size_t buf_size)
 {
-	int i, a, b;
+	size_t i, a, b;
 
 	b = buf_size >> 3;
 	a = b - 512;
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index 8f235d8b67b6..842dba02f082 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -418,7 +418,7 @@ static int intel_pt_track_switches(struct evlist *evlist)
 
 	evsel = evlist__add_sched_switch(evlist, true);
 	if (IS_ERR(evsel)) {
-		err = PTR_ERR(evsel);
+		err = (int)PTR_ERR(evsel);
 		pr_debug2("%s: failed to create %s, error = %d\n",
 			  __func__, sched_switch, err);
 		return err;
@@ -692,7 +692,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
 			size_t sz = opts->auxtrace_snapshot_size;
 
 			sz = round_up(sz, page_size) / page_size;
-			opts->auxtrace_mmap_pages = roundup_pow_of_two(sz);
+			opts->auxtrace_mmap_pages = (unsigned int)roundup_pow_of_two(sz);
 		}
 		if (opts->auxtrace_snapshot_size >
 				opts->auxtrace_mmap_pages * (size_t)page_size) {
@@ -726,7 +726,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
 		if (!opts->auxtrace_mmap_pages) {
 			size_t sz = round_up(max_sz, page_size) / page_size;
 
-			opts->auxtrace_mmap_pages = roundup_pow_of_two(sz);
+			opts->auxtrace_mmap_pages = (unsigned int)roundup_pow_of_two(sz);
 		}
 		if (max_sz > opts->auxtrace_mmap_pages * (size_t)page_size) {
 			pr_err("Sample size %zu must not be greater than AUX area tracing mmap size %zu\n",
@@ -772,7 +772,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
 
 	if (!opts->auxtrace_snapshot_mode && !opts->auxtrace_sample_mode) {
 		size_t aw = opts->auxtrace_mmap_pages * (size_t)page_size / 4;
-		u32 aux_watermark = aw > UINT_MAX ? UINT_MAX : aw;
+		u32 aux_watermark = aw > UINT_MAX ? UINT_MAX : (u32)aw;
 
 		intel_pt_evsel->core.attr.aux_watermark = aux_watermark;
 	}
@@ -1093,7 +1093,7 @@ static bool intel_pt_wrapped(struct intel_pt_recording *ptr, int idx,
 
 static bool intel_pt_first_wrap(u64 *data, size_t buf_size)
 {
-	int i, a, b;
+	size_t i, a, b;
 
 	b = buf_size >> 3;
 	a = b - 512;
diff --git a/tools/perf/arch/x86/util/iostat.c b/tools/perf/arch/x86/util/iostat.c
index 7442a2cd87ed..ed508698dc22 100644
--- a/tools/perf/arch/x86/util/iostat.c
+++ b/tools/perf/arch/x86/util/iostat.c
@@ -305,7 +305,7 @@ static int iostat_event_group(struct evlist *evl,
 	  uncore_iio_%x/event=0x83,umask=0x01,ch_mask=0xF,fc_mask=0x07/,\
 	  uncore_iio_%x/event=0xc0,umask=0x04,ch_mask=0xF,fc_mask=0x07/,\
 	  uncore_iio_%x/event=0xc0,umask=0x01,ch_mask=0xF,fc_mask=0x07/}";
-	const int len_template = strlen(iostat_cmd_template) + 1;
+	const size_t len_template = strlen(iostat_cmd_template) + 1;
 	struct evsel *evsel = NULL;
 	int metrics_count = iostat_metrics_count();
 	char *iostat_cmd = calloc(len_template, 1);
diff --git a/tools/perf/arch/x86/util/kvm-stat.c b/tools/perf/arch/x86/util/kvm-stat.c
index 424716518b75..6e97198b055a 100644
--- a/tools/perf/arch/x86/util/kvm-stat.c
+++ b/tools/perf/arch/x86/util/kvm-stat.c
@@ -31,7 +31,7 @@ static void mmio_event_get_key(struct evsel *evsel, struct perf_sample *sample,
 			       struct event_key *key)
 {
 	key->key  = evsel__intval(evsel, sample, "gpa");
-	key->info = evsel__intval(evsel, sample, "type");
+	key->info = (int)evsel__intval(evsel, sample, "type");
 }
 
 #define KVM_TRACE_MMIO_READ_UNSATISFIED 0
@@ -94,7 +94,7 @@ static void ioport_event_get_key(struct evsel *evsel,
 				 struct event_key *key)
 {
 	key->key  = evsel__intval(evsel, sample, "port");
-	key->info = evsel__intval(evsel, sample, "rw");
+	key->info = (int)evsel__intval(evsel, sample, "rw");
 }
 
 static bool ioport_event_begin(struct evsel *evsel,
@@ -138,7 +138,7 @@ static void msr_event_get_key(struct evsel *evsel,
 				 struct event_key *key)
 {
 	key->key  = evsel__intval(evsel, sample, "ecx");
-	key->info = evsel__intval(evsel, sample, "write");
+	key->info = (int)evsel__intval(evsel, sample, "write");
 }
 
 static bool msr_event_begin(struct evsel *evsel,
diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/perf_regs.c
index 12fd93f04802..ed0c564dad7e 100644
--- a/tools/perf/arch/x86/util/perf_regs.c
+++ b/tools/perf/arch/x86/util/perf_regs.c
@@ -195,7 +195,8 @@ static void sdt_rename_register(char *sdt_reg, int sdt_len, char *uprobe_reg)
 int arch_sdt_arg_parse_op(char *old_op, char **new_op)
 {
 	char new_reg[SDT_REG_NAME_SIZE] = {0};
-	int new_len = 0, ret;
+	int ret;
+	size_t new_len = 0;
 	/*
 	 * rm[0]:  +/-NUM(REG)
 	 * rm[1]:  +/-
diff --git a/tools/perf/arch/x86/util/topdown.c b/tools/perf/arch/x86/util/topdown.c
index d1c654839049..c93c35c46145 100644
--- a/tools/perf/arch/x86/util/topdown.c
+++ b/tools/perf/arch/x86/util/topdown.c
@@ -43,7 +43,7 @@ bool arch_is_topdown_slots(const struct evsel *evsel)
 
 bool arch_is_topdown_metrics(const struct evsel *evsel)
 {
-	int config = evsel->core.attr.config;
+	__u64 config = evsel->core.attr.config;
 	const char *name_from_config;
 	struct perf_pmu *pmu;
 
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index 3625c6224750..2598df776d4e 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -850,9 +850,9 @@ int intel_bts_process_auxtrace_info(union perf_event *event,
 	bts->session = session;
 	bts->machine = &session->machines.host; /* No kvm support */
 	bts->auxtrace_type = auxtrace_info->type;
-	bts->pmu_type = auxtrace_info->priv[INTEL_BTS_PMU_TYPE];
+	bts->pmu_type = (u32)auxtrace_info->priv[INTEL_BTS_PMU_TYPE];
 	bts->tc.time_shift = auxtrace_info->priv[INTEL_BTS_TIME_SHIFT];
-	bts->tc.time_mult = auxtrace_info->priv[INTEL_BTS_TIME_MULT];
+	bts->tc.time_mult = (u32)auxtrace_info->priv[INTEL_BTS_TIME_MULT];
 	bts->tc.time_zero = auxtrace_info->priv[INTEL_BTS_TIME_ZERO];
 	bts->cap_user_time_zero =
 			auxtrace_info->priv[INTEL_BTS_CAP_USER_TIME_ZERO];
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index e733f6b1f7ac..abb891f778cb 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -841,7 +841,7 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
 		if (!data->have_tma)
 			return 0;
 
-		mtc = pkt_info->packet.payload;
+		mtc = (uint32_t)pkt_info->packet.payload;
 		if (decoder->mtc_shift > 8 && data->fixup_last_mtc) {
 			data->fixup_last_mtc = false;
 			intel_pt_fixup_last_mtc(mtc, decoder->mtc_shift,
@@ -904,7 +904,7 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
 		if (!decoder->tsc_ctc_ratio_d)
 			return 0;
 
-		ctc = pkt_info->packet.payload;
+		ctc = (uint32_t)pkt_info->packet.payload;
 		fc = pkt_info->packet.count;
 		ctc_rem = ctc & decoder->ctc_rem_mask;
 
@@ -930,7 +930,7 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
 		return 0;
 
 	case INTEL_PT_CBR:
-		cbr = pkt_info->packet.payload;
+		cbr = (uint32_t)pkt_info->packet.payload;
 		if (data->cbr && data->cbr != cbr)
 			return 1;
 		data->cbr = cbr;
@@ -1268,7 +1268,7 @@ static void intel_pt_mode_exec_status(struct intel_pt_decoder *decoder)
 {
 	bool iflag = decoder->packet.count & INTEL_PT_IFLAG;
 
-	decoder->exec_mode = decoder->packet.payload;
+	decoder->exec_mode = (int)decoder->packet.payload;
 	decoder->iflag = iflag;
 	decoder->next_iflag = iflag;
 	decoder->state.from_iflag = iflag;
@@ -1279,7 +1279,7 @@ static void intel_pt_mode_exec(struct intel_pt_decoder *decoder)
 {
 	bool iflag = decoder->packet.count & INTEL_PT_IFLAG;
 
-	decoder->exec_mode = decoder->packet.payload;
+	decoder->exec_mode = (int)decoder->packet.payload;
 	decoder->next_iflag = iflag;
 }
 
@@ -1331,7 +1331,7 @@ static bool intel_pt_fup_event(struct intel_pt_decoder *decoder, bool no_tip)
 		if (!ip && decoder->pge)
 			decoder->state.type |= INTEL_PT_BRANCH;
 		decoder->state.cfe_type = decoder->fup_cfe_pkt.count;
-		decoder->state.cfe_vector = decoder->fup_cfe_pkt.payload;
+		decoder->state.cfe_vector = (int)decoder->fup_cfe_pkt.payload;
 		decoder->state.evd_cnt = decoder->evd_cnt;
 		decoder->state.evd = decoder->evd;
 		decoder->evd_cnt = 0;
@@ -1906,7 +1906,7 @@ static inline void intel_pt_mtc_cyc_cnt_upd(struct intel_pt_decoder *decoder)
 
 static void intel_pt_calc_tma(struct intel_pt_decoder *decoder)
 {
-	uint32_t ctc = decoder->packet.payload;
+	uint32_t ctc = (uint32_t)decoder->packet.payload;
 	uint32_t fc = decoder->packet.count;
 	uint32_t ctc_rem = ctc & decoder->ctc_rem_mask;
 
@@ -1943,7 +1943,7 @@ static void intel_pt_calc_mtc_timestamp(struct intel_pt_decoder *decoder)
 	if (!decoder->have_tma)
 		return;
 
-	mtc = decoder->packet.payload;
+	mtc = (uint32_t)decoder->packet.payload;
 
 	if (decoder->mtc_shift > 8 && decoder->fixup_last_mtc) {
 		decoder->fixup_last_mtc = false;
@@ -2044,7 +2044,7 @@ static void intel_pt_bbp(struct intel_pt_decoder *decoder)
 		memset(decoder->state.items.mask, 0, sizeof(decoder->state.items.mask));
 		decoder->state.items.is_32_bit = false;
 	}
-	decoder->blk_type = decoder->packet.payload;
+	decoder->blk_type = (enum intel_pt_blk_type)decoder->packet.payload;
 	decoder->blk_type_pos = intel_pt_blk_type_pos(decoder->blk_type);
 	if (decoder->blk_type == INTEL_PT_GP_REGS)
 		decoder->state.items.is_32_bit = decoder->packet.count;
@@ -2488,12 +2488,12 @@ static uint64_t intel_pt_calc_expected_tsc(struct intel_pt_decoder *decoder,
 static uint64_t intel_pt_expected_tsc(struct intel_pt_decoder *decoder,
 				      struct intel_pt_vm_tsc_info *data)
 {
-	uint32_t ctc = data->tma_packet.payload;
+	uint32_t ctc = (uint32_t)data->tma_packet.payload;
 	uint32_t fc = data->tma_packet.count;
 
 	return intel_pt_calc_expected_tsc(decoder, ctc, fc,
 					  decoder->ctc_timestamp,
-					  data->ctc_delta, data->last_ctc);
+					  data->ctc_delta, (uint32_t)data->last_ctc);
 }
 
 static void intel_pt_translate_vm_tsc(struct intel_pt_decoder *decoder,
@@ -2889,7 +2889,7 @@ static int intel_pt_vm_time_correlation(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_BBP:
-			decoder->blk_type = decoder->packet.payload;
+			decoder->blk_type = (enum intel_pt_blk_type)decoder->packet.payload;
 			break;
 
 		case INTEL_PT_BIP:
@@ -3825,7 +3825,7 @@ static int intel_pt_part_psb(struct intel_pt_decoder *decoder)
 		if (i > decoder->len)
 			continue;
 		if (!memcmp(end - i, INTEL_PT_PSB_STR, i))
-			return i;
+			return (int)i;
 	}
 	return 0;
 }
@@ -3839,7 +3839,7 @@ static int intel_pt_rest_psb(struct intel_pt_decoder *decoder, int part_psb)
 	    memcmp(decoder->buf, psb + part_psb, rest_psb))
 		return 0;
 
-	return rest_psb;
+	return (int)rest_psb;
 }
 
 static int intel_pt_get_split_psb(struct intel_pt_decoder *decoder,
@@ -3898,7 +3898,7 @@ static int intel_pt_scan_for_psb(struct intel_pt_decoder *decoder)
 			continue;
 		}
 
-		decoder->pkt_step = next - decoder->buf;
+		decoder->pkt_step = (int)(next - decoder->buf);
 		return intel_pt_get_next_packet(decoder);
 	}
 }
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
index 8fabddc1c0da..03e34afb69a3 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
@@ -193,7 +193,7 @@ int intel_pt_get_insn(const unsigned char *buf, size_t len, int x86_64,
 	struct insn insn;
 	int ret;
 
-	ret = insn_decode(&insn, buf, len,
+	ret = insn_decode(&insn, buf, (int)len,
 			  x86_64 ? INSN_MODE_64 : INSN_MODE_32);
 	if (ret < 0 || insn.length > len)
 		return -1;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-log.c b/tools/perf/util/intel-pt-decoder/intel-pt-log.c
index ef55d6232cf0..324692a45d42 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-log.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-log.c
@@ -232,7 +232,7 @@ void __intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip)
 
 	if (len > INTEL_PT_INSN_BUF_SZ)
 		len = INTEL_PT_INSN_BUF_SZ;
-	intel_pt_print_data(intel_pt_insn->buf, len, ip, 8);
+	intel_pt_print_data(intel_pt_insn->buf, (int)len, ip, 8);
 	if (intel_pt_insn_desc(intel_pt_insn, desc, INTEL_PT_INSN_DESC_MAX) > 0)
 		fprintf(f, "%s\n", desc);
 	else
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
index 94fb16cf9e0c..8f2d7aab9ca4 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
@@ -713,7 +713,7 @@ int intel_pt_pkt_desc(const struct intel_pt_pkt *packet, char *buf,
 		if (ret < 0)
 			return ret;
 		blen -= ret;
-		return buf_len - blen;
+		return (int)(buf_len - blen);
 	}
 	case INTEL_PT_TIP_PGD:
 	case INTEL_PT_TIP_PGE:
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 4e8a9b172fbc..037ccedf5d89 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -557,7 +557,7 @@ static int intel_pt_config_div(const char *var, const char *value, void *data)
 	if (!strcmp(var, "intel-pt.cache-divisor")) {
 		val = strtol(value, NULL, 0);
 		if (val > 0 && val <= INT_MAX)
-			*d = val;
+			*d = (int)val;
 	}
 
 	return 0;
@@ -589,7 +589,7 @@ static unsigned int intel_pt_cache_size(struct dso *dso,
 		return 10;
 	if (size > (1 << 21))
 		return 21;
-	return 32 - __builtin_clz(size);
+	return 32 - __builtin_clz((unsigned int)size);
 }
 
 static struct auxtrace_cache *intel_pt_cache(struct dso *dso,
@@ -635,7 +635,7 @@ static int intel_pt_cache_add(struct dso *dso, struct machine *machine,
 	e->rel = intel_pt_insn->rel;
 	memcpy(e->insn, intel_pt_insn->buf, INTEL_PT_INSN_BUF_SZ);
 
-	err = auxtrace_cache__add(c, offset, &e->entry);
+	err = auxtrace_cache__add(c, (u32)offset, &e->entry);
 	if (err)
 		auxtrace_cache__free_entry(c, e);
 
@@ -650,7 +650,7 @@ intel_pt_cache_lookup(struct dso *dso, struct machine *machine, u64 offset)
 	if (!c)
 		return NULL;
 
-	return auxtrace_cache__lookup(dso__auxtrace_cache(dso), offset);
+	return auxtrace_cache__lookup(dso__auxtrace_cache(dso), (u32)offset);
 }
 
 static void intel_pt_cache_invalidate(struct dso *dso, struct machine *machine,
@@ -661,7 +661,7 @@ static void intel_pt_cache_invalidate(struct dso *dso, struct machine *machine,
 	if (!c)
 		return;
 
-	auxtrace_cache__remove(dso__auxtrace_cache(dso), offset);
+	auxtrace_cache__remove(dso__auxtrace_cache(dso), (u32)offset);
 }
 
 static inline bool intel_pt_guest_kernel_ip(uint64_t ip)
@@ -1101,7 +1101,7 @@ static unsigned int intel_pt_mtc_period(struct intel_pt *pt)
 
 	evlist__for_each_entry(pt->session->evlist, evsel) {
 		if (intel_pt_get_config(pt, &evsel->core.attr, &config))
-			return (config & pt->mtc_freq_bits) >> shift;
+			return (unsigned int)((config & pt->mtc_freq_bits) >> shift);
 	}
 	return 0;
 }
@@ -2424,7 +2424,7 @@ static int intel_pt_synth_pebs_sample(struct intel_pt_queue *ptq)
 	struct intel_pt_pebs_event *pe;
 	struct intel_pt *pt = ptq->pt;
 	int err = -EINVAL;
-	int hw_id;
+	size_t hw_id;
 
 	if (!items->has_applicable_counters || !items->applicable_counters) {
 		if (!pt->single_pebs)
@@ -2435,9 +2435,10 @@ static int intel_pt_synth_pebs_sample(struct intel_pt_queue *ptq)
 	for_each_set_bit(hw_id, (unsigned long *)&items->applicable_counters, INTEL_PT_MAX_PEBS) {
 		pe = &ptq->pebs[hw_id];
 		if (!pe->evsel) {
-			if (!pt->single_pebs)
-				pr_err("PEBS-via-PT record with no matching event, hw_id %d\n",
+			if (!pt->single_pebs) {
+				pr_err("PEBS-via-PT record with no matching event, hw_id %zu\n",
 				       hw_id);
+			}
 			return intel_pt_synth_single_pebs_sample(ptq);
 		}
 		err = intel_pt_do_synth_pebs_sample(ptq, pe->evsel, pe->id);
@@ -3272,7 +3273,7 @@ static int intel_pt_process_switch(struct intel_pt *pt,
 	if (evsel != pt->switch_evsel)
 		return 0;
 
-	tid = evsel__intval(evsel, sample, "next_pid");
+	tid = (pid_t)evsel__intval(evsel, sample, "next_pid");
 	cpu = sample->cpu;
 
 	intel_pt_log("sched_switch: cpu %d tid %d time %"PRIu64" tsc %#"PRIx64"\n",
@@ -4258,14 +4259,14 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
 	pt->session = session;
 	pt->machine = &session->machines.host; /* No kvm support */
 	pt->auxtrace_type = auxtrace_info->type;
-	pt->pmu_type = auxtrace_info->priv[INTEL_PT_PMU_TYPE];
+	pt->pmu_type = (u32)auxtrace_info->priv[INTEL_PT_PMU_TYPE];
 	pt->tc.time_shift = auxtrace_info->priv[INTEL_PT_TIME_SHIFT];
-	pt->tc.time_mult = auxtrace_info->priv[INTEL_PT_TIME_MULT];
+	pt->tc.time_mult = (u32)auxtrace_info->priv[INTEL_PT_TIME_MULT];
 	pt->tc.time_zero = auxtrace_info->priv[INTEL_PT_TIME_ZERO];
 	pt->cap_user_time_zero = auxtrace_info->priv[INTEL_PT_CAP_USER_TIME_ZERO];
 	pt->tsc_bit = auxtrace_info->priv[INTEL_PT_TSC_BIT];
 	pt->noretcomp_bit = auxtrace_info->priv[INTEL_PT_NORETCOMP_BIT];
-	pt->have_sched_switch = auxtrace_info->priv[INTEL_PT_HAVE_SCHED_SWITCH];
+	pt->have_sched_switch = (int)auxtrace_info->priv[INTEL_PT_HAVE_SCHED_SWITCH];
 	pt->snapshot_mode = auxtrace_info->priv[INTEL_PT_SNAPSHOT_MODE];
 	pt->per_cpu_mmaps = auxtrace_info->priv[INTEL_PT_PER_CPU_MMAPS];
 	intel_pt_print_info(&auxtrace_info->priv[0], INTEL_PT_PMU_TYPE,
@@ -4274,8 +4275,8 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
 	if (intel_pt_has(auxtrace_info, INTEL_PT_CYC_BIT)) {
 		pt->mtc_bit = auxtrace_info->priv[INTEL_PT_MTC_BIT];
 		pt->mtc_freq_bits = auxtrace_info->priv[INTEL_PT_MTC_FREQ_BITS];
-		pt->tsc_ctc_ratio_n = auxtrace_info->priv[INTEL_PT_TSC_CTC_N];
-		pt->tsc_ctc_ratio_d = auxtrace_info->priv[INTEL_PT_TSC_CTC_D];
+		pt->tsc_ctc_ratio_n = (u32)auxtrace_info->priv[INTEL_PT_TSC_CTC_N];
+		pt->tsc_ctc_ratio_d = (u32)auxtrace_info->priv[INTEL_PT_TSC_CTC_D];
 		pt->cyc_bit = auxtrace_info->priv[INTEL_PT_CYC_BIT];
 		intel_pt_print_info(&auxtrace_info->priv[0], INTEL_PT_MTC_BIT,
 				    INTEL_PT_CYC_BIT);
@@ -4283,7 +4284,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
 
 	if (intel_pt_has(auxtrace_info, INTEL_PT_MAX_NONTURBO_RATIO)) {
 		pt->max_non_turbo_ratio =
-			auxtrace_info->priv[INTEL_PT_MAX_NONTURBO_RATIO];
+			(unsigned int)auxtrace_info->priv[INTEL_PT_MAX_NONTURBO_RATIO];
 		intel_pt_print_info(&auxtrace_info->priv[0],
 				    INTEL_PT_MAX_NONTURBO_RATIO,
 				    INTEL_PT_MAX_NONTURBO_RATIO);
@@ -4418,12 +4419,11 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
 		u64 tsc_freq = intel_pt_ns_to_ticks(pt, 1000000000);
 
 		if (!pt->max_non_turbo_ratio)
-			pt->max_non_turbo_ratio =
-					(tsc_freq + 50000000) / 100000000;
+			pt->max_non_turbo_ratio = (unsigned int)((tsc_freq + 50000000) / 100000000);
 		intel_pt_log("TSC frequency %"PRIu64"\n", tsc_freq);
 		intel_pt_log("Maximum non-turbo ratio %u\n",
 			     pt->max_non_turbo_ratio);
-		pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio / 1000;
+		pt->cbr2khz = (unsigned int)(tsc_freq / pt->max_non_turbo_ratio / 1000);
 	}
 
 	err = intel_pt_setup_time_ranges(pt, session->itrace_synth_opts);
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 11/47] perf arm-spe: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (9 preceding siblings ...)
  2025-04-30 17:49 ` [PATCH v2 10/47] perf arch x86: " Ian Rogers
@ 2025-04-30 17:49 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 12/47] perf trace: " Ian Rogers
                   ` (35 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:49 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 .../util/arm-spe-decoder/arm-spe-decoder.c    |  4 ++--
 .../arm-spe-decoder/arm-spe-pkt-decoder.c     |  2 +-
 tools/perf/util/arm-spe.c                     | 24 +++++++++----------
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-decoder.c
index 688fe6d75244..58107970b215 100644
--- a/tools/perf/util/arm-spe-decoder/arm-spe-decoder.c
+++ b/tools/perf/util/arm-spe-decoder/arm-spe-decoder.c
@@ -117,7 +117,7 @@ static int arm_spe_get_data(struct arm_spe_decoder *decoder)
 	if (!decoder->len)
 		pr_debug("No more data\n");
 
-	return decoder->len;
+	return (int)decoder->len;
 }
 
 static int arm_spe_get_next_packet(struct arm_spe_decoder *decoder)
@@ -187,7 +187,7 @@ static int arm_spe_read_record(struct arm_spe_decoder *decoder)
 			break;
 		case ARM_SPE_COUNTER:
 			if (idx == SPE_CNT_PKT_HDR_INDEX_TOTAL_LAT)
-				decoder->record.latency = payload;
+				decoder->record.latency = (u32)payload;
 			break;
 		case ARM_SPE_CONTEXT:
 			decoder->record.context_id = payload;
diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
index 13cadb2f1cea..a6d04ad50db6 100644
--- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
+++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c
@@ -63,7 +63,7 @@ static int arm_spe_get_payload(const unsigned char *buf, size_t len,
 	default: return ARM_SPE_BAD_PACKET;
 	}
 
-	return 1 + ext_hdr + payload_len;
+	return 1 + ext_hdr + (int)payload_len;
 }
 
 static int arm_spe_get_pad(struct arm_spe_pkt *packet)
diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 2a9775649cc2..561bef7b4628 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -786,7 +786,7 @@ static bool arm_spe__synth_ds(struct arm_spe_queue *speq,
 	}
 
 	for (i = 0; i < ARRAY_SIZE(data_source_handles); i++) {
-		if (is_midr_in_range_list(midr, data_source_handles[i].midr_ranges)) {
+		if (is_midr_in_range_list((u32)midr, data_source_handles[i].midr_ranges)) {
 			data_source_handles[i].ds_synth(record, data_src);
 			return true;
 		}
@@ -956,7 +956,7 @@ static int arm_spe_run_decoder(struct arm_spe_queue *speq, u64 *timestamp)
 		 */
 		record = &speq->decoder->record;
 		if (!spe->timeless_decoding && record->context_id != (u64)-1) {
-			ret = arm_spe_set_tid(speq, record->context_id);
+			ret = arm_spe_set_tid(speq, (pid_t)record->context_id);
 			if (ret)
 				return ret;
 
@@ -1344,8 +1344,8 @@ static u64 **arm_spe__alloc_metadata(struct perf_record_auxtrace_info *info,
 	}
 
 	*ver = ptr[ARM_SPE_HEADER_VERSION];
-	hdr_sz = ptr[ARM_SPE_HEADER_SIZE];
-	*nr_cpu = ptr[ARM_SPE_CPUS_NUM];
+	hdr_sz = (int)ptr[ARM_SPE_HEADER_SIZE];
+	*nr_cpu = (int)ptr[ARM_SPE_CPUS_NUM];
 
 	metadata = calloc(*nr_cpu, sizeof(*metadata));
 	if (!metadata)
@@ -1353,7 +1353,7 @@ static u64 **arm_spe__alloc_metadata(struct perf_record_auxtrace_info *info,
 
 	/* Locate the start address of per CPU metadata */
 	ptr += hdr_sz;
-	per_cpu_sz = (metadata_size - (hdr_sz * sizeof(u64))) / (*nr_cpu);
+	per_cpu_sz = (int)((metadata_size - (hdr_sz * sizeof(u64))) / (*nr_cpu));
 
 	for (i = 0; i < *nr_cpu; i++) {
 		metadata[i] = arm_spe__alloc_per_cpu_metadata(ptr, per_cpu_sz);
@@ -1405,7 +1405,7 @@ static void arm_spe_free(struct perf_session *session)
 	auxtrace_heap__free(&spe->heap);
 	arm_spe_free_events(session);
 	session->auxtrace = NULL;
-	arm_spe__free_metadata(spe->metadata, spe->metadata_nr_cpu);
+	arm_spe__free_metadata(spe->metadata, (int)spe->metadata_nr_cpu);
 	free(spe);
 }
 
@@ -1451,8 +1451,8 @@ static void arm_spe_print_info(struct arm_spe *spe, __u64 *arr)
 		hdr_size = ARM_SPE_AUXTRACE_V1_PRIV_MAX;
 		hdr_fmts = metadata_hdr_v1_fmts;
 	} else {
-		cpu_num = arr[ARM_SPE_CPUS_NUM];
-		hdr_size = arr[ARM_SPE_HEADER_SIZE];
+		cpu_num = (unsigned int)arr[ARM_SPE_CPUS_NUM];
+		hdr_size = (unsigned int)arr[ARM_SPE_HEADER_SIZE];
 		hdr_fmts = metadata_hdr_fmts;
 	}
 
@@ -1466,7 +1466,7 @@ static void arm_spe_print_info(struct arm_spe *spe, __u64 *arr)
 		 * are fixed. The sequential parameter size is decided by the
 		 * field 'ARM_SPE_CPU_NR_PARAMS'.
 		 */
-		cpu_size = (ARM_SPE_CPU_NR_PARAMS + 1) + arr[ARM_SPE_CPU_NR_PARAMS];
+		cpu_size = (unsigned int)((ARM_SPE_CPU_NR_PARAMS + 1) + arr[ARM_SPE_CPU_NR_PARAMS]);
 		for (i = 0; i < cpu_size; i++)
 			fprintf(stdout, metadata_per_cpu_fmts[i], arr[i]);
 		arr += cpu_size;
@@ -1731,9 +1731,9 @@ int arm_spe_process_auxtrace_info(union perf_event *event,
 	spe->machine = &session->machines.host; /* No kvm support */
 	spe->auxtrace_type = auxtrace_info->type;
 	if (metadata_ver == 1)
-		spe->pmu_type = auxtrace_info->priv[ARM_SPE_PMU_TYPE];
+		spe->pmu_type = (u32)auxtrace_info->priv[ARM_SPE_PMU_TYPE];
 	else
-		spe->pmu_type = auxtrace_info->priv[ARM_SPE_PMU_TYPE_V2];
+		spe->pmu_type = (u32)auxtrace_info->priv[ARM_SPE_PMU_TYPE_V2];
 	spe->metadata = metadata;
 	spe->metadata_ver = metadata_ver;
 	spe->metadata_nr_cpu = nr_cpu;
@@ -1752,7 +1752,7 @@ int arm_spe_process_auxtrace_info(union perf_event *event,
 	 * "time_cycles" only if they are contained in the event.
 	 */
 	spe->tc.time_shift = tc->time_shift;
-	spe->tc.time_mult = tc->time_mult;
+	spe->tc.time_mult = (u32)tc->time_mult;
 	spe->tc.time_zero = tc->time_zero;
 
 	if (event_contains(*tc, time_cycles)) {
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 12/47] perf trace: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (10 preceding siblings ...)
  2025-04-30 17:49 ` [PATCH v2 11/47] perf arm-spe: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 13/47] perf trace-event: " Ian Rogers
                   ` (34 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-trace.c                    | 98 ++++++++++---------
 tools/perf/trace/beauty/arch_prctl.c          |  2 +-
 tools/perf/trace/beauty/eventfd.c             |  2 +-
 tools/perf/trace/beauty/fcntl.c               |  5 +-
 tools/perf/trace/beauty/flock.c               |  2 +-
 tools/perf/trace/beauty/fs_at_flags.c         |  4 +-
 tools/perf/trace/beauty/futex_op.c            |  2 +-
 tools/perf/trace/beauty/futex_val3.c          |  2 +-
 tools/perf/trace/beauty/ioctl.c               |  2 +-
 tools/perf/trace/beauty/kcmp.c                |  8 +-
 tools/perf/trace/beauty/mmap.c                |  2 +-
 tools/perf/trace/beauty/mode_t.c              |  2 +-
 tools/perf/trace/beauty/msg_flags.c           |  2 +-
 tools/perf/trace/beauty/open_flags.c          |  2 +-
 tools/perf/trace/beauty/perf_event_open.c     |  4 +-
 tools/perf/trace/beauty/pid.c                 |  2 +-
 tools/perf/trace/beauty/pkey_alloc.c          |  2 +-
 tools/perf/trace/beauty/prctl.c               | 10 +-
 tools/perf/trace/beauty/sched_policy.c        |  2 +-
 tools/perf/trace/beauty/seccomp.c             |  4 +-
 tools/perf/trace/beauty/signum.c              |  2 +-
 tools/perf/trace/beauty/socket.c              |  6 +-
 tools/perf/trace/beauty/socket_type.c         |  2 +-
 tools/perf/trace/beauty/statx.c               |  2 +-
 .../beauty/tracepoints/x86_irq_vectors.c      |  3 +-
 tools/perf/trace/beauty/tracepoints/x86_msr.c |  3 +-
 tools/perf/trace/beauty/waitid_options.c      |  2 +-
 27 files changed, 94 insertions(+), 85 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 809b4d5b0a8a..5da84d4eba7c 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -549,7 +549,7 @@ static struct evsel *perf_evsel__raw_syscall_newtp(const char *direction, void *
 
 size_t strarray__scnprintf_suffix(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_suffix, int val)
 {
-	int idx = val - sa->offset;
+	int idx = (int)(val - sa->offset);
 
 	if (idx < 0 || idx >= sa->nr_entries || sa->entries[idx] == NULL) {
 		size_t printed = scnprintf(bf, size, intfmt, val);
@@ -563,7 +563,7 @@ size_t strarray__scnprintf_suffix(struct strarray *sa, char *bf, size_t size, co
 
 size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_prefix, int val)
 {
-	int idx = val - sa->offset;
+	int idx = (int)(val - sa->offset);
 
 	if (idx < 0 || idx >= sa->nr_entries || sa->entries[idx] == NULL) {
 		size_t printed = scnprintf(bf, size, intfmt, val);
@@ -579,7 +579,8 @@ static size_t __syscall_arg__scnprintf_strarray(char *bf, size_t size,
 						const char *intfmt,
 					        struct syscall_arg *arg)
 {
-	return strarray__scnprintf(arg->parm, bf, size, intfmt, arg->show_string_prefix, arg->val);
+	return strarray__scnprintf(arg->parm, bf, size, intfmt, arg->show_string_prefix,
+				   (int)arg->val);
 }
 
 static size_t syscall_arg__scnprintf_strarray(char *bf, size_t size,
@@ -617,7 +618,7 @@ size_t strarrays__scnprintf(struct strarrays *sas, char *bf, size_t size, const
 
 	for (i = 0; i < sas->nr_entries; ++i) {
 		struct strarray *sa = sas->entries[i];
-		int idx = val - sa->offset;
+		int idx = (int)(val - sa->offset);
 
 		if (idx >= 0 && idx < sa->nr_entries) {
 			if (sa->entries[idx] == NULL)
@@ -654,7 +655,7 @@ bool strarray__strtoul_flags(struct strarray *sa, char *bf, size_t size, u64 *re
 	*ret = 0;
 
 	while (size != 0) {
-		int toklen = size;
+		size_t toklen = size;
 
 		sep = memchr(tok, '|', size);
 		if (sep != NULL) {
@@ -703,7 +704,8 @@ bool strarrays__strtoul(struct strarrays *sas, char *bf, size_t size, u64 *ret)
 size_t syscall_arg__scnprintf_strarrays(char *bf, size_t size,
 					struct syscall_arg *arg)
 {
-	return strarrays__scnprintf(arg->parm, bf, size, "%d", arg->show_string_prefix, arg->val);
+	return strarrays__scnprintf(arg->parm, bf, size, "%d", arg->show_string_prefix,
+				    (int)arg->val);
 }
 
 #ifndef AT_FDCWD
@@ -713,7 +715,7 @@ size_t syscall_arg__scnprintf_strarrays(char *bf, size_t size,
 static size_t syscall_arg__scnprintf_fd_at(char *bf, size_t size,
 					   struct syscall_arg *arg)
 {
-	int fd = arg->val;
+	int fd = (int)arg->val;
 	const char *prefix = "AT_FD";
 
 	if (fd == AT_FDCWD)
@@ -855,7 +857,7 @@ static size_t syscall_arg__scnprintf_access_mode(char *bf, size_t size,
 	bool show_prefix = arg->show_string_prefix;
 	const char *suffix = "_OK";
 	size_t printed = 0;
-	int mode = arg->val;
+	int mode = (int)arg->val;
 
 	if (mode == F_OK) /* 0 */
 		return scnprintf(bf, size, "F%s", show_prefix ? suffix : "");
@@ -897,7 +899,7 @@ static size_t syscall_arg__scnprintf_pipe_flags(char *bf, size_t size,
 {
 	bool show_prefix = arg->show_string_prefix;
 	const char *prefix = "O_";
-	int printed = 0, flags = arg->val;
+	int printed = 0, flags = (int)arg->val;
 
 #define	P_FLAG(n) \
 	if (flags & O_##n) { \
@@ -929,7 +931,7 @@ static size_t syscall_arg__scnprintf_getrandom_flags(char *bf, size_t size,
 {
 	bool show_prefix = arg->show_string_prefix;
 	const char *prefix = "GRND_";
-	int printed = 0, flags = arg->val;
+	int printed = 0, flags = (int)arg->val;
 
 #define	P_FLAG(n) \
 	if (flags & GRND_##n) { \
@@ -975,7 +977,7 @@ static bool syscall_arg__strtoul_btf_enum(char *bf, size_t size, struct syscall_
 
 	for (int i = 0; i < btf_vlen(bt); ++i, ++be) {
 		const char *name = btf__name_by_offset(btf, be->name_off);
-		int max_len = max(size, strlen(name));
+		size_t max_len = max(size, strlen(name));
 
 		if (strncmp(name, bf, max_len) == 0) {
 			*val = be->val;
@@ -1713,7 +1715,7 @@ static int thread__read_fd_path(struct thread *thread, int fd)
 {
 	char linkname[PATH_MAX], pathname[PATH_MAX];
 	struct stat st;
-	int ret;
+	ssize_t ret;
 
 	if (thread__pid(thread) == thread__tid(thread)) {
 		scnprintf(linkname, sizeof(linkname),
@@ -1760,7 +1762,7 @@ static const char *thread__fd_path(struct thread *thread, int fd,
 
 size_t syscall_arg__scnprintf_fd(char *bf, size_t size, struct syscall_arg *arg)
 {
-	int fd = arg->val;
+	int fd = (int)arg->val;
 	size_t printed = scnprintf(bf, size, "%d", fd);
 	const char *path = thread__fd_path(arg->thread, fd, arg->trace);
 
@@ -1790,7 +1792,7 @@ size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_
 static size_t syscall_arg__scnprintf_close_fd(char *bf, size_t size,
 					      struct syscall_arg *arg)
 {
-	int fd = arg->val;
+	int fd = (int)arg->val;
 	size_t printed = syscall_arg__scnprintf_fd(bf, size, arg);
 	struct thread_trace *ttrace = thread__priv(arg->thread);
 
@@ -2063,11 +2065,11 @@ syscall_arg_fmt__init_array(struct syscall_arg_fmt *arg, struct tep_format_field
 			    bool *use_btf)
 {
 	struct tep_format_field *last_field = NULL;
-	int len;
 
 	for (; field; field = field->next, ++arg) {
-		last_field = field;
+		size_t len;
 
+		last_field = field;
 		if (arg->scnprintf)
 			continue;
 
@@ -2167,7 +2169,7 @@ static int syscall__read_info(struct syscall *sc, struct trace *trace)
 	 */
 	if (IS_ERR(sc->tp_format)) {
 		sc->nonexistent = true;
-		err = PTR_ERR(sc->tp_format);
+		err = (int)PTR_ERR(sc->tp_format);
 		sc->tp_format = NULL;
 		return err;
 	}
@@ -2436,7 +2438,8 @@ static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,
 
 			if (trace->force_btf || default_scnprintf == NULL || default_scnprintf == SCA_PTR) {
 				btf_printed = trace__btf_scnprintf(trace, &arg, bf + printed,
-								   size - printed, val, field->type);
+								   size - printed, (int)val,
+								   field->type);
 				if (btf_printed) {
 					printed += btf_printed;
 					continue;
@@ -2653,7 +2656,7 @@ static void thread__update_stats(struct thread *thread, struct thread_trace *ttr
 			}
 
 			stats->errnos = new_errnos;
-			stats->max_errno = err;
+			stats->max_errno = (int)err;
 		}
 
 		++stats->errnos[err - 1];
@@ -2685,7 +2688,7 @@ static int trace__printf_interrupted_entry(struct trace *trace)
 	ttrace->entry_pending = false;
 	++trace->nr_events_printed;
 
-	return printed;
+	return (int)printed;
 }
 
 static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel,
@@ -2752,8 +2755,8 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel,
 	void *args;
 	int printed = 0;
 	struct thread *thread;
-	int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1;
-	int augmented_args_size = 0, e_machine;
+	int id = (int)perf_evsel__sc_tp_uint(evsel, id, sample);
+	int err = -1, augmented_args_size = 0, e_machine;
 	void *augmented_args = NULL;
 	struct syscall *sc;
 	struct thread_trace *ttrace;
@@ -2829,11 +2832,11 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,
 {
 	struct thread_trace *ttrace;
 	struct thread *thread;
-	int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1;
+	int id = (int)perf_evsel__sc_tp_uint(evsel, id, sample);
 	struct syscall *sc;
 	char msg[1024];
 	void *args, *augmented_args = NULL;
-	int augmented_args_size, e_machine;
+	int err = -1, augmented_args_size, e_machine;
 	size_t printed = 0;
 
 
@@ -2905,7 +2908,8 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel,
 	u64 duration = 0;
 	bool duration_calculated = false;
 	struct thread *thread;
-	int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1, callchain_ret = 0, printed = 0;
+	int id = (int)perf_evsel__sc_tp_uint(evsel, id, sample);
+	int err = -1, callchain_ret = 0, printed = 0;
 	int alignment = trace->args_alignment, e_machine;
 	struct syscall *sc;
 	struct thread_trace *ttrace;
@@ -2927,7 +2931,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel,
 		thread__update_stats(thread, ttrace, id, sample, ret, trace);
 
 	if (!trace->fd_path_disabled && sc->is_open && ret >= 0 && ttrace->filename.pending_open) {
-		trace__set_fd_pathname(thread, ret, ttrace->filename.name);
+		trace__set_fd_pathname(thread, (int)ret, ttrace->filename.name);
 		ttrace->filename.pending_open = false;
 		++trace->stats.vfs_getname;
 	}
@@ -2982,8 +2986,8 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel,
 	} else if (ret < 0) {
 errno_print: {
 		char bf[STRERR_BUFSIZE];
-		const char *emsg = str_error_r(-ret, bf, sizeof(bf)),
-			   *e = errno_to_name(evsel, -ret);
+		const char *emsg = str_error_r((int)-ret, bf, sizeof(bf));
+		const char *e = errno_to_name(evsel, (int)-ret);
 
 		fprintf(trace->output, "-1 %s (%s)", e, emsg);
 	}
@@ -3002,7 +3006,7 @@ errno_print: {
 	} else if (sc->fmt->hexret)
 		fprintf(trace->output, "%#lx", ret);
 	else if (sc->fmt->errpid) {
-		struct thread *child = machine__find_thread(trace->host, ret, ret);
+		struct thread *child = machine__find_thread(trace->host, (int)ret, (int)ret);
 
 		if (child != NULL) {
 			fprintf(trace->output, "%ld", ret);
@@ -3062,7 +3066,7 @@ static int trace__vfs_getname(struct trace *trace, struct evsel *evsel,
 		if (f == NULL)
 			goto out_put;
 
-		ttrace->filename.namelen = filename_len;
+		ttrace->filename.namelen = (unsigned int)filename_len;
 		ttrace->filename.name = f;
 	}
 
@@ -3190,7 +3194,8 @@ static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel,
 			int offset = field->offset;
 
 			if (field->flags & TEP_FIELD_IS_DYNAMIC) {
-				offset = format_field__intval(field, sample, evsel->needs_swap);
+				offset = (int)format_field__intval(field, sample,
+								   evsel->needs_swap);
 				syscall_arg.len = offset >> 16;
 				offset &= 0xffff;
 				if (tep_field_is_relative(field->flags))
@@ -3215,7 +3220,8 @@ static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel,
 		if (trace->show_arg_names)
 			printed += scnprintf(bf + printed, size - printed, "%s: ", field->name);
 
-		btf_printed = trace__btf_scnprintf(trace, &syscall_arg, bf + printed, size - printed, val, field->type);
+		btf_printed = trace__btf_scnprintf(trace, &syscall_arg, bf + printed,
+						   size - printed, (int)val, field->type);
 		if (btf_printed) {
 			printed += btf_printed;
 			continue;
@@ -3260,7 +3266,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel,
 		trace__fprintf_comm_tid(trace, thread, trace->output);
 
 	if (evsel == trace->syscalls.events.bpf_output) {
-		int id = perf_evsel__sc_tp_uint(evsel, id, sample);
+		int id = (int)perf_evsel__sc_tp_uint(evsel, id, sample);
 		int e_machine = thread ? thread__e_machine(thread, trace->host) : EM_HOST;
 		struct syscall *sc = trace__syscall_info(trace, evsel, e_machine, id);
 
@@ -4277,8 +4283,8 @@ static int trace__expand_filter(struct trace *trace, struct evsel *evsel)
 
 		if (isalpha(*right)) {
 			struct syscall_arg_fmt *fmt;
-			int left_size = tok - left,
-			    right_size = right_end - right;
+			int left_size = (int)(tok - left);
+			int right_size = (int)(right_end - right);
 			char arg[128], *type;
 
 			while (isspace(left[left_size - 1]))
@@ -4308,7 +4314,7 @@ static int trace__expand_filter(struct trace *trace, struct evsel *evsel)
 				if (fmt->strtoul(right, right_size, &syscall_arg, &val)) {
 					char *n, expansion[19];
 					int expansion_lenght = scnprintf(expansion, sizeof(expansion), "%#" PRIx64, val);
-					int expansion_offset = right - new_filter;
+					int expansion_offset = (int)(right - new_filter);
 
 					pr_debug("%s", expansion);
 
@@ -4737,7 +4743,7 @@ static int trace__replay(struct trace *trace)
 
 	session = perf_session__new(&data, &trace->tool);
 	if (IS_ERR(session))
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 
 	if (trace->opts.target.pid)
 		symbol_conf.pid_list_str = strdup(trace->opts.target.pid);
@@ -4835,7 +4841,7 @@ static struct syscall_entry *syscall__sort_stats(struct hashmap *syscall_stats)
 {
 	struct syscall_entry *entry;
 	struct hashmap_entry *pos;
-	unsigned bkt, i, nr;
+	size_t bkt, i, nr;
 
 	nr = syscall_stats->sz;
 	entry = malloc(nr * sizeof(*entry));
@@ -4849,7 +4855,7 @@ static struct syscall_entry *syscall__sort_stats(struct hashmap *syscall_stats)
 
 		entry[i].stats = ss;
 		entry[i].msecs = (u64)st->n * (avg_stats(st) / NSEC_PER_MSEC);
-		entry[i].syscall = pos->key;
+		entry[i].syscall = (int)pos->key;
 		i++;
 	}
 	assert(i == nr);
@@ -5030,7 +5036,6 @@ static int trace__set_filter_pids_from_option(const struct option *opt, const ch
 					      int unset __maybe_unused)
 {
 	int ret = -1;
-	size_t i;
 	struct trace *trace = opt->value;
 	/*
 	 * FIXME: introduce a intarray class, plain parse csv and create a
@@ -5041,16 +5046,16 @@ static int trace__set_filter_pids_from_option(const struct option *opt, const ch
 	if (list == NULL)
 		return -1;
 
-	i = trace->filter_pids.nr = intlist__nr_entries(list) + 1;
-	trace->filter_pids.entries = calloc(i, sizeof(pid_t));
+	trace->filter_pids.nr = intlist__nr_entries(list) + 1;
+	trace->filter_pids.entries = calloc(trace->filter_pids.nr, sizeof(pid_t));
 
 	if (trace->filter_pids.entries == NULL)
 		goto out;
 
 	trace->filter_pids.entries[0] = getpid();
 
-	for (i = 1; i < trace->filter_pids.nr; ++i)
-		trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i;
+	for (unsigned int i = 1; i < trace->filter_pids.nr; ++i)
+		trace->filter_pids.entries[i] = (pid_t)intlist__entry(list, i - 1)->i;
 
 	intlist__delete(list);
 	ret = 0;
@@ -5186,7 +5191,8 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
 	struct trace *trace = (struct trace *)opt->value;
 	const char *s = str;
 	char *sep = NULL, *lists[2] = { NULL, NULL, };
-	int len = strlen(str) + 1, err = -1, list, idx;
+	size_t len = strlen(str) + 1;
+	int err = -1, list, idx;
 	char *strace_groups_dir = system_path(STRACE_GROUPS_DIR);
 	char group_name[PATH_MAX];
 	const struct syscall_fmt *fmt;
@@ -5653,7 +5659,7 @@ int cmd_trace(int argc, const char **argv)
 
 	if (callchain_param.enabled) {
 		if (!mmap_pages_user_set && geteuid() == 0)
-			trace.opts.mmap_pages = perf_event_mlock_kb_in_pages() * 4;
+			trace.opts.mmap_pages = (unsigned int)perf_event_mlock_kb_in_pages() * 4;
 
 		symbol_conf.use_callchain = true;
 	}
diff --git a/tools/perf/trace/beauty/arch_prctl.c b/tools/perf/trace/beauty/arch_prctl.c
index a211348d3204..c8193e04831d 100644
--- a/tools/perf/trace/beauty/arch_prctl.c
+++ b/tools/perf/trace/beauty/arch_prctl.c
@@ -29,7 +29,7 @@ static size_t x86_arch_prctl__scnprintf_code(int option, char *bf, size_t size,
 
 size_t syscall_arg__scnprintf_x86_arch_prctl_code(char *bf, size_t size, struct syscall_arg *arg)
 {
-	unsigned long code = arg->val;
+	int code = (int)arg->val;
 
 	return x86_arch_prctl__scnprintf_code(code, bf, size, arg->show_string_prefix);
 }
diff --git a/tools/perf/trace/beauty/eventfd.c b/tools/perf/trace/beauty/eventfd.c
index 4bab106213c6..38d9e6585375 100644
--- a/tools/perf/trace/beauty/eventfd.c
+++ b/tools/perf/trace/beauty/eventfd.c
@@ -15,7 +15,7 @@ static size_t syscall_arg__scnprintf_eventfd_flags(char *bf, size_t size, struct
 {
 	bool show_prefix = arg->show_string_prefix;
 	const char *prefix = "EFD_";
-	int printed = 0, flags = arg->val;
+	int printed = 0, flags = (int)arg->val;
 
 	if (flags == 0)
 		return scnprintf(bf, size, "NONE");
diff --git a/tools/perf/trace/beauty/fcntl.c b/tools/perf/trace/beauty/fcntl.c
index d075904dccce..6fbeeb1fcf82 100644
--- a/tools/perf/trace/beauty/fcntl.c
+++ b/tools/perf/trace/beauty/fcntl.c
@@ -25,7 +25,8 @@ static size_t fcntl__scnprintf_getlease(unsigned long val, char *bf, size_t size
 	static const char *fcntl_setlease[] = { "RDLCK", "WRLCK", "UNLCK", };
 	static DEFINE_STRARRAY(fcntl_setlease, "F_");
 
-	return strarray__scnprintf(&strarray__fcntl_setlease, bf, size, "%x", show_prefix, val);
+	return strarray__scnprintf(&strarray__fcntl_setlease, bf, size, "%x", show_prefix,
+				   (int)val);
 }
 
 static size_t syscall_arg__scnprintf_fcntl_getlease(char *bf, size_t size, struct syscall_arg *arg)
@@ -70,7 +71,7 @@ size_t syscall_arg__scnprintf_fcntl_cmd(char *bf, size_t size, struct syscall_ar
 size_t syscall_arg__scnprintf_fcntl_arg(char *bf, size_t size, struct syscall_arg *arg)
 {
 	bool show_prefix = arg->show_string_prefix;
-	int cmd = syscall_arg__val(arg, 1);
+	size_t cmd = syscall_arg__val(arg, 1);
 
 	if (cmd == F_DUPFD)
 		return syscall_arg__scnprintf_fd(bf, size, arg);
diff --git a/tools/perf/trace/beauty/flock.c b/tools/perf/trace/beauty/flock.c
index a6514a6f07cf..ace7309ee1fc 100644
--- a/tools/perf/trace/beauty/flock.c
+++ b/tools/perf/trace/beauty/flock.c
@@ -24,7 +24,7 @@ size_t syscall_arg__scnprintf_flock(char *bf, size_t size, struct syscall_arg *a
 {
 	bool show_prefix = arg->show_string_prefix;
 	const char *prefix = "LOCK_";
-	int printed = 0, op = arg->val;
+	int printed = 0, op = (int)arg->val;
 
 	if (op == 0)
 		return scnprintf(bf, size, "NONE");
diff --git a/tools/perf/trace/beauty/fs_at_flags.c b/tools/perf/trace/beauty/fs_at_flags.c
index c200669cb944..f9ab43300171 100644
--- a/tools/perf/trace/beauty/fs_at_flags.c
+++ b/tools/perf/trace/beauty/fs_at_flags.c
@@ -29,7 +29,7 @@ static size_t fs_at__scnprintf_flags(unsigned long flags, char *bf, size_t size,
 size_t syscall_arg__scnprintf_fs_at_flags(char *bf, size_t size, struct syscall_arg *arg)
 {
 	bool show_prefix = arg->show_string_prefix;
-	int flags = arg->val;
+	int flags = (int)arg->val;
 
 	return fs_at__scnprintf_flags(flags, bf, size, show_prefix);
 }
@@ -52,7 +52,7 @@ static size_t faccessat2__scnprintf_flags(unsigned long flags, char *bf, size_t
 size_t syscall_arg__scnprintf_faccessat2_flags(char *bf, size_t size, struct syscall_arg *arg)
 {
 	bool show_prefix = arg->show_string_prefix;
-	int flags = arg->val;
+	int flags = (int)arg->val;
 
 	return faccessat2__scnprintf_flags(flags, bf, size, show_prefix);
 }
diff --git a/tools/perf/trace/beauty/futex_op.c b/tools/perf/trace/beauty/futex_op.c
index 00365156782b..8c1741aab9be 100644
--- a/tools/perf/trace/beauty/futex_op.c
+++ b/tools/perf/trace/beauty/futex_op.c
@@ -29,7 +29,7 @@ static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, struct sysc
 		SCF_UADDR2  = (1 << 4),
 		SCF_VAL3    = (1 << 5),
 	};
-	int op = arg->val;
+	int op = (int)arg->val;
 	int cmd = op & FUTEX_CMD_MASK;
 	size_t printed = 0;
 
diff --git a/tools/perf/trace/beauty/futex_val3.c b/tools/perf/trace/beauty/futex_val3.c
index 9114f7620571..6f02e8d5961d 100644
--- a/tools/perf/trace/beauty/futex_val3.c
+++ b/tools/perf/trace/beauty/futex_val3.c
@@ -8,7 +8,7 @@
 static size_t syscall_arg__scnprintf_futex_val3(char *bf, size_t size, struct syscall_arg *arg)
 {
 	const char *prefix = "FUTEX_BITSET_";
-	unsigned int bitset = arg->val;
+	unsigned int bitset = (unsigned int)arg->val;
 
 	if (bitset == FUTEX_BITSET_MATCH_ANY)
 		return scnprintf(bf, size, "%s%s", arg->show_string_prefix ? prefix : "", "MATCH_ANY");
diff --git a/tools/perf/trace/beauty/ioctl.c b/tools/perf/trace/beauty/ioctl.c
index e19eb6ea361d..abb959be372d 100644
--- a/tools/perf/trace/beauty/ioctl.c
+++ b/tools/perf/trace/beauty/ioctl.c
@@ -175,7 +175,7 @@ static size_t ioctl__scnprintf_cmd(unsigned long cmd, char *bf, size_t size, boo
 size_t syscall_arg__scnprintf_ioctl_cmd(char *bf, size_t size, struct syscall_arg *arg)
 {
 	unsigned long cmd = arg->val;
-	int fd = syscall_arg__val(arg, 0);
+	int fd = (int)syscall_arg__val(arg, 0);
 	struct file *file = thread__files_entry(arg->thread, fd);
 
 	if (file != NULL) {
diff --git a/tools/perf/trace/beauty/kcmp.c b/tools/perf/trace/beauty/kcmp.c
index 9351f84390a1..bc81eaef4944 100644
--- a/tools/perf/trace/beauty/kcmp.c
+++ b/tools/perf/trace/beauty/kcmp.c
@@ -15,14 +15,14 @@
 
 size_t syscall_arg__scnprintf_kcmp_idx(char *bf, size_t size, struct syscall_arg *arg)
 {
-	unsigned long fd = arg->val;
-	int type = syscall_arg__val(arg, 2);
+	int fd = (int)arg->val;
+	int type = (int)syscall_arg__val(arg, 2);
 	pid_t pid;
 
 	if (type != KCMP_FILE)
 		return syscall_arg__scnprintf_long(bf, size, arg);
 
-	pid = syscall_arg__val(arg, arg->idx == 3 ? 0 : 1); /* idx1 -> pid1, idx2 -> pid2 */
+	pid = (pid_t)syscall_arg__val(arg, arg->idx == 3 ? 0 : 1); /* idx1 -> pid1, idx2 -> pid2 */
 	return pid__scnprintf_fd(arg->trace, pid, fd, bf, size);
 }
 
@@ -34,7 +34,7 @@ static size_t kcmp__scnprintf_type(int type, char *bf, size_t size, bool show_pr
 
 size_t syscall_arg__scnprintf_kcmp_type(char *bf, size_t size, struct syscall_arg *arg)
 {
-	unsigned long type = arg->val;
+	int type = (int)arg->val;
 
 	if (type != KCMP_FILE)
 		arg->mask |= (1 << 3) | (1 << 4); /* Ignore idx1 and idx2 */
diff --git a/tools/perf/trace/beauty/mmap.c b/tools/perf/trace/beauty/mmap.c
index 3c5e97b93dd5..b3136b7b31ac 100644
--- a/tools/perf/trace/beauty/mmap.c
+++ b/tools/perf/trace/beauty/mmap.c
@@ -76,7 +76,7 @@ static size_t madvise__scnprintf_behavior(int behavior, char *bf, size_t size)
 static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size,
 						      struct syscall_arg *arg)
 {
-	return madvise__scnprintf_behavior(arg->val, bf, size);
+	return madvise__scnprintf_behavior((int)arg->val, bf, size);
 }
 
 #define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior
diff --git a/tools/perf/trace/beauty/mode_t.c b/tools/perf/trace/beauty/mode_t.c
index 29a8fadfb7f9..802f856c7bd1 100644
--- a/tools/perf/trace/beauty/mode_t.c
+++ b/tools/perf/trace/beauty/mode_t.c
@@ -24,7 +24,7 @@ static size_t syscall_arg__scnprintf_mode_t(char *bf, size_t size, struct syscal
 {
 	bool show_prefix = arg->show_string_prefix;
 	const char *prefix = "S_";
-	int printed = 0, mode = arg->val;
+	int printed = 0, mode = (int)arg->val;
 
 #define	P_MODE(n) \
 	if ((mode & S_##n) == S_##n) { \
diff --git a/tools/perf/trace/beauty/msg_flags.c b/tools/perf/trace/beauty/msg_flags.c
index 2da581ff0c80..2fd0ddcd7f88 100644
--- a/tools/perf/trace/beauty/msg_flags.c
+++ b/tools/perf/trace/beauty/msg_flags.c
@@ -32,7 +32,7 @@ static size_t syscall_arg__scnprintf_msg_flags(char *bf, size_t size,
 {
 	bool show_prefix = arg->show_string_prefix;
 	const char *prefix = "MSG_";
-	int printed = 0, flags = arg->val;
+	int printed = 0, flags = (int)arg->val;
 
 	if (flags == 0)
 		return scnprintf(bf, size, "NONE");
diff --git a/tools/perf/trace/beauty/open_flags.c b/tools/perf/trace/beauty/open_flags.c
index 78f6566ef110..17ceb0f1b36a 100644
--- a/tools/perf/trace/beauty/open_flags.c
+++ b/tools/perf/trace/beauty/open_flags.c
@@ -79,7 +79,7 @@ size_t open__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool sh
 
 size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, struct syscall_arg *arg)
 {
-	int flags = arg->val;
+	int flags = (int)arg->val;
 
 	if (!(flags & O_CREAT))
 		arg->mask |= 1 << (arg->idx + 1); /* Mask the mode parm */
diff --git a/tools/perf/trace/beauty/perf_event_open.c b/tools/perf/trace/beauty/perf_event_open.c
index 9f1ed989c775..d62c9d0261ad 100644
--- a/tools/perf/trace/beauty/perf_event_open.c
+++ b/tools/perf/trace/beauty/perf_event_open.c
@@ -20,7 +20,7 @@ static size_t syscall_arg__scnprintf_perf_flags(char *bf, size_t size,
 {
 	bool show_prefix = arg->show_string_prefix;
 	const char *prefix = "PERF_";
-	int printed = 0, flags = arg->val;
+	int printed = 0, flags = (int)arg->val;
 
 	if (flags == 0)
 		return 0;
@@ -58,7 +58,7 @@ static int attr__fprintf(FILE *fp __maybe_unused, const char *name, const char *
 
 	args->first = false;
 	args->printed += printed;
-	return printed;
+	return (int)printed;
 }
 
 static size_t perf_event_attr___scnprintf(struct perf_event_attr *attr, char *bf, size_t size, bool show_zeros __maybe_unused)
diff --git a/tools/perf/trace/beauty/pid.c b/tools/perf/trace/beauty/pid.c
index 8f9c9950f8ba..609a582e0221 100644
--- a/tools/perf/trace/beauty/pid.c
+++ b/tools/perf/trace/beauty/pid.c
@@ -2,7 +2,7 @@
 
 size_t syscall_arg__scnprintf_pid(char *bf, size_t size, struct syscall_arg *arg)
 {
-	int pid = arg->val;
+	int pid = (int)arg->val;
 	struct trace *trace = arg->trace;
 	size_t printed = scnprintf(bf, size, "%d", pid);
 	struct thread *thread = machine__findnew_thread(trace->host, pid, pid);
diff --git a/tools/perf/trace/beauty/pkey_alloc.c b/tools/perf/trace/beauty/pkey_alloc.c
index f9596ed02cc4..c597a0f26a3d 100644
--- a/tools/perf/trace/beauty/pkey_alloc.c
+++ b/tools/perf/trace/beauty/pkey_alloc.c
@@ -48,7 +48,7 @@ static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, s
 
 size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg)
 {
-	unsigned long cmd = arg->val;
+	int cmd = (int)arg->val;
 
 	return pkey_alloc__scnprintf_access_rights(cmd, bf, size, arg->show_string_prefix);
 }
diff --git a/tools/perf/trace/beauty/prctl.c b/tools/perf/trace/beauty/prctl.c
index 7d1aa9fd03da..7768a72134a3 100644
--- a/tools/perf/trace/beauty/prctl.c
+++ b/tools/perf/trace/beauty/prctl.c
@@ -26,10 +26,10 @@ static size_t prctl__scnprintf_set_mm(int option, char *bf, size_t size, bool sh
 
 size_t syscall_arg__scnprintf_prctl_arg2(char *bf, size_t size, struct syscall_arg *arg)
 {
-	int option = syscall_arg__val(arg, 0);
+	int option = (int)syscall_arg__val(arg, 0);
 
 	if (option == PR_SET_MM)
-		return prctl__scnprintf_set_mm(arg->val, bf, size, arg->show_string_prefix);
+		return prctl__scnprintf_set_mm((int)arg->val, bf, size, arg->show_string_prefix);
 	/*
 	 * We still don't grab the contents of pointers on entry or exit,
 	 * so just print them as hex numbers
@@ -42,7 +42,7 @@ size_t syscall_arg__scnprintf_prctl_arg2(char *bf, size_t size, struct syscall_a
 
 size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_arg *arg)
 {
-	int option = syscall_arg__val(arg, 0);
+	int option = (int)syscall_arg__val(arg, 0);
 
 	if (option == PR_SET_MM)
 		return syscall_arg__scnprintf_hex(bf, size, arg);
@@ -52,7 +52,7 @@ size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_a
 
 size_t syscall_arg__scnprintf_prctl_option(char *bf, size_t size, struct syscall_arg *arg)
 {
-	unsigned long option = arg->val;
+	int option = (int)arg->val;
 	enum {
                 SPO_ARG2 = (1 << 1),
                 SPO_ARG3 = (1 << 2),
@@ -75,7 +75,7 @@ size_t syscall_arg__scnprintf_prctl_option(char *bf, size_t size, struct syscall
 		[PR_SET_PDEATHSIG]	 = all_but2,
 	};
 
-	if (option < ARRAY_SIZE(masks))
+	if (option < (int)ARRAY_SIZE(masks))
 		arg->mask |= masks[option];
 
 	return prctl__scnprintf_option(option, bf, size, arg->show_string_prefix);
diff --git a/tools/perf/trace/beauty/sched_policy.c b/tools/perf/trace/beauty/sched_policy.c
index 68aa59eeed8d..69dad444fa41 100644
--- a/tools/perf/trace/beauty/sched_policy.c
+++ b/tools/perf/trace/beauty/sched_policy.c
@@ -23,7 +23,7 @@ static size_t syscall_arg__scnprintf_sched_policy(char *bf, size_t size,
 		"NORMAL", "FIFO", "RR", "BATCH", "ISO", "IDLE", "DEADLINE",
 	};
 	size_t printed;
-	int policy = arg->val,
+	int policy = (int)arg->val,
 	    flags = policy & ~SCHED_POLICY_MASK;
 
 	policy &= SCHED_POLICY_MASK;
diff --git a/tools/perf/trace/beauty/seccomp.c b/tools/perf/trace/beauty/seccomp.c
index 637722e2796b..42c213a9eb88 100644
--- a/tools/perf/trace/beauty/seccomp.c
+++ b/tools/perf/trace/beauty/seccomp.c
@@ -10,7 +10,7 @@ static size_t syscall_arg__scnprintf_seccomp_op(char *bf, size_t size, struct sy
 {
 	bool show_prefix = arg->show_string_prefix;
 	const char *prefix = "SECCOMP_SET_MODE_";
-	int op = arg->val;
+	int op = (int)arg->val;
 	size_t printed = 0;
 
 	switch (op) {
@@ -35,7 +35,7 @@ static size_t syscall_arg__scnprintf_seccomp_flags(char *bf, size_t size,
 {
 	bool show_prefix = arg->show_string_prefix;
 	const char *prefix = "SECCOMP_FILTER_FLAG_";
-	int printed = 0, flags = arg->val;
+	int printed = 0, flags = (int)arg->val;
 
 #define	P_FLAG(n) \
 	if (flags & SECCOMP_FILTER_FLAG_##n) { \
diff --git a/tools/perf/trace/beauty/signum.c b/tools/perf/trace/beauty/signum.c
index 21220c56500a..a78bceeaa23e 100644
--- a/tools/perf/trace/beauty/signum.c
+++ b/tools/perf/trace/beauty/signum.c
@@ -5,7 +5,7 @@ static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscal
 {
 	bool show_prefix = arg->show_string_prefix;
 	const char *prefix = "SIG";
-	int sig = arg->val;
+	int sig = (int)arg->val;
 
 	switch (sig) {
 #define	P_SIGNUM(n) case SIG##n: return scnprintf(bf, size, "%s%s", show_prefix ? prefix : "", #n)
diff --git a/tools/perf/trace/beauty/socket.c b/tools/perf/trace/beauty/socket.c
index b0870c7b48e5..07a0bfa164d1 100644
--- a/tools/perf/trace/beauty/socket.c
+++ b/tools/perf/trace/beauty/socket.c
@@ -20,10 +20,10 @@ static size_t socket__scnprintf_ipproto(int protocol, char *bf, size_t size, boo
 
 size_t syscall_arg__scnprintf_socket_protocol(char *bf, size_t size, struct syscall_arg *arg)
 {
-	int domain = syscall_arg__val(arg, 0);
+	int domain = (int)syscall_arg__val(arg, 0);
 
 	if (domain == AF_INET || domain == AF_INET6)
-		return socket__scnprintf_ipproto(arg->val, bf, size, arg->show_string_prefix);
+		return socket__scnprintf_ipproto((int)arg->val, bf, size, arg->show_string_prefix);
 
 	return syscall_arg__scnprintf_int(bf, size, arg);
 }
@@ -43,5 +43,5 @@ static size_t socket__scnprintf_level(int level, char *bf, size_t size, bool sho
 
 size_t syscall_arg__scnprintf_socket_level(char *bf, size_t size, struct syscall_arg *arg)
 {
-	return socket__scnprintf_level(arg->val, bf, size, arg->show_string_prefix);
+	return socket__scnprintf_level((int)arg->val, bf, size, arg->show_string_prefix);
 }
diff --git a/tools/perf/trace/beauty/socket_type.c b/tools/perf/trace/beauty/socket_type.c
index bed8d5761ca8..2c7e3801ba34 100644
--- a/tools/perf/trace/beauty/socket_type.c
+++ b/tools/perf/trace/beauty/socket_type.c
@@ -23,7 +23,7 @@ static size_t syscall_arg__scnprintf_socket_type(char *bf, size_t size, struct s
 	bool show_prefix = arg->show_string_prefix;
 	const char *prefix = "SOCK_";
 	size_t printed;
-	int type = arg->val,
+	int type = (int)arg->val,
 	    flags = type & ~SOCK_TYPE_MASK;
 
 	type &= SOCK_TYPE_MASK;
diff --git a/tools/perf/trace/beauty/statx.c b/tools/perf/trace/beauty/statx.c
index 24843e614b93..de47bc0c03e5 100644
--- a/tools/perf/trace/beauty/statx.c
+++ b/tools/perf/trace/beauty/statx.c
@@ -19,7 +19,7 @@ static size_t statx__scnprintf_mask(unsigned long mask, char *bf, size_t size, b
 size_t syscall_arg__scnprintf_statx_mask(char *bf, size_t size, struct syscall_arg *arg)
 {
 	bool show_prefix = arg->show_string_prefix;
-	int mask = arg->val;
+	int mask = (int)arg->val;
 
 	return statx__scnprintf_mask(mask, bf, size, show_prefix);
 }
diff --git a/tools/perf/trace/beauty/tracepoints/x86_irq_vectors.c b/tools/perf/trace/beauty/tracepoints/x86_irq_vectors.c
index 8eb9bc8534ac..6430d1084dc1 100644
--- a/tools/perf/trace/beauty/tracepoints/x86_irq_vectors.c
+++ b/tools/perf/trace/beauty/tracepoints/x86_irq_vectors.c
@@ -13,7 +13,8 @@ static DEFINE_STRARRAY(x86_irq_vectors, "_VECTOR");
 
 static size_t x86_irq_vectors__scnprintf(unsigned long vector, char *bf, size_t size, bool show_prefix)
 {
-	return strarray__scnprintf_suffix(&strarray__x86_irq_vectors, bf, size, "%#x", show_prefix, vector);
+	return strarray__scnprintf_suffix(&strarray__x86_irq_vectors, bf, size, "%#x", show_prefix,
+					  (int)vector);
 }
 
 size_t syscall_arg__scnprintf_x86_irq_vectors(char *bf, size_t size, struct syscall_arg *arg)
diff --git a/tools/perf/trace/beauty/tracepoints/x86_msr.c b/tools/perf/trace/beauty/tracepoints/x86_msr.c
index 6b8f129579d6..2be91be1af05 100644
--- a/tools/perf/trace/beauty/tracepoints/x86_msr.c
+++ b/tools/perf/trace/beauty/tracepoints/x86_msr.c
@@ -23,7 +23,8 @@ static DEFINE_STRARRAYS(x86_MSRs_tables);
 
 static size_t x86_MSR__scnprintf(unsigned long msr, char *bf, size_t size, bool show_prefix)
 {
-	return strarrays__scnprintf(&strarrays__x86_MSRs_tables, bf, size, "%#x", show_prefix, msr);
+	return strarrays__scnprintf(&strarrays__x86_MSRs_tables, bf, size, "%#x", show_prefix,
+				    (int)msr);
 }
 
 size_t syscall_arg__scnprintf_x86_MSR(char *bf, size_t size, struct syscall_arg *arg)
diff --git a/tools/perf/trace/beauty/waitid_options.c b/tools/perf/trace/beauty/waitid_options.c
index d4d10b33ba0e..2a920a0f41d0 100644
--- a/tools/perf/trace/beauty/waitid_options.c
+++ b/tools/perf/trace/beauty/waitid_options.c
@@ -7,7 +7,7 @@ static size_t syscall_arg__scnprintf_waitid_options(char *bf, size_t size,
 {
 	bool show_prefix = arg->show_string_prefix;
 	const char *prefix = "W";
-	int printed = 0, options = arg->val;
+	int printed = 0, options = (int)arg->val;
 
 #define	P_OPTION(n) \
 	if (options & W##n) { \
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 13/47] perf trace-event: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (11 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 12/47] perf trace: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 14/47] perf jvmti: " Ian Rogers
                   ` (33 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/util/python.c                      |  4 ++--
 .../scripting-engines/trace-event-python.c    | 13 ++++++-----
 tools/perf/util/trace-event-info.c            |  3 ++-
 tools/perf/util/trace-event-parse.c           |  2 +-
 tools/perf/util/trace-event-read.c            | 23 +++++++++----------
 tools/perf/util/trace-event-scripting.c       |  2 +-
 6 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index f3c05da25b4a..f55b2b7435ad 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -305,7 +305,7 @@ tracepoint_field(const struct pyrf_event *pe, struct tep_format_field *field)
 		len    = field->size;
 		if (field->flags & TEP_FIELD_IS_DYNAMIC) {
 			val     = tep_read_number(pevent, data + offset, len);
-			offset  = val;
+			offset  = (unsigned int)val;
 			len     = offset >> 16;
 			offset &= 0xffff;
 			if (tep_field_is_relative(field->flags))
@@ -599,7 +599,7 @@ static PyObject *pyrf_thread_map__item(PyObject *obj, Py_ssize_t i)
 	if (i >= perf_thread_map__nr(pthreads->threads))
 		return NULL;
 
-	return Py_BuildValue("i", perf_thread_map__pid(pthreads->threads, i));
+	return Py_BuildValue("i", (int)perf_thread_map__pid(pthreads->threads, (int)i));
 }
 
 static PySequenceMethods pyrf_thread_map__sequence_methods = {
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 520729e78965..547eeb45a832 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -713,9 +713,10 @@ static void set_sample_datasrc_in_dict(PyObject *dict,
 			_PyUnicode_FromString(decode));
 }
 
-static void regs_map(struct regs_dump *regs, uint64_t mask, const char *arch, char *bf, int size)
+static void regs_map(struct regs_dump *regs, uint64_t mask, const char *arch, char *bf, size_t size)
 {
-	unsigned int i = 0, r;
+	unsigned int i = 0;
+	u64 r;
 	int printed = 0;
 
 	bf[0] = 0;
@@ -731,7 +732,7 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, const char *arch, ch
 
 		printed += scnprintf(bf + printed, size - printed,
 				     "%5s:0x%" PRIx64 " ",
-				     perf_reg_name(r, arch), val);
+				     perf_reg_name((int)r, arch), val);
 	}
 }
 
@@ -744,7 +745,7 @@ static int set_regs_in_dict(PyObject *dict,
 	struct perf_event_attr *attr = &evsel->core.attr;
 	const char *arch = perf_env__arch(evsel__env(evsel));
 
-	int size = (__sw_hweight64(attr->sample_regs_intr) * MAX_REG_SIZE) + 1;
+	size_t size = (__sw_hweight64(attr->sample_regs_intr) * MAX_REG_SIZE) + 1;
 	char *bf = NULL;
 
 	if (sample->intr_regs) {
@@ -957,7 +958,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
 		Py_FatalError(handler_name);
 	}
 
-	pid = raw_field_value(event, "common_pid", data);
+	pid = (int)raw_field_value(event, "common_pid", data);
 
 	sprintf(handler_name, "%s__%s", event->system, event->name);
 
@@ -1017,7 +1018,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
 			if (field->flags & TEP_FIELD_IS_DYNAMIC) {
 				val     = tep_read_number(scripting_context->pevent,
 							  data + offset, len);
-				offset  = val;
+				offset  = (unsigned int)val;
 				len     = offset >> 16;
 				offset &= 0xffff;
 				if (tep_field_is_relative(field->flags))
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index c8755679281e..0f012890ff21 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -45,7 +45,8 @@ static int record_file(const char *file, ssize_t hdr_sz)
 	unsigned long long size = 0;
 	char buf[BUFSIZ], *sizep;
 	off_t hdr_pos = lseek(output_fd, 0, SEEK_CUR);
-	int r, fd;
+	int fd;
+	ssize_t r;
 	int err = -EIO;
 
 	fd = open(file, O_RDONLY);
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index 9c015fc2bcfb..982cbbc57168 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -34,7 +34,7 @@ static int get_common_field(struct scripting_context *context,
 		*size = field->size;
 	}
 
-	return tep_read_number(pevent, context->event_data + *offset, *size);
+	return (int)tep_read_number(pevent, context->event_data + *offset, *size);
 }
 
 int common_lock_depth(struct scripting_context *context)
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index ecbbb93f0185..78a3b3801d69 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -25,18 +25,18 @@ static int input_fd;
 static ssize_t trace_data_size;
 static bool repipe;
 
-static int __do_read(int fd, void *buf, int size)
+static int __do_read(int fd, void *buf, size_t size)
 {
-	int rsize = size;
+	int rsize = (int)size;
 
 	while (size) {
-		int ret = read(fd, buf, size);
+		ssize_t ret = read(fd, buf, size);
 
 		if (ret <= 0)
 			return -1;
 
 		if (repipe) {
-			int retw = write(STDOUT_FILENO, buf, ret);
+			ssize_t retw = write(STDOUT_FILENO, buf, ret);
 
 			if (retw <= 0 || retw != ret) {
 				pr_debug("repiping input file");
@@ -51,14 +51,13 @@ static int __do_read(int fd, void *buf, int size)
 	return rsize;
 }
 
-static int do_read(void *data, int size)
+static int do_read(void *data, size_t size)
 {
 	int r;
 
 	r = __do_read(input_fd, data, size);
 	if (r <= 0) {
-		pr_debug("reading input file (size expected=%d received=%d)",
-			 size, r);
+		pr_debug("reading input file (size expected=%zd received=%d)", size, r);
 		return -1;
 	}
 
@@ -68,10 +67,10 @@ static int do_read(void *data, int size)
 }
 
 /* If it fails, the next read will report it */
-static void skip(int size)
+static void skip(unsigned long long size)
 {
 	char buf[BUFSIZ];
-	int r;
+	unsigned long long r;
 
 	while (size) {
 		r = size > BUFSIZ ? BUFSIZ : size;
@@ -86,7 +85,7 @@ static unsigned int read4(struct tep_handle *pevent)
 
 	if (do_read(&data, 4) < 0)
 		return 0;
-	return tep_read_number(pevent, &data, 4);
+	return (unsigned int)tep_read_number(pevent, &data, 4);
 }
 
 static unsigned long long read8(struct tep_handle *pevent)
@@ -119,7 +118,7 @@ static char *read_string(void)
 		}
 
 		if (repipe) {
-			int retw = write(STDOUT_FILENO, &c, 1);
+			ssize_t retw = write(STDOUT_FILENO, &c, 1);
 
 			if (retw <= 0 || retw != r) {
 				pr_debug("repiping input file string");
@@ -365,7 +364,7 @@ static int read_saved_cmdline(struct tep_handle *pevent)
 	}
 	buf[ret] = '\0';
 
-	parse_saved_cmdline(pevent, buf, size);
+	parse_saved_cmdline(pevent, buf, (unsigned int)size);
 	ret = 0;
 out:
 	free(buf);
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index 72abb28b7b5a..fb1fa227c98e 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -422,5 +422,5 @@ int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz)
 	if (pos < sz)
 		str[pos] = 0;
 
-	return pos;
+	return (int)pos;
 }
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 14/47] perf jvmti: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (12 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 13/47] perf trace-event: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 15/47] perf pmu: " Ian Rogers
                   ` (32 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/jvmti/jvmti_agent.c |  6 +++---
 tools/perf/util/genelf.c       |  2 +-
 tools/perf/util/jitdump.c      | 24 +++++++++++++-----------
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c
index 526dcaf9f079..2e2be9d8a118 100644
--- a/tools/perf/jvmti/jvmti_agent.c
+++ b/tools/perf/jvmti/jvmti_agent.c
@@ -377,7 +377,7 @@ jvmti_write_code(void *agent, char const *sym,
 	sym_len = strlen(sym) + 1;
 
 	rec.p.id           = JIT_CODE_LOAD;
-	rec.p.total_size   = sizeof(rec) + sym_len;
+	rec.p.total_size   = (uint32_t)(sizeof(rec) + sym_len);
 	rec.p.timestamp    = perf_get_timestamp();
 
 	rec.code_size  = size;
@@ -400,7 +400,7 @@ jvmti_write_code(void *agent, char const *sym,
 	 */
 	rec.code_index = code_generation++;
 
-	ret = fwrite_unlocked(&rec, sizeof(rec), 1, fp);
+	ret = (int)fwrite_unlocked(&rec, sizeof(rec), 1, fp);
 	fwrite_unlocked(sym, sym_len, 1, fp);
 
 	if (code)
@@ -454,7 +454,7 @@ jvmti_write_debug_info(void *agent, uint64_t code,
 	 */
 	size += nr_lines * sizeof(struct debug_entry);
 	size += flen;
-	rec.p.total_size = size;
+	rec.p.total_size = (uint32_t)size;
 
 	/*
 	 * If JVM is multi-threaded, multiple concurrent calls to agent
diff --git a/tools/perf/util/genelf.c b/tools/perf/util/genelf.c
index cdce7f173d00..6da8f3c53f7d 100644
--- a/tools/perf/util/genelf.c
+++ b/tools/perf/util/genelf.c
@@ -252,7 +252,7 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym,
 	Elf_Shdr *shdr;
 	uint64_t eh_frame_base_offset;
 	char *strsym = NULL;
-	int symlen;
+	size_t symlen;
 	int retval = -1;
 
 	if (elf_version(EV_CURRENT) == EV_NONE) {
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 624964f01b5f..874ced77d0a4 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -160,7 +160,7 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 	 */
 	flockfile(jd->in);
 
-	ret = fread(buf, sizeof(header), 1, jd->in);
+	ret = (int)fread(buf, sizeof(header), 1, jd->in);
 	if (ret != 1)
 		goto error;
 
@@ -226,7 +226,7 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 		bsz = bs;
 		buf = n;
 		/* read extra we do not know about */
-		ret = fread(buf, bs - bsz, 1, jd->in);
+		ret = (int)fread(buf, bs - bsz, 1, jd->in);
 		if (ret != 1)
 			goto error;
 	}
@@ -274,7 +274,7 @@ jit_get_next_entry(struct jit_buf_desc *jd)
 	/*
 	 * file is still locked at this point
 	 */
-	ret = fread(prefix, sizeof(*prefix), 1, jd->in);
+	ret = (int)fread(prefix, sizeof(*prefix), 1, jd->in);
 	if (ret  != 1)
 		return NULL;
 
@@ -304,7 +304,7 @@ jit_get_next_entry(struct jit_buf_desc *jd)
 
 	addr = ((void *)jd->buf) + sizeof(*prefix);
 
-	ret = fread(addr, bs - sizeof(*prefix), 1, jd->in);
+	ret = (int)fread(addr, bs - sizeof(*prefix), 1, jd->in);
 	if (ret != 1)
 		return NULL;
 
@@ -398,7 +398,7 @@ static uint64_t convert_timestamp(struct jit_buf_desc *jd, uint64_t timestamp)
 		return timestamp;
 
 	tc.time_shift = time_conv->time_shift;
-	tc.time_mult  = time_conv->time_mult;
+	tc.time_mult  = (unsigned int)time_conv->time_mult;
 	tc.time_zero  = time_conv->time_zero;
 
 	/*
@@ -443,8 +443,8 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 	nspid = jr->load.pid;
 	pid   = jr_entry_pid(jd, jr);
 	tid   = jr_entry_tid(jd, jr);
-	csize = jr->load.code_size;
-	usize = jd->unwinding_mapped_size;
+	csize = (int)jr->load.code_size;
+	usize = (int)jd->unwinding_mapped_size;
 	addr  = jr->load.code_addr;
 	sym   = (void *)((unsigned long)jr + sizeof(jr->load));
 	code  = (unsigned long)jr + jr->load.p.total_size - csize;
@@ -465,8 +465,10 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 
 	size = PERF_ALIGN(size, sizeof(u64));
 	uaddr = (uintptr_t)code;
-	ret = jit_emit_elf(jd, filename, sym, addr, (const void *)uaddr, csize, jd->debug_data, jd->nr_debug_entries,
-			   jd->unwinding_data, jd->eh_frame_hdr_size, jd->unwinding_size);
+	ret = jit_emit_elf(jd, filename, sym, addr, (const void *)uaddr, csize, jd->debug_data,
+			   (int)jd->nr_debug_entries, jd->unwinding_data,
+			   (uint32_t)jd->eh_frame_hdr_size,
+			   (uint32_t)jd->unwinding_size);
 
 	if (jd->debug_data && jd->nr_debug_entries) {
 		zfree(&jd->debug_data);
@@ -559,8 +561,8 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
 
 	nspid = jr->load.pid;
 	pid   = jr_entry_pid(jd, jr);
-	tid   = jr_entry_tid(jd, jr);
-	usize = jd->unwinding_mapped_size;
+	tid   = (int)jr_entry_tid(jd, jr);
+	usize = (int)jd->unwinding_mapped_size;
 	idr_size = jd->machine->id_hdr_size;
 
 	/*
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 15/47] perf pmu: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (13 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 14/47] perf jvmti: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 16/47] perf annotate powerpc: " Ian Rogers
                   ` (31 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/util/hwmon_pmu.c |  8 ++++----
 tools/perf/util/pmu.c       |  9 ++++-----
 tools/perf/util/pmus.c      | 16 ++++++++--------
 tools/perf/util/tool_pmu.c  |  2 +-
 4 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c
index 3cce77fc8004..6245eeb593c9 100644
--- a/tools/perf/util/hwmon_pmu.c
+++ b/tools/perf/util/hwmon_pmu.c
@@ -170,7 +170,7 @@ bool parse_hwmon_filename(const char *filename,
 	for (size_t i = 0; fn_type[i] != '\0'; i++) {
 		if (fn_type[i] >= '0' && fn_type[i] <= '9') {
 			fn_type[i] = '\0';
-			*number = strtoul(&filename[i], (char **)&fn_item, 10);
+			*number = (int)strtoul(&filename[i], (char **)&fn_item, 10);
 			if (*fn_item == '_')
 				fn_item++;
 			break;
@@ -194,7 +194,7 @@ bool parse_hwmon_filename(const char *filename,
 		return false;
 	}
 
-	*type = elem - &hwmon_type_strs[0];
+	*type = (enum hwmon_type)(elem - &hwmon_type_strs[0]);
 	if (!item)
 		return true;
 
@@ -213,7 +213,7 @@ bool parse_hwmon_filename(const char *filename,
 			 fn_item, filename);
 		return false;
 	}
-	*item = elem - &hwmon_item_strs[0];
+	*item = (enum hwmon_item)(elem - &hwmon_item_strs[0]);
 	return true;
 }
 
@@ -352,7 +352,7 @@ struct perf_pmu *hwmon_pmu__new(struct list_head *pmus, int hwmon_dir, const cha
 		return NULL;
 
 	hwm->hwmon_dir_fd = hwmon_dir;
-	hwm->pmu.type = PERF_PMU_TYPE_HWMON_START + strtoul(sysfs_name + 5, NULL, 10);
+	hwm->pmu.type = PERF_PMU_TYPE_HWMON_START + (int)strtoul(sysfs_name + 5, NULL, 10);
 	if (hwm->pmu.type > PERF_PMU_TYPE_HWMON_END) {
 		pr_err("Unable to encode hwmon type from %s in valid PMU type\n", sysfs_name);
 		goto err_out;
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index bbb906bb2159..0a3c9e5eb527 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1310,7 +1310,7 @@ __u64 perf_pmu__format_bits(struct perf_pmu *pmu, const char *name)
 {
 	struct perf_pmu_format *format = pmu_find_format(&pmu->format, name);
 	__u64 bits = 0;
-	int fbit;
+	size_t fbit;
 
 	if (!format)
 		return 0;
@@ -1355,9 +1355,8 @@ static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
 
 static __u64 pmu_format_max_value(const unsigned long *format)
 {
-	int w;
+	size_t w = bitmap_weight(format, PERF_PMU_FORMAT_BITS);
 
-	w = bitmap_weight(format, PERF_PMU_FORMAT_BITS);
 	if (!w)
 		return 0;
 	if (w < 64)
@@ -1872,7 +1871,7 @@ int perf_pmu__for_each_format(struct perf_pmu *pmu, void *state, pmu_format_call
 	if (!pmu->is_core)
 		return 0;
 
-	for (size_t i = 0; i < ARRAY_SIZE(terms); i++) {
+	for (int i = 0; i < (int)ARRAY_SIZE(terms); i++) {
 		int config = PERF_PMU_FORMAT_VALUE_CONFIG;
 
 		if (i < PERF_PMU_FORMAT_VALUE_CONFIG_END)
@@ -2329,7 +2328,7 @@ static void perf_pmu__compute_config_masks(struct perf_pmu *pmu)
 		return;
 
 	list_for_each_entry(format, &pmu->format, list)	{
-		unsigned int i;
+		size_t i;
 		__u64 *mask;
 
 		if (format->value >= PERF_PMU_FORMAT_VALUE_CONFIG_END)
diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
index b99292de7669..0b9071219376 100644
--- a/tools/perf/util/pmus.c
+++ b/tools/perf/util/pmus.c
@@ -59,7 +59,7 @@ static void pmu_read_sysfs(unsigned int to_read_pmus);
 
 size_t pmu_name_len_no_suffix(const char *str)
 {
-	int orig_len, len;
+	size_t orig_len, len;
 	bool has_hex_digits = false;
 
 	orig_len = len = strlen(str);
@@ -353,7 +353,7 @@ struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *pmu)
 static struct perf_pmu *perf_pmus__scan_skip_duplicates(struct perf_pmu *pmu)
 {
 	bool use_core_pmus = !pmu || pmu->is_core;
-	int last_pmu_name_len = 0;
+	size_t last_pmu_name_len = 0;
 	const char *last_pmu_name = (pmu && pmu->name) ? pmu->name : "";
 
 	if (!pmu) {
@@ -364,7 +364,7 @@ static struct perf_pmu *perf_pmus__scan_skip_duplicates(struct perf_pmu *pmu)
 
 	if (use_core_pmus) {
 		list_for_each_entry_continue(pmu, &core_pmus, list) {
-			int pmu_name_len = pmu_name_len_no_suffix(pmu->name ?: "");
+			size_t pmu_name_len = pmu_name_len_no_suffix(pmu->name ?: "");
 
 			if (last_pmu_name_len == pmu_name_len &&
 			    !strncmp(last_pmu_name, pmu->name ?: "", pmu_name_len))
@@ -376,7 +376,7 @@ static struct perf_pmu *perf_pmus__scan_skip_duplicates(struct perf_pmu *pmu)
 		pmu = list_prepare_entry(pmu, &other_pmus, list);
 	}
 	list_for_each_entry_continue(pmu, &other_pmus, list) {
-		int pmu_name_len = pmu_name_len_no_suffix(pmu->name ?: "");
+		size_t pmu_name_len = pmu_name_len_no_suffix(pmu->name ?: "");
 
 		if (last_pmu_name_len == pmu_name_len &&
 		    !strncmp(last_pmu_name, pmu->name ?: "", pmu_name_len))
@@ -581,7 +581,7 @@ static int build_format_string(void *state, const char *name, int config,
 			       const unsigned long *bits)
 {
 	struct build_format_string_args *args = state;
-	unsigned int num_bits;
+	size_t num_bits;
 	int ret1, ret2 = 0;
 
 	(void)config;
@@ -631,14 +631,14 @@ void perf_pmus__print_raw_pmu_events(const struct print_callbacks *print_cb, voi
 			.long_string = STRBUF_INIT,
 			.num_formats = 0,
 		};
-		int len = pmu_name_len_no_suffix(pmu->name);
+		size_t len = pmu_name_len_no_suffix(pmu->name);
 		const char *desc = "(see 'man perf-list' or 'man perf-record' on how to encode it)";
 
 		if (!pmu->is_core)
 			desc = NULL;
 
-		strbuf_addf(&format_args.short_string, "%.*s/", len, pmu->name);
-		strbuf_addf(&format_args.long_string, "%.*s/", len, pmu->name);
+		strbuf_addf(&format_args.short_string, "%.*s/", (int)len, pmu->name);
+		strbuf_addf(&format_args.long_string, "%.*s/", (int)len, pmu->name);
 		perf_pmu__for_each_format(pmu, &format_args, build_format_string);
 
 		if (format_args.num_formats > 3)
diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c
index 727a10e3f990..3f9367424440 100644
--- a/tools/perf/util/tool_pmu.c
+++ b/tools/perf/util/tool_pmu.c
@@ -103,7 +103,7 @@ enum tool_pmu_event evsel__tool_event(const struct evsel *evsel)
 
 const char *evsel__tool_pmu_event_name(const struct evsel *evsel)
 {
-	return tool_pmu__event_to_str(evsel->core.attr.config);
+	return tool_pmu__event_to_str((enum tool_pmu_event)evsel->core.attr.config);
 }
 
 static bool read_until_char(struct io *io, char e)
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 16/47] perf annotate powerpc: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (14 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 15/47] perf pmu: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 17/47] perf s390: " Ian Rogers
                   ` (30 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/arch/powerpc/annotate/instructions.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/arch/powerpc/annotate/instructions.c b/tools/perf/arch/powerpc/annotate/instructions.c
index ca567cfdcbdb..598dc10a1751 100644
--- a/tools/perf/arch/powerpc/annotate/instructions.c
+++ b/tools/perf/arch/powerpc/annotate/instructions.c
@@ -18,7 +18,7 @@ static struct ins_ops *powerpc__associate_instruction_ops(struct arch *arch, con
 
 	ops = &jump_ops;
 
-	i = strlen(name) - 1;
+	i = (int)strlen(name) - 1;
 	if (i < 0)
 		return NULL;
 
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 17/47] perf s390: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (15 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 16/47] perf annotate powerpc: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 18/47] perf cs-etm: " Ian Rogers
                   ` (29 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/util/s390-sample-raw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c
index 335217bb532b..7e5c1448ea6b 100644
--- a/tools/perf/util/s390-sample-raw.c
+++ b/tools/perf/util/s390-sample-raw.c
@@ -202,7 +202,7 @@ static void s390_cpumcfdg_dump(struct perf_pmu *pmu, struct perf_sample *sample)
 		color_fprintf(stdout, color, "    [%#08zx] Counterset:%d"
 			      " Counters:%d\n", offset, ce.set, ce.ctr);
 		for (i = 0, p = (u64 *)(cep + 1); i < ce.ctr; ++i, ++p) {
-			char *ev_name = get_counter_name(ce.set, i, pmu);
+			char *ev_name = get_counter_name(ce.set, (int)i, pmu);
 
 			color_fprintf(stdout, color,
 				      "\tCounter:%03zd %s Value:%#018"PRIx64"\n", i,
@@ -258,7 +258,7 @@ static void s390_pai_all_dump(struct evsel *evsel, struct perf_sample *sample)
 		p += sizeof(pai_data.event_val);
 		offset += sizeof(pai_data.event_val);
 
-		ev_name = get_counter_name(evsel->core.attr.config,
+		ev_name = get_counter_name((int)evsel->core.attr.config,
 					   pai_data.event_nr, evsel->pmu);
 		color_fprintf(stdout, color, "\tCounter:%03d %s Value:%#018"PRIx64"\n",
 			      pai_data.event_nr, ev_name ?: "<unknown>",
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 18/47] perf cs-etm: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (16 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 17/47] perf s390: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 19/47] perf stat: " Ian Rogers
                   ` (28 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/util/cs-etm-base.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/cs-etm-base.c b/tools/perf/util/cs-etm-base.c
index 4abe416e3feb..3aa1ccc9e452 100644
--- a/tools/perf/util/cs-etm-base.c
+++ b/tools/perf/util/cs-etm-base.c
@@ -101,7 +101,7 @@ static int cs_etm__print_cpu_metadata_v1(u64 *val, int *offset)
 
 	magic = val[i + CS_ETM_MAGIC];
 	/* total params to print is NR_PARAMS + common block size for v1 */
-	total_params = val[i + CS_ETM_NR_TRC_PARAMS] + CS_ETM_COMMON_BLK_MAX_V1;
+	total_params = (int)val[i + CS_ETM_NR_TRC_PARAMS] + CS_ETM_COMMON_BLK_MAX_V1;
 
 	if (magic == __perf_cs_etmv3_magic) {
 		for (j = 0; j < total_params; j++, i++) {
@@ -140,7 +140,7 @@ static void cs_etm__print_auxtrace_info(u64 *val, int num)
 {
 	int i, cpu = 0, version, err;
 
-	version = val[0];
+	version = (int)val[0];
 
 	for (i = 0; i < CS_HEADER_VERSION_MAX; i++)
 		fprintf(stdout, cs_etm_global_header_fmts[i], val[i]);
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 19/47] perf stat: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (17 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 18/47] perf cs-etm: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 20/47] perf dlfilter: " Ian Rogers
                   ` (27 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-stat.c      |  6 +++---
 tools/perf/util/metricgroup.c  | 15 +++++++--------
 tools/perf/util/stat-display.c | 10 +++++-----
 3 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 300b6393bb41..8c6bf194bba0 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -831,7 +831,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
 
 		l = strlen(counter->unit);
 		if (l > stat_config.unit_width)
-			stat_config.unit_width = l;
+			stat_config.unit_width = (unsigned int)l;
 
 		if (evsel__should_store_id(counter) &&
 		    evsel__store_ids(counter, evsel_list)) {
@@ -2099,7 +2099,7 @@ static int __cmd_record(const struct option stat_options[], struct opt_aggr_mode
 	session = perf_session__new(data, NULL);
 	if (IS_ERR(session)) {
 		pr_err("Perf session creation failed\n");
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 	}
 
 	init_features(session);
@@ -2281,7 +2281,7 @@ static int __cmd_report(int argc, const char **argv)
 
 	session = perf_session__new(&perf_stat.data, &perf_stat.tool);
 	if (IS_ERR(session))
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 
 	perf_stat.session  = session;
 	stat_config.output = stderr;
diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 46920ebadfd1..1e07dcaed3d7 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -256,12 +256,10 @@ static struct metric *metric__new(const struct pmu_metric *pm,
 	return NULL;
 }
 
-static bool contains_metric_id(struct evsel **metric_events, int num_events,
+static bool contains_metric_id(struct evsel **metric_events, size_t num_events,
 			       const char *metric_id)
 {
-	int i;
-
-	for (i = 0; i < num_events; i++) {
+	for (size_t i = 0; i < num_events; i++) {
 		if (!strcmp(evsel__metric_id(metric_events[i]), metric_id))
 			return true;
 	}
@@ -355,7 +353,7 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids,
 
 static bool match_metric(const char *metric_or_groups, const char *sought)
 {
-	int len;
+	size_t len;
 	char *m;
 
 	if (!sought)
@@ -570,7 +568,7 @@ static int encode_metric_id(struct strbuf *sb, const char *x)
 			if (ret)
 				break;
 
-			ret = strbuf_addch(sb, '0' + (c - code_characters));
+			ret = strbuf_addch(sb, '0' + (int)(c - code_characters));
 			if (ret)
 				break;
 		} else {
@@ -1145,7 +1143,8 @@ static int metric_list_cmp(void *priv __maybe_unused, const struct list_head *l,
 	const struct metric *left = container_of(l, struct metric, nd);
 	const struct metric *right = container_of(r, struct metric, nd);
 	struct expr_id_data *data;
-	int i, left_count, right_count;
+	int i;
+	size_t left_count, right_count;
 
 	left_count = hashmap__size(left->pctx->ids);
 	tool_pmu__for_each_event(i) {
@@ -1159,7 +1158,7 @@ static int metric_list_cmp(void *priv __maybe_unused, const struct list_head *l,
 			right_count--;
 	}
 
-	return right_count - left_count;
+	return (int)right_count - (int)left_count;
 }
 
 /**
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index e852ac0d9847..0aa172cf5e39 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -622,7 +622,7 @@ static void print_metric_only(struct perf_stat_config *config,
 	struct outstate *os = ctx;
 	FILE *out = os->fh;
 	char buf[1024], str[1024];
-	unsigned mlen = config->metric_only_len;
+	size_t mlen = config->metric_only_len;
 	const char *color = metric_threshold_classify__color(thresh);
 
 	if (!valid_only_metric(unit))
@@ -635,7 +635,7 @@ static void print_metric_only(struct perf_stat_config *config,
 		mlen += strlen(color) + sizeof(PERF_COLOR_RESET) - 1;
 
 	color_snprintf(str, sizeof(str), color ?: "", fmt ?: "", val);
-	fprintf(out, "%*s ", mlen, str);
+	fprintf(out, "%*s ", (int)mlen, str);
 	os->first = false;
 }
 
@@ -954,7 +954,7 @@ static void evsel__uniquify_counter(struct evsel *counter)
 
 	config = strchr(name, '/');
 	if (config) {
-		int len = config - name;
+		int len = (int)(config - name);
 
 		if (config[1] == '/') {
 			/* case: event// */
@@ -967,7 +967,7 @@ static void evsel__uniquify_counter(struct evsel *counter)
 		config = strchr(name, ':');
 		if (config) {
 			/* case: event:.. */
-			int len = config - name;
+			int len = (int)(config - name);
 
 			ret = asprintf(&new_name, "%s/%.*s/%s", pmu_name, len, name, config + 1);
 		} else {
@@ -1493,7 +1493,7 @@ static int get_precision(double num)
 	if (num > 1)
 		return 0;
 
-	return lround(ceil(-log10(num)));
+	return (int)lround(ceil(-log10(num)));
 }
 
 static void print_table(struct perf_stat_config *config,
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 20/47] perf dlfilter: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (18 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 19/47] perf stat: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 21/47] perf demangle: " Ian Rogers
                   ` (26 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/dlfilters/dlfilter-test-api-v0.c |  4 ++--
 tools/perf/util/dlfilter.c                  | 10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/perf/dlfilters/dlfilter-test-api-v0.c b/tools/perf/dlfilters/dlfilter-test-api-v0.c
index 4ca2d7b2ea6c..bf2a1a7b3c71 100644
--- a/tools/perf/dlfilters/dlfilter-test-api-v0.c
+++ b/tools/perf/dlfilters/dlfilter-test-api-v0.c
@@ -166,10 +166,10 @@ int start(void **data, void *ctx)
 
 	CHECK(dlargc == 6);
 	CHECK(!strcmp(dlargv[0], "first"));
-	verbose = strtol(dlargv[1], NULL, 0);
+	verbose = (int)strtol(dlargv[1], NULL, 0);
 	d->ip = strtoull(dlargv[2], NULL, 0);
 	d->addr = strtoull(dlargv[3], NULL, 0);
-	d->do_early = strtol(dlargv[4], NULL, 0);
+	d->do_early = (int)strtol(dlargv[4], NULL, 0);
 	CHECK(!strcmp(dlargv[5], "last"));
 
 	pr_debug("%s API\n", __func__);
diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c
index ddacef881af2..0e513ac7feae 100644
--- a/tools/perf/util/dlfilter.c
+++ b/tools/perf/util/dlfilter.c
@@ -38,7 +38,7 @@ static void al_to_d_al(struct addr_location *al, struct perf_dlfilter_al *d_al)
 		else
 			d_al->dso = dso__name(dso);
 		d_al->is_64_bit = dso__is_64_bit(dso);
-		d_al->buildid_size = dso__bid(dso)->size;
+		d_al->buildid_size = (__u32)dso__bid(dso)->size;
 		d_al->buildid = dso__bid(dso)->data;
 	} else {
 		d_al->dso = NULL;
@@ -51,9 +51,9 @@ static void al_to_d_al(struct addr_location *al, struct perf_dlfilter_al *d_al)
 		d_al->sym_start = sym->start;
 		d_al->sym_end = sym->end;
 		if (al->addr < sym->end)
-			d_al->symoff = al->addr - sym->start;
+			d_al->symoff = (__u32)(al->addr - sym->start);
 		else if (al->map)
-			d_al->symoff = al->addr - map__start(al->map) - sym->start;
+			d_al->symoff = (__u32)(al->addr - map__start(al->map) - sym->start);
 		else
 			d_al->symoff = 0;
 		d_al->sym_binding = sym->binding;
@@ -290,9 +290,9 @@ static __s32 code_read(__u64 ip, struct map *map, struct machine *machine, void
 	u64 offset = map__map_ip(map, ip);
 
 	if (ip + len >= map__end(map))
-		len = map__end(map) - ip;
+		len = (__u32)(map__end(map) - ip);
 
-	return dso__data_read_offset(map__dso(map), machine, offset, buf, len);
+	return (__s32)dso__data_read_offset(map__dso(map), machine, offset, buf, len);
 }
 
 static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 21/47] perf demangle: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (19 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 20/47] perf dlfilter: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 22/47] perf annotate: " Ian Rogers
                   ` (25 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/util/demangle-java.c  | 4 ++--
 tools/perf/util/demangle-ocaml.c | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/demangle-java.c b/tools/perf/util/demangle-java.c
index ddf33d58bcd3..ee20f4d08765 100644
--- a/tools/perf/util/demangle-java.c
+++ b/tools/perf/util/demangle-java.c
@@ -42,9 +42,9 @@ static const char *base_types['Z' - 'A' + 1] = {
  *	error  : NULL
  */
 static char *
-__demangle_java_sym(const char *str, const char *end, char *buf, int maxlen, int mode)
+__demangle_java_sym(const char *str, const char *end, char *buf, size_t maxlen, int mode)
 {
-	int rlen = 0;
+	size_t rlen = 0;
 	int array = 0;
 	int narg = 0;
 	const char *q;
diff --git a/tools/perf/util/demangle-ocaml.c b/tools/perf/util/demangle-ocaml.c
index 9d707bb60b4b..25fe755df5ab 100644
--- a/tools/perf/util/demangle-ocaml.c
+++ b/tools/perf/util/demangle-ocaml.c
@@ -30,8 +30,7 @@ ocaml_demangle_sym(const char *sym)
 {
 	char *result;
 	int j = 0;
-	int i;
-	int len;
+	size_t i, len;
 
 	if (!ocaml_is_mangled(sym)) {
 		return NULL;
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 22/47] perf annotate: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (20 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 21/47] perf demangle: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 23/47] perf report: " Ian Rogers
                   ` (24 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-annotate.c |  4 ++--
 tools/perf/util/annotate.c    | 22 +++++++++++-----------
 tools/perf/util/disasm.c      | 11 ++++++-----
 3 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 9833c2c82a2f..97943a12b6c9 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -157,7 +157,7 @@ static void process_branch_stack(struct branch_stack *bs, struct addr_location *
 	if (!bi)
 		return;
 
-	for (i = bs->nr - 1; i >= 0; i--) {
+	for (i = (int)bs->nr - 1; i >= 0; i--) {
 		/*
 		 * XXX filter against symbol
 		 */
@@ -880,7 +880,7 @@ int cmd_annotate(int argc, const char **argv)
 
 	annotate.session = perf_session__new(&data, &annotate.tool);
 	if (IS_ERR(annotate.session))
-		return PTR_ERR(annotate.session);
+		return (int)PTR_ERR(annotate.session);
 
 	annotate.session->itrace_synth_opts = &itrace_synth_opts;
 
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 264a212b47df..055f3da1b95b 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -337,7 +337,8 @@ static int symbol__account_br_cntr(struct annotated_branch *branch,
 	unsigned int base = evsel__leader(evsel)->br_cntr_idx;
 	unsigned int off = offset * evsel->evlist->nr_br_cntr;
 	u64 *branch_br_cntr = branch->br_cntr;
-	unsigned int i, mask, width;
+	unsigned int i, width;
+	u64 mask;
 
 	if (!br_cntr || !branch_br_cntr)
 		return 0;
@@ -360,7 +361,7 @@ static int symbol__account_cycles(u64 addr, u64 start, struct symbol *sym,
 				  u64 br_cntr)
 {
 	struct annotated_branch *branch;
-	unsigned offset;
+	unsigned int offset;
 	int ret;
 
 	if (sym == NULL)
@@ -377,7 +378,7 @@ static int symbol__account_cycles(u64 addr, u64 start, struct symbol *sym,
 		if (start >= addr)
 			start = 0;
 	}
-	offset = addr - sym->start;
+	offset = (unsigned int)(addr - sym->start);
 	ret = __symbol__account_cycles(branch->cycles_hist,
 					start ? start - sym->start : 0,
 					offset, cycles,
@@ -1563,7 +1564,7 @@ static int annotation__max_ins_name(struct annotation *notes)
 		if (al->offset == -1)
 			continue;
 
-		len = strlen(disasm_line(al)->ins.name);
+		len = (int)strlen(disasm_line(al)->ins.name);
 		if (max_name < len)
 			max_name = len;
 	}
@@ -2183,20 +2184,20 @@ static int annotation_options__add_disassemblers_str(struct annotation_options *
 {
 	while (str && *str != '\0') {
 		const char *comma = strchr(str, ',');
-		int len = comma ? comma - str : (int)strlen(str);
+		size_t len = comma ? (size_t)(comma - str) : strlen(str);
 		bool match = false;
 
 		for (u8 i = 0; i < ARRAY_SIZE(perf_disassembler__strs); i++) {
 			const char *dis_str = perf_disassembler__strs[i];
 
-			if (len == (int)strlen(dis_str) && !strncmp(str, dis_str, len)) {
+			if (len == strlen(dis_str) && !strncmp(str, dis_str, len)) {
 				annotation_options__add_disassembler(options, i);
 				match = true;
 				break;
 			}
 		}
 		if (!match) {
-			pr_err("Invalid disassembler '%.*s'\n", len, str);
+			pr_err("Invalid disassembler '%.*s'\n", (int)len, str);
 			return -1;
 		}
 		str = comma ? comma + 1 : NULL;
@@ -2406,7 +2407,7 @@ static int extract_reg_offset(struct arch *arch, const char *str,
 			str++;
 	}
 
-	op_loc->offset = strtol(str, &p, 0);
+	op_loc->offset = (int)strtol(str, &p, 0);
 
 	p = strchr(p, arch->objdump.register_char);
 	if (p == NULL)
@@ -2516,8 +2517,7 @@ int annotate_get_insn_location(struct arch *arch, struct disasm_line *dl,
 				/* FIXME: Handle other segment registers */
 				if (!strncmp(insn_str, "%gs:", 4)) {
 					op_loc->segment = INSN_SEG_X86_GS;
-					op_loc->offset = strtol(insn_str + 4,
-								&p, 0);
+					op_loc->offset = (int)strtol(insn_str + 4, &p, 0);
 					if (p && p != insn_str + 4)
 						op_loc->imm = true;
 					continue;
@@ -2531,7 +2531,7 @@ int annotate_get_insn_location(struct arch *arch, struct disasm_line *dl,
 			if (*s == arch->objdump.register_char)
 				op_loc->reg1 = get_dwarf_regnum(s, arch->e_machine, arch->e_flags);
 			else if (*s == arch->objdump.imm_char) {
-				op_loc->offset = strtol(s + 1, &p, 0);
+				op_loc->offset = (int)strtol(s + 1, &p, 0);
 				if (p && p != s + 1)
 					op_loc->imm = true;
 			}
diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
index 8f0eb56c6fc6..7e24851a3934 100644
--- a/tools/perf/util/disasm.c
+++ b/tools/perf/util/disasm.c
@@ -856,7 +856,7 @@ static int ins__cmp(const void *a, const void *b)
 
 static void ins__sort(struct arch *arch)
 {
-	const int nmemb = arch->nr_instructions;
+	const size_t nmemb = arch->nr_instructions;
 
 	qsort(arch->instructions, nmemb, sizeof(struct ins), ins__cmp);
 }
@@ -864,7 +864,7 @@ static void ins__sort(struct arch *arch)
 static struct ins_ops *__ins__find(struct arch *arch, const char *name, struct disasm_line *dl)
 {
 	struct ins *ins;
-	const int nmemb = arch->nr_instructions;
+	const size_t nmemb = arch->nr_instructions;
 
 	if (arch__is(arch, "powerpc")) {
 		/*
@@ -1263,7 +1263,7 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil
 	char *build_id_filename;
 	char *build_id_path = NULL;
 	char *pos;
-	int len;
+	size_t len;
 
 	if (dso__symtab_type(dso) == DSO_BINARY_TYPE__KALLSYMS &&
 	    !dso__is_kcore(dso))
@@ -1754,7 +1754,8 @@ static int symbol__disassemble_raw(char *filename, struct symbol *sym,
 	u64 end = map__rip_2objdump(map, sym->end);
 	u64 len = end - start;
 	u64 offset;
-	int i, count;
+	int i;
+	ssize_t count;
 	u8 *buf = NULL;
 	char disasm_buf[512];
 	struct disasm_line *dl;
@@ -1823,7 +1824,7 @@ static int symbol__disassemble_raw(char *filename, struct symbol *sym,
 
 out:
 	free(buf);
-	return count < 0 ? count : 0;
+	return count < 0 ? (int)count : 0;
 
 err:
 	count = -1;
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 23/47] perf report: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (21 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 22/47] perf annotate: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 24/47] perf help: " Ian Rogers
                   ` (23 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-report.c |  4 ++--
 tools/perf/util/callchain.c | 12 ++++++------
 tools/perf/util/callchain.h |  2 +-
 tools/perf/util/srccode.c   |  6 +++---
 tools/perf/util/srcline.c   |  2 +-
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index f0299c7ee025..9c10209d7b57 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -800,7 +800,7 @@ static int count_lost_samples_event(const struct perf_tool *tool,
 	evsel = evlist__id2evsel(rep->session->evlist, sample->id);
 	if (evsel) {
 		struct hists *hists = evsel__hists(evsel);
-		u32 count = event->lost_samples.lost;
+		u32 count = (u32)event->lost_samples.lost;
 
 		if (event->header.misc & PERF_RECORD_MISC_LOST_SAMPLES_BPF)
 			hists__inc_nr_dropped_samples(hists, count);
@@ -1602,7 +1602,7 @@ int cmd_report(int argc, const char **argv)
 
 	session = perf_session__new(&data, &report.tool);
 	if (IS_ERR(session)) {
-		ret = PTR_ERR(session);
+		ret = (int)PTR_ERR(session);
 		goto exit;
 	}
 
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index d7b7eef740b9..c3206b9d7b52 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -214,7 +214,7 @@ __parse_callchain_report_opt(const char *arg, bool allow_record_opt)
 
 			if (get_stack_size(tok, &size) < 0)
 				return -1;
-			callchain_param.dump_size = size;
+			callchain_param.dump_size = (u32)size;
 			try_stack_size = false;
 		} else if (!minpcnt_set) {
 			/* try to get the min percent */
@@ -224,7 +224,7 @@ __parse_callchain_report_opt(const char *arg, bool allow_record_opt)
 			minpcnt_set = true;
 		} else {
 			/* try print limit at last */
-			callchain_param.print_limit = strtoul(tok, &endptr, 0);
+			callchain_param.print_limit = (u32)strtoul(tok, &endptr, 0);
 			if (tok == endptr)
 				return -1;
 		}
@@ -295,7 +295,7 @@ int parse_callchain_record(const char *arg, struct callchain_param *param)
 				unsigned long size = 0;
 
 				ret = get_stack_size(tok, &size);
-				param->dump_size = size;
+				param->dump_size = (u32)size;
 			}
 		} else if (!strncmp(name, "lbr", sizeof("lbr"))) {
 			if (!strtok_r(NULL, ",", &saveptr)) {
@@ -332,7 +332,7 @@ int perf_callchain_config(const char *var, const char *value)
 		int ret;
 
 		ret = get_stack_size(value, &size);
-		callchain_param.dump_size = size;
+		callchain_param.dump_size = (u32)size;
 
 		return ret;
 	}
@@ -817,7 +817,7 @@ split_add_child(struct callchain_node *parent,
 {
 	struct callchain_node *new;
 	struct list_head *old_tail;
-	unsigned int idx_total = idx_parents + idx_local;
+	u64 idx_total = idx_parents + idx_local;
 
 	/* split */
 	new = create_child(parent, true);
@@ -1027,7 +1027,7 @@ merge_chain_branch(struct callchain_cursor *cursor,
 	struct callchain_node *child;
 	struct callchain_list *list, *next_list;
 	struct rb_node *n;
-	int old_pos = cursor->nr;
+	u64 old_pos = cursor->nr;
 	int err = 0;
 
 	list_for_each_entry_safe(list, next_list, &src->val, list) {
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 86ed9e4d04f9..7a2abff6d0a5 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -65,7 +65,7 @@ struct callchain_node {
 	struct rb_node		rb_node;    /* to sort nodes in an output tree */
 	struct rb_root		rb_root_in; /* input tree of children */
 	struct rb_root		rb_root;    /* sorted output tree of children */
-	unsigned int		val_nr;
+	u64			val_nr;
 	unsigned int		count;
 	unsigned int		children_count;
 	u64			hit;
diff --git a/tools/perf/util/srccode.c b/tools/perf/util/srccode.c
index 476e99896d5e..f5f8cdfd00c1 100644
--- a/tools/perf/util/srccode.c
+++ b/tools/perf/util/srccode.c
@@ -37,7 +37,7 @@ static LIST_HEAD(srcfile_list);
 static long map_total_sz;
 static int num_srcfiles;
 
-static int countlines(char *map, int maplen)
+static int countlines(char *map, size_t maplen)
 {
 	int numl;
 	char *end = map + maplen;
@@ -136,7 +136,7 @@ static struct srcfile *find_srcfile(char *fn)
 	h->lines = calloc(h->numlines, sizeof(char *));
 	if (!h->lines)
 		goto out_map;
-	fill_lines(h->lines, h->numlines, h->map, h->maplen);
+	fill_lines(h->lines, h->numlines, h->map, (int)h->maplen);
 	list_add(&h->nd, &srcfile_list);
 	hlist_add_head(&h->hash_nd, &srcfile_htab[hval]);
 	map_total_sz += h->maplen;
@@ -166,6 +166,6 @@ char *find_sourceline(char *fn, unsigned line, int *lenp)
 	if (!l)
 		return NULL;
 	p = memchr(l, '\n', sf->map + sf->maplen - l);
-	*lenp = p - l;
+	*lenp = (int)(p - l);
 	return l;
 }
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index f32d0d4f4bc9..b2003c5490a2 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -443,7 +443,7 @@ static int filename_split(char *filename, unsigned int *line_nr)
 	sep = strchr(filename, ':');
 	if (sep) {
 		*sep++ = '\0';
-		*line_nr = strtoul(sep, NULL, 0);
+		*line_nr = (unsigned int)strtoul(sep, NULL, 0);
 		return 1;
 	}
 	pr_debug("addr2line missing ':' in filename split\n");
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 24/47] perf help: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (22 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 23/47] perf report: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 25/47] perf hisi-ptt: " Ian Rogers
                   ` (22 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-help.c          |  4 ++--
 tools/perf/util/help-unknown-cmd.c | 14 ++++++++------
 tools/perf/util/levenshtein.c      | 18 +++++++++---------
 3 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 7be6fb6df595..05151c68191f 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -301,7 +301,7 @@ static struct cmdnames main_cmds, other_cmds;
 
 void list_common_cmds_help(void)
 {
-	unsigned int i, longest = 0;
+	size_t i, longest = 0;
 
 	for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
 		if (longest < strlen(common_cmds[i].name))
@@ -310,7 +310,7 @@ void list_common_cmds_help(void)
 
 	puts(" The most commonly used perf commands are:");
 	for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
-		printf("   %-*s   ", longest, common_cmds[i].name);
+		printf("   %-*s   ", (int)longest, common_cmds[i].name);
 		puts(common_cmds[i].help);
 	}
 }
diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c
index a0a46e34f8d1..f0a0b8c13a92 100644
--- a/tools/perf/util/help-unknown-cmd.c
+++ b/tools/perf/util/help-unknown-cmd.c
@@ -24,14 +24,15 @@ static int levenshtein_compare(const void *p1, const void *p2)
 {
 	const struct cmdname *const *c1 = p1, *const *c2 = p2;
 	const char *s1 = (*c1)->name, *s2 = (*c2)->name;
-	int l1 = (*c1)->len;
-	int l2 = (*c2)->len;
-	return l1 != l2 ? l1 - l2 : strcmp(s1, s2);
+	ssize_t l1 = (*c1)->len;
+	ssize_t l2 = (*c2)->len;
+
+	return l1 != l2 ? (int)(l1 - l2) : (int)strcmp(s1, s2);
 }
 
 static int add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
 {
-	unsigned int i, nr = cmds->cnt + old->cnt;
+	size_t nr = cmds->cnt + old->cnt;
 	void *tmp;
 
 	if (nr > cmds->alloc) {
@@ -45,7 +46,7 @@ static int add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
 			return -1;
 		cmds->names = tmp;
 	}
-	for (i = 0; i < old->cnt; i++)
+	for (size_t i = 0; i < old->cnt; i++)
 		cmds->names[cmds->cnt++] = old->names[i];
 	zfree(&old->names);
 	old->cnt = 0;
@@ -54,7 +55,8 @@ static int add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
 
 const char *help_unknown_cmd(const char *cmd, struct cmdnames *main_cmds)
 {
-	unsigned int i, n = 0, best_similarity = 0;
+	unsigned int i, n = 0;
+	size_t best_similarity = 0;
 	struct cmdnames other_cmds;
 
 	memset(&other_cmds, 0, sizeof(other_cmds));
diff --git a/tools/perf/util/levenshtein.c b/tools/perf/util/levenshtein.c
index 6a6712635aa4..f6912b848c4a 100644
--- a/tools/perf/util/levenshtein.c
+++ b/tools/perf/util/levenshtein.c
@@ -44,19 +44,19 @@
 int levenshtein(const char *string1, const char *string2,
 		int w, int s, int a, int d)
 {
-	int len1 = strlen(string1), len2 = strlen(string2);
+	size_t len1 = strlen(string1), len2 = strlen(string2);
 	int *row0 = malloc(sizeof(int) * (len2 + 1));
 	int *row1 = malloc(sizeof(int) * (len2 + 1));
 	int *row2 = malloc(sizeof(int) * (len2 + 1));
-	int i, j;
+	int ret;
 
-	for (j = 0; j <= len2; j++)
-		row1[j] = j * a;
-	for (i = 0; i < len1; i++) {
+	for (size_t j = 0; j <= len2; j++)
+		row1[j] = (int)j * a;
+	for (size_t i = 0; i < len1; i++) {
 		int *dummy;
 
-		row2[0] = (i + 1) * d;
-		for (j = 0; j < len2; j++) {
+		row2[0] = ((int)i + 1) * d;
+		for (size_t j = 0; j < len2; j++) {
 			/* substitution */
 			row2[j + 1] = row1[j] + s * (string1[i] != string2[j]);
 			/* swap */
@@ -78,10 +78,10 @@ int levenshtein(const char *string1, const char *string2,
 		row2 = dummy;
 	}
 
-	i = row1[len2];
+	ret = row1[len2];
 	free(row0);
 	free(row1);
 	free(row2);
 
-	return i;
+	return ret;
 }
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 25/47] perf hisi-ptt: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (23 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 24/47] perf help: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 26/47] perf probe: " Ian Rogers
                   ` (21 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/util/hisi-ptt.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/hisi-ptt.c b/tools/perf/util/hisi-ptt.c
index e4cc4785f744..978f5781c990 100644
--- a/tools/perf/util/hisi-ptt.c
+++ b/tools/perf/util/hisi-ptt.c
@@ -59,7 +59,7 @@ static void hisi_ptt_dump(struct hisi_ptt *ptt __maybe_unused,
 		      len);
 
 	while (len > 0) {
-		pkt_len = hisi_ptt_pkt_desc(buf, pos, type);
+		pkt_len = hisi_ptt_pkt_desc(buf, (int)pos, type);
 		if (!pkt_len)
 			color_fprintf(stdout, color, " Bad packet!\n");
 
@@ -91,10 +91,10 @@ static int hisi_ptt_process_auxtrace_event(struct perf_session *session,
 	struct hisi_ptt *ptt = container_of(session->auxtrace, struct hisi_ptt,
 					    auxtrace);
 	int fd = perf_data__fd(session->data);
-	int size = event->auxtrace.size;
+	u64 size = event->auxtrace.size;
 	void *data = malloc(size);
 	off_t data_offset;
-	int err;
+	ssize_t err;
 
 	if (!data)
 		return -errno;
@@ -174,7 +174,7 @@ int hisi_ptt_process_auxtrace_info(union perf_event *event,
 	ptt->session = session;
 	ptt->machine = &session->machines.host; /* No kvm support */
 	ptt->auxtrace_type = auxtrace_info->type;
-	ptt->pmu_type = auxtrace_info->priv[0];
+	ptt->pmu_type = (unsigned int)auxtrace_info->priv[0];
 
 	ptt->auxtrace.process_event = hisi_ptt_process_event;
 	ptt->auxtrace.process_auxtrace_event = hisi_ptt_process_auxtrace_event;
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 26/47] perf probe: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (24 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 25/47] perf hisi-ptt: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 27/47] perf kwork: " Ian Rogers
                   ` (20 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/util/probe-event.c | 13 +++++++------
 tools/perf/util/probe-file.c  | 12 +++++++-----
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 307ad6242a4e..55bc68e5bd97 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1336,7 +1336,7 @@ static int parse_line_num(char **ptr, int *val, const char *what)
 	const char *start = *ptr;
 
 	errno = 0;
-	*val = strtol(*ptr, ptr, 0);
+	*val = (int)strtol(*ptr, ptr, 0);
 	if (errno || *ptr == start) {
 		semantic_error("'%s' is not a valid number.\n", what);
 		return -EINVAL;
@@ -1620,7 +1620,7 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
 		}
 		switch (c) {
 		case ':':	/* Line number */
-			pp->line = strtoul(arg, &tmp, 0);
+			pp->line = (int)strtoul(arg, &tmp, 0);
 			if (*tmp != '\0') {
 				semantic_error("There is non-digit char"
 					       " in line number.\n");
@@ -2065,8 +2065,8 @@ char *synthesize_perf_probe_arg(struct perf_probe_arg *pa)
 static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
 {
 	struct strbuf buf;
-	char *tmp, *ret = NULL;
-	int len, err = 0;
+	char *ret = NULL;
+	int err = 0;
 
 	if (strbuf_init(&buf, 64) < 0)
 		return NULL;
@@ -2084,8 +2084,9 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
 			goto out;
 	}
 	if (pp->file) {
-		tmp = pp->file;
-		len = strlen(tmp);
+		char *tmp = pp->file;
+		size_t len = strlen(tmp);
+
 		if (len > 30) {
 			tmp = strchr(pp->file + len - 30, '/');
 			tmp = tmp ? tmp + 1 : pp->file + len - 30;
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index ec8ac242fedb..2d84002710f3 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -167,7 +167,7 @@ int probe_file__open_both(int *kfd, int *ufd, int flag)
 /* Get raw string list of current kprobe_events  or uprobe_events */
 struct strlist *probe_file__get_rawlist(int fd)
 {
-	int ret, idx, fddup;
+	int ret, fddup;
 	FILE *fp;
 	char buf[MAX_CMDLEN];
 	char *p;
@@ -189,6 +189,8 @@ struct strlist *probe_file__get_rawlist(int fd)
 		goto out_close_fddup;
 
 	while (!feof(fp)) {
+		size_t idx;
+
 		p = fgets(buf, MAX_CMDLEN, fp);
 		if (!p)
 			break;
@@ -307,7 +309,7 @@ static int __del_trace_probe_event(int fd, struct str_node *ent)
 	*p = '/';
 
 	pr_debug("Writing event: %s\n", buf);
-	ret = write(fd, buf, strlen(buf));
+	ret = (int)write(fd, buf, strlen(buf));
 	if (ret < 0) {
 		ret = -errno;
 		goto error;
@@ -962,7 +964,7 @@ static int probe_cache_entry__write(struct probe_cache_entry *entry, int fd)
 	iov[0].iov_base = (void *)prefix; iov[0].iov_len = 1;
 	iov[1].iov_base = entry->spev; iov[1].iov_len = strlen(entry->spev);
 	iov[2].iov_base = (void *)"\n"; iov[2].iov_len = 1;
-	ret = writev(fd, iov, 3);
+	ret = (int)writev(fd, iov, 3);
 	if (ret < (int)iov[1].iov_len + 2)
 		goto rollback;
 
@@ -970,7 +972,7 @@ static int probe_cache_entry__write(struct probe_cache_entry *entry, int fd)
 		iov[0].iov_base = (void *)snode->s;
 		iov[0].iov_len = strlen(snode->s);
 		iov[1].iov_base = (void *)"\n"; iov[1].iov_len = 1;
-		ret = writev(fd, iov, 2);
+		ret = (int)writev(fd, iov, 2);
 		if (ret < (int)iov[0].iov_len + 1)
 			goto rollback;
 	}
@@ -992,7 +994,7 @@ int probe_cache__commit(struct probe_cache *pcache)
 	int ret = 0;
 
 	/* TBD: if we do not update existing entries, skip it */
-	ret = lseek(pcache->fd, 0, SEEK_SET);
+	ret = (int)lseek(pcache->fd, 0, SEEK_SET);
 	if (ret < 0)
 		goto out;
 
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 27/47] perf kwork: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (25 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 26/47] perf probe: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 28/47] perf buildid: " Ian Rogers
                   ` (19 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-kwork.c      | 11 +++++------
 tools/perf/util/bpf_kwork_top.c |  2 +-
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c
index c41a68d073de..cc5488cb98e4 100644
--- a/tools/perf/builtin-kwork.c
+++ b/tools/perf/builtin-kwork.c
@@ -1574,8 +1574,7 @@ static void top_print_per_cpu_load(struct perf_kwork *kwork)
 		load = stat->cpus_runtime[i].load;
 		if (test_bit(i, stat->all_cpus_bitmap) && total) {
 			load_ratio = load * 10000 / total;
-			load_width = PRINT_CPU_USAGE_HIST_WIDTH *
-				load_ratio / 10000;
+			load_width = (int)(PRINT_CPU_USAGE_HIST_WIDTH * load_ratio / 10000);
 
 			printf("%%Cpu%-*d[%.*s%.*s %*.*f%%]\n",
 			       PRINT_CPU_WIDTH, i,
@@ -1595,7 +1594,7 @@ static void top_print_cpu_usage(struct perf_kwork *kwork)
 	u64 idle_time = stat->cpus_runtime[MAX_NR_CPUS].idle;
 	u64 hardirq_time = stat->cpus_runtime[MAX_NR_CPUS].irq;
 	u64 softirq_time = stat->cpus_runtime[MAX_NR_CPUS].softirq;
-	int cpus_nr = bitmap_weight(stat->all_cpus_bitmap, MAX_NR_CPUS);
+	int cpus_nr = (int)bitmap_weight(stat->all_cpus_bitmap, MAX_NR_CPUS);
 	u64 cpus_total_time = stat->cpus_runtime[MAX_NR_CPUS].total;
 
 	printf("Total  : %*.*f ms, %d cpus\n",
@@ -1801,7 +1800,7 @@ static int perf_kwork__read_events(struct perf_kwork *kwork)
 	session = perf_session__new(&data, &kwork->tool);
 	if (IS_ERR(session)) {
 		pr_debug("Error creating perf session\n");
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 	}
 
 	symbol__init(&session->header.env);
@@ -2088,8 +2087,8 @@ static void top_calc_cpu_usage(struct perf_kwork *kwork)
 
 		top_subtract_irq_runtime(kwork, work);
 
-		work->cpu_usage = work->total_runtime * 10000 /
-			stat->cpus_runtime[work->cpu].total;
+		work->cpu_usage = (u32)(work->total_runtime *
+					10000 / stat->cpus_runtime[work->cpu].total);
 
 		top_calc_idle_time(kwork, work);
 next:
diff --git a/tools/perf/util/bpf_kwork_top.c b/tools/perf/util/bpf_kwork_top.c
index b6f187dd9136..808d0c84d26d 100644
--- a/tools/perf/util/bpf_kwork_top.c
+++ b/tools/perf/util/bpf_kwork_top.c
@@ -219,7 +219,7 @@ static void read_task_info(struct kwork_work *work)
 	int fd;
 	struct task_data data;
 	struct task_key key = {
-		.pid = work->id,
+		.pid = (__u32)work->id,
 		.cpu = work->cpu,
 	};
 
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 28/47] perf buildid: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (26 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 27/47] perf kwork: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 29/47] perf lock: " Ian Rogers
                   ` (18 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-buildid-cache.c | 2 +-
 tools/perf/builtin-buildid-list.c  | 2 +-
 tools/perf/util/build-id.c         | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index b0511d16aeb6..7f7ebd625ed6 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -450,7 +450,7 @@ int cmd_buildid_cache(int argc, const char **argv)
 
 		session = perf_session__new(&data, NULL);
 		if (IS_ERR(session))
-			return PTR_ERR(session);
+			return (int)PTR_ERR(session);
 	}
 
 	if (symbol__init(session ? &session->header.env : NULL) < 0)
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index 52dfacaff8e3..ef84d1adb98f 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -109,7 +109,7 @@ static int perf_session__list_build_ids(bool force, bool with_hits)
 
 	session = perf_session__new(&data, &build_id__mark_dso_hit_ops);
 	if (IS_ERR(session))
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 
 	/*
 	 * We take all buildids when the file contains AUX area tracing data
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index e763e8d99a43..6a3ae17b1ccf 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -81,7 +81,7 @@ int build_id__sprintf(const struct build_id *build_id, char *bf)
 		bid += 2;
 	}
 
-	return (bid - bf) + 1;
+	return (int)(bid - bf) + 1;
 }
 
 int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 29/47] perf lock: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (27 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 28/47] perf buildid: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 30/47] perf mem: " Ian Rogers
                   ` (17 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-lock.c             | 16 ++++++++--------
 tools/perf/util/bpf_lock_contention.c | 17 +++++++++--------
 2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 05e7bc30488a..0f7e627394aa 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -569,7 +569,7 @@ static int report_lock_acquire_event(struct evsel *evsel,
 	struct lock_seq_stat *seq;
 	const char *name = evsel__strval(evsel, sample, "name");
 	u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
-	int flag = evsel__intval(evsel, sample, "flags");
+	int flag = (int)evsel__intval(evsel, sample, "flags");
 	u64 key;
 	int ret;
 
@@ -837,7 +837,7 @@ static int get_symbol_name_offset(struct map *map, struct symbol *sym, u64 ip,
 	if (offset)
 		return scnprintf(buf, size, "%s+%#lx", sym->name, offset);
 	else
-		return strlcpy(buf, sym->name, size);
+		return (int)strlcpy(buf, sym->name, size);
 }
 static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sample,
 				  char *buf, int size)
@@ -968,7 +968,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel,
 	struct thread_stat *ts;
 	struct lock_seq_stat *seq;
 	u64 addr = evsel__intval(evsel, sample, "lock_addr");
-	unsigned int flags = evsel__intval(evsel, sample, "flags");
+	unsigned int flags = (unsigned int)evsel__intval(evsel, sample, "flags");
 	u64 key;
 	int i, ret;
 	static bool kmap_loaded;
@@ -1303,7 +1303,7 @@ static void print_result(void)
 				struct thread *t;
 
 				/* st->addr contains tid of thread */
-				t = perf_session__findnew(session, st->addr);
+				t = perf_session__findnew(session, (int)st->addr);
 				name = thread__comm_str(t);
 			}
 
@@ -1638,7 +1638,7 @@ static void print_lock_stat_stdio(struct lock_contention *con, struct lock_stat
 		fprintf(lock_output, "  %10s   %s\n", get_type_flags_name(st->flags), st->name);
 		break;
 	case LOCK_AGGR_TASK:
-		pid = st->addr;
+		pid = (int)st->addr;
 		t = perf_session__findnew(session, pid);
 		fprintf(lock_output, "  %10d   %s\n",
 			pid, pid == -1 ? "Unknown" : thread__comm_str(t));
@@ -1691,7 +1691,7 @@ static void print_lock_stat_csv(struct lock_contention *con, struct lock_stat *s
 			fprintf(lock_output, "\n");
 		break;
 	case LOCK_AGGR_TASK:
-		pid = st->addr;
+		pid = (int)st->addr;
 		t = perf_session__findnew(session, pid);
 		fprintf(lock_output, "%d%s %s\n", pid, sep,
 			pid == -1 ? "Unknown" : thread__comm_str(t));
@@ -1870,7 +1870,7 @@ static int __cmd_report(bool display_info)
 	session = perf_session__new(&data, &eops);
 	if (IS_ERR(session)) {
 		pr_err("Initializing perf session failed\n");
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 	}
 
 	symbol_conf.allow_aliases = true;
@@ -2023,7 +2023,7 @@ static int __cmd_contention(int argc, const char **argv)
 	session = perf_session__new(use_bpf ? NULL : &data, &eops);
 	if (IS_ERR(session)) {
 		pr_err("Initializing perf session failed\n");
-		err = PTR_ERR(session);
+		err = (int)PTR_ERR(session);
 		session = NULL;
 		goto out_delete;
 	}
diff --git a/tools/perf/util/bpf_lock_contention.c b/tools/perf/util/bpf_lock_contention.c
index 5af8f6d1bc95..5a7a820000d4 100644
--- a/tools/perf/util/bpf_lock_contention.c
+++ b/tools/perf/util/bpf_lock_contention.c
@@ -54,7 +54,7 @@ static void check_slab_cache_iter(struct lock_contention *con)
 
 	has_slab_iter = true;
 
-	bpf_map__set_max_entries(skel->maps.slab_caches, con->map_nr_entries);
+	bpf_map__set_max_entries(skel->maps.slab_caches, (__u32)con->map_nr_entries);
 out:
 	btf__free(btf);
 }
@@ -123,23 +123,24 @@ int lock_contention_prepare(struct lock_contention *con)
 	}
 
 	bpf_map__set_value_size(skel->maps.stacks, con->max_stack * sizeof(u64));
-	bpf_map__set_max_entries(skel->maps.lock_stat, con->map_nr_entries);
-	bpf_map__set_max_entries(skel->maps.tstamp, con->map_nr_entries);
+	bpf_map__set_max_entries(skel->maps.lock_stat, (__u32)con->map_nr_entries);
+	bpf_map__set_max_entries(skel->maps.tstamp, (__u32)con->map_nr_entries);
 
 	if (con->aggr_mode == LOCK_AGGR_TASK)
-		bpf_map__set_max_entries(skel->maps.task_data, con->map_nr_entries);
+		bpf_map__set_max_entries(skel->maps.task_data, (__u32)con->map_nr_entries);
 	else
 		bpf_map__set_max_entries(skel->maps.task_data, 1);
 
 	if (con->save_callstack) {
-		bpf_map__set_max_entries(skel->maps.stacks, con->map_nr_entries);
+		bpf_map__set_max_entries(skel->maps.stacks, (__u32)con->map_nr_entries);
 		if (con->owner) {
 			bpf_map__set_value_size(skel->maps.stack_buf, con->max_stack * sizeof(u64));
 			bpf_map__set_key_size(skel->maps.owner_stacks,
 						con->max_stack * sizeof(u64));
-			bpf_map__set_max_entries(skel->maps.owner_stacks, con->map_nr_entries);
-			bpf_map__set_max_entries(skel->maps.owner_data, con->map_nr_entries);
-			bpf_map__set_max_entries(skel->maps.owner_stat, con->map_nr_entries);
+			bpf_map__set_max_entries(skel->maps.owner_stacks,
+						 (__u32)con->map_nr_entries);
+			bpf_map__set_max_entries(skel->maps.owner_data, (__u32)con->map_nr_entries);
+			bpf_map__set_max_entries(skel->maps.owner_stat, (__u32)con->map_nr_entries);
 			skel->rodata->max_stack = con->max_stack;
 		}
 	} else {
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 30/47] perf mem: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (28 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 29/47] perf lock: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 31/47] perf script: " Ian Rogers
                   ` (16 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-c2c.c     | 21 ++++++++++---------
 tools/perf/builtin-kmem.c    | 39 ++++++++++++++++++------------------
 tools/perf/builtin-mem.c     |  2 +-
 tools/perf/util/mem-events.c | 12 +++++------
 tools/perf/util/mem2node.c   |  2 +-
 5 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index e2e257bcc461..c99266b4f365 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -1206,7 +1206,7 @@ node_entry(struct perf_hpp_fmt *fmt __maybe_unused, struct perf_hpp *hpp,
 			break;
 		case 1:
 		{
-			int num = bitmap_weight(set, c2c.cpus_cnt);
+			int num = (int)bitmap_weight(set, c2c.cpus_cnt);
 			struct c2c_stats *stats = &c2c_he->node_stats[node];
 
 			ret = scnprintf(hpp->buf, hpp->size, "%2d{%2d ", node, num);
@@ -1249,7 +1249,7 @@ node_entry(struct perf_hpp_fmt *fmt __maybe_unused, struct perf_hpp *hpp,
 			ret = scnprintf(hpp->buf, hpp->size, "%2d{", node);
 			advance_hpp(hpp, ret);
 
-			ret = bitmap_scnprintf(set, c2c.cpus_cnt, hpp->buf, hpp->size);
+			ret = (int)bitmap_scnprintf(set, c2c.cpus_cnt, hpp->buf, hpp->size);
 			advance_hpp(hpp, ret);
 
 			ret = scnprintf(hpp->buf, hpp->size, "}");
@@ -1911,7 +1911,7 @@ static int c2c_se_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
 			len = symbol_width(he->hists, dim->se);
 	}
 
-	return dim->se->se_snprintf(he, hpp->buf, hpp->size, len);
+	return dim->se->se_snprintf(he, hpp->buf, hpp->size, (unsigned int)len);
 }
 
 static int64_t c2c_se_cmp(struct perf_hpp_fmt *fmt,
@@ -2164,7 +2164,7 @@ static void set_node_width(struct c2c_hist_entry *c2c_he, int len)
 static int set_nodestr(struct c2c_hist_entry *c2c_he)
 {
 	char buf[30];
-	int len;
+	size_t len;
 
 	if (c2c_he->nodestr)
 		return 0;
@@ -2176,7 +2176,7 @@ static int set_nodestr(struct c2c_hist_entry *c2c_he)
 		len = scnprintf(buf, sizeof(buf), "N/A");
 	}
 
-	set_node_width(c2c_he, len);
+	set_node_width(c2c_he, (int)len);
 	c2c_he->nodestr = strdup(buf);
 	return c2c_he->nodestr ? 0 : -ENOMEM;
 }
@@ -2353,7 +2353,7 @@ static int hists__iterate_cb(struct hists *hists, hists__resort_cb_t cb)
 
 static void print_c2c__display_stats(FILE *out)
 {
-	int llc_misses;
+	uint64_t llc_misses;
 	struct c2c_stats *stats = &c2c.hists.stats;
 
 	llc_misses = get_load_llc_misses(stats);
@@ -2379,7 +2379,7 @@ static void print_c2c__display_stats(FILE *out)
 	fprintf(out, "  Load Remote DRAM                  : %10d\n", stats->rmt_dram);
 	fprintf(out, "  Load MESI State Exclusive         : %10d\n", stats->ld_excl);
 	fprintf(out, "  Load MESI State Shared            : %10d\n", stats->ld_shared);
-	fprintf(out, "  Load LLC Misses                   : %10d\n", llc_misses);
+	fprintf(out, "  Load LLC Misses                   : %10"PRIu64"\n", llc_misses);
 	fprintf(out, "  Load access blocked by data       : %10d\n", stats->blk_data);
 	fprintf(out, "  Load access blocked by address    : %10d\n", stats->blk_addr);
 	fprintf(out, "  Load HIT Local Peer               : %10d\n", stats->lcl_peer);
@@ -2738,9 +2738,10 @@ static void perf_c2c_display(struct perf_session *session)
 }
 #endif /* HAVE_SLANG_SUPPORT */
 
-static char *fill_line(const char *orig, int len)
+static char *fill_line(const char *orig, size_t len)
 {
-	int i, j, olen = strlen(orig);
+	size_t i, j;
+	size_t olen = strlen(orig);
 	char *buf;
 
 	buf = zalloc(len + 1);
@@ -3068,7 +3069,7 @@ static int perf_c2c__report(int argc, const char **argv)
 	c2c.tool.ordering_requires_timestamps = true;
 	session = perf_session__new(&data, &c2c.tool);
 	if (IS_ERR(session)) {
-		err = PTR_ERR(session);
+		err = (int)PTR_ERR(session);
 		pr_debug("Error creating perf session\n");
 		goto out;
 	}
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 67fb1946ef13..6a905161f21b 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -173,10 +173,10 @@ static int insert_caller_stat(unsigned long call_site,
 
 static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *sample)
 {
-	unsigned long ptr = evsel__intval(evsel, sample, "ptr"),
-		      call_site = evsel__intval(evsel, sample, "call_site");
-	int bytes_req = evsel__intval(evsel, sample, "bytes_req"),
-	    bytes_alloc = evsel__intval(evsel, sample, "bytes_alloc");
+	unsigned long ptr = evsel__intval(evsel, sample, "ptr");
+	unsigned long call_site = evsel__intval(evsel, sample, "call_site");
+	int bytes_req = (int)evsel__intval(evsel, sample, "bytes_req");
+	int bytes_alloc = (int)evsel__intval(evsel, sample, "bytes_alloc");
 
 	if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) ||
 	    insert_caller_stat(call_site, bytes_req, bytes_alloc))
@@ -202,7 +202,7 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s
 		int node1, node2;
 
 		node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu});
-		node2 = evsel__intval(evsel, sample, "node");
+		node2 = (int)evsel__intval(evsel, sample, "node");
 
 		/*
 		 * If the field "node" is NUMA_NO_NODE (-1), we don't take it
@@ -737,7 +737,7 @@ static char *compact_gfp_flags(char *gfp_flags)
 	return new_flags;
 }
 
-static char *compact_gfp_string(unsigned long gfp_flags)
+static char *compact_gfp_string(unsigned int gfp_flags)
 {
 	struct gfp_flag key = {
 		.flags = gfp_flags,
@@ -808,10 +808,9 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample,
 static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sample *sample)
 {
 	u64 page;
-	unsigned int order = evsel__intval(evsel, sample, "order");
-	unsigned int gfp_flags = evsel__intval(evsel, sample, "gfp_flags");
-	unsigned int migrate_type = evsel__intval(evsel, sample,
-						       "migratetype");
+	unsigned int order = (unsigned int)evsel__intval(evsel, sample, "order");
+	unsigned int gfp_flags = (unsigned int)evsel__intval(evsel, sample, "gfp_flags");
+	unsigned int migrate_type = (unsigned int)evsel__intval(evsel, sample, "migratetype");
 	u64 bytes = kmem_page_size << order;
 	u64 callsite;
 	struct page_stat *pstat;
@@ -880,7 +879,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp
 static int evsel__process_page_free_event(struct evsel *evsel, struct perf_sample *sample)
 {
 	u64 page;
-	unsigned int order = evsel__intval(evsel, sample, "order");
+	unsigned int order = (unsigned int)evsel__intval(evsel, sample, "order");
 	u64 bytes = kmem_page_size << order;
 	struct page_stat *pstat;
 	struct page_stat this = {
@@ -1064,12 +1063,12 @@ static void __print_page_alloc_result(struct perf_session *session, int n_lines)
 	struct rb_node *next = rb_first(&page_alloc_sorted);
 	struct machine *machine = &session->machines.host;
 	const char *format;
-	int gfp_len = max(strlen("GFP flags"), max_gfp_len);
+	size_t gfp_len = max(strlen("GFP flags"), max_gfp_len);
 
 	printf("\n%.105s\n", graph_dotted_line);
 	printf(" %-16s | %5s alloc (KB) | Hits      | Order | Mig.type | %-*s | Callsite\n",
 	       use_pfn ? "PFN" : "Page", live_page ? "Live" : "Total",
-	       gfp_len, "GFP flags");
+		(int)gfp_len, "GFP flags");
 	printf("%.105s\n", graph_dotted_line);
 
 	if (use_pfn)
@@ -1102,7 +1101,7 @@ static void __print_page_alloc_result(struct perf_session *session, int n_lines)
 
 	if (n_lines == -1) {
 		printf(" ...              | ...              | ...       | ...   | ...      | %-*s | ...\n",
-		       gfp_len, "...");
+		       (int)gfp_len, "...");
 	}
 
 	printf("%.105s\n", graph_dotted_line);
@@ -1112,11 +1111,11 @@ static void __print_page_caller_result(struct perf_session *session, int n_lines
 {
 	struct rb_node *next = rb_first(&page_caller_sorted);
 	struct machine *machine = &session->machines.host;
-	int gfp_len = max(strlen("GFP flags"), max_gfp_len);
+	size_t gfp_len = max(strlen("GFP flags"), max_gfp_len);
 
 	printf("\n%.105s\n", graph_dotted_line);
 	printf(" %5s alloc (KB) | Hits      | Order | Mig.type | %-*s | Callsite\n",
-	       live_page ? "Live" : "Total", gfp_len, "GFP flags");
+	       live_page ? "Live" : "Total", (int)gfp_len, "GFP flags");
 	printf("%.105s\n", graph_dotted_line);
 
 	while (next && n_lines--) {
@@ -1137,14 +1136,14 @@ static void __print_page_caller_result(struct perf_session *session, int n_lines
 		       (unsigned long long)data->alloc_bytes / 1024,
 		       data->nr_alloc, data->order,
 		       migrate_type_str[data->migrate_type],
-		       gfp_len, compact_gfp_string(data->gfp_flags), caller);
+		       (int)gfp_len, compact_gfp_string(data->gfp_flags), caller);
 
 		next = rb_next(next);
 	}
 
 	if (n_lines == -1) {
 		printf(" ...              | ...       | ...   | ...      | %-*s | ...\n",
-		       gfp_len, "...");
+		       (int)gfp_len, "...");
 	}
 
 	printf("%.105s\n", graph_dotted_line);
@@ -1828,7 +1827,7 @@ static int parse_line_opt(const struct option *opt __maybe_unused,
 	if (!arg)
 		return -1;
 
-	lines = strtoul(arg, NULL, 10);
+	lines = (int)strtoul(arg, NULL, 10);
 
 	if (caller_flag > alloc_flag)
 		caller_lines = lines;
@@ -2001,7 +2000,7 @@ int cmd_kmem(int argc, const char **argv)
 
 	kmem_session = session = perf_session__new(&data, &perf_kmem);
 	if (IS_ERR(session))
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 
 	ret = -1;
 
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 5ec83cd85650..988b3877cde8 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -293,7 +293,7 @@ static int report_raw_events(struct perf_mem *mem)
 	session = perf_session__new(&data, &mem->tool);
 
 	if (IS_ERR(session))
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 
 	session->itrace_synth_opts = &itrace_synth_opts;
 
diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index 884d9aebce91..6ad99ace56e3 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -364,7 +364,7 @@ int perf_mem__tlb_scnprintf(char *out, size_t sz, const struct mem_info *mem_inf
 	if (miss)
 		l += scnprintf(out + l, sz - l, " miss");
 
-	return l;
+	return (int)l;
 }
 
 static const char * const mem_lvl[] = {
@@ -476,7 +476,7 @@ int perf_mem__lvl_scnprintf(char *out, size_t sz, const struct mem_info *mem_inf
 			l += scnprintf(out + l, sz - l, "Unknown level %d", lvl);
 
 		l += scnprintf(out + l, sz - l, " %s", hit_miss);
-		return l;
+		return (int)l;
 	}
 
 	lvl = data_src.mem_lvl;
@@ -499,7 +499,7 @@ int perf_mem__lvl_scnprintf(char *out, size_t sz, const struct mem_info *mem_inf
 
 	if (printed) {
 		l += scnprintf(out + l, sz - l, " %s", hit_miss);
-		return l;
+		return (int)l;
 	}
 
 na:
@@ -559,7 +559,7 @@ int perf_mem__snp_scnprintf(char *out, size_t sz, const struct mem_info *mem_inf
 	if (*out == '\0')
 		l += scnprintf(out, sz - l, "N/A");
 
-	return l;
+	return (int)l;
 }
 
 int perf_mem__lck_scnprintf(char *out, size_t sz, const struct mem_info *mem_info)
@@ -593,14 +593,14 @@ int perf_mem__blk_scnprintf(char *out, size_t sz, const struct mem_info *mem_inf
 
 	if (!mask || (mask & PERF_MEM_BLK_NA)) {
 		l += scnprintf(out + l, sz - l, " N/A");
-		return l;
+		return (int)l;
 	}
 	if (mask & PERF_MEM_BLK_DATA)
 		l += scnprintf(out + l, sz - l, " Data");
 	if (mask & PERF_MEM_BLK_ADDR)
 		l += scnprintf(out + l, sz - l, " Addr");
 
-	return l;
+	return (int)l;
 }
 
 int perf_script__meminfo_scnprintf(char *out, size_t sz, const struct mem_info *mem_info)
diff --git a/tools/perf/util/mem2node.c b/tools/perf/util/mem2node.c
index 03a7d7b27737..2d76626dec01 100644
--- a/tools/perf/util/mem2node.c
+++ b/tools/perf/util/mem2node.c
@@ -56,7 +56,7 @@ int mem2node__init(struct mem2node *map, struct perf_env *env)
 
 	for (i = 0; i < env->nr_memory_nodes; i++) {
 		n = &nodes[i];
-		max += bitmap_weight(n->set, n->size);
+		max += bitmap_weight(n->set, (unsigned int)n->size);
 	}
 
 	entries = zalloc(sizeof(*entries) * max);
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 31/47] perf script: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (29 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 30/47] perf mem: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 32/47] perf evlist: " Ian Rogers
                   ` (15 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.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.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 32/47] perf evlist: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (30 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 31/47] perf script: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 33/47] perf bpf_counter: " Ian Rogers
                   ` (14 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-evlist.c |  2 +-
 tools/perf/util/evlist.c    | 29 +++++++++++++++--------------
 tools/perf/util/evsel.c     | 35 ++++++++++++++---------------------
 3 files changed, 30 insertions(+), 36 deletions(-)

diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index a9bd7bbef5a9..d8888c46238a 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -44,7 +44,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details
 	tool.feature = process_header_feature;
 	session = perf_session__new(&data, &tool);
 	if (IS_ERR(session))
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 
 	if (data.is_pipe)
 		perf_session__process_events(session);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 0a21da4f990f..72af905bbc11 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -919,7 +919,7 @@ int __evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str)
 		return -1;
 	}
 
-	*mmap_pages = pages;
+	*mmap_pages = (unsigned int)pages;
 	return 0;
 }
 
@@ -1441,7 +1441,7 @@ int evlist__prepare_workload(struct evlist *evlist, struct target *target, const
 	}
 
 	if (!evlist->workload.pid) {
-		int ret;
+		ssize_t ret;
 
 		if (pipe_output)
 			dup2(2, 1);
@@ -1481,7 +1481,7 @@ int evlist__prepare_workload(struct evlist *evlist, struct target *target, const
 		if (ret != 1) {
 			if (ret == -1)
 				perror("unable to read pipe");
-			exit(ret);
+			exit((int)ret);
 		}
 
 		execvp(argv[0], (char **)argv);
@@ -1542,7 +1542,7 @@ int evlist__start_workload(struct evlist *evlist)
 {
 	if (evlist->workload.cork_fd >= 0) {
 		char bf = 0;
-		int ret;
+		ssize_t ret;
 		/*
 		 * Remove the cork, let it rip!
 		 */
@@ -1552,7 +1552,7 @@ int evlist__start_workload(struct evlist *evlist)
 
 		close(evlist->workload.cork_fd);
 		evlist->workload.cork_fd = -1;
-		return ret;
+		return (int)ret;
 	}
 
 	return 0;
@@ -1655,7 +1655,8 @@ int evlist__strerror_open(struct evlist *evlist, int err, char *buf, size_t size
 int evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_t size)
 {
 	char sbuf[STRERR_BUFSIZE], *emsg = str_error_r(err, sbuf, sizeof(sbuf));
-	int pages_attempted = evlist->core.mmap_len / 1024, pages_max_per_user, printed = 0;
+	int pages_attempted = (int)evlist->core.mmap_len / 1024;
+	int pages_max_per_user, printed = 0;
 
 	switch (err) {
 	case EPERM:
@@ -1940,7 +1941,7 @@ int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *c
 	if (strncmp(str, "fd:", 3))
 		return evlist__parse_control_fifo(str, ctl_fd, ctl_fd_ack, ctl_fd_close);
 
-	*ctl_fd = strtoul(&str[3], &endptr, 0);
+	*ctl_fd = (int)strtoul(&str[3], &endptr, 0);
 	if (endptr == &str[3])
 		return -EINVAL;
 
@@ -1949,7 +1950,7 @@ int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *c
 		if (endptr != comma)
 			return -EINVAL;
 
-		*ctl_fd_ack = strtoul(comma + 1, &endptr, 0);
+		*ctl_fd_ack = (int)strtoul(comma + 1, &endptr, 0);
 		if (endptr == comma + 1 || *endptr != '\0')
 			return -EINVAL;
 	}
@@ -2015,7 +2016,7 @@ int evlist__finalize_ctlfd(struct evlist *evlist)
 static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd,
 			      char *cmd_data, size_t data_size)
 {
-	int err;
+	ssize_t err;
 	char c;
 	size_t bytes_read = 0;
 
@@ -2069,12 +2070,12 @@ static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd,
 		}
 	}
 
-	return bytes_read ? (int)bytes_read : err;
+	return bytes_read ? (int)bytes_read : (int)err;
 }
 
 int evlist__ctlfd_ack(struct evlist *evlist)
 {
-	int err;
+	ssize_t err;
 
 	if (evlist->ctl_fd.ack == -1)
 		return 0;
@@ -2084,7 +2085,7 @@ int evlist__ctlfd_ack(struct evlist *evlist)
 	if (err == -1)
 		pr_err("failed to write to ctl_ack_fd %d: %m\n", evlist->ctl_fd.ack);
 
-	return err;
+	return (int)err;
 }
 
 static int get_cmd_arg(char *cmd_data, size_t cmd_size, char **arg)
@@ -2304,7 +2305,7 @@ static int str_to_delay(const char *str)
 	d = strtol(str, &endptr, 10);
 	if (*endptr || d > INT_MAX || d < -1)
 		return 0;
-	return d;
+	return (int)d;
 }
 
 int evlist__parse_event_enable_time(struct evlist *evlist, struct record_opts *opts,
@@ -2325,7 +2326,7 @@ int evlist__parse_event_enable_time(struct evlist *evlist, struct record_opts *o
 
 	ret = parse_event_enable_times(str, NULL);
 	if (ret < 0)
-		return ret;
+		return (int)ret;
 
 	times_cnt = ret;
 	if (times_cnt == 0)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 1d79ffecd41f..6cdb9313778a 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -655,12 +655,12 @@ struct tep_event *evsel__tp_format(struct evsel *evsel)
 		return NULL;
 
 	if (!evsel->tp_sys)
-		tp_format = trace_event__tp_format_id(evsel->core.attr.config);
+		tp_format = trace_event__tp_format_id((int)evsel->core.attr.config);
 	else
 		tp_format = trace_event__tp_format(evsel->tp_sys, evsel->tp_name);
 
 	if (IS_ERR(tp_format)) {
-		int err = -PTR_ERR(evsel->tp_format);
+		int err = (int)-PTR_ERR(evsel->tp_format);
 
 		pr_err("Error getting tracepoint format '%s' '%s'(%d)\n",
 			evsel__name(evsel), strerror(err), err);
@@ -688,7 +688,7 @@ char *evsel__bpf_counter_events;
 
 bool evsel__match_bpf_counter_events(const char *name)
 {
-	int name_len;
+	size_t name_len;
 	bool match;
 	char *ptr;
 
@@ -1154,7 +1154,7 @@ static void evsel__apply_config_terms(struct evsel *evsel,
 				evsel__reset_sample_bit(evsel, BRANCH_STACK);
 			break;
 		case EVSEL__CONFIG_TERM_STACK_USER:
-			dump_size = term->val.stack_user;
+			dump_size = (u32)term->val.stack_user;
 			break;
 		case EVSEL__CONFIG_TERM_MAX_STACK:
 			max_stack = term->val.max_stack;
@@ -1770,7 +1770,7 @@ static u64 evsel__group_read_size(struct evsel *leader)
 	u64 read_format = leader->core.attr.read_format;
 	int entry = sizeof(u64); /* value */
 	int size = 0;
-	int nr = 1;
+	u64 nr = 1;
 
 	if (!evsel__group_has_tpebs(leader))
 		return perf_evsel__read_size(&leader->core);
@@ -1834,7 +1834,7 @@ static int evsel__read_group(struct evsel *leader, int cpu_map_idx, int thread)
 {
 	struct perf_stat_evsel *ps = leader->stats;
 	u64 read_format = leader->core.attr.read_format;
-	int size = evsel__group_read_size(leader);
+	size_t size = evsel__group_read_size(leader);
 	u64 *data = ps->group_data;
 
 	if (!(read_format & PERF_FORMAT_ID))
@@ -2176,31 +2176,27 @@ int evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus,
 static bool __has_attr_feature(struct perf_event_attr *attr,
 			       struct perf_cpu cpu, unsigned long flags)
 {
-	int fd = syscall(SYS_perf_event_open, attr, /*pid=*/0, cpu.cpu,
-			 /*group_fd=*/-1, flags);
+	int fd = sys_perf_event_open(attr, /*pid=*/0, cpu.cpu, /*group_fd=*/-1, flags);
 	close(fd);
 
 	if (fd < 0) {
 		attr->exclude_kernel = 1;
 
-		fd = syscall(SYS_perf_event_open, attr, /*pid=*/0, cpu.cpu,
-			     /*group_fd=*/-1, flags);
+		fd = sys_perf_event_open(attr, /*pid=*/0, cpu.cpu, /*group_fd=*/-1, flags);
 		close(fd);
 	}
 
 	if (fd < 0) {
 		attr->exclude_hv = 1;
 
-		fd = syscall(SYS_perf_event_open, attr, /*pid=*/0, cpu.cpu,
-			     /*group_fd=*/-1, flags);
+		fd = sys_perf_event_open(attr, /*pid=*/0, cpu.cpu, /*group_fd=*/-1, flags);
 		close(fd);
 	}
 
 	if (fd < 0) {
 		attr->exclude_guest = 1;
 
-		fd = syscall(SYS_perf_event_open, attr, /*pid=*/0, cpu.cpu,
-			     /*group_fd=*/-1, flags);
+		fd = sys_perf_event_open(attr, /*pid=*/0, cpu.cpu, /*group_fd=*/-1, flags);
 		close(fd);
 	}
 
@@ -3464,7 +3460,7 @@ char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const cha
 	 * We can change this if we have a good reason in the future.
 	 */
 	val = evsel__intval(evsel, sample, name);
-	bit = val ? ffs(val) : 0;
+	bit = val ? ffs((int)val) : 0;
 	state = (!bit || bit > strlen(states)) ? 'R' : states[bit-1];
 	return state;
 }
@@ -3809,18 +3805,15 @@ struct perf_env *evsel__env(struct evsel *evsel)
 
 static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist)
 {
-	int cpu_map_idx, thread;
-
 	if (evsel__is_retire_lat(evsel))
 		return 0;
 
-	for (cpu_map_idx = 0; cpu_map_idx < xyarray__max_x(evsel->core.fd); cpu_map_idx++) {
-		for (thread = 0; thread < xyarray__max_y(evsel->core.fd);
-		     thread++) {
+	for (size_t cpu_map_idx = 0; cpu_map_idx < xyarray__max_x(evsel->core.fd); cpu_map_idx++) {
+		for (size_t thread = 0; thread < xyarray__max_y(evsel->core.fd); thread++) {
 			int fd = FD(evsel, cpu_map_idx, thread);
 
 			if (perf_evlist__id_add_fd(&evlist->core, &evsel->core,
-						   cpu_map_idx, thread, fd) < 0)
+						   (int)cpu_map_idx, (int)thread, fd) < 0)
 				return -1;
 		}
 	}
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 33/47] perf bpf_counter: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (31 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 32/47] perf evlist: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 34/47] perf ftrace: " Ian Rogers
                   ` (13 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/util/bpf_counter.c        | 6 +++---
 tools/perf/util/bpf_counter_cgroup.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c
index 73fcafbffc6a..3b1dbf1f5f66 100644
--- a/tools/perf/util/bpf_counter.c
+++ b/tools/perf/util/bpf_counter.c
@@ -177,7 +177,7 @@ static int bpf_program_profiler__load(struct evsel *evsel, struct target *target
 		return -1;
 
 	while ((tok = strtok_r(bpf_str, ",", &saveptr)) != NULL) {
-		prog_id = strtoul(tok, &p, 10);
+		prog_id = (unsigned int)strtoul(tok, &p, 10);
 		if (prog_id == 0 || prog_id == UINT_MAX ||
 		    (*p != '\0' && *p != ',')) {
 			pr_err("Failed to parse bpf prog ids %s\n",
@@ -418,7 +418,7 @@ static int bperf_reload_leader_program(struct evsel *evsel, int attr_map_fd,
 	link = bpf_program__attach(skel->progs.on_switch);
 	if (IS_ERR(link)) {
 		pr_err("Failed to attach leader program\n");
-		err = PTR_ERR(link);
+		err = (int)PTR_ERR(link);
 		goto out;
 	}
 
@@ -459,7 +459,7 @@ static int bperf_attach_follower_program(struct bperf_follower_bpf *skel,
 	else {
 		link = bpf_program__attach(skel->progs.fexit_XXX);
 		if (IS_ERR(link))
-			err = PTR_ERR(link);
+			err = (int)PTR_ERR(link);
 	}
 
 	return err;
diff --git a/tools/perf/util/bpf_counter_cgroup.c b/tools/perf/util/bpf_counter_cgroup.c
index 6ff42619de12..35d1b950e803 100644
--- a/tools/perf/util/bpf_counter_cgroup.c
+++ b/tools/perf/util/bpf_counter_cgroup.c
@@ -98,7 +98,7 @@ static int bperf_load_program(struct evlist *evlist)
 						      FD(cgrp_switch, i));
 		if (IS_ERR(link)) {
 			pr_err("Failed to attach cgroup program\n");
-			err = PTR_ERR(link);
+			err = (int)PTR_ERR(link);
 			goto out;
 		}
 	}
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 34/47] perf ftrace: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (32 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 33/47] perf bpf_counter: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 35/47] perf record: " Ian Rogers
                   ` (12 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-ftrace.c  | 17 +++++++++++------
 tools/perf/util/bpf_ftrace.c |  4 ++--
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 7caa18d5ffc3..1484d798de40 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -182,7 +182,8 @@ static int read_tracing_file_to_stdout(const char *name)
 
 	/* read contents to stdout */
 	while (true) {
-		int n = read(fd, buf, sizeof(buf));
+		ssize_t n = read(fd, buf, sizeof(buf));
+
 		if (n == 0)
 			break;
 		else if (n < 0)
@@ -449,7 +450,7 @@ static int set_tracing_percpu_buffer_size(struct perf_ftrace *ftrace)
 		return 0;
 
 	ret = write_tracing_file_int("buffer_size_kb",
-				     ftrace->percpu_buffer_size / 1024);
+				     (int)(ftrace->percpu_buffer_size / 1024));
 	if (ret < 0)
 		return ret;
 
@@ -691,7 +692,8 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace)
 			break;
 
 		if (pollfd.revents & POLLIN) {
-			int n = read(trace_fd, buf, sizeof(buf));
+			ssize_t n = read(trace_fd, buf, sizeof(buf));
+
 			if (n < 0)
 				break;
 			if (fwrite(buf, n, 1, stdout) != 1)
@@ -713,7 +715,8 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace)
 
 	/* read remaining buffer contents */
 	while (true) {
-		int n = read(trace_fd, buf, sizeof(buf));
+		ssize_t n = read(trace_fd, buf, sizeof(buf));
+
 		if (n <= 0)
 			break;
 		if (fwrite(buf, n, 1, stdout) != 1)
@@ -1031,7 +1034,8 @@ static int __cmd_latency(struct perf_ftrace *ftrace)
 			break;
 
 		if (pollfd.revents & POLLIN) {
-			int n = read(trace_fd, buf, sizeof(buf) - 1);
+			ssize_t n = read(trace_fd, buf, sizeof(buf) - 1);
+
 			if (n < 0)
 				break;
 
@@ -1049,7 +1053,8 @@ static int __cmd_latency(struct perf_ftrace *ftrace)
 
 	/* read remaining buffer contents */
 	while (!ftrace->target.use_bpf) {
-		int n = read(trace_fd, buf, sizeof(buf) - 1);
+		ssize_t n = read(trace_fd, buf, sizeof(buf) - 1);
+
 		if (n <= 0)
 			break;
 		make_histogram(ftrace, buckets, buf, n, line);
diff --git a/tools/perf/util/bpf_ftrace.c b/tools/perf/util/bpf_ftrace.c
index 7324668cc83e..c4b3bb4e5922 100644
--- a/tools/perf/util/bpf_ftrace.c
+++ b/tools/perf/util/bpf_ftrace.c
@@ -97,7 +97,7 @@ int perf_ftrace__latency_prepare_bpf(struct perf_ftrace *ftrace)
 							    false, func->name);
 	if (IS_ERR(skel->links.func_begin)) {
 		pr_err("Failed to attach fentry program\n");
-		err = PTR_ERR(skel->links.func_begin);
+		err = (int)PTR_ERR(skel->links.func_begin);
 		goto out;
 	}
 
@@ -105,7 +105,7 @@ int perf_ftrace__latency_prepare_bpf(struct perf_ftrace *ftrace)
 							  true, func->name);
 	if (IS_ERR(skel->links.func_end)) {
 		pr_err("Failed to attach fexit program\n");
-		err = PTR_ERR(skel->links.func_end);
+		err = (int)PTR_ERR(skel->links.func_end);
 		goto out;
 	}
 
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 35/47] perf record: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (33 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 34/47] perf ftrace: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 36/47] perf inject: " Ian Rogers
                   ` (11 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-record.c   | 66 ++++++++++++++++++-----------------
 tools/perf/builtin-top.c      |  4 +--
 tools/perf/util/auxtrace.c    |  8 ++---
 tools/perf/util/bpf-filter.c  | 20 +++++------
 tools/perf/util/bpf_off_cpu.c |  4 +--
 tools/perf/util/mmap.c        |  6 ++--
 6 files changed, 55 insertions(+), 53 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index ba20bf7c011d..e524b9cae531 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -443,7 +443,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t size
 
 	aio->size += size;
 
-	return size;
+	return (int)size;
 }
 
 static int record__aio_push(struct record *rec, struct mmap *map, off_t *off)
@@ -523,7 +523,7 @@ static int record__aio_parse(const struct option *opt,
 		opts->nr_cblocks = 0;
 	} else {
 		if (str)
-			opts->nr_cblocks = strtol(str, NULL, 0);
+			opts->nr_cblocks = (int)strtol(str, NULL, 0);
 		if (!opts->nr_cblocks)
 			opts->nr_cblocks = nr_cblocks_default;
 	}
@@ -577,15 +577,15 @@ static int record__mmap_flush_parse(const struct option *opt,
 		return 0;
 
 	if (str) {
-		opts->mmap_flush = parse_tag_value(str, tags);
+		opts->mmap_flush = (int)parse_tag_value(str, tags);
 		if (opts->mmap_flush == (int)-1)
-			opts->mmap_flush = strtol(str, NULL, 0);
+			opts->mmap_flush = (int)strtol(str, NULL, 0);
 	}
 
 	if (!opts->mmap_flush)
 		opts->mmap_flush = MMAP_FLUSH_DEFAULT;
 
-	flush_max = evlist__mmap_size(opts->mmap_pages);
+	flush_max = (int)evlist__mmap_size(opts->mmap_pages);
 	flush_max /= 4;
 	if (opts->mmap_flush > flush_max)
 		opts->mmap_flush = flush_max;
@@ -604,7 +604,7 @@ static int record__parse_comp_level(const struct option *opt, const char *str, i
 		opts->comp_level = 0;
 	} else {
 		if (str)
-			opts->comp_level = strtol(str, NULL, 0);
+			opts->comp_level = (unsigned int)strtol(str, NULL, 0);
 		if (!opts->comp_level)
 			opts->comp_level = comp_level_default;
 	}
@@ -1080,11 +1080,12 @@ static int record__thread_data_init_maps(struct record_thread *thread_data, stru
 	struct perf_cpu_map *cpus = evlist->core.all_cpus;
 	bool per_thread = evlist__per_thread(evlist);
 
-	if (per_thread)
+	if (per_thread) {
 		thread_data->nr_mmaps = nr_mmaps;
-	else
-		thread_data->nr_mmaps = bitmap_weight(thread_data->mask->maps.bits,
-						      thread_data->mask->maps.nbits);
+	} else {
+		thread_data->nr_mmaps = (int)bitmap_weight(thread_data->mask->maps.bits,
+						(unsigned int)thread_data->mask->maps.nbits);
+	}
 	if (mmap) {
 		thread_data->maps = zalloc(thread_data->nr_mmaps * sizeof(struct mmap *));
 		if (!thread_data->maps)
@@ -1519,10 +1520,11 @@ static void record__adjust_affinity(struct record *rec, struct mmap *map)
 {
 	if (rec->opts.affinity != PERF_AFFINITY_SYS &&
 	    !bitmap_equal(thread->mask->affinity.bits, map->affinity_mask.bits,
-			  thread->mask->affinity.nbits)) {
-		bitmap_zero(thread->mask->affinity.bits, thread->mask->affinity.nbits);
+			 (unsigned int)thread->mask->affinity.nbits)) {
+		bitmap_zero(thread->mask->affinity.bits,
+			    (unsigned int)thread->mask->affinity.nbits);
 		bitmap_or(thread->mask->affinity.bits, thread->mask->affinity.bits,
-			  map->affinity_mask.bits, thread->mask->affinity.nbits);
+			  map->affinity_mask.bits, (unsigned int)thread->mask->affinity.nbits);
 		sched_setaffinity(0, MMAP_CPU_MASK_BYTES(&thread->mask->affinity),
 					(cpu_set_t *)thread->mask->affinity.bits);
 		if (verbose == 2) {
@@ -1688,7 +1690,7 @@ static void *record__thread(void *arg)
 	thread = arg;
 	thread->tid = gettid();
 
-	err = write(thread->pipes.ack[1], &msg, sizeof(msg));
+	err = (int)write(thread->pipes.ack[1], &msg, sizeof(msg));
 	if (err == -1)
 		pr_warning("threads[%d]: failed to notify on start: %s\n",
 			   thread->tid, strerror(errno));
@@ -1732,7 +1734,7 @@ static void *record__thread(void *arg)
 	}
 	record__mmap_read_all(thread->rec, true);
 
-	err = write(thread->pipes.ack[1], &msg, sizeof(msg));
+	err = (int)write(thread->pipes.ack[1], &msg, sizeof(msg));
 	if (err == -1)
 		pr_warning("threads[%d]: failed to notify on termination: %s\n",
 			   thread->tid, strerror(errno));
@@ -1958,8 +1960,8 @@ static void record__read_lost_samples(struct record *rec)
 			continue;
 		}
 
-		for (int x = 0; x < xyarray__max_x(xy); x++) {
-			for (int y = 0; y < xyarray__max_y(xy); y++) {
+		for (int x = 0; x < (int)xyarray__max_x(xy); x++) {
+			for (int y = 0; y < (int)xyarray__max_y(xy); y++) {
 				struct perf_counts_values count;
 
 				if (perf_evsel__read(&evsel->core, x, y, &count) < 0) {
@@ -2246,7 +2248,7 @@ static int record__terminate_thread(struct record_thread *thread_data)
 
 	close(thread_data->pipes.msg[1]);
 	thread_data->pipes.msg[1] = -1;
-	err = read(thread_data->pipes.ack[0], &ack, sizeof(ack));
+	err = (int)read(thread_data->pipes.ack[0], &ack, sizeof(ack));
 	if (err > 0)
 		pr_debug2("threads[%d]: sent %s\n", tid, thread_msg_tags[ack]);
 	else
@@ -2294,7 +2296,7 @@ static int record__start_threads(struct record *rec)
 			goto out_err;
 		}
 
-		err = read(thread_data[t].pipes.ack[0], &msg, sizeof(msg));
+		err = (int)read(thread_data[t].pipes.ack[0], &msg, sizeof(msg));
 		if (err > 0)
 			pr_debug2("threads[%d]: sent %s\n", rec->thread_data[t].tid,
 				  thread_msg_tags[msg]);
@@ -2409,7 +2411,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 	session = perf_session__new(data, tool);
 	if (IS_ERR(session)) {
 		pr_err("Perf session creation failed.\n");
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 	}
 
 	if (record__threads_enabled(rec)) {
@@ -2495,7 +2497,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 	}
 	/* Debug message used by test scripts */
 	pr_debug3("perf record done opening and mmapping events\n");
-	session->header.env.comp_mmap_len = session->evlist->core.mmap_len;
+	session->header.env.comp_mmap_len = (u32)session->evlist->core.mmap_len;
 
 	if (rec->opts.kcore) {
 		err = record__kcore_copy(&session->machines.host, data);
@@ -2713,7 +2715,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 
 			/* re-arm the alarm */
 			if (rec->switch_output.time)
-				alarm(rec->switch_output.time);
+				alarm((unsigned int)rec->switch_output.time);
 		}
 
 		if (hits == thread->samples) {
@@ -2976,7 +2978,7 @@ static int perf_record_config(const char *var, const char *value, void *cb)
 	}
 #ifdef HAVE_AIO_SUPPORT
 	if (!strcmp(var, "record.aio")) {
-		rec->opts.nr_cblocks = strtol(value, NULL, 0);
+		rec->opts.nr_cblocks = (int)strtol(value, NULL, 0);
 		if (!rec->opts.nr_cblocks)
 			rec->opts.nr_cblocks = nr_cblocks_default;
 	}
@@ -3016,7 +3018,7 @@ static int record__parse_affinity(const struct option *opt, const char *str, int
 static int record__mmap_cpu_mask_alloc(struct mmap_cpu_mask *mask, int nr_bits)
 {
 	mask->nbits = nr_bits;
-	mask->bits = bitmap_zalloc(mask->nbits);
+	mask->bits = bitmap_zalloc((int)mask->nbits);
 	if (!mask->bits)
 		return -ENOMEM;
 
@@ -3604,7 +3606,7 @@ static int record__mmap_cpu_mask_init_spec(struct mmap_cpu_mask *mask, const cha
 	if (!cpus)
 		return -ENOMEM;
 
-	bitmap_zero(mask->bits, mask->nbits);
+	bitmap_zero(mask->bits, (unsigned int)mask->nbits);
 	if (record__mmap_cpu_mask_init(mask, cpus))
 		return -ENODEV;
 
@@ -3722,13 +3724,13 @@ static int record__init_thread_masks_spec(struct record *rec, struct perf_cpu_ma
 
 		/* ignore invalid CPUs but do not allow empty masks */
 		if (!bitmap_and(thread_mask.maps.bits, thread_mask.maps.bits,
-				cpus_mask.bits, thread_mask.maps.nbits)) {
+				cpus_mask.bits, (unsigned int)thread_mask.maps.nbits)) {
 			pr_err("Empty maps mask: %s\n", maps_spec[s]);
 			ret = -EINVAL;
 			goto out_free;
 		}
 		if (!bitmap_and(thread_mask.affinity.bits, thread_mask.affinity.bits,
-				cpus_mask.bits, thread_mask.affinity.nbits)) {
+				cpus_mask.bits, (unsigned int)thread_mask.affinity.nbits)) {
 			pr_err("Empty affinity mask: %s\n", affinity_spec[s]);
 			ret = -EINVAL;
 			goto out_free;
@@ -3736,22 +3738,22 @@ static int record__init_thread_masks_spec(struct record *rec, struct perf_cpu_ma
 
 		/* do not allow intersection with other masks (full_mask) */
 		if (bitmap_intersects(thread_mask.maps.bits, full_mask.maps.bits,
-				      thread_mask.maps.nbits)) {
+				      (unsigned int)thread_mask.maps.nbits)) {
 			pr_err("Intersecting maps mask: %s\n", maps_spec[s]);
 			ret = -EINVAL;
 			goto out_free;
 		}
 		if (bitmap_intersects(thread_mask.affinity.bits, full_mask.affinity.bits,
-				      thread_mask.affinity.nbits)) {
+				      (unsigned int)thread_mask.affinity.nbits)) {
 			pr_err("Intersecting affinity mask: %s\n", affinity_spec[s]);
 			ret = -EINVAL;
 			goto out_free;
 		}
 
 		bitmap_or(full_mask.maps.bits, full_mask.maps.bits,
-			  thread_mask.maps.bits, full_mask.maps.nbits);
+			  thread_mask.maps.bits, (unsigned int)full_mask.maps.nbits);
 		bitmap_or(full_mask.affinity.bits, full_mask.affinity.bits,
-			  thread_mask.affinity.bits, full_mask.maps.nbits);
+			  thread_mask.affinity.bits, (unsigned int)full_mask.maps.nbits);
 
 		thread_masks = realloc(rec->thread_masks, (t + 1) * sizeof(struct thread_mask));
 		if (!thread_masks) {
@@ -4101,7 +4103,7 @@ int cmd_record(int argc, const char **argv)
 
 	if (rec->switch_output.time) {
 		signal(SIGALRM, alarm_sig_handler);
-		alarm(rec->switch_output.time);
+		alarm((unsigned int)rec->switch_output.time);
 	}
 
 	if (rec->switch_output.num_files) {
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index f9f31391bddb..c24a945b873d 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -375,7 +375,7 @@ static void prompt_integer(int *target, const char *msg)
 			goto out_free;
 		p++;
 	}
-	tmp = strtoul(buf, NULL, 10);
+	tmp = (int)strtoul(buf, NULL, 10);
 	*target = tmp;
 out_free:
 	free(buf);
@@ -1817,7 +1817,7 @@ int cmd_top(int argc, const char **argv)
 
 	top.session = perf_session__new(NULL, NULL);
 	if (IS_ERR(top.session)) {
-		status = PTR_ERR(top.session);
+		status = (int)PTR_ERR(top.session);
 		top.session = NULL;
 		goto out_delete_evlist;
 	}
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 03211c2623de..0caacd38b538 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -780,7 +780,7 @@ int auxtrace_parse_sample_options(struct auxtrace_record *itr,
 		if (evsel__is_group_leader(evsel)) {
 			has_aux_leader = evsel__is_aux_event(evsel);
 		} else if (has_aux_leader) {
-			evsel->core.attr.aux_sample_size = sz;
+			evsel->core.attr.aux_sample_size = (__u32)sz;
 		}
 	}
 no_opt:
@@ -1647,7 +1647,7 @@ int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts,
 			if (isdigit(*p)) {
 				unsigned int val;
 
-				val = strtoul(p, &endptr, 10);
+				val = (unsigned int)strtoul(p, &endptr, 10);
 				p = endptr;
 				if (!val || val > PERF_ITRACE_MAX_CALLCHAIN_SZ)
 					goto out_err;
@@ -1667,7 +1667,7 @@ int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts,
 			if (isdigit(*p)) {
 				unsigned int val;
 
-				val = strtoul(p, &endptr, 10);
+				val = (unsigned int)strtoul(p, &endptr, 10);
 				p = endptr;
 				if (!val ||
 				    val > PERF_ITRACE_MAX_LAST_BRANCH_SZ)
@@ -2300,7 +2300,7 @@ static int parse_sym_idx(char **inp, int *idx)
 		if (endptr == *inp || num > INT_MAX)
 			return -EINVAL;
 		*inp = endptr;
-		*idx = num;
+		*idx = (int)num;
 	}
 
 	return 0;
diff --git a/tools/perf/util/bpf-filter.c b/tools/perf/util/bpf-filter.c
index a4fdf6911ec1..7ad4d5e8fa49 100644
--- a/tools/perf/util/bpf-filter.c
+++ b/tools/perf/util/bpf-filter.c
@@ -217,7 +217,7 @@ static int convert_to_tgid(int tid)
 		return -1;
 	}
 
-	tgid = strtol(p + 6, &q, 0);
+	tgid = (int)strtol(p + 6, &q, 0);
 	free(buf);
 	if (*q != '\n')
 		return -1;
@@ -284,7 +284,7 @@ static void destroy_event_hash(u64 event_id)
  */
 static u64 create_event_hash(struct evsel *evsel)
 {
-	int x, y, fd;
+	int fd;
 	u64 the_id = 0, id;
 
 	fd = get_pinned_fd("event_hash");
@@ -293,8 +293,8 @@ static u64 create_event_hash(struct evsel *evsel)
 		return 0;
 	}
 
-	for (x = 0; x < xyarray__max_x(evsel->core.fd); x++) {
-		for (y = 0; y < xyarray__max_y(evsel->core.fd); y++) {
+	for (size_t x = 0; x < xyarray__max_x(evsel->core.fd); x++) {
+		for (size_t y = 0; y < xyarray__max_y(evsel->core.fd); y++) {
 			int ret = ioctl(FD(evsel, x, y), PERF_EVENT_IOC_ID, &id);
 
 			if (ret < 0) {
@@ -444,7 +444,7 @@ static int create_idx_hash(struct evsel *evsel, struct perf_bpf_filter_entry *en
 
 int perf_bpf_filter__prepare(struct evsel *evsel, struct target *target)
 {
-	int i, x, y, fd, ret;
+	int i, fd, ret;
 	struct sample_filter_bpf *skel = NULL;
 	struct bpf_program *prog;
 	struct bpf_link *link;
@@ -485,8 +485,8 @@ int perf_bpf_filter__prepare(struct evsel *evsel, struct target *target)
 			goto err;
 		}
 
-		for (x = 0; x < xyarray__max_x(evsel->core.fd); x++) {
-			for (y = 0; y < xyarray__max_y(evsel->core.fd); y++) {
+		for (size_t x = 0; x < xyarray__max_x(evsel->core.fd); x++) {
+			for (size_t y = 0; y < xyarray__max_y(evsel->core.fd); y++) {
 				ret = ioctl(FD(evsel, x, y), PERF_EVENT_IOC_SET_BPF, fd);
 				if (ret < 0) {
 					pr_err("Failed to attach perf sample-filter\n");
@@ -519,12 +519,12 @@ int perf_bpf_filter__prepare(struct evsel *evsel, struct target *target)
 	}
 
 	prog = skel->progs.perf_sample_filter;
-	for (x = 0; x < xyarray__max_x(evsel->core.fd); x++) {
-		for (y = 0; y < xyarray__max_y(evsel->core.fd); y++) {
+	for (size_t x = 0; x < xyarray__max_x(evsel->core.fd); x++) {
+		for (size_t y = 0; y < xyarray__max_y(evsel->core.fd); y++) {
 			link = bpf_program__attach_perf_event(prog, FD(evsel, x, y));
 			if (IS_ERR(link)) {
 				pr_err("Failed to attach perf sample-filter program\n");
-				ret = PTR_ERR(link);
+				ret = (int)PTR_ERR(link);
 				goto err;
 			}
 		}
diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c
index 4269b41d1771..3f0a65fb987d 100644
--- a/tools/perf/util/bpf_off_cpu.c
+++ b/tools/perf/util/bpf_off_cpu.c
@@ -164,7 +164,7 @@ int off_cpu_prepare(struct evlist *evlist, struct target *target,
 		ntasks = 0;
 		strlist__for_each_entry(pos, pid_slist) {
 			char *end_ptr;
-			int pid = strtol(pos->s, &end_ptr, 10);
+			int pid = (int)strtol(pos->s, &end_ptr, 10);
 
 			if (pid == INT_MIN || pid == INT_MAX ||
 			    (*end_ptr != '\0' && *end_ptr != ','))
@@ -234,7 +234,7 @@ int off_cpu_prepare(struct evlist *evlist, struct target *target,
 		strlist__for_each_entry(pos, pid_slist) {
 			char *end_ptr;
 			u32 tgid;
-			int pid = strtol(pos->s, &end_ptr, 10);
+			int pid = (int)strtol(pos->s, &end_ptr, 10);
 
 			if (pid == INT_MIN || pid == INT_MAX ||
 			    (*end_ptr != '\0' && *end_ptr != ','))
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index a34726219af3..b8e8865aeb22 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -31,7 +31,7 @@ void mmap_cpu_mask__scnprintf(struct mmap_cpu_mask *mask, const char *tag)
 	char buf[MASK_SIZE + 1];
 	size_t len;
 
-	len = bitmap_scnprintf(mask->bits, mask->nbits, buf, MASK_SIZE);
+	len = bitmap_scnprintf(mask->bits, (unsigned int)mask->nbits, buf, MASK_SIZE);
 	buf[len] = '\0';
 	pr_debug("%p: %s mask[%zd]: %s\n", mask, tag, mask->nbits, buf);
 }
@@ -165,7 +165,7 @@ static int perf_mmap__aio_mmap(struct mmap *map, struct mmap_params *mp)
 			pr_debug2("failed to allocate data buffer, error %m\n");
 			return -1;
 		}
-		delta_max = sysconf(_SC_AIO_PRIO_DELTA_MAX);
+		delta_max = (int)sysconf(_SC_AIO_PRIO_DELTA_MAX);
 		for (i = 0; i < map->aio.nr_cblocks; ++i) {
 			ret = perf_mmap__aio_alloc(map, i);
 			if (ret == -1) {
@@ -261,7 +261,7 @@ static void build_node_mask(int node, struct mmap_cpu_mask *mask)
 static int perf_mmap__setup_affinity_mask(struct mmap *map, struct mmap_params *mp)
 {
 	map->affinity_mask.nbits = cpu__max_cpu().cpu;
-	map->affinity_mask.bits = bitmap_zalloc(map->affinity_mask.nbits);
+	map->affinity_mask.bits = bitmap_zalloc((int)map->affinity_mask.nbits);
 	if (!map->affinity_mask.bits)
 		return -1;
 
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 36/47] perf inject: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (34 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 35/47] perf record: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 37/47] perf sched: " Ian Rogers
                   ` (10 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-inject.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 11e49cafa3af..09a99cec8f78 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -390,7 +390,7 @@ static int perf_event__repipe_sample(const struct perf_tool *tool,
 	if (inject->itrace_synth_opts.set && sample->aux_sample.size) {
 		event = perf_inject__cut_auxtrace_sample(inject, event, sample);
 		if (IS_ERR(event))
-			return PTR_ERR(event);
+			return (int)PTR_ERR(event);
 	}
 
 	return perf_event__repipe_synth(tool, event);
@@ -697,13 +697,13 @@ static struct strlist *perf_inject__parse_known_build_ids(
 {
 	struct str_node *pos, *tmp;
 	struct strlist *known_build_ids;
-	int bid_len;
 
 	known_build_ids = strlist__new(known_build_ids_string, NULL);
 	if (known_build_ids == NULL)
 		return NULL;
 	strlist__for_each_entry_safe(pos, tmp, known_build_ids) {
 		const char *build_id, *dso_name;
+		size_t bid_len;
 
 		build_id = skip_spaces(pos->s);
 		dso_name = strchr(build_id, ' ');
@@ -717,7 +717,7 @@ static struct strlist *perf_inject__parse_known_build_ids(
 			strlist__remove(known_build_ids, pos);
 			continue;
 		}
-		for (int ix = 0; 2 * ix + 1 < bid_len; ++ix) {
+		for (size_t ix = 0; 2 * ix + 1 < bid_len; ++ix) {
 			if (!isxdigit(build_id[2 * ix]) ||
 			    !isxdigit(build_id[2 * ix + 1])) {
 				strlist__remove(known_build_ids, pos);
@@ -732,10 +732,10 @@ static bool perf_inject__lookup_known_build_id(struct perf_inject *inject,
 					       struct dso *dso)
 {
 	struct str_node *pos;
-	int bid_len;
 
 	strlist__for_each_entry(pos, inject->known_build_ids) {
 		const char *build_id, *dso_name;
+		size_t bid_len;
 
 		build_id = skip_spaces(pos->s);
 		dso_name = strchr(build_id, ' ');
@@ -743,7 +743,7 @@ static bool perf_inject__lookup_known_build_id(struct perf_inject *inject,
 		dso_name = skip_spaces(dso_name);
 		if (strcmp(dso__long_name(dso), dso_name))
 			continue;
-		for (int ix = 0; 2 * ix + 1 < bid_len; ++ix) {
+		for (size_t ix = 0; 2 * ix + 1 < bid_len; ++ix) {
 			dso__bid(dso)->data[ix] = (hex(build_id[2 * ix]) << 4 |
 						  hex(build_id[2 * ix + 1]));
 		}
@@ -1006,7 +1006,7 @@ static int perf_inject__sched_stat(const struct perf_tool *tool,
 	union perf_event *event_sw;
 	struct perf_sample sample_sw;
 	struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
-	u32 pid = evsel__intval(evsel, sample, "pid");
+	u32 pid = (u32)evsel__intval(evsel, sample, "pid");
 
 	list_for_each_entry(ent, &inject->samples, node) {
 		if (pid == ent->tid)
@@ -1038,7 +1038,7 @@ static int guest_session__output_bytes(struct guest_session *gs, void *buf, size
 {
 	ssize_t ret = writen(gs->tmp_fd, buf, sz);
 
-	return ret < 0 ? ret : 0;
+	return ret < 0 ? (int)ret : 0;
 }
 
 static int guest_session__repipe(const struct perf_tool *tool,
@@ -1444,7 +1444,7 @@ static int guest_session__start(struct guest_session *gs, const char *name, bool
 
 	session = perf_session__new(&gs->data, &gs->tool);
 	if (IS_ERR(session))
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 	gs->session = session;
 
 	/*
@@ -1518,7 +1518,7 @@ static void guest_session__exit(struct guest_session *gs)
 static void get_tsc_conv(struct perf_tsc_conversion *tc, struct perf_record_time_conv *time_conv)
 {
 	tc->time_shift		= time_conv->time_shift;
-	tc->time_mult		= time_conv->time_mult;
+	tc->time_mult		= (u32)time_conv->time_mult;
 	tc->time_zero		= time_conv->time_zero;
 	tc->time_cycles		= time_conv->time_cycles;
 	tc->time_mask		= time_conv->time_mask;
@@ -1578,7 +1578,7 @@ static int guest_session__fetch(struct guest_session *gs)
 	hdr = buf;
 	ret = readn(gs->tmp_fd, buf, hdr_sz);
 	if (ret < 0)
-		return ret;
+		return (int)ret;
 
 	if (!ret) {
 		/* Zero size means EOF */
@@ -1590,7 +1590,7 @@ static int guest_session__fetch(struct guest_session *gs)
 
 	ret = readn(gs->tmp_fd, buf, hdr->size - hdr_sz);
 	if (ret < 0)
-		return ret;
+		return (int)ret;
 
 	gs->ev.event = (union perf_event *)gs->ev.event_buf;
 	gs->ev.sample.time = 0;
@@ -1603,7 +1603,7 @@ static int guest_session__fetch(struct guest_session *gs)
 	ret = evlist__parse_sample(gs->session->evlist, gs->ev.event, &gs->ev.sample);
 	if (ret) {
 		pr_err("Parse failed fetching guest event");
-		return ret;
+		return (int)ret;
 	}
 
 	if (!gs->have_tc) {
@@ -1982,7 +1982,7 @@ static int parse_guest_data(const struct option *opt, const char *str, int unset
 	tok = strsep(&s, ",");
 	if (!tok)
 		goto bad_args;
-	gs->machine_pid = strtoul(tok, NULL, 0);
+	gs->machine_pid = (u32)strtoul(tok, NULL, 0);
 	if (!inject->guest_session.machine_pid)
 		goto bad_args;
 
@@ -2535,7 +2535,7 @@ int cmd_inject(int argc, const char **argv)
 					     /*trace_event_repipe=*/inject.output.is_pipe);
 
 	if (IS_ERR(inject.session)) {
-		ret = PTR_ERR(inject.session);
+		ret = (int)PTR_ERR(inject.session);
 		goto out_close_output;
 	}
 
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 37/47] perf sched: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (35 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 36/47] perf inject: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 38/47] perf timechart: " Ian Rogers
                   ` (9 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-sched.c | 56 +++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 26ece6e9bfd1..8ddb0bab5748 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -595,7 +595,7 @@ static int self_open_counters(struct perf_sched *sched, unsigned long cur_task)
 static u64 get_cpu_usage_nsec_self(int fd)
 {
 	u64 runtime;
-	int ret;
+	ssize_t ret;
 
 	ret = read(fd, &runtime, sizeof(runtime));
 	BUG_ON(ret != sizeof(runtime));
@@ -823,7 +823,7 @@ replay_wakeup_event(struct perf_sched *sched,
 		    struct machine *machine __maybe_unused)
 {
 	const char *comm = evsel__strval(evsel, sample, "comm");
-	const u32 pid	 = evsel__intval(evsel, sample, "pid");
+	const u32 pid	 = (u32)evsel__intval(evsel, sample, "pid");
 	struct task_desc *waker, *wakee;
 
 	if (verbose > 0) {
@@ -846,8 +846,8 @@ static int replay_switch_event(struct perf_sched *sched,
 {
 	const char *prev_comm  = evsel__strval(evsel, sample, "prev_comm"),
 		   *next_comm  = evsel__strval(evsel, sample, "next_comm");
-	const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"),
-		  next_pid = evsel__intval(evsel, sample, "next_pid");
+	const u32 prev_pid = (u32)evsel__intval(evsel, sample, "prev_pid"),
+		  next_pid = (u32)evsel__intval(evsel, sample, "next_pid");
 	struct task_desc *prev, __maybe_unused *next;
 	u64 timestamp0, timestamp = sample->time;
 	int cpu = sample->cpu;
@@ -1116,8 +1116,8 @@ static int latency_switch_event(struct perf_sched *sched,
 				struct perf_sample *sample,
 				struct machine *machine)
 {
-	const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"),
-		  next_pid = evsel__intval(evsel, sample, "next_pid");
+	const u32 prev_pid = (u32)evsel__intval(evsel, sample, "prev_pid"),
+		  next_pid = (u32)evsel__intval(evsel, sample, "next_pid");
 	const char prev_state = evsel__taskstate(evsel, sample, "prev_state");
 	struct work_atoms *out_events, *in_events;
 	struct thread *sched_out, *sched_in;
@@ -1186,7 +1186,7 @@ static int latency_runtime_event(struct perf_sched *sched,
 				 struct perf_sample *sample,
 				 struct machine *machine)
 {
-	const u32 pid	   = evsel__intval(evsel, sample, "pid");
+	const u32 pid	   = (u32)evsel__intval(evsel, sample, "pid");
 	const u64 runtime  = evsel__intval(evsel, sample, "runtime");
 	struct thread *thread = machine__findnew_thread(machine, -1, pid);
 	struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid);
@@ -1221,7 +1221,7 @@ static int latency_wakeup_event(struct perf_sched *sched,
 				struct perf_sample *sample,
 				struct machine *machine)
 {
-	const u32 pid	  = evsel__intval(evsel, sample, "pid");
+	const u32 pid = (u32)evsel__intval(evsel, sample, "pid");
 	struct work_atoms *atoms;
 	struct work_atom *atom;
 	struct thread *wakee;
@@ -1282,7 +1282,7 @@ static int latency_migrate_task_event(struct perf_sched *sched,
 				      struct perf_sample *sample,
 				      struct machine *machine)
 {
-	const u32 pid = evsel__intval(evsel, sample, "pid");
+	const u32 pid = (u32)evsel__intval(evsel, sample, "pid");
 	u64 timestamp = sample->time;
 	struct work_atoms *atoms;
 	struct work_atom *atom;
@@ -1618,8 +1618,8 @@ static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu,
 static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 			    struct perf_sample *sample, struct machine *machine)
 {
-	const u32 next_pid = evsel__intval(evsel, sample, "next_pid");
-	const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid");
+	const u32 next_pid = (u32)evsel__intval(evsel, sample, "next_pid");
+	const u32 prev_pid = (u32)evsel__intval(evsel, sample, "prev_pid");
 	struct thread *sched_in, *sched_out;
 	struct thread_runtime *tr;
 	int new_shortname;
@@ -1641,7 +1641,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 		sched->max_cpu = this_cpu;
 
 	if (sched->map.comp) {
-		cpus_nr = bitmap_weight(sched->map.comp_cpus_mask, MAX_CPUS);
+		cpus_nr = (int)bitmap_weight(sched->map.comp_cpus_mask, MAX_CPUS);
 		if (!__test_and_set_bit(this_cpu.cpu, sched->map.comp_cpus_mask)) {
 			sched->map.comp_cpus[cpus_nr++] = this_cpu;
 			new_cpu = true;
@@ -1784,8 +1784,8 @@ static int process_sched_switch_event(const struct perf_tool *tool,
 {
 	struct perf_sched *sched = container_of(tool, struct perf_sched, tool);
 	int this_cpu = sample->cpu, err = 0;
-	u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"),
-	    next_pid = evsel__intval(evsel, sample, "next_pid");
+	u32 prev_pid = (u32)evsel__intval(evsel, sample, "prev_pid");
+	u32 next_pid = (u32)evsel__intval(evsel, sample, "next_pid");
 
 	if (sched->curr_pid[this_cpu] != (u32)-1) {
 		/*
@@ -1919,7 +1919,7 @@ static int perf_sched__read_events(struct perf_sched *sched)
 	session = perf_session__new(&data, &sched->tool);
 	if (IS_ERR(session)) {
 		pr_debug("Error creating perf session");
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 	}
 
 	symbol__init(&session->header.env);
@@ -1990,7 +1990,7 @@ static void evsel__save_time(struct evsel *evsel, u64 timestamp, u32 cpu)
 		return;
 
 	if ((cpu >= r->ncpu) || (r->last_time == NULL)) {
-		int i, n = __roundup_pow_of_two(cpu+1);
+		u32 n = (u32)__roundup_pow_of_two(cpu+1);
 		void *p = r->last_time;
 
 		p = realloc(r->last_time, n * sizeof(u64));
@@ -1998,7 +1998,7 @@ static void evsel__save_time(struct evsel *evsel, u64 timestamp, u32 cpu)
 			return;
 
 		r->last_time = p;
-		for (i = r->ncpu; i < n; ++i)
+		for (u32 i = r->ncpu; i < n; ++i)
 			r->last_time[i] = (u64) 0;
 
 		r->ncpu = n;
@@ -2146,7 +2146,7 @@ static void timehist_print_sample(struct perf_sched *sched,
 {
 	struct thread_runtime *tr = thread__priv(thread);
 	const char *next_comm = evsel__strval(evsel, sample, "next_comm");
-	const u32 next_pid = evsel__intval(evsel, sample, "next_pid");
+	const u32 next_pid = (u32)evsel__intval(evsel, sample, "next_pid");
 	u32 max_cpus = sched->max_cpu.cpu + 1;
 	char tstr[64];
 	char nstr[30];
@@ -2415,7 +2415,7 @@ static struct thread *get_idle_thread(int cpu)
 	 * structs if needed
 	 */
 	if ((cpu >= idle_max_cpu) || (idle_threads == NULL)) {
-		int i, j = __roundup_pow_of_two(cpu+1);
+		int j = (int)__roundup_pow_of_two(cpu+1);
 		void *p;
 
 		p = realloc(idle_threads, j * sizeof(struct thread *));
@@ -2423,7 +2423,7 @@ static struct thread *get_idle_thread(int cpu)
 			return NULL;
 
 		idle_threads = (struct thread **) p;
-		for (i = idle_max_cpu; i < j; ++i)
+		for (int i = idle_max_cpu; i < j; ++i)
 			idle_threads[i] = NULL;
 
 		idle_max_cpu = j;
@@ -2530,7 +2530,7 @@ static bool timehist_skip_sample(struct perf_sched *sched,
 		if (tr && tr->prio != -1)
 			prio = tr->prio;
 		else if (evsel__name_is(evsel, "sched:sched_switch"))
-			prio = evsel__intval(evsel, sample, "prev_prio");
+			prio = (int)evsel__intval(evsel, sample, "prev_prio");
 
 		if (prio != -1 && !test_bit(prio, sched->prio_bitmap)) {
 			rc = true;
@@ -2602,7 +2602,7 @@ static int timehist_sched_wakeup_event(const struct perf_tool *tool,
 	struct thread *thread;
 	struct thread_runtime *tr = NULL;
 	/* want pid of awakened task not pid in sample */
-	const u32 pid = evsel__intval(evsel, sample, "pid");
+	const u32 pid = (u32)evsel__intval(evsel, sample, "pid");
 
 	thread = machine__findnew_thread(machine, 0, pid);
 	if (thread == NULL)
@@ -2638,8 +2638,8 @@ static void timehist_print_migration_event(struct perf_sched *sched,
 		return;
 
 	max_cpus = sched->max_cpu.cpu + 1;
-	ocpu = evsel__intval(evsel, sample, "orig_cpu");
-	dcpu = evsel__intval(evsel, sample, "dest_cpu");
+	ocpu = (u32)evsel__intval(evsel, sample, "orig_cpu");
+	dcpu = (u32)evsel__intval(evsel, sample, "dest_cpu");
 
 	thread = machine__findnew_thread(machine, sample->pid, sample->tid);
 	if (thread == NULL)
@@ -2686,7 +2686,7 @@ static int timehist_migrate_task_event(const struct perf_tool *tool,
 	struct thread *thread;
 	struct thread_runtime *tr = NULL;
 	/* want pid of migrated task not pid in sample */
-	const u32 pid = evsel__intval(evsel, sample, "pid");
+	const u32 pid = (u32)evsel__intval(evsel, sample, "pid");
 
 	thread = machine__findnew_thread(machine, 0, pid);
 	if (thread == NULL)
@@ -2714,8 +2714,8 @@ static void timehist_update_task_prio(struct evsel *evsel,
 {
 	struct thread *thread;
 	struct thread_runtime *tr = NULL;
-	const u32 next_pid = evsel__intval(evsel, sample, "next_pid");
-	const u32 next_prio = evsel__intval(evsel, sample, "next_prio");
+	const u32 next_pid = (u32)evsel__intval(evsel, sample, "next_pid");
+	const u32 next_prio = (u32)evsel__intval(evsel, sample, "next_prio");
 
 	if (next_pid == 0)
 		thread = get_idle_thread(sample->cpu);
@@ -3258,7 +3258,7 @@ static int perf_sched__timehist(struct perf_sched *sched)
 
 	session = perf_session__new(&data, &sched->tool);
 	if (IS_ERR(session))
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 
 	if (cpu_list) {
 		err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 38/47] perf timechart: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (36 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 37/47] perf sched: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 39/47] perf list: " Ian Rogers
                   ` (8 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-timechart.c | 60 ++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 28 deletions(-)

diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 068d297aaf44..6d8d695f3099 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -118,7 +118,7 @@ struct per_pidcomm {
 	int		Y;
 	int		display;
 
-	long		state;
+	int		state;
 	u64		state_since;
 
 	char		*comm;
@@ -385,7 +385,7 @@ static struct power_event *p_state_end(struct timechart *tchart, int cpu,
 	if (!pwr)
 		return NULL;
 
-	pwr->state = cpus_pstate_state[cpu];
+	pwr->state = (int)cpus_pstate_state[cpu];
 	pwr->start_time = cpus_pstate_start_times[cpu];
 	pwr->end_time = timestamp;
 	pwr->cpu = cpu;
@@ -601,8 +601,8 @@ process_sample_cpu_idle(struct timechart *tchart __maybe_unused,
 			struct perf_sample *sample,
 			const char *backtrace __maybe_unused)
 {
-	u32 state  = evsel__intval(evsel, sample, "state");
-	u32 cpu_id = evsel__intval(evsel, sample, "cpu_id");
+	u32 state  = (u32)evsel__intval(evsel, sample, "state");
+	u32 cpu_id = (u32)evsel__intval(evsel, sample, "cpu_id");
 
 	if (state == (u32)PWR_EVENT_EXIT)
 		c_state_end(tchart, cpu_id, sample->time);
@@ -617,8 +617,8 @@ process_sample_cpu_frequency(struct timechart *tchart,
 			     struct perf_sample *sample,
 			     const char *backtrace __maybe_unused)
 {
-	u32 state  = evsel__intval(evsel, sample, "state");
-	u32 cpu_id = evsel__intval(evsel, sample, "cpu_id");
+	u32 state  = (u32)evsel__intval(evsel, sample, "state");
+	u32 cpu_id = (u32)evsel__intval(evsel, sample, "cpu_id");
 
 	p_state_change(tchart, cpu_id, sample->time, state);
 	return 0;
@@ -631,8 +631,8 @@ process_sample_sched_wakeup(struct timechart *tchart,
 			    const char *backtrace)
 {
 	u8 flags  = evsel__intval(evsel, sample, "common_flags");
-	int waker = evsel__intval(evsel, sample, "common_pid");
-	int wakee = evsel__intval(evsel, sample, "pid");
+	int waker = (int)evsel__intval(evsel, sample, "common_pid");
+	int wakee = (int)evsel__intval(evsel, sample, "pid");
 
 	sched_wakeup(tchart, sample->cpu, sample->time, waker, wakee, flags, backtrace);
 	return 0;
@@ -644,8 +644,8 @@ process_sample_sched_switch(struct timechart *tchart,
 			    struct perf_sample *sample,
 			    const char *backtrace)
 {
-	int prev_pid   = evsel__intval(evsel, sample, "prev_pid");
-	int next_pid   = evsel__intval(evsel, sample, "next_pid");
+	int prev_pid   = (int)evsel__intval(evsel, sample, "prev_pid");
+	int next_pid   = (int)evsel__intval(evsel, sample, "next_pid");
 	u64 prev_state = evsel__intval(evsel, sample, "prev_state");
 
 	sched_switch(tchart, sample->cpu, sample->time, prev_pid, next_pid,
@@ -660,8 +660,8 @@ process_sample_power_start(struct timechart *tchart __maybe_unused,
 			   struct perf_sample *sample,
 			   const char *backtrace __maybe_unused)
 {
-	u64 cpu_id = evsel__intval(evsel, sample, "cpu_id");
-	u64 value  = evsel__intval(evsel, sample, "value");
+	int cpu_id = (int)evsel__intval(evsel, sample, "cpu_id");
+	int value  = (int)evsel__intval(evsel, sample, "value");
 
 	c_state_start(cpu_id, sample->time, value);
 	return 0;
@@ -683,7 +683,7 @@ process_sample_power_frequency(struct timechart *tchart,
 			       struct perf_sample *sample,
 			       const char *backtrace __maybe_unused)
 {
-	u64 cpu_id = evsel__intval(evsel, sample, "cpu_id");
+	int cpu_id = (int)evsel__intval(evsel, sample, "cpu_id");
 	u64 value  = evsel__intval(evsel, sample, "value");
 
 	p_state_change(tchart, cpu_id, sample->time, value);
@@ -697,10 +697,9 @@ process_sample_power_frequency(struct timechart *tchart,
  */
 static void end_sample_processing(struct timechart *tchart)
 {
-	u64 cpu;
 	struct power_event *pwr;
 
-	for (cpu = 0; cpu <= tchart->numcpus; cpu++) {
+	for (unsigned int cpu = 0; cpu <= tchart->numcpus; cpu++) {
 		/* C state */
 #if 0
 		pwr = zalloc(sizeof(*pwr));
@@ -723,7 +722,7 @@ static void end_sample_processing(struct timechart *tchart)
 			return;
 
 		if (!pwr->state)
-			pwr->state = tchart->min_freq;
+			pwr->state = (int)tchart->min_freq;
 	}
 }
 
@@ -812,7 +811,7 @@ static int pid_end_io_sample(struct timechart *tchart, int pid, int type,
 	}
 
 	if (ret < 0) {
-		sample->err = ret;
+		sample->err = (int)ret;
 	} else if (type == IOTYPE_READ || type == IOTYPE_WRITE ||
 		   type == IOTYPE_TX || type == IOTYPE_RX) {
 
@@ -852,7 +851,8 @@ process_enter_read(struct timechart *tchart,
 		   struct evsel *evsel,
 		   struct perf_sample *sample)
 {
-	long fd = evsel__intval(evsel, sample, "fd");
+	int fd = (int)evsel__intval(evsel, sample, "fd");
+
 	return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ,
 				   sample->time, fd);
 }
@@ -872,7 +872,8 @@ process_enter_write(struct timechart *tchart,
 		    struct evsel *evsel,
 		    struct perf_sample *sample)
 {
-	long fd = evsel__intval(evsel, sample, "fd");
+	int fd = (int)evsel__intval(evsel, sample, "fd");
+
 	return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE,
 				   sample->time, fd);
 }
@@ -892,7 +893,8 @@ process_enter_sync(struct timechart *tchart,
 		   struct evsel *evsel,
 		   struct perf_sample *sample)
 {
-	long fd = evsel__intval(evsel, sample, "fd");
+	int fd = (int)evsel__intval(evsel, sample, "fd");
+
 	return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC,
 				   sample->time, fd);
 }
@@ -912,7 +914,8 @@ process_enter_tx(struct timechart *tchart,
 		 struct evsel *evsel,
 		 struct perf_sample *sample)
 {
-	long fd = evsel__intval(evsel, sample, "fd");
+	int fd = (int)evsel__intval(evsel, sample, "fd");
+
 	return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX,
 				   sample->time, fd);
 }
@@ -932,7 +935,8 @@ process_enter_rx(struct timechart *tchart,
 		 struct evsel *evsel,
 		 struct perf_sample *sample)
 {
-	long fd = evsel__intval(evsel, sample, "fd");
+	int fd = (int)evsel__intval(evsel, sample, "fd");
+
 	return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX,
 				   sample->time, fd);
 }
@@ -952,7 +956,8 @@ process_enter_poll(struct timechart *tchart,
 		   struct evsel *evsel,
 		   struct perf_sample *sample)
 {
-	long fd = evsel__intval(evsel, sample, "fd");
+	int fd = (int)evsel__intval(evsel, sample, "fd");
+
 	return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL,
 				   sample->time, fd);
 }
@@ -1034,7 +1039,7 @@ static void draw_c_p_states(struct timechart *tchart)
 	while (pwr) {
 		if (pwr->type == PSTATE) {
 			if (!pwr->state)
-				pwr->state = tchart->min_freq;
+				pwr->state = (int)tchart->min_freq;
 			svg_pstate(pwr->cpu, pwr->start_time, pwr->end_time, pwr->state);
 		}
 		pwr = pwr->next;
@@ -1310,7 +1315,7 @@ static void draw_process_bars(struct timechart *tchart)
 
 static void add_process_filter(const char *string)
 {
-	int pid = strtoull(string, NULL, 10);
+	int pid = (int)strtoull(string, NULL, 10);
 	struct process_filter *filt = malloc(sizeof(*filt));
 
 	if (!filt)
@@ -1458,7 +1463,6 @@ static int determine_display_io_tasks(struct timechart *timechart, u64 threshold
 
 static void write_svg_file(struct timechart *tchart, const char *filename)
 {
-	u64 i;
 	int count;
 	int thresh = tchart->io_events ? BYTES_THRESH : TIME_THRESH;
 
@@ -1494,7 +1498,7 @@ static void write_svg_file(struct timechart *tchart, const char *filename)
 
 		svg_legenda();
 
-		for (i = 0; i < tchart->numcpus; i++)
+		for (unsigned int i = 0; i < tchart->numcpus; i++)
 			svg_cpu_box(i, tchart->max_freq, tchart->turbo_frequency);
 
 		draw_cpu_usage(tchart);
@@ -1616,7 +1620,7 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)
 
 	session = perf_session__new(&data, &tchart->tool);
 	if (IS_ERR(session))
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 
 	symbol__init(&session->header.env);
 
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 39/47] perf list: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (37 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 38/47] perf timechart: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 40/47] perf kvm: " Ian Rogers
                   ` (7 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-list.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index fed482adb039..ffe2e972e3f2 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -93,7 +93,7 @@ static void wordwrap(FILE *fp, const char *s, int start, int max, int corr)
 	bool comma = false;
 
 	while (*s) {
-		int wlen = strcspn(s, " ,\t\n");
+		int wlen = (int)strcspn(s, " ,\t\n");
 		const char *sep = comma ? "," : " ";
 
 		if ((column + wlen >= max && column > start) || saw_newline) {
@@ -171,7 +171,7 @@ static void default_print_event(void *ps, const char *topic, const char *pmu_nam
 		int desc_len = -1;
 
 		if (pmu_name && strcmp(pmu_name, "default_core")) {
-			desc_len = strlen(desc);
+			desc_len = (int)strlen(desc);
 			desc_len = asprintf(&desc_with_unit,
 					    desc_len > 0 && desc[desc_len - 1] != '.'
 					      ? "%s. Unit: %s" : "%s Unit: %s",
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 40/47] perf kvm: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (38 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 39/47] perf list: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 41/47] perf diff: " Ian Rogers
                   ` (6 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-kvm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 67fd2b006b0b..a81874b7f2d3 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -928,7 +928,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread,
 			return NULL;
 		}
 
-		vcpu_record->vcpu_id = evsel__intval(evsel, sample, vcpu_id_str);
+		vcpu_record->vcpu_id = (int)evsel__intval(evsel, sample, vcpu_id_str);
 		thread__set_priv(thread, vcpu_record);
 	}
 
@@ -1337,7 +1337,7 @@ static int perf_kvm__handle_timerfd(struct perf_kvm_stat *kvm)
 	uint64_t c;
 	int rc;
 
-	rc = read(kvm->timerfd, &c, sizeof(uint64_t));
+	rc = (int)read(kvm->timerfd, &c, sizeof(uint64_t));
 	if (rc < 0) {
 		if (errno == EAGAIN)
 			return 0;
@@ -1558,7 +1558,7 @@ static int read_events(struct perf_kvm_stat *kvm)
 	kvm->session = perf_session__new(&file, &kvm->tool);
 	if (IS_ERR(kvm->session)) {
 		pr_err("Initializing perf session failed\n");
-		return PTR_ERR(kvm->session);
+		return (int)PTR_ERR(kvm->session);
 	}
 
 	symbol__init(&kvm->session->header.env);
@@ -1924,7 +1924,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
 	 */
 	kvm->session = perf_session__new(&data, &kvm->tool);
 	if (IS_ERR(kvm->session)) {
-		err = PTR_ERR(kvm->session);
+		err = (int)PTR_ERR(kvm->session);
 		goto out;
 	}
 	kvm->session->evlist = kvm->evlist;
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 41/47] perf diff: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (39 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 40/47] perf kvm: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 42/47] perf daemon: " Ian Rogers
                   ` (5 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-diff.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index ae490d58af92..9c21ea8f242a 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -243,7 +243,7 @@ static int setup_compute(const struct option *opt, const char *str,
 
 	option = strchr(str, ':');
 	if (option) {
-		unsigned len = option++ - str;
+		size_t len = option++ - str;
 
 		/*
 		 * The str data are not writeable, so we need
@@ -1148,7 +1148,7 @@ static int check_file_brstack(void)
 		d->session = perf_session__new(&d->data, &pdiff.tool);
 		if (IS_ERR(d->session)) {
 			pr_err("Failed to open %s\n", d->data.path);
-			return PTR_ERR(d->session);
+			return (int)PTR_ERR(d->session);
 		}
 
 		has_br_stack = perf_header__has_feat(&d->session->header,
@@ -1179,7 +1179,7 @@ static int __cmd_diff(void)
 	data__for_each_file(i, d) {
 		d->session = perf_session__new(&d->data, &pdiff.tool);
 		if (IS_ERR(d->session)) {
-			ret = PTR_ERR(d->session);
+			ret = (int)PTR_ERR(d->session);
 			pr_err("Failed to open %s\n", d->data.path);
 			goto out_delete;
 		}
@@ -1492,10 +1492,10 @@ static int print_cycles_spark(char *bf, int size, unsigned long *svals, u64 n)
 
 	if (n > NUM_SPARKS)
 		n = NUM_SPARKS;
-	if (all_zero(svals, n))
+	if (all_zero(svals, (int)n))
 		return 0;
 
-	printed = print_spark(bf, size, svals, n);
+	printed = print_spark(bf, size, svals, (int)n);
 	printed += scnprintf(bf + printed, size - printed, " ");
 	return printed;
 }
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 42/47] perf daemon: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (40 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 41/47] perf diff: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 43/47] perf zlib: " Ian Rogers
                   ` (4 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/builtin-daemon.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
index f0568431fbd5..640ba8191083 100644
--- a/tools/perf/builtin-daemon.c
+++ b/tools/perf/builtin-daemon.c
@@ -514,7 +514,8 @@ static int daemon_session__control(struct daemon_session *session,
 	struct pollfd pollfd = { .events = POLLIN, };
 	char control_path[PATH_MAX];
 	char ack_path[PATH_MAX];
-	int control, ack = -1, len;
+	int control, ack = -1;
+	size_t len;
 	char buf[20];
 	int ret = -1;
 	ssize_t err;
@@ -543,7 +544,7 @@ static int daemon_session__control(struct daemon_session *session,
 	len = strlen(msg);
 
 	err = writen(control, msg, len);
-	if (err != len) {
+	if (err != (ssize_t)len) {
 		pr_err("failed: write to control pipe: %d (%s)\n",
 		       errno, control_path);
 		goto out;
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 43/47] perf zlib: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (41 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 42/47] perf daemon: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 44/47] perf symbol: " Ian Rogers
                   ` (3 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/util/zlib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/zlib.c b/tools/perf/util/zlib.c
index 78d2297c1b67..d30597701fd1 100644
--- a/tools/perf/util/zlib.c
+++ b/tools/perf/util/zlib.c
@@ -44,7 +44,7 @@ int gzip_decompress_to_file(const char *input, int output_fd)
 		goto out_unmap;
 
 	zs.next_in = ptr;
-	zs.avail_in = stbuf.st_size;
+	zs.avail_in = (uInt)stbuf.st_size;
 
 	do {
 		zs.next_out = buf;
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 44/47] perf symbol: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (42 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 43/47] perf zlib: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 45/47] perf util: " Ian Rogers
                   ` (2 subsequent siblings)
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/util/symbol-elf.c | 33 +++++++++++++++++----------------
 tools/perf/util/symbol.c     | 10 +++++-----
 2 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index fbf6d0f73af9..9de6e963ca79 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -261,7 +261,7 @@ static int elf_read_program_header(Elf *elf, u64 vaddr, GElf_Phdr *phdr)
 		return -1;
 
 	for (i = 0; i < phdrnum; i++) {
-		if (gelf_getphdr(elf, i, phdr) == NULL)
+		if (gelf_getphdr(elf, (int)i, phdr) == NULL)
 			return -1;
 
 		if (phdr->p_type != PT_LOAD)
@@ -550,7 +550,7 @@ static void get_rela_dyn_info(Elf *elf, GElf_Ehdr *ehdr, struct rela_dyn_info *d
 	if (!scn || !rela_dyn_shdr.sh_link || !rela_dyn_shdr.sh_entsize)
 		return;
 
-	di->nr_entries = rela_dyn_shdr.sh_size / rela_dyn_shdr.sh_entsize;
+	di->nr_entries = (u32)(rela_dyn_shdr.sh_size / rela_dyn_shdr.sh_entsize);
 	di->rela_dyn_data = elf_getdata(scn, NULL);
 
 	scn = elf_getscn(elf, rela_dyn_shdr.sh_link);
@@ -789,7 +789,7 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss)
 	if (symstrs->d_size == 0)
 		goto out_elf_end;
 
-	ri.nr_entries = shdr_rel_plt.sh_size / shdr_rel_plt.sh_entsize;
+	ri.nr_entries = (u32)(shdr_rel_plt.sh_size / shdr_rel_plt.sh_entsize);
 
 	ri.is_rela = shdr_rel_plt.sh_type == SHT_RELA;
 
@@ -925,7 +925,7 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)
 				size_t sz = min(size, descsz);
 				memcpy(bf, ptr, sz);
 				memset(bf + sz, 0, size - sz);
-				err = sz;
+				err = (int)sz;
 				break;
 			}
 		}
@@ -1066,14 +1066,14 @@ int sysfs__read_build_id(const char *filename, struct build_id *bid)
 			} else if (read(fd, bf, descsz) != (ssize_t)descsz)
 				break;
 		} else {
-			int n = namesz + descsz;
+			size_t n = namesz + descsz;
 
-			if (n > (int)sizeof(bf)) {
+			if (n > sizeof(bf)) {
 				n = sizeof(bf);
 				pr_debug("%s: truncating reading of build id in sysfs file %s: n_namesz=%u, n_descsz=%u.\n",
 					 __func__, filename, nhdr.n_namesz, nhdr.n_descsz);
 			}
-			if (read(fd, bf, n) != n)
+			if (read(fd, bf, n) != (ssize_t)n)
 				break;
 		}
 	}
@@ -1426,7 +1426,7 @@ static u64 max_text_section(Elf *elf, GElf_Ehdr *ehdr)
 		if (!gelf_getshdr(sec, &shdr))
 			break;
 
-		if (!is_exe_text(shdr.sh_flags))
+		if (!is_exe_text((int)shdr.sh_flags))
 			continue;
 
 		/* .init and .exit sections are not placed with .text */
@@ -1546,7 +1546,7 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
 	 * perf does not record module section addresses except for .text, but
 	 * some sections can use the same mapping as .text.
 	 */
-	if (kmodule && adjust_kernel_syms && is_exe_text(shdr->sh_flags) &&
+	if (kmodule && adjust_kernel_syms && is_exe_text((int)shdr->sh_flags) &&
 	    shdr->sh_offset <= max_text_sh_offset) {
 		dso__put(*curr_dsop);
 		*curr_dsop = dso__get(dso);
@@ -1672,7 +1672,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 	if (secstrs_sym == NULL)
 		goto out_elf_end;
 
-	nr_syms = shdr.sh_size / shdr.sh_entsize;
+	nr_syms = (uint32_t)(shdr.sh_size / shdr.sh_entsize);
 
 	memset(&sym, 0, sizeof(sym));
 
@@ -1734,7 +1734,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 		}
 
 		if (runtime_ss->opdsec && sym.st_shndx == runtime_ss->opdidx) {
-			u32 offset = sym.st_value - syms_ss->opdshdr.sh_addr;
+			u32 offset = (u32)(sym.st_value - syms_ss->opdshdr.sh_addr);
 			u64 *opd = opddata->d_buf + offset;
 			sym.st_value = DSO__SWAP(dso, u64, *opd);
 			sym.st_shndx = elf_addr_to_index(runtime_ss->elf,
@@ -1946,7 +1946,7 @@ static int elf_read_maps(Elf *elf, bool exe, mapfn_t mapfn, void *data)
 		return -1;
 
 	for (i = 0; i < phdrnum; i++) {
-		if (gelf_getphdr(elf, i, &phdr) == NULL)
+		if (gelf_getphdr(elf, (int)i, &phdr) == NULL)
 			return -1;
 		if (phdr.p_type != PT_LOAD)
 			continue;
@@ -2767,14 +2767,15 @@ static void sdt_adjust_loc(struct sdt_note *tmp, GElf_Addr base_off)
 	if (!base_off)
 		return;
 
-	if (tmp->bit32)
+	if (tmp->bit32) {
 		tmp->addr.a32[SDT_NOTE_IDX_LOC] =
-			tmp->addr.a32[SDT_NOTE_IDX_LOC] + base_off -
-			tmp->addr.a32[SDT_NOTE_IDX_BASE];
-	else
+			(Elf32_Addr)(tmp->addr.a32[SDT_NOTE_IDX_LOC] + base_off -
+				     tmp->addr.a32[SDT_NOTE_IDX_BASE]);
+	} else {
 		tmp->addr.a64[SDT_NOTE_IDX_LOC] =
 			tmp->addr.a64[SDT_NOTE_IDX_LOC] + base_off -
 			tmp->addr.a64[SDT_NOTE_IDX_BASE];
+	}
 }
 
 static void sdt_adjust_refctr(struct sdt_note *tmp, GElf_Addr base_addr,
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 11540219481b..7eceb6679ed5 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -111,7 +111,7 @@ static int prefix_underscores_count(const char *str)
 	while (*tail == '_')
 		tail++;
 
-	return tail - str;
+	return (int)(tail - str);
 }
 
 const char * __weak arch__normalize_symbol_name(const char *name)
@@ -481,10 +481,10 @@ int symbol__match_symbol_name(const char *name, const char *str,
 
 	if (includes == SYMBOL_TAG_INCLUDE__DEFAULT_ONLY &&
 	    (versioning = strstr(name, "@@"))) {
-		int len = strlen(str);
+		int len = (int)strlen(str);
 
 		if (len < versioning - name)
-			len = versioning - name;
+			len = (int)(versioning - name);
 
 		return arch__compare_symbol_names_n(name, str, len);
 	} else
@@ -638,7 +638,7 @@ void dso__sort_by_name(struct dso *dso)
  * While we find nice hex chars, build a long_val.
  * Return number of chars processed.
  */
-static int hex2u64(const char *ptr, u64 *long_val)
+static size_t hex2u64(const char *ptr, u64 *long_val)
 {
 	char *p;
 
@@ -1532,7 +1532,7 @@ static int dso__load_perf_map(const char *map_path, struct dso *dso)
 	while (!feof(file)) {
 		u64 start, size;
 		struct symbol *sym;
-		int line_len, len;
+		size_t line_len, len;
 
 		line_len = getline(&line, &n, file);
 		if (line_len < 0)
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 45/47] perf util: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (43 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 44/47] perf symbol: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 46/47] perf hashmap: " Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 47/47] perf: " Ian Rogers
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/perf-sys.h        |  3 +--
 tools/perf/util/cacheline.c  |  5 ++++-
 tools/perf/util/cgroup.c     |  4 ++--
 tools/perf/util/comm.c       |  2 +-
 tools/perf/util/config.c     |  6 +++---
 tools/perf/util/cpumap.c     |  4 ++--
 tools/perf/util/debug.c      |  7 +++----
 tools/perf/util/memswap.c    |  4 ++--
 tools/perf/util/memswap.h    |  4 ++--
 tools/perf/util/strfilter.c  |  2 +-
 tools/perf/util/string.c     | 11 ++++++-----
 tools/perf/util/svghelper.c  | 23 ++++++++++++-----------
 tools/perf/util/time-utils.c |  9 +++++----
 tools/perf/util/util.c       |  9 +++++----
 tools/perf/util/util.h       |  2 +-
 15 files changed, 50 insertions(+), 45 deletions(-)

diff --git a/tools/perf/perf-sys.h b/tools/perf/perf-sys.h
index 7a2264e1e4e1..89e44798ed2b 100644
--- a/tools/perf/perf-sys.h
+++ b/tools/perf/perf-sys.h
@@ -14,8 +14,7 @@ sys_perf_event_open(struct perf_event_attr *attr,
 		      pid_t pid, int cpu, int group_fd,
 		      unsigned long flags)
 {
-	return syscall(__NR_perf_event_open, attr, pid, cpu,
-		       group_fd, flags);
+	return (int)syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags);
 }
 
 #endif /* _PERF_SYS_H */
diff --git a/tools/perf/util/cacheline.c b/tools/perf/util/cacheline.c
index e98b5250a517..6d4505aeaa5f 100644
--- a/tools/perf/util/cacheline.c
+++ b/tools/perf/util/cacheline.c
@@ -3,7 +3,10 @@
 #include <unistd.h>
 
 #ifdef _SC_LEVEL1_DCACHE_LINESIZE
-#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
+static void cache_line_size(int *cacheline_sizep)
+{
+	*cacheline_sizep = (int)sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+}
 #else
 #include <api/fs/fs.h>
 #include "debug.h"
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index fbcc0626f9ce..30c7f60048b7 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -310,7 +310,7 @@ static int match_cgroups(const char *str)
 		return -1;
 
 	/* cgroup_name will have a full path, skip the root directory */
-	prefix_len = strlen(mnt);
+	prefix_len = (int)strlen(mnt);
 
 	/* collect all cgroups in the cgroup_list */
 	if (nftw(mnt, add_cgroup_name, 20, 0) < 0)
@@ -607,7 +607,7 @@ void read_all_cgroups(struct rb_root *root)
 {
 	char mnt[PATH_MAX];
 	struct cgroup_name *cn;
-	int prefix_len;
+	size_t prefix_len;
 
 	if (cgroupfs_find_mountpoint(mnt, sizeof(mnt), "perf_event"))
 		return;
diff --git a/tools/perf/util/comm.c b/tools/perf/util/comm.c
index 8aa456d7c2cd..3d8f30ddcac1 100644
--- a/tools/perf/util/comm.c
+++ b/tools/perf/util/comm.c
@@ -111,7 +111,7 @@ static void comm_strs__remove_if_last(struct comm_str *cs)
 		entry = bsearch(comm_str__str(cs), comm_strs->strs, comm_strs->num_strs,
 				sizeof(struct comm_str *), comm_str__search);
 		comm_str__put(*entry);
-		for (int i = entry - comm_strs->strs; i < comm_strs->num_strs - 1; i++)
+		for (long i = entry - comm_strs->strs; i < comm_strs->num_strs - 1; i++)
 			comm_strs->strs[i] = comm_strs->strs[i + 1];
 		comm_strs->num_strs--;
 	}
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index ae72b66b6ded..5fd20776e6bb 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -388,7 +388,7 @@ int perf_config_int(int *dest, const char *name, const char *value)
 		bad_config(name);
 		return -1;
 	}
-	*dest = ret;
+	*dest = (int)ret;
 	return 0;
 }
 
@@ -454,10 +454,10 @@ static int perf_buildid_config(const char *var, const char *value)
 static int perf_default_core_config(const char *var, const char *value)
 {
 	if (!strcmp(var, "core.proc-map-timeout"))
-		proc_map_timeout = strtoul(value, NULL, 10);
+		proc_map_timeout = (int)strtoul(value, NULL, 10);
 
 	if (!strcmp(var, "core.addr2line-timeout"))
-		addr2line_timeout_ms = strtoul(value, NULL, 10);
+		addr2line_timeout_ms = (int)strtoul(value, NULL, 10);
 
 	/* Add other config variables here. */
 	return 0;
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 89570397a4b3..7a8bf6843362 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -107,14 +107,14 @@ static struct perf_cpu_map *cpu_map__from_mask(const struct perf_record_cpu_map_
 
 	for (int i = 0, j = 0; i < mask_nr; i++) {
 		int cpus_per_i = (i * data->mask32_data.long_size  * BITS_PER_BYTE);
-		int cpu;
+		size_t cpu;
 
 		perf_record_cpu_map_data__read_one_mask(data, i, local_copy);
 		for_each_set_bit(cpu, local_copy, 64) {
 			if (cpu + cpus_per_i < INT16_MAX) {
 				RC_CHK_ACCESS(map)->map[j++].cpu = cpu + cpus_per_i;
 			} else {
-				pr_err("Invalid cpumap entry %d\n", cpu + cpus_per_i);
+				pr_err("Invalid cpumap entry %zu\n", cpu + cpus_per_i);
 				perf_cpu_map__put(map);
 				return NULL;
 			}
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index f9ef7d045c92..3027477652b6 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -303,13 +303,12 @@ void perf_debug_setup(void)
 void dump_stack(void)
 {
 	void *array[16];
-	size_t size = backtrace(array, ARRAY_SIZE(array));
+	int size = backtrace(array, ARRAY_SIZE(array));
 	char **strings = backtrace_symbols(array, size);
-	size_t i;
 
-	printf("Obtained %zd stack frames.\n", size);
+	printf("Obtained %d stack frames.\n", size);
 
-	for (i = 0; i < size; i++)
+	for (int i = 0; i < size; i++)
 		printf("%s\n", strings[i]);
 
 	free(strings);
diff --git a/tools/perf/util/memswap.c b/tools/perf/util/memswap.c
index c1317e4983bc..68f9b3f72812 100644
--- a/tools/perf/util/memswap.c
+++ b/tools/perf/util/memswap.c
@@ -3,7 +3,7 @@
 #include "memswap.h"
 #include <linux/types.h>
 
-void mem_bswap_32(void *src, int byte_size)
+void mem_bswap_32(void *src, size_t byte_size)
 {
 	u32 *m = src;
 	while (byte_size > 0) {
@@ -13,7 +13,7 @@ void mem_bswap_32(void *src, int byte_size)
 	}
 }
 
-void mem_bswap_64(void *src, int byte_size)
+void mem_bswap_64(void *src, size_t byte_size)
 {
 	u64 *m = src;
 
diff --git a/tools/perf/util/memswap.h b/tools/perf/util/memswap.h
index 2c38e8c2d548..956de6b014f8 100644
--- a/tools/perf/util/memswap.h
+++ b/tools/perf/util/memswap.h
@@ -9,7 +9,7 @@ union u64_swap {
 	u32 val32[2];
 };
 
-void mem_bswap_64(void *src, int byte_size);
-void mem_bswap_32(void *src, int byte_size);
+void mem_bswap_64(void *src, size_t byte_size);
+void mem_bswap_32(void *src, size_t byte_size);
 
 #endif /* PERF_MEMSWAP_H_ */
diff --git a/tools/perf/util/strfilter.c b/tools/perf/util/strfilter.c
index 02807b9d4122..d09523712138 100644
--- a/tools/perf/util/strfilter.c
+++ b/tools/perf/util/strfilter.c
@@ -287,7 +287,7 @@ static int strfilter_node__sprint(struct strfilter_node *node, char *buf)
 		len += rlen;
 		break;
 	default:
-		len = strlen(node->p);
+		len = (int)strlen(node->p);
 		if (buf)
 			strcpy(buf, node->p);
 	}
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index c0e927bbadf6..cfc8f4d07abb 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -199,8 +199,9 @@ bool strlazymatch(const char *str, const char *pat)
  */
 int strtailcmp(const char *s1, const char *s2)
 {
-	int i1 = strlen(s1);
-	int i2 = strlen(s2);
+	size_t i1 = strlen(s1);
+	size_t i2 = strlen(s2);
+
 	while (--i1 >= 0 && --i2 >= 0) {
 		if (s1[i1] != s2[i2])
 			return s1[i1] - s2[i2];
@@ -331,7 +332,7 @@ char *strdup_esc(const char *str)
 }
 
 /* Remove backslash right before quote and return next quote address. */
-static char *remove_consumed_esc(char *str, int len, int quote)
+static char *remove_consumed_esc(char *str, size_t len, int quote)
 {
 	char *ptr = str, *end = str + len;
 
@@ -373,7 +374,7 @@ char *strdup_esq(const char *str)
 		if (*d == '"' || *d == '\'') {
 			/* This is non-escaped quote */
 			int quote = *d;
-			int len = strlen(d + 1) + 1;
+			size_t len = strlen(d + 1) + 1;
 
 			/*
 			 * Remove the start quote and remove consumed escape (backslash
@@ -420,7 +421,7 @@ unsigned int hex(char c)
  */
 char *strreplace_chars(char needle, const char *haystack, const char *replace)
 {
-	int replace_len = strlen(replace);
+	size_t replace_len = strlen(replace);
 	char *new_s, *to;
 	const char *loc = strchr(haystack, needle);
 	const char *from = haystack;
diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c
index b1d259f590e9..487860f557ac 100644
--- a/tools/perf/util/svghelper.c
+++ b/tools/perf/util/svghelper.c
@@ -100,7 +100,7 @@ void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end)
 	 * if the recording is short, we default to a width of 1000, but
 	 * for longer recordings we want at least 200 units of width per second
 	 */
-	new_width = (last_time - first_time) / 5000000;
+	new_width = (int)((last_time - first_time) / 5000000);
 
 	if (new_width > svg_page_width)
 		svg_page_width = new_width;
@@ -344,7 +344,8 @@ static char *cpu_model(void)
 	file = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies", "r");
 	if (file) {
 		while (fgets(buf, 255, file)) {
-			unsigned int freq;
+			unsigned long long freq;
+
 			freq = strtoull(buf, NULL, 10);
 			if (freq > max_freq)
 				max_freq = freq;
@@ -698,12 +699,11 @@ struct topology {
 };
 
 static void scan_thread_topology(int *map, struct topology *t, int cpu,
-				 int *pos, int nr_cpus)
+				 int *pos, size_t nr_cpus)
 {
-	int i;
-	int thr;
+	for (int i = 0; i < t->sib_thr_nr; i++) {
+		size_t thr;
 
-	for (i = 0; i < t->sib_thr_nr; i++) {
 		if (!test_bit(cpu, cpumask_bits(&t->sib_thr[i])))
 			continue;
 
@@ -713,15 +713,16 @@ static void scan_thread_topology(int *map, struct topology *t, int cpu,
 	}
 }
 
-static void scan_core_topology(int *map, struct topology *t, int nr_cpus)
+static void scan_core_topology(int *map, struct topology *t, size_t nr_cpus)
 {
 	int pos = 0;
-	int i;
-	int cpu;
 
-	for (i = 0; i < t->sib_core_nr; i++)
+	for (int i = 0; i < t->sib_core_nr; i++) {
+		size_t cpu;
+
 		for_each_set_bit(cpu, cpumask_bits(&t->sib_core[i]), nr_cpus)
-			scan_thread_topology(map, t, cpu, &pos, nr_cpus);
+			scan_thread_topology(map, t, (int)cpu, &pos, nr_cpus);
+	}
 }
 
 static int str_to_bitmap(char *s, cpumask_t *b, int nr_cpus)
diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 1b91ccd4d523..8579c2800ceb 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -25,7 +25,6 @@ int parse_nsec_time(const char *str, u64 *ptime)
 		return -1;
 
 	if (*end == '.') {
-		int i;
 		char nsec_buf[10];
 
 		if (strlen(++end) > 9)
@@ -35,7 +34,7 @@ int parse_nsec_time(const char *str, u64 *ptime)
 		nsec_buf[9] = '\0';
 
 		/* make it nsec precision */
-		for (i = strlen(nsec_buf); i < 9; i++)
+		for (size_t i = strlen(nsec_buf); i < 9; i++)
 			nsec_buf[i] = '0';
 
 		time_nsec = strtoull(nsec_buf, &end, 10);
@@ -284,7 +283,8 @@ static int percent_comma_split(struct perf_time_interval *ptime_buf, int num,
 			       time_pecent_split func)
 {
 	char *str, *p1, *p2;
-	int len, ret, i = 0;
+	int ret, i = 0;
+	size_t len;
 
 	str = strdup(ostr);
 	if (str == NULL)
@@ -328,7 +328,8 @@ static int one_percent_convert(struct perf_time_interval *ptime_buf,
 			       const char *ostr, u64 start, u64 end, char *c)
 {
 	char *str;
-	int len = strlen(ostr), ret;
+	size_t len = strlen(ostr);
+	int ret;
 
 	/*
 	 * c points to '%'.
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 0f031eb80b4c..85bb8049ce65 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -360,7 +360,7 @@ int perf_tip(char **strp, const char *dirpath)
 	if (strlist__nr_entries(tips) == 0)
 		goto out;
 
-	node = strlist__entry(tips, random() % strlist__nr_entries(tips));
+	node = strlist__entry(tips, (unsigned int)random() % strlist__nr_entries(tips));
 	if (asprintf(strp, "Tip: %s", node->s) < 0)
 		ret = -ENOMEM;
 
@@ -370,9 +370,10 @@ int perf_tip(char **strp, const char *dirpath)
 	return ret;
 }
 
-char *perf_exe(char *buf, int len)
+char *perf_exe(char *buf, size_t len)
 {
-	int n = readlink("/proc/self/exe", buf, len);
+	ssize_t n = readlink("/proc/self/exe", buf, len);
+
 	if (n > 0) {
 		buf[n] = 0;
 		return buf;
@@ -409,7 +410,7 @@ char *filename_with_chroot(int pid, const char *filename)
 	char buf[PATH_MAX];
 	char proc_root[32];
 	char *new_name = NULL;
-	int ret;
+	ssize_t ret;
 
 	scnprintf(proc_root, sizeof(proc_root), "/proc/%d/root", pid);
 	ret = readlink(proc_root, buf, sizeof(buf) - 1);
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 3423778e39a5..f0057d8410ff 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -64,7 +64,7 @@ extern bool perf_singlethreaded;
 void perf_set_singlethreaded(void);
 void perf_set_multithreaded(void);
 
-char *perf_exe(char *buf, int len);
+char *perf_exe(char *buf, size_t len);
 
 #ifndef O_CLOEXEC
 #ifdef __sparc__
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 46/47] perf hashmap: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (44 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 45/47] perf util: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  2025-04-30 17:50 ` [PATCH v2 47/47] perf: " Ian Rogers
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/util/hashmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/hashmap.c b/tools/perf/util/hashmap.c
index 140ee4055676..f2719f522b84 100644
--- a/tools/perf/util/hashmap.c
+++ b/tools/perf/util/hashmap.c
@@ -115,7 +115,7 @@ static int hashmap_grow(struct hashmap *map)
 		return -ENOMEM;
 
 	hashmap__for_each_entry_safe(map, cur, tmp, bkt) {
-		h = hash_bits(map->hash_fn(cur->key, map->ctx), new_cap_bits);
+		h = hash_bits(map->hash_fn(cur->key, map->ctx), (int)new_cap_bits);
 		hashmap_add_entry(&new_buckets[h], cur);
 	}
 
@@ -164,7 +164,7 @@ int hashmap_insert(struct hashmap *map, long key, long value,
 	if (old_value)
 		*old_value = 0;
 
-	h = hash_bits(map->hash_fn(key, map->ctx), map->cap_bits);
+	h = hash_bits(map->hash_fn(key, map->ctx), (int)map->cap_bits);
 	if (strategy != HASHMAP_APPEND &&
 	    hashmap_find_entry(map, key, h, NULL, &entry)) {
 		if (old_key)
@@ -188,7 +188,7 @@ int hashmap_insert(struct hashmap *map, long key, long value,
 		err = hashmap_grow(map);
 		if (err)
 			return err;
-		h = hash_bits(map->hash_fn(key, map->ctx), map->cap_bits);
+		h = hash_bits(map->hash_fn(key, map->ctx), (int)map->cap_bits);
 	}
 
 	entry = malloc(sizeof(struct hashmap_entry));
@@ -208,7 +208,7 @@ bool hashmap_find(const struct hashmap *map, long key, long *value)
 	struct hashmap_entry *entry;
 	size_t h;
 
-	h = hash_bits(map->hash_fn(key, map->ctx), map->cap_bits);
+	h = hash_bits(map->hash_fn(key, map->ctx), (int)map->cap_bits);
 	if (!hashmap_find_entry(map, key, h, NULL, &entry))
 		return false;
 
@@ -223,7 +223,7 @@ bool hashmap_delete(struct hashmap *map, long key,
 	struct hashmap_entry **pprev, *entry;
 	size_t h;
 
-	h = hash_bits(map->hash_fn(key, map->ctx), map->cap_bits);
+	h = hash_bits(map->hash_fn(key, map->ctx), (int)map->cap_bits);
 	if (!hashmap_find_entry(map, key, h, &pprev, &entry))
 		return false;
 
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [PATCH v2 47/47] perf: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
                   ` (45 preceding siblings ...)
  2025-04-30 17:50 ` [PATCH v2 46/47] perf hashmap: " Ian Rogers
@ 2025-04-30 17:50 ` Ian Rogers
  46 siblings, 0 replies; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 17:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria,
	Howard Chu, Charlie Jenkins, Colin Ian King, Dominique Martinet,
	Jann Horn, Masahiro Yamada, Arnd Bergmann, Yang Jihong,
	Dmitry Vyukov, Andi Kleen, Graham Woodward, Ilkka Koskinen,
	Anshuman Khandual, Zhongqiu Han, Hao Ge, Tengda Wu,
	Gabriele Monaco, Chun-Tse Shao, Casey Chen,
	Dr. David Alan Gilbert, Li Huafei, Steinar H. Gunderson, Levi Yun,
	Weilin Wang, Thomas Falcon, Thomas Richter, Andrew Kreimer,
	Krzysztof Łopatowski, Christophe Leroy, Jean-Philippe Romain,
	Junhao He, Masami Hiramatsu (Google), Xu Yang, Steve Clevenger,
	Zixian Cai, Stephen Brennan, Yujie Liu, linux-kernel,
	linux-perf-users, linux-arm-kernel, llvm
  Cc: Ian Rogers

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@google.com>
---
 tools/perf/perf.c                  |  2 +-
 tools/perf/util/bpf-event.c        |  2 +-
 tools/perf/util/env.c              |  2 +-
 tools/perf/util/event.c            |  4 +--
 tools/perf/util/header.c           | 54 ++++++++++++++++--------------
 tools/perf/util/hist.c             |  7 ++--
 tools/perf/util/machine.c          | 14 ++++----
 tools/perf/util/map.c              |  4 +--
 tools/perf/util/maps.c             |  6 ++--
 tools/perf/util/parse-events.c     | 16 ++++-----
 tools/perf/util/session.c          | 29 ++++++++--------
 tools/perf/util/sort.c             | 20 +++++------
 tools/perf/util/synthetic-events.c | 22 ++++++------
 tools/perf/util/target.c           |  2 +-
 tools/perf/util/thread-stack.c     |  2 +-
 tools/perf/util/thread.c           |  4 +--
 tools/perf/util/thread_map.c       |  6 ++--
 tools/perf/util/tool.c             |  2 +-
 tools/perf/util/values.c           |  4 +--
 19 files changed, 104 insertions(+), 98 deletions(-)

diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index f0617cc41f5f..2e98a29df3b2 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -476,7 +476,7 @@ int main(int argc, const char **argv)
 	if (!cmd)
 		cmd = "perf-help";
 
-	srandom(time(NULL));
+	srandom((unsigned int)time(NULL));
 
 	/* Setting $PERF_CONFIG makes perf read _only_ the given config file. */
 	config_exclusive_filename = getenv("PERF_CONFIG");
diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
index c81444059ad0..3cf7d1a2b624 100644
--- a/tools/perf/util/bpf-event.c
+++ b/tools/perf/util/bpf-event.c
@@ -332,7 +332,7 @@ process_bpf_image(char *name, u64 addr, struct kallsyms_parse *data)
 			.size = offsetof(struct perf_record_ksymbol, name),
 		},
 		.addr      = addr,
-		.len       = page_size,
+		.len       = (__u32)page_size,
 		.ksym_type = PERF_RECORD_KSYMBOL_TYPE_BPF,
 		.flags     = 0,
 	};
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 36411749e007..8238a9a609ab 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -596,7 +596,7 @@ char *perf_env__find_pmu_cap(struct perf_env *env, const char *pmu_name,
 			     const char *cap)
 {
 	char *cap_eq;
-	int cap_size;
+	size_t cap_size;
 	char **ptr;
 	int i, j;
 
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index c23b77f8f854..edd7e2fccf60 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -156,7 +156,7 @@ void perf_event__read_stat_config(struct perf_stat_config *config,
 		switch (event->data[i].tag) {
 #define CASE(__term, __val)					\
 		case PERF_STAT_CONFIG_TERM__##__term:		\
-			config->__val = event->data[i].val;	\
+			config->__val = (typeof(config->__val))event->data[i].val; \
 			break;
 
 		CASE(AGGR_MODE,  aggr_mode)
@@ -190,7 +190,7 @@ size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp)
 	u32 nr_namespaces, idx;
 
 	ns_link_info = event->namespaces.link_info;
-	nr_namespaces = event->namespaces.nr_namespaces;
+	nr_namespaces = (u32)event->namespaces.nr_namespaces;
 
 	ret += fprintf(fp, " %d/%d - nr_namespaces: %u\n\t\t[",
 		       event->namespaces.pid,
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index e3cdc3b7b4ab..e364dea9e243 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -185,7 +185,7 @@ static int do_write_string(struct feat_fd *ff, const char *str)
 	u32 len, olen;
 	int ret;
 
-	olen = strlen(str) + 1;
+	olen = (u32)strlen(str) + 1;
 	len = PERF_ALIGN(olen, NAME_ALIGN);
 
 	/* write len, incl. \0 */
@@ -286,7 +286,7 @@ static int do_read_bitmap(struct feat_fd *ff, unsigned long **pset, u64 *psize)
 	if (ret)
 		return ret;
 
-	set = bitmap_zalloc(size);
+	set = bitmap_zalloc((int)size);
 	if (!set)
 		return -ENOMEM;
 
@@ -1369,7 +1369,9 @@ static int memory_node__sort(const void *a, const void *b)
 	const struct memory_node *na = a;
 	const struct memory_node *nb = b;
 
-	return na->node - nb->node;
+	if (na->node == nb->node)
+		return 0;
+	return na->node < nb->node ? -1 : 1;
 }
 
 static int build_mem_topology(struct memory_node **nodesp, u64 *cntp)
@@ -2144,7 +2146,7 @@ static void print_pmu_mappings(struct feat_fd *ff, FILE *fp)
 	str = ff->ph->env.pmu_mappings;
 
 	while (pmu_num) {
-		type = strtoul(str, &tmp, 0);
+		type = (u32)strtoul(str, &tmp, 0);
 		if (*tmp != ':')
 			goto error;
 
@@ -2214,10 +2216,10 @@ static void memory_node__fprintf(struct memory_node *n,
 	char buf_map[100], buf_size[50];
 	unsigned long long size;
 
-	size = bsize * bitmap_weight(n->set, n->size);
+	size = bsize * bitmap_weight(n->set, (unsigned int)n->size);
 	unit_number__scnprintf(buf_size, 50, size);
 
-	bitmap_scnprintf(n->set, n->size, buf_map, 100);
+	bitmap_scnprintf(n->set, (unsigned int)n->size, buf_map, 100);
 	fprintf(fp, "#  %3" PRIu64 " [%s]: %s\n", n->node, buf_size, buf_map);
 }
 
@@ -2782,7 +2784,7 @@ static int process_pmu_mappings(struct feat_fd *ff, void *data __maybe_unused)
 
 static int process_group_desc(struct feat_fd *ff, void *data __maybe_unused)
 {
-	size_t ret = -1;
+	int ret = -1;
 	u32 i, nr, nr_groups;
 	struct perf_session *session;
 	struct evsel *evsel, *leader = NULL;
@@ -2996,7 +2998,7 @@ static int process_mem_topology(struct feat_fd *ff,
 
 	ff->ph->env.memory_bsize    = bsize;
 	ff->ph->env.memory_nodes    = nodes;
-	ff->ph->env.nr_memory_nodes = nr;
+	ff->ph->env.nr_memory_nodes = (int)nr;
 	ret = 0;
 
 out:
@@ -3489,7 +3491,8 @@ int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full)
 	int fd = perf_data__fd(session->data);
 	struct stat st;
 	time_t stctime;
-	int ret, bit;
+	int ret;
+	size_t bit;
 
 	hd.fp = fp;
 	hd.full = full;
@@ -3586,15 +3589,15 @@ static int perf_header__adds_write(struct perf_header *header,
 				   struct evlist *evlist, int fd,
 				   struct feat_copier *fc)
 {
-	int nr_sections;
+	size_t nr_sections;
 	struct feat_fd ff = {
 		.fd  = fd,
 		.ph = header,
 	};
 	struct perf_file_section *feat_sec, *p;
-	int sec_size;
+	size_t sec_size;
 	u64 sec_start;
-	int feat;
+	size_t feat;
 	int err;
 
 	nr_sections = bitmap_weight(header->adds_features, HEADER_FEAT_BITS);
@@ -3611,8 +3614,8 @@ static int perf_header__adds_write(struct perf_header *header,
 	lseek(fd, sec_start + sec_size, SEEK_SET);
 
 	for_each_set_bit(feat, header->adds_features, HEADER_FEAT_BITS) {
-		if (do_write_feat(&ff, feat, &p, evlist, fc))
-			perf_header__clear_feat(header, feat);
+		if (do_write_feat(&ff, (int)feat, &p, evlist, fc))
+			perf_header__clear_feat(header, (int)feat);
 	}
 
 	lseek(fd, sec_start, SEEK_SET);
@@ -3821,9 +3824,9 @@ int perf_header__process_sections(struct perf_header *header, int fd,
 						 int feat, int fd, void *data))
 {
 	struct perf_file_section *feat_sec, *sec;
-	int nr_sections;
-	int sec_size;
-	int feat;
+	size_t nr_sections;
+	size_t sec_size;
+	size_t feat;
 	int err;
 
 	nr_sections = bitmap_weight(header->adds_features, HEADER_FEAT_BITS);
@@ -3843,7 +3846,7 @@ int perf_header__process_sections(struct perf_header *header, int fd,
 		goto out_free;
 
 	for_each_set_bit(feat, header->adds_features, HEADER_LAST_FEATURE) {
-		err = process(sec++, header, feat, fd, data);
+		err = process(sec++, header, (int)feat, fd, data);
 		if (err < 0)
 			goto out_free;
 	}
@@ -4183,7 +4186,7 @@ static int evsel__prepare_tracepoint_event(struct evsel *evsel, struct tep_handl
 		return -1;
 	}
 
-	event = tep_find_event(pevent, evsel->core.attr.config);
+	event = tep_find_event(pevent, (int)evsel->core.attr.config);
 	if (event == NULL) {
 		pr_debug("cannot find event format for %d\n", (int)evsel->core.attr.config);
 		return -1;
@@ -4221,8 +4224,8 @@ int perf_session__read_header(struct perf_session *session)
 	struct perf_file_header	f_header;
 	struct perf_file_attr	f_attr;
 	u64			f_id;
-	int nr_attrs, nr_ids, i, j, err;
-	int fd = perf_data__fd(data);
+	u64 nr_attrs, nr_ids;
+	int err, fd = perf_data__fd(data);
 
 	session->evlist = evlist__new();
 	if (session->evlist == NULL)
@@ -4271,7 +4274,7 @@ int perf_session__read_header(struct perf_session *session)
 	nr_attrs = f_header.attrs.size / f_header.attr_size;
 	lseek(fd, f_header.attrs.offset, SEEK_SET);
 
-	for (i = 0; i < nr_attrs; i++) {
+	for (u64 i = 0; i < nr_attrs; i++) {
 		struct evsel *evsel;
 		off_t tmp;
 
@@ -4308,7 +4311,7 @@ int perf_session__read_header(struct perf_session *session)
 
 		lseek(fd, f_attr.ids.offset, SEEK_SET);
 
-		for (j = 0; j < nr_ids; j++) {
+		for (int j = 0; j < (int)nr_ids; j++) {
 			if (perf_header__getbuffer64(header, fd, &f_id, sizeof(f_id)))
 				goto out_errno;
 
@@ -4537,7 +4540,8 @@ int perf_event__process_tracing_data(struct perf_session *session,
 		return -1;
 	}
 	if (session->trace_event_repipe) {
-		int retw = write(STDOUT_FILENO, buf, padding);
+		ssize_t retw = write(STDOUT_FILENO, buf, padding);
+
 		if (retw <= 0 || retw != padding) {
 			pr_err("%s: repiping tracing data padding", __func__);
 			return -1;
@@ -4551,7 +4555,7 @@ int perf_event__process_tracing_data(struct perf_session *session,
 
 	evlist__prepare_tracepoint_events(session->evlist, session->tevent.pevent);
 
-	return size_read + padding;
+	return (int)(size_read + padding);
 }
 #endif
 
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index d65228c11412..37469da4afc2 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -700,7 +700,8 @@ static unsigned random_max(unsigned high)
 {
 	unsigned thresh = -high % high;
 	for (;;) {
-		unsigned r = random();
+		unsigned int r = (unsigned int)random();
+
 		if (r >= thresh)
 			return r % high;
 	}
@@ -929,7 +930,7 @@ iter_prepare_branch_entry(struct hist_entry_iter *iter, struct addr_location *al
 		return -ENOMEM;
 
 	iter->curr = 0;
-	iter->total = sample->branch_stack->nr;
+	iter->total = (int)sample->branch_stack->nr;
 
 	iter->bi = bi;
 	return 0;
@@ -2770,7 +2771,7 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
 			 * Note that perf stores branches reversed from
 			 * program order!
 			 */
-			for (int i = bs->nr - 1; i >= 0; i--) {
+			for (int i = (int)bs->nr - 1; i >= 0; i--) {
 				addr_map_symbol__account_cycles(&bi[i].from,
 					nonany_branch_mode ? NULL : prev,
 					bi[i].flags.cycles, evsel,
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 2531b373f2cf..0881b83532fd 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -809,7 +809,7 @@ int machine__process_text_poke(struct machine *machine, union perf_event *event,
 
 	if (dso) {
 		u8 *new_bytes = event->text_poke.bytes + event->text_poke.old_len;
-		int ret;
+		ssize_t ret;
 
 		/*
 		 * Kernel maps might be changed when loading symbols so loading
@@ -2306,7 +2306,7 @@ static int lbr_callchain_add_lbr_ip(struct thread *thread,
 	struct branch_stack *lbr_stack = sample->branch_stack;
 	struct branch_entry *entries = perf_sample__branch_entries(sample);
 	u8 cpumode = PERF_RECORD_MISC_USER;
-	int lbr_nr = lbr_stack->nr;
+	int lbr_nr = (int)lbr_stack->nr;
 	struct branch_flags *flags;
 	int err, i;
 	u64 ip;
@@ -2472,7 +2472,7 @@ static bool has_stitched_lbr(struct thread *thread,
 	 *
 	 * Starts from the base-of-stack of current sample.
 	 */
-	for (i = distance, j = cur_stack->nr - 1; (i >= 0) && (j >= 0); i--, j--) {
+	for (i = (int)distance, j = (int)cur_stack->nr - 1; (i >= 0) && (j >= 0); i--, j--) {
 		if ((prev_entries[i].from != cur_entries[j].from) ||
 		    (prev_entries[i].to != cur_entries[j].to) ||
 		    (prev_entries[i].flags.value != cur_entries[j].flags.value))
@@ -2488,7 +2488,7 @@ static bool has_stitched_lbr(struct thread *thread,
 	 * and the base-of-stack of current sample into lbr_stitch->lists.
 	 * These LBRs will be stitched later.
 	 */
-	for (i = prev_stack->nr - 1; i > (int)distance; i--) {
+	for (i = (int)prev_stack->nr - 1; i > (int)distance; i--) {
 
 		if (!lbr_stitch->prev_lbr_cursor[i].valid)
 			continue;
@@ -2687,7 +2687,7 @@ static int thread__resolve_callchain_sample(struct thread *thread,
 	u64 leaf_frame_caller;
 
 	if (chain)
-		chain_nr = chain->nr;
+		chain_nr = (int)chain->nr;
 
 	if (evsel__has_branch_callstack(evsel)) {
 		struct perf_env *env = evsel__env(evsel);
@@ -2783,7 +2783,7 @@ static int thread__resolve_callchain_sample(struct thread *thread,
 check_calls:
 	if (chain && callchain_param.order != ORDER_CALLEE) {
 		err = find_prev_cpumode(chain, thread, cursor, parent, root_al,
-					&cpumode, chain->nr - first_call, symbols);
+					&cpumode, (int)(chain->nr - first_call), symbols);
 		if (err)
 			return (err < 0) ? err : 0;
 	}
@@ -2794,7 +2794,7 @@ static int thread__resolve_callchain_sample(struct thread *thread,
 		if (callchain_param.order == ORDER_CALLEE)
 			j = i;
 		else
-			j = chain->nr - i - 1;
+			j = (int)(chain->nr - i - 1);
 
 #ifdef HAVE_SKIP_CALLCHAIN_IDX
 		if (j == skip_idx)
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index d729438b7d65..57e22e49e65c 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -74,8 +74,8 @@ static inline bool replace_android_lib(const char *filename, char *newfilename)
 		if (!(ndk && app))
 			return false;
 
-		ndk_length = strlen(ndk);
-		app_length = strlen(app);
+		ndk_length = (int)strlen(ndk);
+		app_length = (int)strlen(app);
 
 		if (!(ndk_length && app_length && app_abi_length))
 			return false;
diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c
index 0b40d901675e..8101a3e3810b 100644
--- a/tools/perf/util/maps.c
+++ b/tools/perf/util/maps.c
@@ -396,7 +396,7 @@ static unsigned int maps__by_address_index(const struct maps *maps, const struct
 				sizeof(*mapp), map__start_cmp);
 
 		if (mapp)
-			return mapp - maps_by_address;
+			return (unsigned int)(mapp - maps_by_address);
 	} else {
 		for (unsigned int i = 0; i < maps__nr_maps(maps); i++) {
 			if (RC_CHK_ACCESS(maps_by_address[i]) == RC_CHK_ACCESS(map))
@@ -417,7 +417,7 @@ static unsigned int maps__by_name_index(const struct maps *maps, const struct ma
 				sizeof(*mapp), map__strcmp);
 
 		if (mapp)
-			return mapp - maps_by_name;
+			return (unsigned int)(mapp - maps_by_name);
 	} else {
 		for (unsigned int i = 0; i < maps__nr_maps(maps); i++) {
 			if (RC_CHK_ACCESS(maps_by_name[i]) == RC_CHK_ACCESS(map))
@@ -1134,7 +1134,7 @@ struct map *maps__find_by_name(struct maps *maps, const char *name)
 
 			if (mapp) {
 				result = map__get(*mapp);
-				i = mapp - maps__maps_by_name(maps);
+				i = (unsigned int)(mapp - maps__maps_by_name(maps));
 				RC_CHK_ACCESS(maps)->last_search_by_name_idx = i;
 			}
 			done = true;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 89708d1769c8..de879ab45ea5 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -317,7 +317,7 @@ static int parse_aliases(const char *str, const char *const names[][EVSEL__MAX_A
 	*longest = -1;
 	for (int i = 0; i < size; i++) {
 		for (int j = 0; j < EVSEL__MAX_ALIASES && names[i][j]; j++) {
-			int n = strlen(names[i][j]);
+			int n = (int)strlen(names[i][j]);
 
 			if (n > *longest && !strncasecmp(str, names[i][j], n))
 				*longest = n;
@@ -532,8 +532,8 @@ static int add_tracepoint(struct parse_events_state *parse_state,
 					       !parse_state->fake_tp);
 
 	if (IS_ERR(evsel)) {
-		tracepoint_error(err, PTR_ERR(evsel), sys_name, evt_name, loc->first_column);
-		return PTR_ERR(evsel);
+		tracepoint_error(err, (int)PTR_ERR(evsel), sys_name, evt_name, loc->first_column);
+		return (int)PTR_ERR(evsel);
 	}
 
 	if (head_config) {
@@ -1153,7 +1153,7 @@ static int get_config_terms(const struct parse_events_terms *head_config,
 #define ADD_CONFIG_TERM_VAL(__type, __name, __val, __weak)	\
 do {								\
 	ADD_CONFIG_TERM(__type, __weak);			\
-	__t->val.__name = __val;				\
+	__t->val.__name = (typeof(__t->val.__name))__val;	\
 } while (0)
 
 #define ADD_CONFIG_TERM_STR(__type, __val, __weak)		\
@@ -2303,12 +2303,12 @@ static void __parse_events_error__print(int err_idx, const char *err_str,
 	const char *str = "invalid or unsupported event: ";
 	char _buf[MAX_WIDTH];
 	char *buf = (char *) event;
-	int idx = 0;
+	size_t idx = 0;
 	if (err_str) {
 		/* -2 for extra '' in the final fprintf */
 		int width       = get_term_width() - 2;
-		int len_event   = strlen(event);
-		int len_str, max_len, cut = 0;
+		size_t len_event   = strlen(event);
+		size_t len_str, max_len, cut = 0;
 
 		/*
 		 * Maximum error index indent, we will cut
@@ -2346,7 +2346,7 @@ static void __parse_events_error__print(int err_idx, const char *err_str,
 
 	fprintf(stderr, "%s'%s'\n", str, buf);
 	if (idx) {
-		fprintf(stderr, "%*s\\___ %s\n", idx + 1, "", err_str);
+		fprintf(stderr, "%*s\\___ %s\n", (int)idx + 1, "", err_str);
 		if (err_help)
 			fprintf(stderr, "\n%s\n", err_help);
 	}
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 81cc56503a2d..395cd82e44d1 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -263,7 +263,7 @@ void perf_session__delete(struct perf_session *session)
 static void swap_sample_id_all(union perf_event *event, void *data)
 {
 	void *end = (void *) event + event->header.size;
-	int size = end - data;
+	size_t size = end - data;
 
 	BUG_ON(size % sizeof(u64));
 	mem_bswap_64(data, size);
@@ -912,13 +912,13 @@ static void branch_stack__printf(struct perf_sample *sample,
 
 static void regs_dump__printf(u64 mask, u64 *regs, const char *arch)
 {
-	unsigned rid, i = 0;
+	unsigned int i = 0;
+	size_t rid;
 
 	for_each_set_bit(rid, (unsigned long *) &mask, sizeof(mask) * 8) {
 		u64 val = regs[i++];
 
-		printf(".... %-5s 0x%016" PRIx64 "\n",
-		       perf_reg_name(rid, arch), val);
+		printf(".... %-5s 0x%016" PRIx64 "\n", perf_reg_name((int)rid, arch), val);
 	}
 }
 
@@ -1452,7 +1452,7 @@ static s64 perf_session__process_user_event(struct perf_session *session,
 		 */
 		if (!perf_data__is_pipe(session->data))
 			lseek(fd, file_offset + event->header.size, SEEK_SET);
-		err = tool->auxtrace(session, event);
+		err = (int)tool->auxtrace(session, event);
 		break;
 	case PERF_RECORD_AUXTRACE_ERROR:
 		perf_session__auxtrace_error_inc(session, event);
@@ -1506,7 +1506,7 @@ int perf_session__deliver_synth_event(struct perf_session *session,
 	events_stats__inc(&evlist->stats, event->header.type);
 
 	if (event->header.type >= PERF_RECORD_USER_TYPE_START)
-		return perf_session__process_user_event(session, event, 0, NULL);
+		return (int)perf_session__process_user_event(session, event, 0, NULL);
 
 	return machines__deliver_event(&session->machines, evlist, event, sample, tool, 0, NULL);
 }
@@ -1944,7 +1944,7 @@ static int __perf_session__process_pipe_events(struct perf_session *session)
 		perf_session__warn_about_errors(session);
 	ordered_events__free(&session->ordered_events);
 	auxtrace__free_events(session);
-	return err;
+	return (int)err;
 }
 
 static union perf_event *
@@ -2164,7 +2164,7 @@ reader__read_event(struct reader *rd, struct perf_session *session,
 	event = fetch_mmaped_event(rd->head, rd->mmap_size, rd->mmap_cur,
 				   session->header.needs_swap);
 	if (IS_ERR(event))
-		return PTR_ERR(event);
+		return (int)PTR_ERR(event);
 
 	if (!event)
 		return READER_NODATA;
@@ -2177,8 +2177,8 @@ reader__read_event(struct reader *rd, struct perf_session *session,
 	    (skip = rd->process(session, event, rd->file_pos, rd->path)) < 0) {
 		pr_err("%#" PRIx64 " [%#x]: failed to process type: %d [%s]\n",
 		       rd->file_offset + rd->head, event->header.size,
-		       event->header.type, strerror(-skip));
-		err = skip;
+			event->header.type, strerror((int)-skip));
+		err = (int)skip;
 		goto out;
 	}
 
@@ -2692,14 +2692,14 @@ int perf_event__process_id_index(struct perf_session *session,
 		if (!sid)
 			return -ENOENT;
 
-		sid->idx = e->idx;
+		sid->idx = (int)e->idx;
 		sid->cpu.cpu = e->cpu;
-		sid->tid = e->tid;
+		sid->tid = (pid_t)e->tid;
 
 		if (!e2)
 			continue;
 
-		sid->machine_pid = e2->machine_pid;
+		sid->machine_pid = (pid_t)e2->machine_pid;
 		sid->vcpu.cpu = e2->vcpu;
 
 		if (!sid->machine_pid)
@@ -2713,7 +2713,8 @@ int perf_event__process_id_index(struct perf_session *session,
 			perf_guest = true;
 		}
 
-		ret = perf_session__set_guest_cpu(session, sid->machine_pid, e->tid, e2->vcpu);
+		ret = perf_session__set_guest_cpu(session, sid->machine_pid,
+						(pid_t)e->tid, (int)e2->vcpu);
 		if (ret)
 			return ret;
 	}
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 594b75ca95bf..898f811e23a2 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -91,7 +91,7 @@ static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...)
 	va_end(ap);
 
 	if (n >= (int)size)
-		return size - 1;
+		return (int)size - 1;
 	return n;
 }
 
@@ -392,7 +392,7 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
 				       len, ip);
 	}
 
-	return ret;
+	return (int)ret;
 }
 
 int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width)
@@ -1339,7 +1339,7 @@ static int _hist_entry__addr_snprintf(struct map_symbol *ms,
 				       len, ip);
 	}
 
-	return ret;
+	return (int)ret;
 }
 
 static int hist_entry__addr_from_snprintf(struct hist_entry *he, char *bf,
@@ -2667,7 +2667,7 @@ static int __sort__hpp_width(struct perf_hpp_fmt *fmt,
 	if (!len)
 		len = hists__col_len(hists, hse->se->se_width_idx);
 
-	return len;
+	return (int)len;
 }
 
 static int __sort__hpp_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
@@ -2681,7 +2681,7 @@ static int __sort__hpp_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
 	if (!len)
 		len = hists__col_len(he->hists, hse->se->se_width_idx);
 
-	return hse->se->se_snprintf(he, hpp->buf, hpp->size, len);
+	return hse->se->se_snprintf(he, hpp->buf, hpp->size, (unsigned int)len);
 }
 
 static int64_t __sort__hpp_cmp(struct perf_hpp_fmt *fmt,
@@ -2919,7 +2919,7 @@ static int hde_width(struct hpp_dynamic_entry *hde)
 {
 	if (!hde->hpp.len) {
 		int len = hde->dynamic_len;
-		int namelen = strlen(hde->field->name);
+		int namelen = (int)strlen(hde->field->name);
 		int fieldlen = hde->field->size;
 
 		if (namelen > len)
@@ -2969,7 +2969,7 @@ static void update_dynamic_len(struct hpp_dynamic_entry *hde,
 			len = pos - str;
 
 			if (len > hde->dynamic_len)
-				hde->dynamic_len = len;
+				hde->dynamic_len = (unsigned int)len;
 			break;
 		}
 
@@ -3008,7 +3008,7 @@ static int __sort__hde_width(struct perf_hpp_fmt *fmt,
 	if (!len)
 		len = hde_width(hde);
 
-	return len;
+	return (int)len;
 }
 
 bool perf_hpp__defined_dynamic_entry(struct perf_hpp_fmt *fmt, struct hists *hists)
@@ -3257,7 +3257,7 @@ static struct evsel *find_evsel(struct evlist *evlist, char *event_name)
 
 	/* case 1 */
 	if (event_name[0] == '%') {
-		int nr = strtol(event_name+1, NULL, 0);
+		int nr = (int)strtol(event_name+1, NULL, 0);
 
 		if (nr > evlist->core.nr_entries)
 			return NULL;
@@ -4222,7 +4222,7 @@ char *sort_help(const char *prefix, enum sort_mode mode)
 {
 	struct strbuf sb;
 	char *s;
-	int len = strlen(prefix) + INDENT;
+	int len = (int)strlen(prefix) + INDENT;
 
 	strbuf_init(&sb, 300);
 	strbuf_addstr(&sb, prefix);
diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
index 2fc4d0537840..f65bb4b76ccb 100644
--- a/tools/perf/util/synthetic-events.c
+++ b/tools/perf/util/synthetic-events.c
@@ -338,10 +338,10 @@ static bool read_proc_maps_line(struct io *io, __u64 *start, __u64 *end,
 
 	if (io__get_hex(io, &temp) != ':')
 		return false;
-	*maj = temp;
+	*maj = (u32)temp;
 	if (io__get_hex(io, &temp) != ' ')
 		return false;
-	*min = temp;
+	*min = (u32)temp;
 
 	ch = io__get_dec(io, inode);
 	if (ch != ' ') {
@@ -433,7 +433,7 @@ int perf_event__synthesize_mmap_events(const struct perf_tool *tool,
 	unsigned long long timeout = proc_map_timeout * 1000000ULL;
 	int rc = 0;
 	const char *hugetlbfs_mnt = hugetlbfs__mountpoint();
-	int hugetlbfs_mnt_len = hugetlbfs_mnt ? strlen(hugetlbfs_mnt) : 0;
+	size_t hugetlbfs_mnt_len = hugetlbfs_mnt ? strlen(hugetlbfs_mnt) : 0;
 
 	if (machine__is_default_guest(machine))
 		return 0;
@@ -815,7 +815,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
 		if (!isdigit(dent->d_name[0]))
 			continue;
 
-		_pid = strtol(dent->d_name, &end, 10);
+		_pid = (pid_t)strtol(dent->d_name, &end, 10);
 		if (*end)
 			continue;
 
@@ -1043,7 +1043,7 @@ int perf_event__synthesize_threads(const struct perf_tool *tool,
 		return err;
 
 	if (nr_threads_synthesize == UINT_MAX)
-		thread_nr = sysconf(_SC_NPROCESSORS_ONLN);
+		thread_nr = (int)sysconf(_SC_NPROCESSORS_ONLN);
 	else
 		thread_nr = nr_threads_synthesize;
 
@@ -1829,7 +1829,7 @@ int perf_event__synthesize_id_sample(__u64 *array, u64 type, const struct perf_s
 		array++;
 	}
 
-	return (void *)array - (void *)start;
+	return (int)((void *)array - (void *)start);
 }
 
 int __perf_event__synthesize_id_index(const struct perf_tool *tool, perf_event__handler_t process,
@@ -2213,7 +2213,7 @@ int perf_event__synthesize_tracing_data(const struct perf_tool *tool, int fd, st
 	aligned_size = PERF_ALIGN(size, sizeof(u64));
 	padding = aligned_size - size;
 	ev.tracing_data.header.size = sizeof(ev.tracing_data);
-	ev.tracing_data.size = aligned_size;
+	ev.tracing_data.size = (__u32)aligned_size;
 
 	process(tool, &ev, NULL, NULL);
 
@@ -2227,7 +2227,7 @@ int perf_event__synthesize_tracing_data(const struct perf_tool *tool, int fd, st
 	if (write_padded(&ff, NULL, 0, padding))
 		return -1;
 
-	return aligned_size;
+	return (int)aligned_size;
 }
 #endif
 
@@ -2375,8 +2375,8 @@ int perf_event__synthesize_features(const struct perf_tool *tool, struct perf_se
 	struct perf_header *header = &session->header;
 	struct perf_record_header_feature *fe;
 	struct feat_fd ff;
-	size_t sz, sz_hdr;
-	int feat, ret;
+	size_t sz, sz_hdr, feat;
+	int ret;
 
 	sz_hdr = sizeof(fe->header);
 	sz = sizeof(union perf_event);
@@ -2394,7 +2394,7 @@ int perf_event__synthesize_features(const struct perf_tool *tool, struct perf_se
 
 	for_each_set_bit(feat, header->adds_features, HEADER_FEAT_BITS) {
 		if (!feat_ops[feat].synthesize) {
-			pr_debug("No record header feature for header :%d\n", feat);
+			pr_debug("No record header feature for header :%zu\n", feat);
 			continue;
 		}
 
diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c
index 0f383418e3df..6a331743a099 100644
--- a/tools/perf/util/target.c
+++ b/tools/perf/util/target.c
@@ -112,7 +112,7 @@ enum target_errno target__parse_uid(struct target *target)
 		 * The user name not found. Maybe it's a UID number.
 		 */
 		char *endptr;
-		int uid = strtol(str, &endptr, 10);
+		int uid = (int)strtol(str, &endptr, 10);
 
 		if (*endptr != '\0')
 			return TARGET_ERRNO__INVALID_UID;
diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c
index c6a0a27b12c2..09cd14854aa5 100644
--- a/tools/perf/util/thread-stack.c
+++ b/tools/perf/util/thread-stack.c
@@ -180,7 +180,7 @@ static struct thread_stack *thread_stack__new(struct thread *thread, int cpu,
 	unsigned int new_sz = 1;
 
 	if (thread_stack__per_cpu(thread) && cpu > 0)
-		new_sz = roundup_pow_of_two(cpu + 1);
+		new_sz = (unsigned int)roundup_pow_of_two(cpu + 1);
 
 	if (!ts || new_sz > old_sz) {
 		new_ts = calloc(new_sz, sizeof(*ts));
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 89585f53c1d5..c108f238012e 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -309,7 +309,7 @@ static int __thread__comm_len(struct thread *thread, const char *comm)
 {
 	if (!comm)
 		return 0;
-	thread__set_comm_len(thread, strlen(comm));
+	thread__set_comm_len(thread, (int)strlen(comm));
 
 	return thread__var_comm_len(thread);
 }
@@ -544,7 +544,7 @@ int thread__memcpy(struct thread *thread, struct machine *machine,
 
 	addr_location__exit(&al);
 
-	return dso__data_read_offset(dso, machine, offset, buf, len);
+	return (int)dso__data_read_offset(dso, machine, offset, buf, len);
 }
 
 void thread__free_stitch_list(struct thread *thread)
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index b5f12390c355..141fbb819a65 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -93,7 +93,7 @@ static struct perf_thread_map *__thread_map__new_all_cpus(uid_t uid)
 	while ((dirent = readdir(proc)) != NULL) {
 		char *end;
 		bool grow = false;
-		pid_t pid = strtol(dirent->d_name, &end, 10);
+		pid_t pid = (pid_t)strtol(dirent->d_name, &end, 10);
 
 		if (*end) /* only interested in proper numerical dirents */
 			continue;
@@ -195,7 +195,7 @@ static struct perf_thread_map *thread_map__new_by_pid_str(const char *pid_str)
 		return NULL;
 
 	strlist__for_each_entry(pos, slist) {
-		pid = strtol(pos->s, &end_ptr, 10);
+		pid = (pid_t)strtol(pos->s, &end_ptr, 10);
 
 		if (pid == INT_MIN || pid == INT_MAX ||
 		    (*end_ptr != '\0' && *end_ptr != ','))
@@ -259,7 +259,7 @@ struct perf_thread_map *thread_map__new_by_tid_str(const char *tid_str)
 		return NULL;
 
 	strlist__for_each_entry(pos, slist) {
-		tid = strtol(pos->s, &end_ptr, 10);
+		tid = (pid_t)strtol(pos->s, &end_ptr, 10);
 
 		if (tid == INT_MIN || tid == INT_MAX ||
 		    (*end_ptr != '\0' && *end_ptr != ','))
diff --git a/tools/perf/util/tool.c b/tools/perf/util/tool.c
index 3b7f390f26eb..f13d5c1e3cd7 100644
--- a/tools/perf/util/tool.c
+++ b/tools/perf/util/tool.c
@@ -134,7 +134,7 @@ static int skipn(int fd, off_t n)
 	while (n > 0) {
 		ret = read(fd, buf, min(n, (off_t)sizeof(buf)));
 		if (ret <= 0)
-			return ret;
+			return (int)ret;
 		n -= ret;
 	}
 
diff --git a/tools/perf/util/values.c b/tools/perf/util/values.c
index ec72d29f3d58..e44dbceaa88b 100644
--- a/tools/perf/util/values.c
+++ b/tools/perf/util/values.c
@@ -197,7 +197,7 @@ static void perf_read_values__display_pretty(FILE *fp,
 	tidwidth = 3;
 	pidwidth = 3;
 	for (j = 0; j < values->num_counters; j++)
-		counterwidth[j] = strlen(evsel__name(values->counters[j]));
+		counterwidth[j] = (int)strlen(evsel__name(values->counters[j]));
 	for (i = 0; i < values->threads; i++) {
 		int width;
 
@@ -251,7 +251,7 @@ static void perf_read_values__display_raw(FILE *fp,
 			tidwidth = width;
 	}
 	for (j = 0; j < values->num_counters; j++) {
-		width = strlen(evsel__name(values->counters[j]));
+		width = (int)strlen(evsel__name(values->counters[j]));
 		if (width > namewidth)
 			namewidth = width;
 		width = snprintf(NULL, 0, "%x", values->counters[j]->core.idx);
-- 
2.49.0.906.g1f30a19c02-goog


^ permalink raw reply related	[flat|nested] 58+ messages in thread

* Re: [PATCH v2 04/47] perf bench: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 ` [PATCH v2 04/47] perf bench: " Ian Rogers
@ 2025-04-30 20:23   ` Dirk Gouders
  2025-04-30 21:04     ` Ian Rogers
  0 siblings, 1 reply; 58+ messages in thread
From: Dirk Gouders @ 2025-04-30 20:23 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Brian Geffon, Ravi Bangoria, Howard Chu,
	Charlie Jenkins, Colin Ian King, Dominique Martinet, Jann Horn,
	Masahiro Yamada, Arnd Bergmann, Yang Jihong, Dmitry Vyukov,
	Andi Kleen, Graham Woodward, Ilkka Koskinen, Anshuman Khandual,
	Zhongqiu Han, Hao Ge, Tengda Wu, Gabriele Monaco, Chun-Tse Shao,
	Casey Chen, Dr. David Alan Gilbert, Li Huafei,
	Steinar H. Gunderson, Levi Yun, Weilin Wang, Thomas Falcon,
	Thomas Richter, Andrew Kreimer, Krzysztof Łopatowski,
	Christophe Leroy, Jean-Philippe Romain, Junhao He,
	Masami Hiramatsu (Google), Xu Yang, Steve Clevenger, Zixian Cai,
	Stephen Brennan, Yujie Liu, linux-kernel, linux-perf-users,
	linux-arm-kernel, llvm

Hi Ian,

considering so many eyes looking at this, I am probably wrong.

So, this is only a "gauge reply" to see if it's worth I really read
through all the commits ;-)

Ian Rogers <irogers@google.com> writes:

[SNIP]

> diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
> index 70139036d68f..b847213fd616 100644
> --- a/tools/perf/bench/sched-pipe.c
> +++ b/tools/perf/bench/sched-pipe.c
> @@ -102,7 +102,8 @@ static const char * const bench_sched_pipe_usage[] = {
>  static int enter_cgroup(int nr)
>  {
>  	char buf[32];
> -	int fd, len, ret;
> +	int fd;
> +	ssize_t ret, len;
>  	int saved_errno;
>  	struct cgroup *cgrp;
>  	pid_t pid;
> @@ -118,7 +119,7 @@ static int enter_cgroup(int nr)
>  	cgrp = cgrps[nr];
>  
>  	if (threaded)
> -		pid = syscall(__NR_gettid);
> +		pid = (pid_t)syscall(__NR_gettid);
>  	else
>  		pid = getpid();
>  
> @@ -172,23 +173,25 @@ static void exit_cgroup(int nr)
>  
>  static inline int read_pipe(struct thread_data *td)
>  {
> -	int ret, m;
> +	ssize_t ret;
> +	int m;
>  retry:
>  	if (nonblocking) {
>  		ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);

The epoll_wait(), I know of, returns an int and not ssize_t.

That shouldn't show up, because it doesn't cause real problems...


Best regards,

Dirk



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2 04/47] perf bench: Silence -Wshorten-64-to-32 warnings
  2025-04-30 20:23   ` Dirk Gouders
@ 2025-04-30 21:04     ` Ian Rogers
  2025-04-30 22:18       ` Dirk Gouders
  0 siblings, 1 reply; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 21:04 UTC (permalink / raw)
  To: Dirk Gouders
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Brian Geffon, Ravi Bangoria, Howard Chu,
	Charlie Jenkins, Colin Ian King, Dominique Martinet, Jann Horn,
	Masahiro Yamada, Arnd Bergmann, Yang Jihong, Dmitry Vyukov,
	Andi Kleen, Graham Woodward, Ilkka Koskinen, Anshuman Khandual,
	Zhongqiu Han, Hao Ge, Tengda Wu, Gabriele Monaco, Chun-Tse Shao,
	Casey Chen, Dr. David Alan Gilbert, Li Huafei,
	Steinar H. Gunderson, Levi Yun, Weilin Wang, Thomas Falcon,
	Thomas Richter, Andrew Kreimer, Krzysztof Łopatowski,
	Christophe Leroy, Jean-Philippe Romain, Junhao He,
	Masami Hiramatsu (Google), Xu Yang, Steve Clevenger, Zixian Cai,
	Stephen Brennan, Yujie Liu, linux-kernel, linux-perf-users,
	linux-arm-kernel, llvm

On Wed, Apr 30, 2025 at 1:23 PM Dirk Gouders <dirk@gouders.net> wrote:
>
> Hi Ian,
>
> considering so many eyes looking at this, I am probably wrong.
>
> So, this is only a "gauge reply" to see if it's worth I really read
> through all the commits ;-)
>
> Ian Rogers <irogers@google.com> writes:
>
> [SNIP]
>
> > diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
> > index 70139036d68f..b847213fd616 100644
> > --- a/tools/perf/bench/sched-pipe.c
> > +++ b/tools/perf/bench/sched-pipe.c
> > @@ -102,7 +102,8 @@ static const char * const bench_sched_pipe_usage[] = {
> >  static int enter_cgroup(int nr)
> >  {
> >       char buf[32];
> > -     int fd, len, ret;
> > +     int fd;
> > +     ssize_t ret, len;
> >       int saved_errno;
> >       struct cgroup *cgrp;
> >       pid_t pid;
> > @@ -118,7 +119,7 @@ static int enter_cgroup(int nr)
> >       cgrp = cgrps[nr];
> >
> >       if (threaded)
> > -             pid = syscall(__NR_gettid);
> > +             pid = (pid_t)syscall(__NR_gettid);
> >       else
> >               pid = getpid();
> >
> > @@ -172,23 +173,25 @@ static void exit_cgroup(int nr)
> >
> >  static inline int read_pipe(struct thread_data *td)
> >  {
> > -     int ret, m;
> > +     ssize_t ret;
> > +     int m;
> >  retry:
> >       if (nonblocking) {
> >               ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);
>
> The epoll_wait(), I know of, returns an int and not ssize_t.
>
> That shouldn't show up, because it doesn't cause real problems...

So the function is read_pipe so it should probably return a ssize_t. I
stopped short of that but made ret a ssize_t to silence the truncation
warning on the read call. Assigning smaller to bigger is of course not
an issue for epoll_wait.

Thanks,
Ian

> Best regards,
>
> Dirk
>
>

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2 04/47] perf bench: Silence -Wshorten-64-to-32 warnings
  2025-04-30 21:04     ` Ian Rogers
@ 2025-04-30 22:18       ` Dirk Gouders
  2025-04-30 22:22         ` Ian Rogers
  0 siblings, 1 reply; 58+ messages in thread
From: Dirk Gouders @ 2025-04-30 22:18 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Brian Geffon, Ravi Bangoria, Howard Chu,
	Charlie Jenkins, Colin Ian King, Dominique Martinet, Jann Horn,
	Masahiro Yamada, Arnd Bergmann, Yang Jihong, Dmitry Vyukov,
	Andi Kleen, Graham Woodward, Ilkka Koskinen, Anshuman Khandual,
	Zhongqiu Han, Hao Ge, Tengda Wu, Gabriele Monaco, Chun-Tse Shao,
	Casey Chen, Dr. David Alan Gilbert, Li Huafei,
	Steinar H. Gunderson, Levi Yun, Weilin Wang, Thomas Falcon,
	Thomas Richter, Andrew Kreimer, Krzysztof Łopatowski,
	Christophe Leroy, Jean-Philippe Romain, Junhao He,
	Masami Hiramatsu (Google), Xu Yang, Steve Clevenger, Zixian Cai,
	Stephen Brennan, Yujie Liu, linux-kernel, linux-perf-users,
	linux-arm-kernel, llvm

Ian Rogers <irogers@google.com> writes:

> On Wed, Apr 30, 2025 at 1:23 PM Dirk Gouders <dirk@gouders.net> wrote:
>>
>> Hi Ian,
>>
>> considering so many eyes looking at this, I am probably wrong.
>>
>> So, this is only a "gauge reply" to see if it's worth I really read
>> through all the commits ;-)
>>
>> Ian Rogers <irogers@google.com> writes:
>>
>> [SNIP]
>>
>> > diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
>> > index 70139036d68f..b847213fd616 100644
>> > --- a/tools/perf/bench/sched-pipe.c
>> > +++ b/tools/perf/bench/sched-pipe.c
>> > @@ -102,7 +102,8 @@ static const char * const bench_sched_pipe_usage[] = {
>> >  static int enter_cgroup(int nr)
>> >  {
>> >       char buf[32];
>> > -     int fd, len, ret;
>> > +     int fd;
>> > +     ssize_t ret, len;
>> >       int saved_errno;
>> >       struct cgroup *cgrp;
>> >       pid_t pid;
>> > @@ -118,7 +119,7 @@ static int enter_cgroup(int nr)
>> >       cgrp = cgrps[nr];
>> >
>> >       if (threaded)
>> > -             pid = syscall(__NR_gettid);
>> > +             pid = (pid_t)syscall(__NR_gettid);
>> >       else
>> >               pid = getpid();
>> >
>> > @@ -172,23 +173,25 @@ static void exit_cgroup(int nr)
>> >
>> >  static inline int read_pipe(struct thread_data *td)
>> >  {
>> > -     int ret, m;
>> > +     ssize_t ret;
>> > +     int m;
>> >  retry:
>> >       if (nonblocking) {
>> >               ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);
>>
>> The epoll_wait(), I know of, returns an int and not ssize_t.
>>
>> That shouldn't show up, because it doesn't cause real problems...
>
> So the function is read_pipe so it should probably return a ssize_t. I
> stopped short of that but made ret a ssize_t to silence the truncation
> warning on the read call. Assigning smaller to bigger is of course not
> an issue for epoll_wait.

Oh yes, I missed that ret is also used for the result of read().

Some lines down there is also a combination of

ret = enter_cgroup() (which is int)

and

ret = write()


Just confusing but yes, because ret is also used for read() and write()
in those cases it should be ssize_t.

I'm sorry for the noise.

Best regards,

Dirk

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2 04/47] perf bench: Silence -Wshorten-64-to-32 warnings
  2025-04-30 22:18       ` Dirk Gouders
@ 2025-04-30 22:22         ` Ian Rogers
  2025-04-30 23:11           ` Dirk Gouders
  0 siblings, 1 reply; 58+ messages in thread
From: Ian Rogers @ 2025-04-30 22:22 UTC (permalink / raw)
  To: Dirk Gouders
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Brian Geffon, Ravi Bangoria, Howard Chu,
	Charlie Jenkins, Colin Ian King, Dominique Martinet, Jann Horn,
	Masahiro Yamada, Arnd Bergmann, Yang Jihong, Dmitry Vyukov,
	Andi Kleen, Graham Woodward, Ilkka Koskinen, Anshuman Khandual,
	Zhongqiu Han, Hao Ge, Tengda Wu, Gabriele Monaco, Chun-Tse Shao,
	Casey Chen, Dr. David Alan Gilbert, Li Huafei,
	Steinar H. Gunderson, Levi Yun, Weilin Wang, Thomas Falcon,
	Thomas Richter, Andrew Kreimer, Krzysztof Łopatowski,
	Christophe Leroy, Jean-Philippe Romain, Junhao He,
	Masami Hiramatsu (Google), Xu Yang, Steve Clevenger, Zixian Cai,
	Stephen Brennan, Yujie Liu, linux-kernel, linux-perf-users,
	linux-arm-kernel, llvm

On Wed, Apr 30, 2025 at 3:19 PM Dirk Gouders <dirk@gouders.net> wrote:
>
> Ian Rogers <irogers@google.com> writes:
>
> > On Wed, Apr 30, 2025 at 1:23 PM Dirk Gouders <dirk@gouders.net> wrote:
> >>
> >> Hi Ian,
> >>
> >> considering so many eyes looking at this, I am probably wrong.
> >>
> >> So, this is only a "gauge reply" to see if it's worth I really read
> >> through all the commits ;-)
> >>
> >> Ian Rogers <irogers@google.com> writes:
> >>
> >> [SNIP]
> >>
> >> > diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
> >> > index 70139036d68f..b847213fd616 100644
> >> > --- a/tools/perf/bench/sched-pipe.c
> >> > +++ b/tools/perf/bench/sched-pipe.c
> >> > @@ -102,7 +102,8 @@ static const char * const bench_sched_pipe_usage[] = {
> >> >  static int enter_cgroup(int nr)
> >> >  {
> >> >       char buf[32];
> >> > -     int fd, len, ret;
> >> > +     int fd;
> >> > +     ssize_t ret, len;
> >> >       int saved_errno;
> >> >       struct cgroup *cgrp;
> >> >       pid_t pid;
> >> > @@ -118,7 +119,7 @@ static int enter_cgroup(int nr)
> >> >       cgrp = cgrps[nr];
> >> >
> >> >       if (threaded)
> >> > -             pid = syscall(__NR_gettid);
> >> > +             pid = (pid_t)syscall(__NR_gettid);
> >> >       else
> >> >               pid = getpid();
> >> >
> >> > @@ -172,23 +173,25 @@ static void exit_cgroup(int nr)
> >> >
> >> >  static inline int read_pipe(struct thread_data *td)
> >> >  {
> >> > -     int ret, m;
> >> > +     ssize_t ret;
> >> > +     int m;
> >> >  retry:
> >> >       if (nonblocking) {
> >> >               ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);
> >>
> >> The epoll_wait(), I know of, returns an int and not ssize_t.
> >>
> >> That shouldn't show up, because it doesn't cause real problems...
> >
> > So the function is read_pipe so it should probably return a ssize_t. I
> > stopped short of that but made ret a ssize_t to silence the truncation
> > warning on the read call. Assigning smaller to bigger is of course not
> > an issue for epoll_wait.
>
> Oh yes, I missed that ret is also used for the result of read().
>
> Some lines down there is also a combination of
>
> ret = enter_cgroup() (which is int)
>
> and
>
> ret = write()
>
>
> Just confusing but yes, because ret is also used for read() and write()
> in those cases it should be ssize_t.
>
> I'm sorry for the noise.

No worries, I'm appreciative of the eyes. I suspect we'll only pick up
the first patches in this series to fix what is a bug on ARM. I think
I'm responsible for too much noise here ;-)

Thanks,
Ian

> Best regards,
>
> Dirk

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2 04/47] perf bench: Silence -Wshorten-64-to-32 warnings
  2025-04-30 22:22         ` Ian Rogers
@ 2025-04-30 23:11           ` Dirk Gouders
  2025-05-02 12:06             ` David Laight
  0 siblings, 1 reply; 58+ messages in thread
From: Dirk Gouders @ 2025-04-30 23:11 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Brian Geffon, Ravi Bangoria, Howard Chu,
	Charlie Jenkins, Colin Ian King, Dominique Martinet, Jann Horn,
	Masahiro Yamada, Arnd Bergmann, Yang Jihong, Dmitry Vyukov,
	Andi Kleen, Graham Woodward, Ilkka Koskinen, Anshuman Khandual,
	Zhongqiu Han, Hao Ge, Tengda Wu, Gabriele Monaco, Chun-Tse Shao,
	Casey Chen, Dr. David Alan Gilbert, Li Huafei,
	Steinar H. Gunderson, Levi Yun, Weilin Wang, Thomas Falcon,
	Thomas Richter, Andrew Kreimer, Krzysztof Łopatowski,
	Christophe Leroy, Jean-Philippe Romain, Junhao He,
	Masami Hiramatsu (Google), Xu Yang, Steve Clevenger, Zixian Cai,
	Stephen Brennan, Yujie Liu, linux-kernel, linux-perf-users,
	linux-arm-kernel, llvm

Ian Rogers <irogers@google.com> writes:

> On Wed, Apr 30, 2025 at 3:19 PM Dirk Gouders <dirk@gouders.net> wrote:
>>
>> Ian Rogers <irogers@google.com> writes:
>>
>> > On Wed, Apr 30, 2025 at 1:23 PM Dirk Gouders <dirk@gouders.net> wrote:
>> >>
>> >> Hi Ian,
>> >>
>> >> considering so many eyes looking at this, I am probably wrong.
>> >>
>> >> So, this is only a "gauge reply" to see if it's worth I really read
>> >> through all the commits ;-)
>> >>
>> >> Ian Rogers <irogers@google.com> writes:
>> >>
>> >> [SNIP]
>> >>
>> >> > diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
>> >> > index 70139036d68f..b847213fd616 100644
>> >> > --- a/tools/perf/bench/sched-pipe.c
>> >> > +++ b/tools/perf/bench/sched-pipe.c
>> >> > @@ -102,7 +102,8 @@ static const char * const bench_sched_pipe_usage[] = {
>> >> >  static int enter_cgroup(int nr)
>> >> >  {
>> >> >       char buf[32];
>> >> > -     int fd, len, ret;
>> >> > +     int fd;
>> >> > +     ssize_t ret, len;
>> >> >       int saved_errno;
>> >> >       struct cgroup *cgrp;
>> >> >       pid_t pid;
>> >> > @@ -118,7 +119,7 @@ static int enter_cgroup(int nr)
>> >> >       cgrp = cgrps[nr];
>> >> >
>> >> >       if (threaded)
>> >> > -             pid = syscall(__NR_gettid);
>> >> > +             pid = (pid_t)syscall(__NR_gettid);
>> >> >       else
>> >> >               pid = getpid();
>> >> >
>> >> > @@ -172,23 +173,25 @@ static void exit_cgroup(int nr)
>> >> >
>> >> >  static inline int read_pipe(struct thread_data *td)
>> >> >  {
>> >> > -     int ret, m;
>> >> > +     ssize_t ret;
>> >> > +     int m;
>> >> >  retry:
>> >> >       if (nonblocking) {
>> >> >               ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);
>> >>
>> >> The epoll_wait(), I know of, returns an int and not ssize_t.
>> >>
>> >> That shouldn't show up, because it doesn't cause real problems...
>> >
>> > So the function is read_pipe so it should probably return a ssize_t. I
>> > stopped short of that but made ret a ssize_t to silence the truncation
>> > warning on the read call. Assigning smaller to bigger is of course not
>> > an issue for epoll_wait.
>>
>> Oh yes, I missed that ret is also used for the result of read().
>>
>> Some lines down there is also a combination of
>>
>> ret = enter_cgroup() (which is int)
>>
>> and
>>
>> ret = write()
>>
>>
>> Just confusing but yes, because ret is also used for read() and write()
>> in those cases it should be ssize_t.
>>
>> I'm sorry for the noise.
>
> No worries, I'm appreciative of the eyes. I suspect we'll only pick up
> the first patches in this series to fix what is a bug on ARM. I think
> I'm responsible for too much noise here ;-)

A final thought (in case this patch will also be picked):

Why not, in case of read_pipe() and worker_thread() just cast
read() and write() to int?  Both get counts of sizeof(int) and
it would clearly show: we know the result fits into an int.

In case of read_pipe() that would mean to just change one line in
contrast to:

@@ -172,23 +173,25 @@ static void exit_cgroup(int nr)
 
 static inline int read_pipe(struct thread_data *td)
 {
-	int ret, m;
+	ssize_t ret;
+	int m;
 retry:
 	if (nonblocking) {
 		ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);
 		if (ret < 0)
-			return ret;
+			return (int)ret;
 	}
 	ret = read(td->pipe_read, &m, sizeof(int));
 	if (nonblocking && ret < 0 && errno == EWOULDBLOCK)
 		goto retry;
-	return ret;
+	return (int)ret;


Best regards,

Dirk

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2 04/47] perf bench: Silence -Wshorten-64-to-32 warnings
  2025-04-30 23:11           ` Dirk Gouders
@ 2025-05-02 12:06             ` David Laight
  2025-05-02 14:12               ` Dirk Gouders
  0 siblings, 1 reply; 58+ messages in thread
From: David Laight @ 2025-05-02 12:06 UTC (permalink / raw)
  To: Dirk Gouders
  Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Brian Geffon, Ravi Bangoria, Howard Chu,
	Charlie Jenkins, Colin Ian King, Dominique Martinet, Jann Horn,
	Masahiro Yamada, Arnd Bergmann, Yang Jihong, Dmitry Vyukov,
	Andi Kleen, Graham Woodward, Ilkka Koskinen, Anshuman Khandual,
	Zhongqiu Han, Hao Ge, Tengda Wu, Gabriele Monaco, Chun-Tse Shao,
	Casey Chen, Dr. David Alan Gilbert, Li Huafei,
	Steinar H. Gunderson, Levi Yun, Weilin Wang, Thomas Falcon,
	Thomas Richter, Andrew Kreimer, Krzysztof Łopatowski,
	Christophe Leroy, Jean-Philippe Romain, Junhao He,
	Masami Hiramatsu (Google), Xu Yang, Steve Clevenger, Zixian Cai,
	Stephen Brennan, Yujie Liu, linux-kernel, linux-perf-users,
	linux-arm-kernel, llvm

On Thu, 01 May 2025 01:11:16 +0200
Dirk Gouders <dirk@gouders.net> wrote:

> Ian Rogers <irogers@google.com> writes:
> 
> > On Wed, Apr 30, 2025 at 3:19 PM Dirk Gouders <dirk@gouders.net> wrote:  
> >>
> >> Ian Rogers <irogers@google.com> writes:
> >>  
> >> > On Wed, Apr 30, 2025 at 1:23 PM Dirk Gouders <dirk@gouders.net> wrote:  
> >> >>
> >> >> Hi Ian,
> >> >>
> >> >> considering so many eyes looking at this, I am probably wrong.
> >> >>
> >> >> So, this is only a "gauge reply" to see if it's worth I really read
> >> >> through all the commits ;-)
> >> >>
> >> >> Ian Rogers <irogers@google.com> writes:
> >> >>
> >> >> [SNIP]
> >> >>  
> >> >> > diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
> >> >> > index 70139036d68f..b847213fd616 100644
> >> >> > --- a/tools/perf/bench/sched-pipe.c
> >> >> > +++ b/tools/perf/bench/sched-pipe.c
> >> >> > @@ -102,7 +102,8 @@ static const char * const bench_sched_pipe_usage[] = {
> >> >> >  static int enter_cgroup(int nr)
> >> >> >  {
> >> >> >       char buf[32];
> >> >> > -     int fd, len, ret;
> >> >> > +     int fd;
> >> >> > +     ssize_t ret, len;
> >> >> >       int saved_errno;
> >> >> >       struct cgroup *cgrp;
> >> >> >       pid_t pid;
> >> >> > @@ -118,7 +119,7 @@ static int enter_cgroup(int nr)
> >> >> >       cgrp = cgrps[nr];
> >> >> >
> >> >> >       if (threaded)
> >> >> > -             pid = syscall(__NR_gettid);
> >> >> > +             pid = (pid_t)syscall(__NR_gettid);
> >> >> >       else
> >> >> >               pid = getpid();
> >> >> >
> >> >> > @@ -172,23 +173,25 @@ static void exit_cgroup(int nr)
> >> >> >
> >> >> >  static inline int read_pipe(struct thread_data *td)
> >> >> >  {
> >> >> > -     int ret, m;
> >> >> > +     ssize_t ret;
> >> >> > +     int m;
> >> >> >  retry:
> >> >> >       if (nonblocking) {
> >> >> >               ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);  
> >> >>
> >> >> The epoll_wait(), I know of, returns an int and not ssize_t.
> >> >>
> >> >> That shouldn't show up, because it doesn't cause real problems...  
> >> >
> >> > So the function is read_pipe so it should probably return a ssize_t. I
> >> > stopped short of that but made ret a ssize_t to silence the truncation
> >> > warning on the read call. Assigning smaller to bigger is of course not
> >> > an issue for epoll_wait.  
> >>
> >> Oh yes, I missed that ret is also used for the result of read().
> >>
> >> Some lines down there is also a combination of
> >>
> >> ret = enter_cgroup() (which is int)
> >>
> >> and
> >>
> >> ret = write()
> >>
> >>
> >> Just confusing but yes, because ret is also used for read() and write()
> >> in those cases it should be ssize_t.
> >>
> >> I'm sorry for the noise.  
> >
> > No worries, I'm appreciative of the eyes. I suspect we'll only pick up
> > the first patches in this series to fix what is a bug on ARM. I think
> > I'm responsible for too much noise here ;-)  
> 
> A final thought (in case this patch will also be picked):
> 
> Why not, in case of read_pipe() and worker_thread() just cast
> read() and write() to int?  Both get counts of sizeof(int) and
> it would clearly show: we know the result fits into an int.

This is an obvious case of the entire insanity of these changes.

	David

> 
> In case of read_pipe() that would mean to just change one line in
> contrast to:
> 
> @@ -172,23 +173,25 @@ static void exit_cgroup(int nr)
>  
>  static inline int read_pipe(struct thread_data *td)
>  {
> -	int ret, m;
> +	ssize_t ret;
> +	int m;
>  retry:
>  	if (nonblocking) {
>  		ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);
>  		if (ret < 0)
> -			return ret;
> +			return (int)ret;
>  	}
>  	ret = read(td->pipe_read, &m, sizeof(int));
>  	if (nonblocking && ret < 0 && errno == EWOULDBLOCK)
>  		goto retry;
> -	return ret;
> +	return (int)ret;
> 
> 
> Best regards,
> 
> Dirk
> 


^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2 04/47] perf bench: Silence -Wshorten-64-to-32 warnings
  2025-05-02 12:06             ` David Laight
@ 2025-05-02 14:12               ` Dirk Gouders
  2025-05-03 10:05                 ` David Laight
  0 siblings, 1 reply; 58+ messages in thread
From: Dirk Gouders @ 2025-05-02 14:12 UTC (permalink / raw)
  To: David Laight
  Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Brian Geffon, Ravi Bangoria, Howard Chu,
	Charlie Jenkins, Colin Ian King, Dominique Martinet, Jann Horn,
	Masahiro Yamada, Arnd Bergmann, Yang Jihong, Dmitry Vyukov,
	Andi Kleen, Graham Woodward, Ilkka Koskinen, Anshuman Khandual,
	Zhongqiu Han, Hao Ge, Tengda Wu, Gabriele Monaco, Chun-Tse Shao,
	Casey Chen, Dr. David Alan Gilbert, Li Huafei,
	Steinar H. Gunderson, Levi Yun, Weilin Wang, Thomas Falcon,
	Thomas Richter, Andrew Kreimer, Krzysztof Łopatowski,
	Christophe Leroy, Jean-Philippe Romain, Junhao He,
	Masami Hiramatsu (Google), Xu Yang, Steve Clevenger, Zixian Cai,
	Stephen Brennan, Yujie Liu, linux-kernel, linux-perf-users,
	linux-arm-kernel, llvm

David Laight <david.laight.linux@gmail.com> writes:

> On Thu, 01 May 2025 01:11:16 +0200
> Dirk Gouders <dirk@gouders.net> wrote:
>
>> Ian Rogers <irogers@google.com> writes:
>> 
>> > On Wed, Apr 30, 2025 at 3:19 PM Dirk Gouders <dirk@gouders.net> wrote:  
>> >>
>> >> Ian Rogers <irogers@google.com> writes:
>> >>  
>> >> > On Wed, Apr 30, 2025 at 1:23 PM Dirk Gouders <dirk@gouders.net> wrote:  
>> >> >>
>> >> >> Hi Ian,
>> >> >>
>> >> >> considering so many eyes looking at this, I am probably wrong.
>> >> >>
>> >> >> So, this is only a "gauge reply" to see if it's worth I really read
>> >> >> through all the commits ;-)
>> >> >>
>> >> >> Ian Rogers <irogers@google.com> writes:
>> >> >>
>> >> >> [SNIP]
>> >> >>  
>> >> >> > diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
>> >> >> > index 70139036d68f..b847213fd616 100644
>> >> >> > --- a/tools/perf/bench/sched-pipe.c
>> >> >> > +++ b/tools/perf/bench/sched-pipe.c
>> >> >> > @@ -102,7 +102,8 @@ static const char * const bench_sched_pipe_usage[] = {
>> >> >> >  static int enter_cgroup(int nr)
>> >> >> >  {
>> >> >> >       char buf[32];
>> >> >> > -     int fd, len, ret;
>> >> >> > +     int fd;
>> >> >> > +     ssize_t ret, len;
>> >> >> >       int saved_errno;
>> >> >> >       struct cgroup *cgrp;
>> >> >> >       pid_t pid;
>> >> >> > @@ -118,7 +119,7 @@ static int enter_cgroup(int nr)
>> >> >> >       cgrp = cgrps[nr];
>> >> >> >
>> >> >> >       if (threaded)
>> >> >> > -             pid = syscall(__NR_gettid);
>> >> >> > +             pid = (pid_t)syscall(__NR_gettid);
>> >> >> >       else
>> >> >> >               pid = getpid();
>> >> >> >
>> >> >> > @@ -172,23 +173,25 @@ static void exit_cgroup(int nr)
>> >> >> >
>> >> >> >  static inline int read_pipe(struct thread_data *td)
>> >> >> >  {
>> >> >> > -     int ret, m;
>> >> >> > +     ssize_t ret;
>> >> >> > +     int m;
>> >> >> >  retry:
>> >> >> >       if (nonblocking) {
>> >> >> >               ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);  
>> >> >>
>> >> >> The epoll_wait(), I know of, returns an int and not ssize_t.
>> >> >>
>> >> >> That shouldn't show up, because it doesn't cause real problems...  
>> >> >
>> >> > So the function is read_pipe so it should probably return a ssize_t. I
>> >> > stopped short of that but made ret a ssize_t to silence the truncation
>> >> > warning on the read call. Assigning smaller to bigger is of course not
>> >> > an issue for epoll_wait.  
>> >>
>> >> Oh yes, I missed that ret is also used for the result of read().
>> >>
>> >> Some lines down there is also a combination of
>> >>
>> >> ret = enter_cgroup() (which is int)
>> >>
>> >> and
>> >>
>> >> ret = write()
>> >>
>> >>
>> >> Just confusing but yes, because ret is also used for read() and write()
>> >> in those cases it should be ssize_t.
>> >>
>> >> I'm sorry for the noise.  
>> >
>> > No worries, I'm appreciative of the eyes. I suspect we'll only pick up
>> > the first patches in this series to fix what is a bug on ARM. I think
>> > I'm responsible for too much noise here ;-)  
>> 
>> A final thought (in case this patch will also be picked):
>> 
>> Why not, in case of read_pipe() and worker_thread() just cast
>> read() and write() to int?  Both get counts of sizeof(int) and
>> it would clearly show: we know the result fits into an int.
>
> This is an obvious case of the entire insanity of these changes.

You mean, because there is still the -1 case where the sign-lost can
happen?

I guess your reply is in combination with your replies to another thread
to this subject.  As far as I understood, Ian also has problems with
full understanding and I wonder if it helps to talk about a real
example.  As far as I understood you say that code like this
(from tools/perf/bench/sched-pipe.c) is simply wrong:

static inline int read_pipe(struct thread_data *td)
{
	int ret, m;
retry:
	if (nonblocking) {
		ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);
		if (ret < 0)
			return ret;
	}
	ret = read(td->pipe_read, &m, sizeof(int));
	if (nonblocking && ret < 0 && errno == EWOULDBLOCK)
		goto retry;
	return ret;
}

And from your reply I understand that casting the read() explicitely to
int is insane.  And now, I wonder what you would suggest -- honestly, I
am expecting to learn something, here.

Best regards,

Dirk

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2 04/47] perf bench: Silence -Wshorten-64-to-32 warnings
  2025-05-02 14:12               ` Dirk Gouders
@ 2025-05-03 10:05                 ` David Laight
  2025-05-03 12:22                   ` Dirk Gouders
  0 siblings, 1 reply; 58+ messages in thread
From: David Laight @ 2025-05-03 10:05 UTC (permalink / raw)
  To: Dirk Gouders
  Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Brian Geffon, Ravi Bangoria, Howard Chu,
	Charlie Jenkins, Colin Ian King, Dominique Martinet, Jann Horn,
	Masahiro Yamada, Arnd Bergmann, Yang Jihong, Dmitry Vyukov,
	Andi Kleen, Graham Woodward, Ilkka Koskinen, Anshuman Khandual,
	Zhongqiu Han, Hao Ge, Tengda Wu, Gabriele Monaco, Chun-Tse Shao,
	Casey Chen, Dr. David Alan Gilbert, Li Huafei,
	Steinar H. Gunderson, Levi Yun, Weilin Wang, Thomas Falcon,
	Thomas Richter, Andrew Kreimer, Krzysztof Łopatowski,
	Christophe Leroy, Jean-Philippe Romain, Junhao He,
	Masami Hiramatsu (Google), Xu Yang, Steve Clevenger, Zixian Cai,
	Stephen Brennan, Yujie Liu, linux-kernel, linux-perf-users,
	linux-arm-kernel, llvm

On Fri, 02 May 2025 16:12:17 +0200
Dirk Gouders <dirk@gouders.net> wrote:

> David Laight <david.laight.linux@gmail.com> writes:
> 
> > On Thu, 01 May 2025 01:11:16 +0200
> > Dirk Gouders <dirk@gouders.net> wrote:
> >  
> >> Ian Rogers <irogers@google.com> writes:
> >>   
> >> > On Wed, Apr 30, 2025 at 3:19 PM Dirk Gouders <dirk@gouders.net> wrote:    
> >> >>
> >> >> Ian Rogers <irogers@google.com> writes:
> >> >>    
> >> >> > On Wed, Apr 30, 2025 at 1:23 PM Dirk Gouders <dirk@gouders.net> wrote:    
> >> >> >>
> >> >> >> Hi Ian,
> >> >> >>
> >> >> >> considering so many eyes looking at this, I am probably wrong.
> >> >> >>
> >> >> >> So, this is only a "gauge reply" to see if it's worth I really read
> >> >> >> through all the commits ;-)
> >> >> >>
> >> >> >> Ian Rogers <irogers@google.com> writes:
> >> >> >>
> >> >> >> [SNIP]
> >> >> >>    
> >> >> >> > diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
> >> >> >> > index 70139036d68f..b847213fd616 100644
> >> >> >> > --- a/tools/perf/bench/sched-pipe.c
> >> >> >> > +++ b/tools/perf/bench/sched-pipe.c
> >> >> >> > @@ -102,7 +102,8 @@ static const char * const bench_sched_pipe_usage[] = {
> >> >> >> >  static int enter_cgroup(int nr)
> >> >> >> >  {
> >> >> >> >       char buf[32];
> >> >> >> > -     int fd, len, ret;
> >> >> >> > +     int fd;
> >> >> >> > +     ssize_t ret, len;
> >> >> >> >       int saved_errno;
> >> >> >> >       struct cgroup *cgrp;
> >> >> >> >       pid_t pid;
> >> >> >> > @@ -118,7 +119,7 @@ static int enter_cgroup(int nr)
> >> >> >> >       cgrp = cgrps[nr];
> >> >> >> >
> >> >> >> >       if (threaded)
> >> >> >> > -             pid = syscall(__NR_gettid);
> >> >> >> > +             pid = (pid_t)syscall(__NR_gettid);
> >> >> >> >       else
> >> >> >> >               pid = getpid();
> >> >> >> >
> >> >> >> > @@ -172,23 +173,25 @@ static void exit_cgroup(int nr)
> >> >> >> >
> >> >> >> >  static inline int read_pipe(struct thread_data *td)
> >> >> >> >  {
> >> >> >> > -     int ret, m;
> >> >> >> > +     ssize_t ret;
> >> >> >> > +     int m;
> >> >> >> >  retry:
> >> >> >> >       if (nonblocking) {
> >> >> >> >               ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);    
> >> >> >>
> >> >> >> The epoll_wait(), I know of, returns an int and not ssize_t.
> >> >> >>
> >> >> >> That shouldn't show up, because it doesn't cause real problems...    
> >> >> >
> >> >> > So the function is read_pipe so it should probably return a ssize_t. I
> >> >> > stopped short of that but made ret a ssize_t to silence the truncation
> >> >> > warning on the read call. Assigning smaller to bigger is of course not
> >> >> > an issue for epoll_wait.    
> >> >>
> >> >> Oh yes, I missed that ret is also used for the result of read().
> >> >>
> >> >> Some lines down there is also a combination of
> >> >>
> >> >> ret = enter_cgroup() (which is int)
> >> >>
> >> >> and
> >> >>
> >> >> ret = write()
> >> >>
> >> >>
> >> >> Just confusing but yes, because ret is also used for read() and write()
> >> >> in those cases it should be ssize_t.
> >> >>
> >> >> I'm sorry for the noise.    
> >> >
> >> > No worries, I'm appreciative of the eyes. I suspect we'll only pick up
> >> > the first patches in this series to fix what is a bug on ARM. I think
> >> > I'm responsible for too much noise here ;-)    
> >> 
> >> A final thought (in case this patch will also be picked):
> >> 
> >> Why not, in case of read_pipe() and worker_thread() just cast
> >> read() and write() to int?  Both get counts of sizeof(int) and
> >> it would clearly show: we know the result fits into an int.  
> >
> > This is an obvious case of the entire insanity of these changes.  
> 
> You mean, because there is still the -1 case where the sign-lost can
> happen?
> 
> I guess your reply is in combination with your replies to another thread
> to this subject.  As far as I understood, Ian also has problems with
> full understanding and I wonder if it helps to talk about a real
> example.  As far as I understood you say that code like this
> (from tools/perf/bench/sched-pipe.c) is simply wrong:
> 
> static inline int read_pipe(struct thread_data *td)
> {
> 	int ret, m;
> retry:
> 	if (nonblocking) {
> 		ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);
> 		if (ret < 0)
> 			return ret;
> 	}
> 	ret = read(td->pipe_read, &m, sizeof(int));
> 	if (nonblocking && ret < 0 && errno == EWOULDBLOCK)
> 		goto retry;
> 	return ret;
> }
> 
> And from your reply I understand that casting the read() explicitely to
> int is insane.  And now, I wonder what you would suggest -- honestly, I
> am expecting to learn something, here.

If you look through pretty much all 'posix' userspace code the return
value from 'read' is assigned to an 'int' variable.
If the compiler is going to complain that the return value doesn't fit
into a 32bit int, it better have a pretty good idea the return value
might exceed 2^^32.
That requires knowledge of what 'read' does and analysis of the domain
(not just type) of the length passed to read.

Now if you add an (int) cast, you won't get an error (on 32bit) if
the value is a pointer - and that is an error you always want.

I'm pretty sure that it is also true the linux limits read (and write)
to INT_MAX - so, for linux, the return value from read() always fits
int 'int'.

The underlying problem is that if you start adding unnecessary casts for
integer type conversions you end up with so many casts that it is far too
easy for a 'broken' one to slip into the code.

If you scan the kernel for min_t() there are plenty of very dubious ones.
They've been added to 'fix' a compile time warning, but there are plenty
that cast to u8, u16 or long (where there are u64 lurking).
One of the u16 ones I found was a real bug and found/fixed separately
from my scans of all the min_t().

	David 

> 
> Best regards,
> 
> Dirk


^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2 04/47] perf bench: Silence -Wshorten-64-to-32 warnings
  2025-05-03 10:05                 ` David Laight
@ 2025-05-03 12:22                   ` Dirk Gouders
  0 siblings, 0 replies; 58+ messages in thread
From: Dirk Gouders @ 2025-05-03 12:22 UTC (permalink / raw)
  To: David Laight
  Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Adrian Hunter, Kan Liang, Yury Norov, Rasmus Villemoes,
	Thomas Gleixner, Darren Hart, Davidlohr Bueso, André Almeida,
	John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
	Yicong Yang, Jonathan Cameron, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey,
	Athira Rajeev, Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi,
	Kuan-Wei Chiu, He Zhe, Brian Geffon, Ravi Bangoria, Howard Chu,
	Charlie Jenkins, Colin Ian King, Dominique Martinet, Jann Horn,
	Masahiro Yamada, Arnd Bergmann, Yang Jihong, Dmitry Vyukov,
	Andi Kleen, Graham Woodward, Ilkka Koskinen, Anshuman Khandual,
	Zhongqiu Han, Hao Ge, Tengda Wu, Gabriele Monaco, Chun-Tse Shao,
	Casey Chen, Dr. David Alan Gilbert, Li Huafei,
	Steinar H. Gunderson, Levi Yun, Weilin Wang, Thomas Falcon,
	Thomas Richter, Andrew Kreimer, Krzysztof Łopatowski,
	Christophe Leroy, Jean-Philippe Romain, Junhao He,
	Masami Hiramatsu (Google), Xu Yang, Steve Clevenger, Zixian Cai,
	Stephen Brennan, Yujie Liu, linux-kernel, linux-perf-users,
	linux-arm-kernel, llvm

David Laight <david.laight.linux@gmail.com> writes:

> On Fri, 02 May 2025 16:12:17 +0200
> Dirk Gouders <dirk@gouders.net> wrote:
>
>> David Laight <david.laight.linux@gmail.com> writes:
>> 
>> > On Thu, 01 May 2025 01:11:16 +0200
>> > Dirk Gouders <dirk@gouders.net> wrote:
>> >  
>> >> Ian Rogers <irogers@google.com> writes:
>> >>   
>> >> > On Wed, Apr 30, 2025 at 3:19 PM Dirk Gouders <dirk@gouders.net> wrote:    
>> >> >>
>> >> >> Ian Rogers <irogers@google.com> writes:
>> >> >>    
>> >> >> > On Wed, Apr 30, 2025 at 1:23 PM Dirk Gouders <dirk@gouders.net> wrote:    
>> >> >> >>
>> >> >> >> Hi Ian,
>> >> >> >>
>> >> >> >> considering so many eyes looking at this, I am probably wrong.
>> >> >> >>
>> >> >> >> So, this is only a "gauge reply" to see if it's worth I really read
>> >> >> >> through all the commits ;-)
>> >> >> >>
>> >> >> >> Ian Rogers <irogers@google.com> writes:
>> >> >> >>
>> >> >> >> [SNIP]
>> >> >> >>    
>> >> >> >> > diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
>> >> >> >> > index 70139036d68f..b847213fd616 100644
>> >> >> >> > --- a/tools/perf/bench/sched-pipe.c
>> >> >> >> > +++ b/tools/perf/bench/sched-pipe.c
>> >> >> >> > @@ -102,7 +102,8 @@ static const char * const bench_sched_pipe_usage[] = {
>> >> >> >> >  static int enter_cgroup(int nr)
>> >> >> >> >  {
>> >> >> >> >       char buf[32];
>> >> >> >> > -     int fd, len, ret;
>> >> >> >> > +     int fd;
>> >> >> >> > +     ssize_t ret, len;
>> >> >> >> >       int saved_errno;
>> >> >> >> >       struct cgroup *cgrp;
>> >> >> >> >       pid_t pid;
>> >> >> >> > @@ -118,7 +119,7 @@ static int enter_cgroup(int nr)
>> >> >> >> >       cgrp = cgrps[nr];
>> >> >> >> >
>> >> >> >> >       if (threaded)
>> >> >> >> > -             pid = syscall(__NR_gettid);
>> >> >> >> > +             pid = (pid_t)syscall(__NR_gettid);
>> >> >> >> >       else
>> >> >> >> >               pid = getpid();
>> >> >> >> >
>> >> >> >> > @@ -172,23 +173,25 @@ static void exit_cgroup(int nr)
>> >> >> >> >
>> >> >> >> >  static inline int read_pipe(struct thread_data *td)
>> >> >> >> >  {
>> >> >> >> > -     int ret, m;
>> >> >> >> > +     ssize_t ret;
>> >> >> >> > +     int m;
>> >> >> >> >  retry:
>> >> >> >> >       if (nonblocking) {
>> >> >> >> >               ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);    
>> >> >> >>
>> >> >> >> The epoll_wait(), I know of, returns an int and not ssize_t.
>> >> >> >>
>> >> >> >> That shouldn't show up, because it doesn't cause real problems...    
>> >> >> >
>> >> >> > So the function is read_pipe so it should probably return a ssize_t. I
>> >> >> > stopped short of that but made ret a ssize_t to silence the truncation
>> >> >> > warning on the read call. Assigning smaller to bigger is of course not
>> >> >> > an issue for epoll_wait.    
>> >> >>
>> >> >> Oh yes, I missed that ret is also used for the result of read().
>> >> >>
>> >> >> Some lines down there is also a combination of
>> >> >>
>> >> >> ret = enter_cgroup() (which is int)
>> >> >>
>> >> >> and
>> >> >>
>> >> >> ret = write()
>> >> >>
>> >> >>
>> >> >> Just confusing but yes, because ret is also used for read() and write()
>> >> >> in those cases it should be ssize_t.
>> >> >>
>> >> >> I'm sorry for the noise.    
>> >> >
>> >> > No worries, I'm appreciative of the eyes. I suspect we'll only pick up
>> >> > the first patches in this series to fix what is a bug on ARM. I think
>> >> > I'm responsible for too much noise here ;-)    
>> >> 
>> >> A final thought (in case this patch will also be picked):
>> >> 
>> >> Why not, in case of read_pipe() and worker_thread() just cast
>> >> read() and write() to int?  Both get counts of sizeof(int) and
>> >> it would clearly show: we know the result fits into an int.  
>> >
>> > This is an obvious case of the entire insanity of these changes.  
>> 
>> You mean, because there is still the -1 case where the sign-lost can
>> happen?
>> 
>> I guess your reply is in combination with your replies to another thread
>> to this subject.  As far as I understood, Ian also has problems with
>> full understanding and I wonder if it helps to talk about a real
>> example.  As far as I understood you say that code like this
>> (from tools/perf/bench/sched-pipe.c) is simply wrong:
>> 
>> static inline int read_pipe(struct thread_data *td)
>> {
>> 	int ret, m;
>> retry:
>> 	if (nonblocking) {
>> 		ret = epoll_wait(td->epoll_fd, &td->epoll_ev, 1, -1);
>> 		if (ret < 0)
>> 			return ret;
>> 	}
>> 	ret = read(td->pipe_read, &m, sizeof(int));
>> 	if (nonblocking && ret < 0 && errno == EWOULDBLOCK)
>> 		goto retry;
>> 	return ret;
>> }
>> 
>> And from your reply I understand that casting the read() explicitely to
>> int is insane.  And now, I wonder what you would suggest -- honestly, I
>> am expecting to learn something, here.

First, thank you for elaborating on this.  As I expected, I indeed learn
more than one thing.

> If you look through pretty much all 'posix' userspace code the return
> value from 'read' is assigned to an 'int' variable.

I looked at some read()s in util-linux and all those that I looked at
use ssize_t.  Two reads, I found in bash use int.  In mpich, both
versions are used...  I didn't see a single cast, though ;-)

> If the compiler is going to complain that the return value doesn't fit
> into a 32bit int, it better have a pretty good idea the return value
> might exceed 2^^32.
> That requires knowledge of what 'read' does and analysis of the domain
> (not just type) of the length passed to read.
> Now if you add an (int) cast, you won't get an error (on 32bit) if
> the value is a pointer - and that is an error you always want.

You mean something like:

char *ptr = (int)read(fd, buf, sizeof(buf));

Here in my environment, I'd get an error:

error: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]

(I have no 32bit system to test it but from my memory, I'd say I know
 such error from times when 64bit wasn't available...)

> I'm pretty sure that it is also true the linux limits read (and write)
> to INT_MAX - so, for linux, the return value from read() always fits
> int 'int'.

Yes, didn't know that.  From read(2):

------------------------------------------------------------------------
NOTES
       On Linux, read() (and similar system calls) will transfer at most
       0x7ffff000 (2,147,479,552) bytes, returning the number of bytes
       actually transferred.  (This is true on both 32-bit and 64-bit systems.)
------------------------------------------------------------------------

Oh well, I myself took `ssize_t read()' always so serious that I gave my
best to always try to match that type...

> The underlying problem is that if you start adding unnecessary casts for
> integer type conversions you end up with so many casts that it is far too
> easy for a 'broken' one to slip into the code.

OK, in the other thread, you also said that, in your opinion, (just
integer?) casts should be kept to an absolute minimum and I wonder, what
would be an example for such (mandatory) cases.  Just the ones where the
compiler would complain (except for -Wshorten-64-to-32)?

> If you scan the kernel for min_t() there are plenty of very dubious ones.
> They've been added to 'fix' a compile time warning, but there are plenty
> that cast to u8, u16 or long (where there are u64 lurking).
> One of the u16 ones I found was a real bug and found/fixed separately
> from my scans of all the min_t().

Sorry for me still failing to fully understand: do your concerns then
mean you'd vote for not enabling -Wshorten-64-to-32 and live with the
perhaps rare cases of problems like the one in

https://lore.kernel.org/lkml/20250331172759.115604-1-leo.yan@arm.com/

or identify them by other means?

Best regards,

Dirk

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2 05/47] arm64: cputype: Silence -Wshorten-64-to-32 warnings
  2025-04-30 17:49 ` [PATCH v2 05/47] arm64: cputype: " Ian Rogers
@ 2025-05-09 12:56   ` Mark Rutland
  0 siblings, 0 replies; 58+ messages in thread
From: Mark Rutland @ 2025-05-09 12:56 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
	Kan Liang, Yury Norov, Rasmus Villemoes, Thomas Gleixner,
	Darren Hart, Davidlohr Bueso, André Almeida, John Garry,
	Will Deacon, James Clark, Mike Leach, Leo Yan, Yicong Yang,
	Jonathan Cameron, Nathan Chancellor, Bill Wendling, Justin Stitt,
	Josh Poimboeuf, Al Viro, Kyle Meyer, Ben Gainey, Athira Rajeev,
	Kajol Jain, Aditya Gupta, Eder Zulian, Dapeng Mi, Kuan-Wei Chiu,
	He Zhe, Dirk Gouders, Brian Geffon, Ravi Bangoria, Howard Chu,
	Charlie Jenkins, Colin Ian King, Dominique Martinet, Jann Horn,
	Masahiro Yamada, Arnd Bergmann, Yang Jihong, Dmitry Vyukov,
	Andi Kleen, Graham Woodward, Ilkka Koskinen, Anshuman Khandual,
	Zhongqiu Han, Hao Ge, Tengda Wu, Gabriele Monaco, Chun-Tse Shao,
	Casey Chen, Dr. David Alan Gilbert, Li Huafei,
	Steinar H. Gunderson, Levi Yun, Weilin Wang, Thomas Falcon,
	Thomas Richter, Andrew Kreimer, Krzysztof Łopatowski,
	Christophe Leroy, Jean-Philippe Romain, Junhao He,
	Masami Hiramatsu (Google), Xu Yang, Steve Clevenger, Zixian Cai,
	Stephen Brennan, Yujie Liu, linux-kernel, linux-perf-users,
	linux-arm-kernel, llvm

On Wed, Apr 30, 2025 at 10:49:53AM -0700, Ian Rogers wrote:
> 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@google.com>
> ---
>  tools/arch/arm64/include/asm/cputype.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/arch/arm64/include/asm/cputype.h b/tools/arch/arm64/include/asm/cputype.h
> index 488f8e751349..d7289b9d2758 100644
> --- a/tools/arch/arm64/include/asm/cputype.h
> +++ b/tools/arch/arm64/include/asm/cputype.h
> @@ -227,7 +227,7 @@
>  
>  #include <asm/sysreg.h>
>  
> -#define read_cpuid(reg)			read_sysreg_s(SYS_ ## reg)
> +#define read_cpuid(reg)			((u32)read_sysreg_s(SYS_ ## reg))

This isn't right.

Architecturally, system registers are 64-bit wide, and some of the ID
registers have allocated fields in the upper 32 bits, e.g. in MPIDR,
where we this will silently discard those when accessed via read_cpuid_mpidr():

static inline u64 __attribute_const__ read_cpuid_mpidr(void)
{
        return read_cpuid(MPIDR_EL1);
}

Mark.

^ permalink raw reply	[flat|nested] 58+ messages in thread

end of thread, other threads:[~2025-05-09 12:56 UTC | newest]

Thread overview: 58+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-30 17:49 [PATCH v2 00/47] Perf build support for -Wshorten-64-to-32 Ian Rogers
2025-04-30 17:49 ` [PATCH v2 01/47] perf build: Avoid building libbpf/bpftool with LIBBPF_DYNAMIC Ian Rogers
2025-04-30 17:49 ` [PATCH v2 02/47] perf tests: Silence -Wshorten-64-to-32 warnings Ian Rogers
2025-04-30 17:49 ` [PATCH v2 03/47] perf ui: " Ian Rogers
2025-04-30 17:49 ` [PATCH v2 04/47] perf bench: " Ian Rogers
2025-04-30 20:23   ` Dirk Gouders
2025-04-30 21:04     ` Ian Rogers
2025-04-30 22:18       ` Dirk Gouders
2025-04-30 22:22         ` Ian Rogers
2025-04-30 23:11           ` Dirk Gouders
2025-05-02 12:06             ` David Laight
2025-05-02 14:12               ` Dirk Gouders
2025-05-03 10:05                 ` David Laight
2025-05-03 12:22                   ` Dirk Gouders
2025-04-30 17:49 ` [PATCH v2 05/47] arm64: cputype: " Ian Rogers
2025-05-09 12:56   ` Mark Rutland
2025-04-30 17:49 ` [PATCH v2 06/47] x86/insn: " Ian Rogers
2025-04-30 17:49 ` [PATCH v2 07/47] tools lib: " Ian Rogers
2025-04-30 17:49 ` [PATCH v2 08/47] libperf: " Ian Rogers
2025-04-30 17:49 ` [PATCH v2 09/47] tools subcmd: " Ian Rogers
2025-04-30 17:49 ` [PATCH v2 10/47] perf arch x86: " Ian Rogers
2025-04-30 17:49 ` [PATCH v2 11/47] perf arm-spe: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 12/47] perf trace: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 13/47] perf trace-event: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 14/47] perf jvmti: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 15/47] perf pmu: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 16/47] perf annotate powerpc: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 17/47] perf s390: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 18/47] perf cs-etm: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 19/47] perf stat: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 20/47] perf dlfilter: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 21/47] perf demangle: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 22/47] perf annotate: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 23/47] perf report: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 24/47] perf help: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 25/47] perf hisi-ptt: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 26/47] perf probe: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 27/47] perf kwork: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 28/47] perf buildid: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 29/47] perf lock: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 30/47] perf mem: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 31/47] perf script: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 32/47] perf evlist: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 33/47] perf bpf_counter: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 34/47] perf ftrace: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 35/47] perf record: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 36/47] perf inject: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 37/47] perf sched: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 38/47] perf timechart: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 39/47] perf list: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 40/47] perf kvm: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 41/47] perf diff: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 42/47] perf daemon: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 43/47] perf zlib: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 44/47] perf symbol: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 45/47] perf util: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 46/47] perf hashmap: " Ian Rogers
2025-04-30 17:50 ` [PATCH v2 47/47] perf: " Ian Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).