From nobody Fri Dec 19 17:27:06 2025 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 2A20F2980CB for ; Wed, 30 Apr 2025 17:52:14 +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=1746035537; cv=none; b=d8HbmjW+MtCQhI/KkZ7Y5aoBpuLgaZ56ZVOPAVnaAFvuQDx0JEPksNBSXw3KKm5mR2Mu8cuBJGcqZP9Z5D7ro3GCw+8UCl+8b1gWSOVbCkbuI0tE33c3aupsUGbDNSUelxedMk/fKPjPywk4Xdynt8CeYGW8x6FUJH52LOJ4aJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746035537; c=relaxed/simple; bh=zW9gwrTc+/elptPi5nLpagW6cIkSTRk2Fzi4B/sicXs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HEHelbIJjVcxNkyqJTDmiUBaJudveLt/Rn9cob/QsE3lv4zndSrcJYRSHsGmmvB97dlaU/hdGh3Rz27507PuRb59WvZuh2VjyQXDsyYRngz4HaNiLfCd3flVBeh8ileW3fX8J16afNdwI9Qd/Ld4/SqazrAC11AkwF7A59mUk5w= 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=EGT95TE4; 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="EGT95TE4" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-225ab228a37so704575ad.2 for ; Wed, 30 Apr 2025 10:52:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746035534; x=1746640334; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rZ+CoAcmYBLBiSfvRWRVDoLVZV5YoqsPUn6PdkVoLDc=; b=EGT95TE41sAvYWrwNjJbAgTsxhwxGBVpJGwqdx7EHXcWWNWKVrcyEsy99kMet2jjsu NNh1U3Nw5eADOXBLNIhi2QNRW/Ns0t/OkENcrNGu+EshNEcn4+nbz6Wll3BXfCQRP9or /QAZjMayjW3qHJhziS+L6HCQBknc3BqfuB0U9c/1o9TBR3Lm/cUSHBzRl983tpvMxPtT Agt71RtrDfSLARXvY4IKdewYg5KwuW8W9XfI072srjJW5fcRAh3S93oFNCJX/vrtEqe5 Y0rPW5b7oi66Ltox6ELzeR3vxP/cNxhxIM+34V0pPCo1Q0MxrM5nS/tC/Eujyyrm7FDd S16Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746035534; x=1746640334; h=cc: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=rZ+CoAcmYBLBiSfvRWRVDoLVZV5YoqsPUn6PdkVoLDc=; b=XJHWo0qdEvLjKZ2kzUEbO2JSuqWjb3x8KScyOYcs1ZPjTCREv3lWewYy3H3XWKsiry n6+Lqg8KMkeX9uhG6R7FEFmemmVhyVUCvwa7VA48OSt7lzyle0UUmoH/AYobjFqPlnq4 bH/EKsp37HRH6jnfJOVegoxVPUTlbnTY/t8VHv79PTfhbRoSe3Wic9cn71E6gddifV8+ Pgpe50iXOLu7iBqEu5GgHB0D+R/UmJyC1hlAQ5P3iOFnzpnmXsSzkYWahRp8edxbc6iT iNk7/l89gAHODVaZpCDSbmo5SbEuuG5sHoGQOph8Tmy7jbsuoxydLyzzWG8Vb3cVjN85 LhIA== X-Forwarded-Encrypted: i=1; AJvYcCXJmUNiRc92KVHXu3RudGoqzTfbI7kxE1ZbfW+7P9AdNbddQtE/oGb1zdz6xoe6IwmUpuIR9n64xnBMLaY=@vger.kernel.org X-Gm-Message-State: AOJu0YwSDKpfPasUMDs6ZBD00XsdAF0gvD3HYrkwKEkDj7Hb7sZNXwPP 2tPTc9oLScS9nogkFIzwoqodwFQwg/DpwVSOm8e1wjyQ8AY5MYtXiAdwxHtmQCPqBtpyW2XTUEl XV+B1ew== X-Google-Smtp-Source: AGHT+IHp/LjxEC/4A96U6Bess1KjcinEpSErDMwJi3W4FOp4Q662t7w7WCYzN140WTM3Oj8+Ts90ea5DhqAS X-Received: from pjbpw14.prod.google.com ([2002:a17:90b:278e:b0:2ef:8055:93d9]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2752:b0:2ee:90a1:5d42 with SMTP id 98e67ed59e1d1-30a331ea3aemr7430537a91.0.1746035534102; Wed, 30 Apr 2025 10:52:14 -0700 (PDT) Date: Wed, 30 Apr 2025 10:50:26 -0700 In-Reply-To: <20250430175036.184610-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: <20250430175036.184610-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250430175036.184610-39-irogers@google.com> Subject: [PATCH v2 38/47] perf timechart: Silence -Wshorten-64-to-32 warnings From: Ian Rogers 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 , "=?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 Cc: Ian Rogers 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.906.g1f30a19c02-goog