mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Jacob Procee <sn125164@gmail.com>
Cc: "Vinod Koul" <vkoul@kernel.org>, "Frank Li" <Frank.Li@kernel.org>,
	"Sven Peter" <sven@kernel.org>, "Janne Grunau" <j@jannau.net>,
	"Neal Gompa" <neal@gompa.dev>,
	"Martin Povišer" <povik+lin@cutebit.org>,
	asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dmaengine: apple-admac: Fix position one period ahead at period boundary
Date: Thu, 29 Oct 2026 10:02:00 -0500	[thread overview]
Message-ID: <auNf6KqfgS5Usrfk@SMW015318> (raw)
In-Reply-To: <20261029105908.22809-1-sn125164@gmail.com>

On Thu, Oct 29, 2026 at 11:59:08AM +0100, Jacob Procee wrote:
> [You don't often get email from sn125164@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> Speaker playback on a MacBook Pro 14" (M1 Pro, J314s) underruns at
> irregular intervals, audible as a tick: 8 times in 3.7 hours of
> playback. Where an underrun was caught (4 of 8), the ALSA hw_ptr had
> jumped by one buffer size while about 70 ms of audio was still queued,
> and a kernel trace showed the DMA position stepping back by exactly one
> period at each of the 6 underruns it covered.
>
> admac_cyclic_read_residue() derives the position from the report ring
> (periods finished but not yet reclaimed) and REG_RESIDUE (bytes left in
> the current descriptor). When a descriptor finishes, the residue first
> drops to zero, then the report is posted and the next descriptor is
> loaded. Usually the last two happen together, but occasionally the
> report comes first. A read in that window counts the finished period
> twice:
>
>  - residue2 == 0 with the report already in ring2: the period is
>    counted in nreports and again as the fully consumed current
>    descriptor;
>  - residue1 == 0 with the report already in ring1, and the next
>    descriptor loaded by the time residue2 is read: the
>    residue2 > residue1 branch adds one to a ring1 that already holds
>    the report.
>
> Either way the position is one period ahead. The next read is behind
> it, snd_pcm_update_hw_ptr0() takes the backwards step for a wrap of the
> whole buffer, and the stream underruns.
>
> While the channel runs, a zero residue only occurs between descriptors,
> so read the registers again while either residue is zero. The retries
> are bounded, as the residue also stays zero on a stopped channel or one
> that ran out of descriptors; after the last retry the position is
> computed as before.
>
> With a debug build counting retries, one hour of playback needed a
> retry for 2210 of 3.39 million reads, at most three retries (3.5 us),
> also across pause and stream restart. Both states above showed up in
> the logged register values. There were no underruns in three hours of
> playback with the fix.
>
> Fixes: b127315d9a78 ("dmaengine: apple-admac: Add Apple ADMAC driver")
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Jacob Procee <sn125164@gmail.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>

  reply	other threads:[~2026-10-29 15:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 10:59 Jacob Procee
2026-10-29 15:02 ` Frank Li [this message]
2026-10-29 15:15 ` Sasha Finkelstein
2026-10-29 16:10 ` Martin Povišer

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=auNf6KqfgS5Usrfk@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=asahi@lists.linux.dev \
    --cc=dmaengine@vger.kernel.org \
    --cc=j@jannau.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neal@gompa.dev \
    --cc=povik+lin@cutebit.org \
    --cc=sn125164@gmail.com \
    --cc=sven@kernel.org \
    --cc=vkoul@kernel.org \
    /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

all inboxes | Powered by JetHome®