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=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 1DC14C0044D for ; Mon, 16 Mar 2020 08:43:56 +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 9CD2420658 for ; Mon, 16 Mar 2020 08:43:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="fytX7NdP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9CD2420658 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 01DA018A0; Mon, 16 Mar 2020 09:43:03 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 01DA018A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1584348234; bh=JL9jOPlePveYGaB4vKwARwDWys91+4yPOEogyOfZo0I=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=fytX7NdPizpBaxUdINDXR2z5caKtDUq1YTS3Ev3nt9CnLV0XAcbRshjBlmT/SsdWF U7yxYUD5Cg2288Qw0vE/6k1xsOy+mZZh2/mtl93uuUxwon7MhPhqPqQOuLIG1H+elb MTj4z9FZfQzGj+NvTECNqab9u2ZfvRvEpdnW8qIo= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 6911CF80110; Mon, 16 Mar 2020 09:43:03 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 88E28F8015B; Mon, 16 Mar 2020 09:43:02 +0100 (CET) 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 8B997F800CD for ; Mon, 16 Mar 2020 09:42:58 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8B997F800CD X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 64625B02C; Mon, 16 Mar 2020 08:42:58 +0000 (UTC) Date: Mon, 16 Mar 2020 09:42:58 +0100 Message-ID: From: Takashi Iwai To: Andreas Steinmetz Subject: Re: [PATCH 0/3] ALSA USB MIDI: Predictable low latency for USB MIDI output In-Reply-To: <42a9a862efbc9cfdacc783f816f93340ccc58cec.camel@domdv.de> References: <42a9a862efbc9cfdacc783f816f93340ccc58cec.camel@domdv.de> 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, clemens@ladisch.de 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 Sat, 14 Mar 2020 09:11:17 +0100, Andreas Steinmetz wrote: > > The following patch series fixes USB MIDI output starvation and allows > to configure a predictable worst case output latency with a minimum of 15ms > for 16x16 devices and 3.8ms for 4x4 devices (excluding USB transfer time > and latencies of the interface device itself). > > The reasoning behind this patch series is first to fix the possible > indefinite latency and then to allow to configure a predictable > low latency to be able to use a cheap embedded Linux system (e.g. > Raspberry Pi) in combination with a multiport USB MIDI interface > as a drop in replacement for commercial hardware based MIDI routing > and filtering products. This includes "real time" (live) usage. > > For this usage the guaranteed latency within the kernel must be as > low as possible, depending on the requirements of the USB MIDI > interface in use. > > Though the current state of the kernel code is acceptable in a > fully controlled by a single user environment, it is not usable > for uncontrolled standalone use as the driver behaviour then > depends on unpredictable MIDI data streams and thus is unpredictable > in behaviour itself. > > After applying this patch series the USB MIDI driver can be used > as usual or it can be tuned to low latency when this is desired. > > >From a developer perspective the actual output rate of USB MIDI > interfaces is typically slower than the expected 320us and even > varies depending on how many ports are busy (e.g. a M-Audio > Midisport 4x4 AE interface exhibits a varying output rate of > 357us to 515us per byte depending on device load). Thus the driver > needs a predictable low latency to allow userspace to use the > rawmidi buffer fill state to estimate the expected output latency > and schedule data accordingly. > > The following table shows relative processing time for varying driver > configurations using the M-Audio Midisport 4x4 AE as the test device. > For the parameters "outqueue" and "events" do see the descriptions > of the following patches. > > | unpatched | outqueue=7 | outqueue=1 | outqueue=1 | > | kernel | events=0 | events=0 | events=4 | > --------+---------------+---------------+---------------+---------------+ > 1 Port | 100% | 100% | 100% | 100.05% | > --------+---------------+---------------+---------------+---------------+ > 4 Ports | n/a | 100% | 99.97% | 100.36% | > --------+---------------+---------------+---------------+---------------+ > > As can be seen from the above table the changes to output latency do > affect throughput only marginally. Thanks for the patches and the analysis. So, judging from the experiments above, outqueue=1 has no measurable performance regression? For 4 ports, it's even an improvement. Then we may change the default value. I guess you kept the old value just to be conservative, but if the number tells a better story and it's no part or ABI, we may consider changing the default for a better performance. Or, is there any other potential risk by changing this? thanks, Takashi