[PATCH v1 33/48] perf evlist: Silence -Wshorten-64-to-32 warnings

Ian Rogers
2025-04-01T18:25:43Z

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 c1a04141aed0..5692ea9f5717 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -920,7 +920,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;
}

@@ -1442,7 +1442,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);
@@ -1482,7 +1482,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);
@@ -1543,7 +1543,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!
*/
@@ -1553,7 +1553,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;
@@ -1656,7 +1656,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:
@@ -1941,7 +1942,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;

@@ -1950,7 +1951,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;
}
@@ -2016,7 +2017,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;

@@ -2070,12 +2071,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;
@@ -2085,7 +2086,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)
@@ -2305,7 +2306,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,
@@ -2326,7 +2327,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 1974395492d7..8b0a3cbb16a0 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;
@@ -1772,7 +1772,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);
@@ -1836,7 +1836,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))
@@ -2178,31 +2178,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);
}

@@ -3488,7 +3484,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;
}
@@ -3833,18 +3829,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.504.g3bcea36a83-goog