alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: David Henningsson <coding@diwic.se>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH v6] sound: rawmidi: Add framing mode
Date: Tue, 20 Apr 2021 11:07:12 +0200	[thread overview]
Message-ID: <s5h4kg1e33z.wl-tiwai@suse.de> (raw)
In-Reply-To: <20210419164023.159967-1-coding@diwic.se>

On Mon, 19 Apr 2021 18:40:23 +0200,
David Henningsson wrote:
> 
> This commit adds a new framing mode that frames all MIDI data into
> 32-byte frames with a timestamp.
> 
> The main benefit is that we can get accurate timestamps even if
> userspace wakeup and processing is not immediate.
> 
> Testing on a Celeron N3150 with this mode has a max jitter of 2.8 ms,
> compared to the in-kernel seq implementation which has a max jitter
> of 5 ms during idle and much worse when running scheduler stress tests
> in parallel.
> 
> Signed-off-by: David Henningsson <coding@diwic.se>
> ---
> 
> Changes since v5: Added realtime clock and changed params struct according to
> Jaroslav's wishes.
> 
> This version of the patch has been compile tested only.

Thanks for the updated patch.  It looks almost good, just some minor
issues below:

> +struct snd_rawmidi_framing_tstamp {
> +	/* For now, frame_type is always 0. Midi 2.0 is expected to add new
> +	 * types here. Applications are expected to skip unknown frame types.
> +	 */
> +	u8 frame_type;
> +	u8 length; /* number of valid bytes in data field */
> +	u8 reserved[2];
> +	u32 tv_nsec;		/* nanoseconds */
> +	u64 tv_sec;		/* seconds */
> +	u8 data[SNDRV_RAWMIDI_FRAMING_DATA_LENGTH];
> +} __attribute__((packed));

Use __packed instead.


> @@ -720,7 +723,18 @@ EXPORT_SYMBOL(snd_rawmidi_output_params);
>  int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
>  			     struct snd_rawmidi_params *params)
>  {
> +	unsigned int framing = params->mode & SNDRV_RAWMIDI_MODE_FRAMING_MASK;
> +	unsigned int clock_type = params->mode & SNDRV_RAWMIDI_MODE_CLOCK_MASK;
> +
> +	if (framing == SNDRV_RAWMIDI_MODE_FRAMING_NONE && clock_type != SNDRV_RAWMIDI_MODE_CLOCK_NONE)
> +		return -EINVAL;
> +	else if (clock_type > SNDRV_RAWMIDI_MODE_CLOCK_MONOTONIC_RAW)
> +		return -EINVAL;
> +	if (framing > SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP)
> +		return -EINVAL;
>  	snd_rawmidi_drain_input(substream);
> +	substream->framing = framing;
> +	substream->clock_type = clock_type;
>  	return resize_runtime_buffer(substream->runtime, params, true);

The stale framing and clock_type are set in the case of errors, which
will confuse the later operations.


> +static int receive_with_tstamp_framing(struct snd_rawmidi_substream *substream,
> +			const unsigned char *buffer, int src_count, const struct timespec64 *tstamp)
> +{
....
> +	return dest_frames * frame_size;

The snd_rawmidi_receive() function is supposed to return the processed
read size, hence this would become incompatible.  Though, I don't find
any code that actually checks the return value from
snd_rawmidi_receive(), but a definition is a definition...


thanks,

Takashi

      parent reply	other threads:[~2021-04-20  9:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19 16:40 [PATCH v6] sound: rawmidi: Add framing mode David Henningsson
2021-04-19 18:00 ` Jaroslav Kysela
2021-04-20  9:07 ` 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=s5h4kg1e33z.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=coding@diwic.se \
    /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;
as well as URLs for NNTP newsgroup(s).