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=-3.8 required=3.0 tests=BAYES_00,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 53AE4C433DB for ; Mon, 1 Mar 2021 15:31: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 C31D7600CF for ; Mon, 1 Mar 2021 15:31:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C31D7600CF 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 4EFE316D1; Mon, 1 Mar 2021 16:31:04 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4EFE316D1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1614612714; bh=NLqs8LEXwd5H118H5H8aSFKLxIA2uzw5nqbxqsUp3xk=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=a5FA7kTty/BneVrgW8UR4RNXuPArlreA+VJO4jGls8Y9WAupmaQVmC+njkcewNbRr CJxwXAjaIQ/zkzV37uiFIzzUfvCu98eQa9V+rSui1dzxj0EbV4LKTkQJGLo2Ynu5pm uVkzhmEONJz5WXrNesuCCRXaw2hJnDvQY2JGFurw= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C226AF80257; Mon, 1 Mar 2021 16:30:40 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id CBA82F8010B; Mon, 1 Mar 2021 16:30:39 +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 60ED7F8010B for ; Mon, 1 Mar 2021 16:30:36 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 60ED7F8010B 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 6387FAF54; Mon, 1 Mar 2021 15:30:36 +0000 (UTC) Date: Mon, 01 Mar 2021 16:30:36 +0100 Message-ID: From: Takashi Iwai To: Anton Yakovlev Subject: Re: [PATCH v6 5/9] ALSA: virtio: handling control and I/O messages for the PCM device In-Reply-To: References: <20210227085956.1700687-1-anton.yakovlev@opensynergy.com> <20210227085956.1700687-6-anton.yakovlev@opensynergy.com> <85bbc067-e7ec-903a-1518-5aab01577655@opensynergy.com> 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: virtio-dev@lists.oasis-open.org, alsa-devel@alsa-project.org, "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, Takashi Iwai , virtualization@lists.linux-foundation.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, 01 Mar 2021 16:24:00 +0100, Anton Yakovlev wrote: > > On 01.03.2021 15:56, Takashi Iwai wrote: > > On Mon, 01 Mar 2021 15:47:46 +0100, > > Anton Yakovlev wrote: > >> > >> On 01.03.2021 14:32, Takashi Iwai wrote: > >>> On Mon, 01 Mar 2021 10:25:05 +0100, > >>> Anton Yakovlev wrote: > >>>> > >>>> On 28.02.2021 12:27, Takashi Iwai wrote: > >>>>> On Sat, 27 Feb 2021 09:59:52 +0100, > >>>>> Anton Yakovlev wrote: > >>>>>> +/** > >>>>>> + * virtsnd_pcm_event() - Handle the PCM device event notification. > >>>>>> + * @snd: VirtIO sound device. > >>>>>> + * @event: VirtIO sound event. > >>>>>> + * > >>>>>> + * Context: Interrupt context. > >>>>> > >>>>> OK, then nonatomic PCM flag is invalid... > >>>> > >>>> Well, no. Here, events are kind of independent entities. PCM-related > >>>> events are just a special case of more generic events, which can carry > >>>> any kind of notification/payload. (And at the moment, only XRUN > >>>> notification is supported for PCM substreams.) So it has nothing to do > >>>> with the atomicity of the PCM device itself. > >>> > >>> OK, thanks. > >>> > >>> Basically the only question is how snd_pcm_period_elapsed() is called. > >>> And I see that it's called inside queue->lock, and this already > >>> invalidates the nonatomic PCM mode. So the code needs the fix: either > >>> fix this locking (and the context is guaranteed not to be an irq > >>> context), or change to the normal PCM mode without nonatomic flag. > >>> Both would bring some side-effect, and we need further changes, I > >>> suppose... > >> > >> Ok, I understood the problem. Well, I would say the nonatomic PCM mode > >> is more important option, since in this mode we can guarantee the > >> correct operation of the device. > > > > Which operation (except for the resume) in the trigger and the pointer > > callbacks need the action that need to sleep? I thought the sync with > > the command queue is done in the sync_stop. And most of others seem > > already taking the spinlock in themselves, so the non-atomic operation > > has little merit for them. > > All three commands from the beginning of that switch in trigger op: > ops->trigger(START) > ops->trigger(PAUSE_RELEASE) > ops->trigger(RESUME) > > They all result in > virtsnd_ctl_msg_send_sync(VIRTIO_SND_R_PCM_START) > > And that command must be sync, i.e. we need to wait/sleep until device > sent response. There are two major reasons for that: we need to be sure, > that substream has been actually started (i.e. device said OK). And we > need to take into account the virtualization overhead as well. Since > substream starting on device side may take some time, we can not > return from the trigger op until it actually happened. In atomic mode > all these nuances are lost, and it may lead to incorrect application > behavior. I see, then the nonatomic mode is the only way to go, indeed. Takashi