From nobody Mon Feb 9 12:12:10 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F58622652D for ; Tue, 1 Apr 2025 18:25:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743531958; cv=none; b=H9YKJUIdsn4BuKmFe4pIQ8p0o2526m1muRDK5KxV5C4qWhBDfqPkdSmhd4zosDI9DFky4AZwVx/KX8KmQWuOTP+FW6nxhENk8ifgqXynV9R3IJYSW1r9Hg+2S1f59ZuI63e/tD+f3gxRBQXiR9QzNkk5yA/zcVWZ9FJzORHDvjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743531958; c=relaxed/simple; bh=Hjo4Ux9EshIB5nfwsYSB2kHln+oQVK3YSkK+wa42IQI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=RRfJtV87nBIGLFz1mVfwja4AyTBtKWZpgeKEFuOBLV4j9q5iJmLldF5a6iujAUnTizsvd7vAW3B0O566fVEZk4nrOOtMICi8YzT6z1Z3L7C0NUUWBSa3dMI+v0W6GXKtgYEiq/LCz98FKG2dSP1hmd+FlmPTVmorSV0EQxIf0H8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yKhRsUlS; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yKhRsUlS" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-229668c8659so5266285ad.3 for ; Tue, 01 Apr 2025 11:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743531956; x=1744136756; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=AINsNHfUQ84TZtdqHe8YbE6Ea6bkBfLpawU4T3dHFsc=; b=yKhRsUlSN6yUyspeokDcU19vuxCDr9Wi13QX1AxHkiX+f94r69hFIIeTitXE8t3ltW XqPizZu36hp1KtcPysp1O7+dkvbD0KTlqD2wApbAbLA6VZPHmAAVzjAOivTTVoalFPfl VoKfoAPO+NV5D99PifdJW0CCbvh7mXQEUwPe5fx3lahtLFB1ME0xxLkfqrVXDX68x4qI /I2udtO7GZnHRIk/7YJD8qwV8/EJufZbPz648k/kOi4gH5jfzxOwN+3XBlq2u+dr0TNK zJIHpYnAWqZrQ1CJYe9/JxZp3NWaBVmdSfAe4TTUPP7nZluj3PPH+aoyLRcGREHWqu5S hc8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743531956; x=1744136756; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AINsNHfUQ84TZtdqHe8YbE6Ea6bkBfLpawU4T3dHFsc=; b=hEtr4L9jQN4OSpTolhasgmV9ATHsd/zc/sjSIQGQfcJKoRUaxhAzcsZJC5dqv69uNP kgcvqn3PDbQ+0iggVsVxwamKdtVAVEdsjhQH/SSS1tbwIdPXWYLjvvgLP4Fd3I6/giZc bCsj7PRkB7b8XmgbzOwmbNTMZp06nkjBCdwWLaInErsiIpJdB6oO9TeRhYOLlMwScotN F4qAH+9FfYut05mC8mCtZI3eS6cZLQ4MU5CQTgPuu7e7pLRbEGXwPEvFspAXYWkQctmJ VOptaJ8UZQ12iY+Gx5VSuiFIkRNCBtj9sE8OOO8khm5AKu9iHhrGRGIFNz+nsyZgGAmN Ceeg== X-Forwarded-Encrypted: i=1; AJvYcCUkcD4ux9zce94sii6m34W294OOHdVG2rV9x++DmFQrQCoJkQNIXZbPgeIOmlCKmO2H3he79L7FvfvC+C4=@vger.kernel.org X-Gm-Message-State: AOJu0Yzxl7cjZDLs8DUIbXi8IQU8rsCzqR0GvJIDUNspN2t1dDrz6byt jGXaBJtez1W0C+kz9qUwlRKaQbsJKgomAVBYF0CkZpVZsuQnPzJvbgEmP814Zt9MPHq7g5+sfEx ufLajuQ== X-Google-Smtp-Source: AGHT+IHXdSNd3g++jqN+fHHZIowU3mAWz41Q2ckrahN9Qab8zKJXOz5RlfbWGg1n8s9o1EELvcDlzidMfBca X-Received: from plse12.prod.google.com ([2002:a17:902:b78c:b0:21f:b748:a1c8]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1106:b0:215:b75f:a1cb with SMTP id d9443c01a7336-2292f9448a5mr207715785ad.9.1743531955685; Tue, 01 Apr 2025 11:25:55 -0700 (PDT) Date: Tue, 1 Apr 2025 11:23:37 -0700 In-Reply-To: <20250401182347.3422199-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250401182347.3422199-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250401182347.3422199-40-irogers@google.com> Subject: [PATCH v1 39/48] perf timechart: Silence -Wshorten-64-to-32 warnings From: Ian Rogers To: Yury Norov , Rasmus Villemoes , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , 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 , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , Christophe Leroy , Jean-Philippe Romain , Junhao He , "Masami Hiramatsu (Google)" , Xu Yang , Steve Clevenger , Zixian Cai , Stephen Brennan , Yujie Liu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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; =20 - long state; + int state; u64 state_since; =20 char *comm; @@ -385,7 +385,7 @@ static struct power_event *p_state_end(struct timechart= *tchart, int cpu, if (!pwr) return NULL; =20 - pwr->state =3D cpus_pstate_state[cpu]; + pwr->state =3D (int)cpus_pstate_state[cpu]; pwr->start_time =3D cpus_pstate_start_times[cpu]; pwr->end_time =3D timestamp; pwr->cpu =3D cpu; @@ -601,8 +601,8 @@ process_sample_cpu_idle(struct timechart *tchart __mayb= e_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u32 state =3D evsel__intval(evsel, sample, "state"); - u32 cpu_id =3D evsel__intval(evsel, sample, "cpu_id"); + u32 state =3D (u32)evsel__intval(evsel, sample, "state"); + u32 cpu_id =3D (u32)evsel__intval(evsel, sample, "cpu_id"); =20 if (state =3D=3D (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 =3D evsel__intval(evsel, sample, "state"); - u32 cpu_id =3D evsel__intval(evsel, sample, "cpu_id"); + u32 state =3D (u32)evsel__intval(evsel, sample, "state"); + u32 cpu_id =3D (u32)evsel__intval(evsel, sample, "cpu_id"); =20 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 =3D evsel__intval(evsel, sample, "common_flags"); - int waker =3D evsel__intval(evsel, sample, "common_pid"); - int wakee =3D evsel__intval(evsel, sample, "pid"); + int waker =3D (int)evsel__intval(evsel, sample, "common_pid"); + int wakee =3D (int)evsel__intval(evsel, sample, "pid"); =20 sched_wakeup(tchart, sample->cpu, sample->time, waker, wakee, flags, back= trace); return 0; @@ -644,8 +644,8 @@ process_sample_sched_switch(struct timechart *tchart, struct perf_sample *sample, const char *backtrace) { - int prev_pid =3D evsel__intval(evsel, sample, "prev_pid"); - int next_pid =3D evsel__intval(evsel, sample, "next_pid"); + int prev_pid =3D (int)evsel__intval(evsel, sample, "prev_pid"); + int next_pid =3D (int)evsel__intval(evsel, sample, "next_pid"); u64 prev_state =3D evsel__intval(evsel, sample, "prev_state"); =20 sched_switch(tchart, sample->cpu, sample->time, prev_pid, next_pid, @@ -660,8 +660,8 @@ process_sample_power_start(struct timechart *tchart __m= aybe_unused, struct perf_sample *sample, const char *backtrace __maybe_unused) { - u64 cpu_id =3D evsel__intval(evsel, sample, "cpu_id"); - u64 value =3D evsel__intval(evsel, sample, "value"); + int cpu_id =3D (int)evsel__intval(evsel, sample, "cpu_id"); + int value =3D (int)evsel__intval(evsel, sample, "value"); =20 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 =3D evsel__intval(evsel, sample, "cpu_id"); + int cpu_id =3D (int)evsel__intval(evsel, sample, "cpu_id"); u64 value =3D evsel__intval(evsel, sample, "value"); =20 p_state_change(tchart, cpu_id, sample->time, value); @@ -697,10 +697,9 @@ process_sample_power_frequency(struct timechart *tchar= t, */ static void end_sample_processing(struct timechart *tchart) { - u64 cpu; struct power_event *pwr; =20 - for (cpu =3D 0; cpu <=3D tchart->numcpus; cpu++) { + for (unsigned int cpu =3D 0; cpu <=3D tchart->numcpus; cpu++) { /* C state */ #if 0 pwr =3D zalloc(sizeof(*pwr)); @@ -723,7 +722,7 @@ static void end_sample_processing(struct timechart *tch= art) return; =20 if (!pwr->state) - pwr->state =3D tchart->min_freq; + pwr->state =3D (int)tchart->min_freq; } } =20 @@ -812,7 +811,7 @@ static int pid_end_io_sample(struct timechart *tchart, = int pid, int type, } =20 if (ret < 0) { - sample->err =3D ret; + sample->err =3D (int)ret; } else if (type =3D=3D IOTYPE_READ || type =3D=3D IOTYPE_WRITE || type =3D=3D IOTYPE_TX || type =3D=3D IOTYPE_RX) { =20 @@ -852,7 +851,8 @@ process_enter_read(struct timechart *tchart, struct evsel *evsel, struct perf_sample *sample) { - long fd =3D evsel__intval(evsel, sample, "fd"); + int fd =3D (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 =3D evsel__intval(evsel, sample, "fd"); + int fd =3D (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 =3D evsel__intval(evsel, sample, "fd"); + int fd =3D (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 =3D evsel__intval(evsel, sample, "fd"); + int fd =3D (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 =3D evsel__intval(evsel, sample, "fd"); + int fd =3D (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 =3D evsel__intval(evsel, sample, "fd"); + int fd =3D (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 =3D=3D PSTATE) { if (!pwr->state) - pwr->state =3D tchart->min_freq; + pwr->state =3D (int)tchart->min_freq; svg_pstate(pwr->cpu, pwr->start_time, pwr->end_time, pwr->state); } pwr =3D pwr->next; @@ -1310,7 +1315,7 @@ static void draw_process_bars(struct timechart *tchar= t) =20 static void add_process_filter(const char *string) { - int pid =3D strtoull(string, NULL, 10); + int pid =3D (int)strtoull(string, NULL, 10); struct process_filter *filt =3D malloc(sizeof(*filt)); =20 if (!filt) @@ -1458,7 +1463,6 @@ static int determine_display_io_tasks(struct timechar= t *timechart, u64 threshold =20 static void write_svg_file(struct timechart *tchart, const char *filename) { - u64 i; int count; int thresh =3D tchart->io_events ? BYTES_THRESH : TIME_THRESH; =20 @@ -1494,7 +1498,7 @@ static void write_svg_file(struct timechart *tchart, = const char *filename) =20 svg_legenda(); =20 - for (i =3D 0; i < tchart->numcpus; i++) + for (unsigned int i =3D 0; i < tchart->numcpus; i++) svg_cpu_box(i, tchart->max_freq, tchart->turbo_frequency); =20 draw_cpu_usage(tchart); @@ -1616,7 +1620,7 @@ static int __cmd_timechart(struct timechart *tchart, = const char *output_name) =20 session =3D perf_session__new(&data, &tchart->tool); if (IS_ERR(session)) - return PTR_ERR(session); + return (int)PTR_ERR(session); =20 symbol__init(&session->header.env); =20 --=20 2.49.0.504.g3bcea36a83-goog