From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38756C43460 for ; Tue, 20 Apr 2021 09:08:21 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 392666135F for ; Tue, 20 Apr 2021 09:08:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 392666135F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 0331E167A; Tue, 20 Apr 2021 11:07:27 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 0331E167A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1618909697; bh=i5bo4iY5IRdzMm3us4eDWwzTNADdLXUNqvyE2xFqAuA=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YO317MymShAh0N9bOaE223XH/QE1djOEwQeWedpE0PJaxojL3ooTWjKTDLcp+0QID DXIborVdsPzazjAIeWv896XLsqS1pLuyqW7R5e4PU3k6S7E0C0zXYSs6R4N7GJ33qG WIMMC4xJ5lWDrl+l4Cj7D+5ShQ5Z7pvSqZPtsMxA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 725C1F80168; Tue, 20 Apr 2021 11:07:26 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id AC08CF80253; Tue, 20 Apr 2021 11:07:24 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 9FCC6F800FE for ; Tue, 20 Apr 2021 11:07:12 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9FCC6F800FE X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A87F7AEE6; Tue, 20 Apr 2021 09:07:12 +0000 (UTC) Date: Tue, 20 Apr 2021 11:07:12 +0200 Message-ID: From: Takashi Iwai To: David Henningsson Subject: Re: [PATCH v6] sound: rawmidi: Add framing mode In-Reply-To: <20210419164023.159967-1-coding@diwic.se> References: <20210419164023.159967-1-coding@diwic.se> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: alsa-devel@alsa-project.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 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 > --- > > 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