From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 1/2] perf tool_pmu: Make tool PMU events respect enable/disable
Date: Mon, 18 May 2026 20:49:19 +0000 [thread overview]
Message-ID: <20260518204920.22E62C2BCB7@smtp.kernel.org> (raw)
In-Reply-To: <20260518201419.2943132-2-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Tool PMU events (user_time and system_time) fail to update their `disabled` state when acting as event group members, leading to missing data (reporting 0).
- [Medium] File descriptor leak in `evsel__tool_pmu_open()` error path.
--
commit 1e5a2efb24e0315c712078601af14ae8cc8be1ff
Author: Ian Rogers <irogers@google.com>
perf tool_pmu: Make tool PMU events respect enable/disable
This commit implements enable and disable support for tool PMU events
(duration_time, user_time, system_time) to make them behave more like regular
counters. It adds accumulated_time tracking to prevent the events from
counting time while paused.
Closes: https://lore.kernel.org/linux-perf-users/20260517093650.2540920-1-nigro.fra@gmail.com/
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 2ee87fd84d3ea..63bfb03b6b13a 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
[ ... ]
> @@ -1795,12 +1798,63 @@ int evsel__append_addr_filter(struct evsel *evsel, const char *filter)
[ ... ]
> int evsel__enable(struct evsel *evsel)
> {
> - int err = perf_evsel__enable(&evsel->core);
> + int err;
> +
> + if (evsel__is_tool(evsel))
> + err = evsel__tool_pmu_enable(evsel);
> + else
> + err = perf_evsel__enable(&evsel->core);
> +
> + if (!err && evsel__is_group_leader(evsel)) {
> + struct evsel *member;
> +
> + for_each_group_member(member, evsel) {
> + if (evsel__is_tool(member)) {
[ ... ]
> + int mem_err = evsel__tool_pmu_enable(member);
> +
> + if (mem_err)
> + return mem_err;
> + }
> + }
> + }
>
> if (!err)
> evsel->disabled = false;
When evsel__enable() iterates over group members to enable them, does the
disabled flag get updated correctly for user_time and system_time events?
Since evsel->disabled = false at the end of this function only applies to
the group leader, it seems the group members are reliant on
evsel__tool_pmu_enable_cpu() to update their state.
> diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c
> index 6a9df3dc0e076..bb398fe82f6d9 100644
> --- a/tools/perf/util/tool_pmu.c
> +++ b/tools/perf/util/tool_pmu.c
[ ... ]
> @@ -246,8 +292,8 @@ int evsel__tool_pmu_open(struct evsel *evsel,
[ ... ]
> + if (evsel->core.attr.disabled) {
> + evsel->disabled = true;
> + *start_time = INVALID_START_TIME;
> } else {
> - struct perf_cpu cpu;
> -
> - cpu = perf_cpu_map__cpu(evsel->core.cpus, idx);
> - err = read_stat_field(fd, cpu, system ? 3 : 1,
> - start_time);
> + evsel->disabled = false;
> + err = tool_pmu__read_stat(evsel, idx, thread, start_time);
> + if (err)
> + goto out_close;
> }
If tool_pmu__read_stat() fails here and jumps to out_close, is the file
descriptor we just successfully opened and saved in FD(evsel, idx, thread)
leaked?
Looking at the out_close cleanup logic:
out_close:
...
do {
while (--thread >= 0) {
if (FD(evsel, idx, thread) >= 0)
close(FD(evsel, idx, thread));
FD(evsel, idx, thread) = -1;
}
thread = nthreads;
} while (--idx >= 0);
Since the loop pre-decrements the thread index, it seems to skip closing
the file descriptor for the currently failing thread.
[ ... ]
> @@ -467,10 +514,108 @@ static void perf_counts__update(struct perf_counts_values *count,
[ ... ]
> +int evsel__tool_pmu_enable_cpu(struct evsel *evsel, int cpu_map_idx)
> +{
> + enum tool_pmu_event ev = evsel__tool_event(evsel);
> + int thread, nthreads;
> +
> + if (!evsel->disabled)
> + return 0;
> +
> + if (ev == TOOL_PMU__EVENT_DURATION_TIME) {
> + if (cpu_map_idx == 0) {
> + evsel->duration_time.start_time = rdclock();
> + evsel->disabled = false;
> + }
> + return 0;
> + }
> +
> + if (ev == TOOL_PMU__EVENT_USER_TIME || ev == TOOL_PMU__EVENT_SYSTEM_TIME) {
> + nthreads = xyarray__max_y(evsel->process_time.start_times);
> + for (thread = 0; thread < nthreads; thread++) {
> + __u64 *start_time = xyarray__entry(evsel->process_time.start_times,
> + cpu_map_idx, thread);
> + __u64 val;
> + int err;
> +
> + err = tool_pmu__read_stat(evsel, cpu_map_idx, thread, &val);
> + if (!err)
> + *start_time = val;
> + else
> + *start_time = INVALID_START_TIME;
> + }
> + }
> + return 0;
> +}
Unlike the duration_time branch, it looks like evsel->disabled is not set
to false when processing user_time or system_time events here.
Will this cause evsel__tool_pmu_read() to see evsel->disabled as still true
and unconditionally return the frozen accumulated time for these members?
A similar pattern appears to be present in the disable path as well.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260518201419.2943132-1-irogers@google.com?part=1
next prev parent reply other threads:[~2026-05-18 20:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-18 18:39 [PATCH v1 0/2] perf tool_pmu: Support enable/disable for tool PMU events Ian Rogers
2026-05-18 18:39 ` [PATCH v1 1/2] perf tool_pmu: Make tool PMU events respect enable/disable Ian Rogers
2026-05-18 19:26 ` sashiko-bot
2026-05-18 18:39 ` [PATCH v1 2/2] perf tests: Add test for stat delay option with duration_time Ian Rogers
2026-05-18 19:33 ` sashiko-bot
2026-05-18 20:14 ` [PATCH v2 0/2] perf tool_pmu: Support enable/disable for tool PMU events Ian Rogers
2026-05-18 20:14 ` [PATCH v2 1/2] perf tool_pmu: Make tool PMU events respect enable/disable Ian Rogers
2026-05-18 20:49 ` sashiko-bot [this message]
2026-05-18 20:14 ` [PATCH v2 2/2] perf tests: Add test for stat delay option with duration_time Ian Rogers
2026-05-18 20:55 ` sashiko-bot
2026-05-18 22:37 ` [PATCH v3 0/2] perf tool_pmu: Support enable/disable for tool PMU events Ian Rogers
2026-05-18 22:37 ` [PATCH v3 1/2] perf tool_pmu: Make tool PMU events respect enable/disable Ian Rogers
2026-05-18 23:02 ` sashiko-bot
2026-05-18 22:37 ` [PATCH v3 2/2] perf tests: Add test for stat delay option with duration_time Ian Rogers
2026-05-19 1:41 ` [PATCH v4 0/2] perf tool_pmu: Support enable/disable for tool PMU events Ian Rogers
2026-05-19 1:41 ` [PATCH v4 1/2] perf tool_pmu: Make tool PMU events respect enable/disable Ian Rogers
2026-05-19 6:43 ` Namhyung Kim
2026-05-19 8:13 ` Ian Rogers
2026-05-20 23:06 ` Namhyung Kim
2026-05-23 0:40 ` Arnaldo Carvalho de Melo
2026-05-19 1:41 ` [PATCH v4 2/2] perf tests: Add test for stat delay option with duration_time Ian Rogers
2026-05-22 22:10 ` [PATCH v4 0/2] perf tool_pmu: Support enable/disable for tool PMU events Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260518204920.22E62C2BCB7@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.