mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Junjie Cao <junjie.cao@intel.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: Takashi Iwai <tiwai@suse.com>, Jaroslav Kysela <perex@perex.cz>,
	John Keeping <jkeeping@inmusicbrands.com>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ruslan <ruslan.panasiuk@gmail.com>
Subject: Re: [PATCH] ALSA: seq: midi: wait for output buffer space on non-atomic delivery
Date: Sun, 13 Sep 2026 19:48:58 +0800	[thread overview]
Message-ID: <20260913114858.585502-1-junjie.cao@intel.com> (raw)
In-Reply-To: <87fqzrah55.wl-tiwai@suse.de>

On Wed, 02 Sep 2026 15:59:18 +0200, Takashi Iwai wrote:
> When it's transferred as a direct delivery, it should
> just fail like the current version.

Direct delivery is the reported case, though: Chromium's
Web MIDI backend encodes SysEx into events of at most 256
bytes and sends each with snd_seq_event_output_direct(),
one write(2) per event, return value unchecked.  The
failure is invisible today: event_process_midi()
returns 0 after dump_midi() fails, so write(2) succeeds
and the tail of the SysEx is gone.  A writer that did
check would have nothing to wait on either, since poll()
reports the sender's pool, not the destination.

A direct event from a user client arrives in write(2)
context, so the push-back can copy it into the sender's
pool at the moment the destination reports "full"
(snd_seq_event_dup(), non-blocking); from then on it is
a cell like any queued one.  A blocking writer then
waits, before its next direct dispatch, until the pool
has room for the whole event.  That is the only sleep,
in snd_seq_write(), outside delivery.  Kernel clients
have no pool by default, so what they dispatch directly
(virmidi, MIDI thru) keeps the current drop.

> then one (or a few) of them might block while others
> can process fully.

A private copy per blocked destination sidesteps that:
the delivery loop completes as now and the original cell
is freed; only a destination that reported "full" keeps
a copy plus the consumed offset, and later events for it
queue behind the copy.  The copies come out of the
sender's pool, so a stuck destination eventually stalls
a blocking sender's other targets, where today it drops
for the stuck one and goes on; a per-connection cap on
parked cells, dropping beyond it as today, bounds that.
snd_seq_subscribers is the natural home for the copies,
with a list on the port's c_dest for events sent to an
explicit address.

On the resume side dump_var_event() already takes an
offset.  What is missing is a space-available callback
on rawmidi output for kernel users: runtime->event fires
on input only, and __snd_rawmidi_transmit_ack() would
have to schedule event_work the way the receive path
does.

I'll write this up as an RFC unless you'd rather see a
different shape first.

      reply	other threads:[~2026-09-13 11:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 14:32 Junjie Cao
2026-09-01 10:49 ` Takashi Iwai
2026-09-01 14:38   ` Junjie Cao
2026-09-02 13:59     ` Takashi Iwai
2026-09-13 11:48       ` Junjie Cao [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=20260913114858.585502-1-junjie.cao@intel.com \
    --to=junjie.cao@intel.com \
    --cc=jkeeping@inmusicbrands.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=ruslan.panasiuk@gmail.com \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    /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®