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, 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 2CE24C433E6 for ; Mon, 1 Mar 2021 15:31:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EADA664DFB for ; Mon, 1 Mar 2021 15:31:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237245AbhCAPby (ORCPT ); Mon, 1 Mar 2021 10:31:54 -0500 Received: from mx2.suse.de ([195.135.220.15]:44502 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237231AbhCAPbS (ORCPT ); Mon, 1 Mar 2021 10:31:18 -0500 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 Cc: , , , "Michael S. Tsirkin" , Jaroslav Kysela , Takashi Iwai , 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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