The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] ALSA: usx2y: Account for every period a URB completes
@ 2026-11-15 12:16 Sinan Turunc
  2026-11-16 15:41 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Sinan Turunc @ 2026-11-15 12:16 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai; +Cc: linux-sound, linux-kernel

usx2y_urb_capt_retire() and usx2y_urb_play_retire() add the frames of a
whole URB to transfer_done and subtract one period_size when it is
reached. With a period of 1 ms, which snd_usx2y_pcm_open() allows, a
URB of nr_of_packs() packets covers several periods, so transfer_done
grows by the difference on every URB. snd_pcm_period_elapsed() is
called once per URB instead of once per period, and transfer_done
overflows after about 16 hours, after which period wake-ups stop.

Keep only the remainder modulo period_size. ALSA's position comes from
the pointer callback, so one call per URB that crosses a period is
enough.

Measured on 7.3-rc7 with an emulated US-122 over USB/IP and a debug
print of transfer_done every 1024 capture URBs, 45-frame periods and
48-frame packets: before, transfer_done is 150573 after 1024 URBs and
8580141 after 58368; after, it never exceeds a period plus one URB and
the stream runs for 30 s as before.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Sinan Turunc <enscrpt@pm.me>
---
 1 file(s) changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
index a3a0bc13632..681e75917bc 100644
--- a/sound/usb/usx2y/usbusx2yaudio.c
+++ b/sound/usb/usx2y/usbusx2yaudio.c
@@ -72,7 +72,7 @@ static int usx2y_urb_capt_retire(struct snd_usx2y_substream *subs)
 	subs->transfer_done += lens;
 	/* update the pointer, call callback if necessary */
 	if (subs->transfer_done >= runtime->period_size) {
-		subs->transfer_done -= runtime->period_size;
+		subs->transfer_done %= runtime->period_size;
 		snd_pcm_period_elapsed(subs->pcm_substream);
 	}
 	return 0;
@@ -155,7 +155,7 @@ static void usx2y_urb_play_retire(struct snd_usx2y_substream *subs, struct urb *
 	if (subs->hwptr_done >= runtime->buffer_size)
 		subs->hwptr_done -= runtime->buffer_size;
 	if (subs->transfer_done >= runtime->period_size) {
-		subs->transfer_done -= runtime->period_size;
+		subs->transfer_done %= runtime->period_size;
 		snd_pcm_period_elapsed(subs->pcm_substream);
 	}
 }
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-16 15:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15 12:16 [PATCH] ALSA: usx2y: Account for every period a URB completes Sinan Turunc
2026-11-16 15:41 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox