Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2935143imu; Fri, 18 Jan 2019 01:46:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN4ujp3GhH8j+G4dtc8Pc9ww6b7sAPDKqgj2oBGWjLcM0U4jLFb7TFRqLmxr3J1K6JepgdlA X-Received: by 2002:a17:902:33c1:: with SMTP id b59mr18297410plc.220.1547804802585; Fri, 18 Jan 2019 01:46:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547804802; cv=none; d=google.com; s=arc-20160816; b=Ua8PptWOXmzPm5lXBktHMjSGUEDdUrduX4CjAq6k8/ShLbZ1sGGGg7A0U8h7DoPCqC hXhQ1jg6iIZjT4dZT3TV0gql4rV8sZWrvTb//26EuJnpri0ynq0nN2SCcAl9htu1uLcQ Xnhi8K+lQ9Xz2M6ArUNnB9v/d4tbctF5e18FQ4eFrjIQjVmLle4qjhXikyQhe171q4hH P6gG4cQuLF0CVvamCY/yXPNXGYuZTixp5kL98krDgtCy87xdsr1/Rt+26ghOAk4qGHPa fv4t9BIhmUsK0328HOQrYZXvzA6Gu9mCJ9u0LYE+r+GT6i5MNndKjbb+webI3MUPP7dM 69Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature:dkim-filter; bh=ti7yUL0m7wtfC5n2oQVV/pTJXNgp+X6Oiw03dQgEj18=; b=MapuYfjOK3kS6tT6711GjTmWy5S2396/sZA+oGkVitUmhQeYjhX3W2DsPd/ogMkZXp gZdPdWgQYg6RIRdS5LD4ZSiL1su/yK95Uxh9EjaWlmdpIfv17aolG5DiVaWCST68ilLl 7fHYpi5QxDT3R3W9LZ0LvAlQw0oWm97h0K6JCgZ5BZpHi0QZFDkdRfrwCxvVO2E7rQEU pELrFdGdAPbNp2Q6ZYupvRJc5k68lw2VGzVPk6/AN9aTKdDrxTMT/MuUqwA+TCUP06Xe 0HdOtkX2yDw5u0WF4FyR44AvrR0aXAdHi52EWkpwlns7MqQco4JQwb2xrMtnJjYxRAZi srIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@perex.cz header.s=default header.b=P+8e8Qhn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j20si3739262pgb.520.2019.01.18.01.46.23; Fri, 18 Jan 2019 01:46:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@perex.cz header.s=default header.b=P+8e8Qhn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727234AbfARJob (ORCPT + 99 others); Fri, 18 Jan 2019 04:44:31 -0500 Received: from mail1.perex.cz ([77.48.224.245]:56018 "EHLO mail1.perex.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726288AbfARJoa (ORCPT ); Fri, 18 Jan 2019 04:44:30 -0500 X-Greylist: delayed 496 seconds by postgrey-1.27 at vger.kernel.org; Fri, 18 Jan 2019 04:44:28 EST Received: from mail1.perex.cz (localhost [127.0.0.1]) by smtp1.perex.cz (Perex's E-mail Delivery System) with ESMTP id F3820A003F; Fri, 18 Jan 2019 10:36:10 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.perex.cz F3820A003F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=perex.cz; s=default; t=1547804171; bh=ti7yUL0m7wtfC5n2oQVV/pTJXNgp+X6Oiw03dQgEj18=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=P+8e8Qhn2JPWGfZ1QdbH4K0EMCtTlb7zkZQRBwv7k05YYN6eRaCeWdkLvL3+1YqyT G2MS85kUditDrC2lCRr8ojSlh7vpFBsqjHlXpaxrM7oPR07lCMQx6bsOHln5oqraLW sovk4rUq1yOkUmL8OwFO/dP1VXyfjlQTiNpOUtZo= Received: from p50.perex-int.cz (unknown [192.168.100.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: perex) by mail1.perex.cz (Perex's E-mail Delivery System) with ESMTPSA; Fri, 18 Jan 2019 10:35:44 +0100 (CET) Subject: Re: [RFC PATCH] ALSA: core: Add DMA share buffer support To: Baolin Wang , tiwai@suse.com, broonie@kernel.org, leo.yan@linaro.org Cc: sboyd@kernel.org, colyli@suse.de, corbet@lwn.net, mathieu.poirier@linaro.org, ckeepax@opensource.wolfsonmicro.com, mchehab+samsung@kernel.org, gustavo@embeddedor.com, joe@perches.com, vkoul@kernel.org, o-takashi@sakamocchi.jp, keescook@chromium.org, jmiller@neverware.com, anna-maria@linutronix.de, willy@infradead.org, sr@denx.de, bgoswami@codeaurora.org, philburk@google.com, srinivas.kandagatla@linaro.org, arnd@arndb.de, daniel.thompson@linaro.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org References: <290f6d3a5fe288b87480cc5fa12c5139728daeca.1547787189.git.baolin.wang@linaro.org> From: Jaroslav Kysela Message-ID: <81e894ba-acad-2fd4-996d-8d35edd8825a@perex.cz> Date: Fri, 18 Jan 2019 10:35:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <290f6d3a5fe288b87480cc5fa12c5139728daeca.1547787189.git.baolin.wang@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dne 18.1.2019 v 05:55 Baolin Wang napsal(a): > This patch adds dma share buffer support, which allows a dma-buf to be shared > between processes by passing file descriptors between them, allowing multiple > processes to cooperate in filling the DMA buffer used by the audio hardware > without the need to copy data around. This reduces both latency and CPU load, > especially in configurations where only one application is playing audio and > so context switches can be avoided. > > In userspace, we can use ioctl:SNDRV_PCM_IOCTL_DMABUF_EXPORT to export one > dma buffer to a PCM, and use ioctl:SNDRV_PCM_IOCTL_DMABUF_ATTACH and > ioctl:SNDRV_PCM_IOCTL_DMABUF_DETACH to attach or detach one device to the > dma buffer. Morevoer we can use dma buffer ioctl:DMA_BUF_IOCTL_SYNC to > guarantee the cache coherency of the DMA buffer. > > You can refer to below patches [1] created by Leo Yan to use the dma buffer > in userspace. > > [1] https://github.com/tinyalsa/tinyalsa/pull/126 > > Welcome any comments. Thanks. > > Signed-off-by: Baolin Wang > --- > Hi, > > Before sending to ALSA mailing list, we had some internal discussion off line, > so I posted them to follow up. > > 1. One issue proposed by Srinivas Kandagatla, he proposed one use case example: > DSP1 pre-process(compress-to-pcm) the buffers, pass the fd to DSP2/audio-ip > to play pcm data. The dmabuf exporter (DSP1) is a different device than > audio device in this instance, so the DSP1 device cannot call > snd_pcm_dmabuf_export() to export one dma buffer and pass to the DSP2/audio-ip. > > Our original design is, the dma buffer should be associated with one PCM > device, since different PCM devices may need different buffer types (see > SNDRV_DMA_TYPE_XXX) to play PCM data, and need consider the PCM device's > coherent capability for DMA memory. My concern is, if we let other > non-audio device to allocate one buffer and export it, how to guarantee > the dma buffer can be used by PCM device and have the same coherent capability > with the PCM device. > > So I am not sure for this issue and need more suggestion to get a consensus. > > 2. Second question raised by Srinivas Kandagatla, he wondered: > "Am still unclear on the whole idea making a audio device dmabuf exporter > in Linux systems, unless you are sharing the dmabuf fd with other devices. > > If you are working with just one device we could just live with mmap, > isn't it?" > > Mark Brown gave the answer: > "The issue is permissions management. We've got a sound server that owns > all the sound hardware and needs to be able to retain administrative control > over it which means that permissions for the sound devices are locked down to > it. For performance reasons on systems where it's practical (eg, where there's > multiple audio streams the system can use to play data to the hardware) we > want to be able to have that server allow other applications with lower > permissions to stream data to/from the hardware without going through it. The > applications can't mmap() the device directly as that's too painful to do that > securely from a permission management point of view so we want to be able to > have the sound server do the mmap() then hand the mapped buffer off to the > application for it to use via a FD over a pipe. That way the only thing with > direct access to the devices is the sound server but the clients have a data > path that doesn't need to bounce through another process. > > Practically speaking the only use case I can think of in an audio context is > for one reader and one writer (AIUI Android is envisioning this as one hardware > and one software), it's difficult to see how you could usefully chain multiple > in place transformations together in the way that you can with video applications > but I'm possibly not thinking of something here." Hi, the tinyalsa implementation does not show much - it's equal to the standard mmap access for the PCM devices. Even considering the Mark's text, there must be an arbiter (sound server) which communicates with the producer or consumer to control the data flow. I really would like to see a real usage for this. It seems to me that the only point to implement this is the permissions. We already have O_APPEND mode for the PCM file descriptor which can reuse the PCM device multiple times (mmap the buffer to multiple tasks). I would probably go in this way and add more extended permission control for the PCM device, so permissions can be restricted for the passed descriptor to the producer or the consumer task. In this way, the restricted task might reuse other control mechanism offered buy the PCM file descriptor without requesting the arbiter to do so (like read the actual position in the DMA buffer, get the audio delay or so - reduce context switches). Thanks, Jaroslav -- Jaroslav Kysela Linux Sound Maintainer; ALSA Project; Red Hat, Inc.