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=-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 4D25AC54FD0 for ; Thu, 23 Apr 2020 17:36:10 +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 D27AE20776 for ; Thu, 23 Apr 2020 17:36:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="Ighi/JlM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D27AE20776 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 32ED1168D; Thu, 23 Apr 2020 19:35:18 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 32ED1168D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1587663368; bh=uKDZVhYeC2mtY2+7cOEflkxW7LKe15x81oNiiuVub+E=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Ighi/JlMSx0aLxydhjdgAn6aFz+XXHKxMCZdJUrBezRwEW6i03KDyjUSbu+mBzp5k JvcbyhZ4zuTq3GcFi/otQssFVyhqeo7JUv4SMXYWScnogMgWYhbWEOIK2J9HXkX0k6 VFFK+ikurrM1ZjUOW+M20jNDaQKxSDQxCsa9Qo1c= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B3D4BF80121; Thu, 23 Apr 2020 19:35:17 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 23A08F801EC; Thu, 23 Apr 2020 19:35:16 +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 CF51FF800FF for ; Thu, 23 Apr 2020 19:35:13 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz CF51FF800FF 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 C5CEAADE8; Thu, 23 Apr 2020 17:35:12 +0000 (UTC) Date: Thu, 23 Apr 2020 19:35:13 +0200 Message-ID: From: Takashi Iwai To: Alexander Tsoy Subject: Re: [PATCH] ALSA: usb-audio: Apply async workaround for Scarlett 2i4 2nd gen In-Reply-To: References: <7190177d62f349eea7a5d1056924a63fc4270d43.camel@tsoy.me> <20200422185522.3347-1-grpintar@gmail.com> <470d034599514e83454663f389bad30fd98ad3e2.camel@tsoy.me> <99bb394ff162a16442fd83c0ab56a9d8c0055877.camel@tsoy.me> 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: Gregor Pintar , 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 Thu, 23 Apr 2020 19:29:08 +0200, Takashi Iwai wrote: > > On Thu, 23 Apr 2020 18:57:34 +0200, > Alexander Tsoy wrote: > > > > And some further notes: > > > > - I removed locking from snd_usb_endpoint_next_packet_size() and this > > seems completely fixed an issue with large URBs I reported here: > > > > https://bugzilla.kernel.org/show_bug.cgi?id=199327#c28 > > > > So playing at 96 kHz, driver packs 48 frames per URB and no more audio > > discontinuities. > > Hmm, that's weird. > > If removing the lock from snd_usb_endpoint_next_packet_size() really > fixes the problem, it implies the lock contention. But as far as I > see the code performed in this lock isn't conflicting so much. The > URB processing shouldn't happen in parallel for the same EP. BTW, one potential racy code I found while looking at the code is the list management in queue_pending_output_urbs(). The fix patch is below. Takashi --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c @@ -321,17 +321,17 @@ static void queue_pending_output_urbs(struct snd_usb_endpoint *ep) ep->next_packet_read_pos %= MAX_URBS; /* take URB out of FIFO */ - if (!list_empty(&ep->ready_playback_urbs)) + if (!list_empty(&ep->ready_playback_urbs)) { ctx = list_first_entry(&ep->ready_playback_urbs, struct snd_urb_ctx, ready_list); + list_del_init(&ctx->ready_list); + } } spin_unlock_irqrestore(&ep->lock, flags); if (ctx == NULL) return; - list_del_init(&ctx->ready_list); - /* copy over the length information */ for (i = 0; i < packet->packets; i++) ctx->packet_size[i] = packet->packet_size[i];