All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Athira Rajeev" <atrajeev@linux.ibm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH V5 4/6] tools/perf: Add powerpc callback support for arch_perf_record__need_read
Date: Fri, 07 Aug 2026 15:32:43 +0000	[thread overview]
Message-ID: <20260807153244.39F5B1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260807144135.2607-5-atrajeev@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Redirecting group sibling reads to the group leader incorrectly accumulates the leader's event count instead of the HTM sibling's pending record count, leading to silent data loss and spurious warnings.
--

--- Patch [4]: [PATCH V5 4/6] tools/perf: Add powerpc callback support for arch_perf_record__need_read ---
commit 27e1bb8fdcf56e1c7b4262795fafefb9a6b92d9e
Author: Athira Rajeev <atrajeev@linux.ibm.com>

tools/perf: Add powerpc callback support for arch_perf_record__need_read

This commit implements the arch_perf_record__need_read() hook for powerpc.
It reads the pending record count for HTM events to determine if more data
needs to be drained during the recording loop.

> diff --git a/tools/perf/arch/powerpc/util/evsel.c b/tools/perf/arch/powerpc/util/evsel.c
> index 2f733cdc8dbbe..2b7851c706774 100644
> --- a/tools/perf/arch/powerpc/util/evsel.c
> +++ b/tools/perf/arch/powerpc/util/evsel.c

[ ... ]

> +/*
> + * powerpc implementation of arch_perf_record__need_read().
> + *
> + * Reads event->count for every open HTM evsel by issuing a direct
> + * read() on the event fd with a plain u64 buffer, bypassing the
> + * PERF_FORMAT_GROUP path in perf_evsel__read().  When an HTM evsel is
> + * a group sibling, evsel__config() sets PERF_FORMAT_GROUP on its attr;
> + * perf_evsel__read() would then call perf_evsel__read_group() which
> + * sizes the buffer by evsel->nr_members (0 for siblings), causing the
> + * kernel to return -ENOSPC.  Reading the fd directly with sizeof(u64)
> + * retrieves the HTM driver's plain pending-record count regardless of
> + * group membership.
> + *
> + * Returns: 1 if more data exists, 0 if collection is complete
> + */
> +int arch_perf_record__need_read(struct evlist *evlist)
> +{

[ ... ]

> +	/* Read HTM event counts to check if more data is available */
> +	evlist__for_each_entry(evlist, evsel) {
> +		struct perf_evsel *rd_evsel;
> +		struct xyarray *xy;
> +
> +		if (strcmp(evsel__pmu_name(evsel), "htm"))
> +			continue;
> +
> +		/*
> +		 * For group siblings nr_members == 0, which makes
> +		 * perf_evsel__read_size() return 0 and readn() fail.
> +		 * Read through the leader instead; perf_evsel__read_group()
> +		 * extracts the leader's own count from the group buffer.
> +		 */
> +		if (evsel->core.leader != &evsel->core)
> +			rd_evsel = evsel->core.leader;
> +		else
> +			rd_evsel = &evsel->core;
> +
> +		xy = rd_evsel->sample_id;
> +
> +		if (xy == NULL || rd_evsel->fd == NULL)
> +			continue;

[ ... ]

> +		for (x = 0; x < xyarray__max_x(xy); x++) {
> +			for (y = 0; y < xyarray__max_y(xy); y++) {
> +				struct perf_counts_values count = { .val = 0 };
> +
> +				if (perf_evsel__read(rd_evsel, x, y, &count) == 0)
> +					total_pending_records += count.val;

[Severity: Medium]
When an HTM event is a sibling, does this inadvertently read and accumulate the
group leader's value rather than the HTM sibling's pending record count?

The block above redirects reading to the leader, and then perf_evsel__read()
is called here. For group leaders, this delegates to perf_evsel__read_group(),
which extracts only the leader's count and discards sibling counts. This would
accumulate the wrong event's data. If the leader is a non-HTM event like
cycles, its continuously increasing counter will be read instead. This might
cause the drain loop to falsely believe data is still pending, exhaust the
drain retry limit, and emit a spurious warning, while ignoring the actual HTM
sibling's pending records.

Also, the function comment explicitly mentions bypassing the PERF_FORMAT_GROUP
path in perf_evsel__read() by issuing a direct read(), but this code directly
calls perf_evsel__read(). Could the comment and implementation be out of sync?

> +			}
> +		}
> +	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260807144135.2607-1-atrajeev@linux.ibm.com?part=4

  reply	other threads:[~2026-08-07 15:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 14:41 [PATCH V5 0/6] tools/perf: Add powerpc HTM auxtrace support Athira Rajeev
2026-08-07 14:41 ` [PATCH V5 1/6] tools/perf: Move powerpc VPA-DTL auxtrace init into a separate file Athira Rajeev
2026-08-07 14:41 ` [PATCH V5 2/6] tools/perf: Add AUXTRACE recording support for powerpc HTM Athira Rajeev
2026-08-07 14:59   ` sashiko-bot
2026-08-08  3:50     ` Athira Rajeev
2026-08-07 14:41 ` [PATCH V5 3/6] tools/perf: Add arch hook to drain remaining data before event close Athira Rajeev
2026-08-07 15:20   ` sashiko-bot
2026-08-08  4:05     ` Athira Rajeev
2026-08-07 14:41 ` [PATCH V5 4/6] tools/perf: Add powerpc callback support for arch_perf_record__need_read Athira Rajeev
2026-08-07 15:32   ` sashiko-bot [this message]
2026-08-07 14:41 ` [PATCH V5 5/6] tools/perf: Add powerpc HTM auxtrace event processing support Athira Rajeev
2026-08-07 15:33   ` sashiko-bot
2026-08-08  4:09     ` Athira Rajeev
2026-08-07 14:41 ` [PATCH V5 6/6] tools/perf: Add perf tool support for processing powerpc HTM AUXTRACE records Athira Rajeev
2026-08-08  5:11 ` [PATCH V5 0/6] tools/perf: Add powerpc HTM auxtrace support Athira Rajeev

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=20260807153244.39F5B1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=atrajeev@linux.ibm.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.