Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Mark Brown <broonie@kernel.org>,
	linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	linux-sound@vger.kernel.org,
	Herve Codina <herve.codina@bootlin.com>
Subject: Re: [PATCH] ALSA: pcm: Rewrite recalculate_boundary() to avoid costly loop
Date: Mon, 09 Jun 2025 09:52:08 +0200	[thread overview]
Message-ID: <875xh58i8n.wl-tiwai@suse.de> (raw)
In-Reply-To: <4836e2cde653eebaf2709ebe30eec736bb8c67fd.1749202237.git.christophe.leroy@csgroup.eu>

On Fri, 06 Jun 2025 11:44:02 +0200,
Christophe Leroy wrote:
> 
> At the time being recalculate_boundary() is implemented with a
> loop which shows up as costly in a perf profile, as depicted by
> the annotate below:
> 
>     0.00 :   c057e934:       3d 40 7f ff     lis     r10,32767
>     0.03 :   c057e938:       61 4a ff ff     ori     r10,r10,65535
>     0.21 :   c057e93c:       7d 49 50 50     subf    r10,r9,r10
>     5.39 :   c057e940:       7d 3c 4b 78     mr      r28,r9
>     2.11 :   c057e944:       55 29 08 3c     slwi    r9,r9,1
>     3.04 :   c057e948:       7c 09 50 40     cmplw   r9,r10
>     2.47 :   c057e94c:       40 81 ff f4     ble     c057e940 <snd_pcm_ioctl+0xee0>
> 
> Total: 13.2% on that simple loop.
> 
> But what the loop does is to multiply the boundary by 2 until it is
> over the wanted border. This can be avoided by using fls() to get the
> boundary value order and shift it by the appropriate number of bits at
> once.
> 
> This change provides the following profile:
> 
>     0.04 :   c057f6e8:       3d 20 7f ff     lis     r9,32767
>     0.02 :   c057f6ec:       61 29 ff ff     ori     r9,r9,65535
>     0.34 :   c057f6f0:       7d 5a 48 50     subf    r10,r26,r9
>     0.23 :   c057f6f4:       7c 1a 50 40     cmplw   r26,r10
>     0.02 :   c057f6f8:       41 81 00 20     bgt     c057f718 <snd_pcm_ioctl+0xf08>
>     0.26 :   c057f6fc:       7f 47 00 34     cntlzw  r7,r26
>     0.09 :   c057f700:       7d 48 00 34     cntlzw  r8,r10
>     0.22 :   c057f704:       7d 08 38 50     subf    r8,r8,r7
>     0.04 :   c057f708:       7f 5a 40 30     slw     r26,r26,r8
>     0.35 :   c057f70c:       7c 0a d0 40     cmplw   r10,r26
>     0.13 :   c057f710:       40 80 05 f8     bge     c057fd08 <snd_pcm_ioctl+0x14f8>
>     0.00 :   c057f714:       57 5a f8 7e     srwi    r26,r26,1
> 
> Total: 1.7% with that loopless alternative.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>

Applied now to for-next branch.  Thanks.


Takashi

      reply	other threads:[~2025-06-09  7:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-06  9:44 [PATCH] ALSA: pcm: Rewrite recalculate_boundary() to avoid costly loop Christophe Leroy
2025-06-09  7:52 ` Takashi Iwai [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=875xh58i8n.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=broonie@kernel.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=herve.codina@bootlin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --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