From: sashiko-bot@kernel.org
To: "Nazar Kazakov" <nazar.kazakov@codethink.co.uk>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf jevents: make events order more deterministic
Date: Mon, 06 Jul 2026 18:01:45 +0000 [thread overview]
Message-ID: <20260706180146.A25AB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260706175624.692736-1-nazar.kazakov@codethink.co.uk>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The `__lt__` method violates strict weak ordering by using flawed boolean logic, breaking Python's sorting guarantees.
--
commit 1d3198ec01401252a35bb75abf7f3dc67eead5ab
Author: Nazar Kazakov <nazar.kazakov@codethink.co.uk>
perf jevents: make events order more deterministic
This commit attempts to fix a non-deterministic sorting order for events
that share the same name by including the description field in the
comparison.
> diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py
> index a91ccb5977f08..b3ab78a0ecb22 100644
> --- a/tools/perf/pmu-events/metric.py
> +++ b/tools/perf/pmu-events/metric.py
> @@ -623,7 +623,7 @@ class Metric:
>
> def __lt__(self, other):
> """Sort order."""
> - return self.name < other.name
> + return self.name < other.name or self.description < other.description
[Severity: Medium]
Does this logic break Python's strict weak ordering requirement for sorting?
If we have two metrics A and B where A.name > B.name, but
A.description < B.description, then A < B will evaluate to True because the
second condition is met. Conversely, B < A will also evaluate to True because
B.name < A.name meets the first condition.
Since A < B and B < A can both evaluate to True, this breaks the asymmetry
requirement for sorting and can lead to inconsistent event ordering or Python
exceptions during the perf build.
Could we compare tuples instead to ensure consistent ordering, such as:
return (self.name, self.description) < (other.name, other.description)
>
> def AddToMetricGroup(self, group):
> """Callback used when being added to a MetricGroup."""
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260706175624.692736-1-nazar.kazakov@codethink.co.uk?part=1
next prev parent reply other threads:[~2026-07-06 18:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 17:56 [PATCH] perf jevents: make events order more deterministic Nazar Kazakov
2026-07-06 18:01 ` sashiko-bot [this message]
2026-07-06 18:04 ` Ian Rogers
2026-07-06 18:22 ` Nazar Kazakov
2026-07-06 18:48 ` Ian Rogers
2026-07-06 19:08 ` Nazar Kazakov
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=20260706180146.A25AB1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=nazar.kazakov@codethink.co.uk \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox