From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: Luke Jones <luke@ljones.dev>
Cc: Julian Sikorski <belegdol@gmail.com>,
akpm@linux-foundation.org, jserv@ccns.ncku.edu.tw,
linux-kernel@vger.kernel.org, lkml@sdf.org,
alexdeucher@gmail.com, perex@perex.cz, tiwai@suse.com,
linux-sound@vger.kernel.org, chuang@cs.nycu.edu.tw,
hui.wang@canonical.com
Subject: Re: [PATCH 2/2] lib/sort: Optimize heapsort with double-pop variation
Date: Wed, 15 Jan 2025 20:49:02 +0800 [thread overview]
Message-ID: <Z4euvhAXAiZXCObx@visitorckw-System-Product-Name> (raw)
In-Reply-To: <651d5c5a228254f20a3e9ddd839ffb3683ec2dc7.camel@ljones.dev>
(+Cc sound developers)
Hi Luke,
On Wed, Jan 15, 2025 at 04:27:52PM +1300, Luke Jones wrote:
> On Thu, 2024-06-20 at 17:36 +0200, Julian Sikorski wrote:
> > Hello,
> >
> > it appears that this patch has caused suspend-to-idle regression:
> >
> > https://gitlab.freedesktop.org/drm/amd/-/issues/3436
> >
>
> Another regression from this has been reported here
> https://bugzilla.kernel.org/show_bug.cgi?id=219158
>
Thank you for reporting this regression!
From a quick look, this seems to be caused by yet another broken
compare function. In sound/pci/hda/hda_auto_parser.c, the
compare_input_type() function can lead to sorting issues when both
is_headset_mic and is_headphone_mic are true for a and b. This can
result in a situation where both a < b and b < a hold true, violating
the antisymmetry and transitivity required by sort().
Additionally, the comments about "swap" and "don't swap" seem to make
incorrect assumptions about how sort() works. Regardless of this
optimization patch, sort() may swap a and b without comparing them.
Could you help test the following code? If it works, I'll submit it as
an official patch.
Regards,
Kuan-Wei
diff --git a/sound/pci/hda/hda_auto_parser.c b/sound/pci/hda/hda_auto_parser.c
index 84393f4f429d..5502ec09b584 100644
--- a/sound/pci/hda/hda_auto_parser.c
+++ b/sound/pci/hda/hda_auto_parser.c
@@ -73,6 +73,8 @@ static int compare_input_type(const void *ap, const void *bp)
return (int)(a->type - b->type);
/* If has both hs_mic and hp_mic, pick the hs_mic ahead of hp_mic. */
+ if (a->is_headset_mic && b->is_headset_mic && a->is_headphone_mic && b->is_headphone_mic)
+ return (int)(b->has_boost_on_pin - a->has_boost_on_pin);
if (a->is_headset_mic && b->is_headphone_mic)
return -1; /* don't swap */
else if (a->is_headphone_mic && b->is_headset_mic)
prev parent reply other threads:[~2025-01-15 12:49 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-13 3:13 [PATCH 0/2] lib/sort: Optimize the number of swaps and comparisons Kuan-Wei Chiu
2024-01-13 3:13 ` [PATCH 1/2] lib/sort: Optimize heapsort for equal elements in sift-down path Kuan-Wei Chiu
2024-01-13 3:13 ` [PATCH 2/2] lib/sort: Optimize heapsort with double-pop variation Kuan-Wei Chiu
2024-06-20 15:36 ` Julian Sikorski
2024-06-20 20:17 ` Mario Limonciello
2024-06-28 15:15 ` Linux regression tracking (Thorsten Leemhuis)
2024-06-28 17:10 ` Kuan-Wei Chiu
2024-06-29 5:03 ` Linux regression tracking (Thorsten Leemhuis)
[not found] ` <20240630210809.37550-1-visitorckw@gmail.com>
2024-06-30 21:13 ` [PATCH] ACPI: processor_idle: Fix invalid comparison with insertion sort for latency Kuan-Wei Chiu
2024-07-01 4:42 ` [PATCH v2] " Kuan-Wei Chiu
2024-07-01 5:06 ` Greg KH
2024-07-01 15:17 ` Mario Limonciello
2024-07-01 16:10 ` [PATCH v3] " Kuan-Wei Chiu
2024-07-01 17:36 ` Rafael J. Wysocki
2024-07-01 20:56 ` [PATCH v4] " Kuan-Wei Chiu
2024-07-02 7:28 ` Julian Sikorski
2024-07-02 12:59 ` Mario Limonciello
2024-07-02 18:38 ` Rafael J. Wysocki
2025-01-15 3:27 ` [PATCH 2/2] lib/sort: Optimize heapsort with double-pop variation Luke Jones
2025-01-15 12:49 ` Kuan-Wei Chiu [this message]
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=Z4euvhAXAiZXCObx@visitorckw-System-Product-Name \
--to=visitorckw@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alexdeucher@gmail.com \
--cc=belegdol@gmail.com \
--cc=chuang@cs.nycu.edu.tw \
--cc=hui.wang@canonical.com \
--cc=jserv@ccns.ncku.edu.tw \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=lkml@sdf.org \
--cc=luke@ljones.dev \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/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