Received: by 10.223.176.5 with SMTP id f5csp3915991wra; Mon, 29 Jan 2018 22:33:01 -0800 (PST) X-Google-Smtp-Source: AH8x227WUZ50OrWLYhiY0mPqOqpitM8gPdRw2s13NsObSrR9ORkvAHQQ1K7LX3wCpz6GDPYLJlCi X-Received: by 10.99.160.88 with SMTP id u24mr23157882pgn.122.1517293981794; Mon, 29 Jan 2018 22:33:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517293981; cv=none; d=google.com; s=arc-20160816; b=BYJpxrU1Kdro991s+dDqsq/MIVtF+aNme/FXkz5qmzxZ4IIA0SpGOI/XyhiIxPQp3u sioTEeuIsm/frtNKtF9R8JA4MIaHkxRdpALfFbsCdMDVRuEvGlzEzaDSVZdutBbvZWFv U6trGfjMdZTmyVqBGlxmL+DBGuLFl4hoQO7GF320SUV8oc9D4MxHSetDa68FZElLZMb8 Epr0aoMjJwBVB5t8htKMH4IkkdE5BGY09NFfyFRT8Pe2SC0YV8Jv3rsdKRO98lRY+icR BpoO4T6MyQ3XdI2B3qwxhBoAMpABNS0CD1Tbes6rMJMuvhigkZufPjVybiACUU01iRAt 0Enw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=ixYLmRQisYPGnZ9Wygg8UUqKi2nToaKcIy4IDRb1Rb8=; b=gCH6aFNaKWtbvlTXN4mwFzQ89dqtIcw7KDQ2BQYVHBGkmZNWMAFtg3tACLdI2iui55 gJpu8BGg7UqPhZkVpBZqcdz3cu6O01E51huM91sIFH5OERXx3Cg2XGS9IcZXy7Ul82P7 VgWepMNDbOGswqLinWuPRrH30oXve1MmI3wWbbt5tMCpoPx4O7R24Ea1FLgngvyWdcSs qPpHQFYlLeVNIJkxbywliuCesOrO/SZCfPIq64KpCosQWaAptWfyCTrIdgq0iwiPHUGO J3jHsnmxL6DRf24zKF6pm6dwlcKC7bm8mLxXrtRTyES9i+WNzcSJzQxVMrRBWIE7lDUe UbJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aKjT8uXU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c193si2595369pfc.90.2018.01.29.22.32.47; Mon, 29 Jan 2018 22:33:01 -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=@chromium.org header.s=google header.b=aKjT8uXU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752828AbeA3Gbu (ORCPT + 99 others); Tue, 30 Jan 2018 01:31:50 -0500 Received: from mail-io0-f178.google.com ([209.85.223.178]:41973 "EHLO mail-io0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752385AbeA3Gbs (ORCPT ); Tue, 30 Jan 2018 01:31:48 -0500 Received: by mail-io0-f178.google.com with SMTP id f4so10254689ioh.8 for ; Mon, 29 Jan 2018 22:31:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ixYLmRQisYPGnZ9Wygg8UUqKi2nToaKcIy4IDRb1Rb8=; b=aKjT8uXU93g6l0JD5GzXPr2EhgLvHTPKXwtdDTLGVecZMt6npH8KJ4tBZwSsJZg4SO XH0bC8tmYYzmNQGP0+hxPryLrWdBUIBGC6Lr8Q7on32bYs7jmlhCaSlK3+j6g0YUxxt/ 9EQmFstrbqGEPVF+fv0jJwS0fLhDCEiKqjX54= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ixYLmRQisYPGnZ9Wygg8UUqKi2nToaKcIy4IDRb1Rb8=; b=cLDbvsU81Q0OsHMwPR8wHymLH4BWZELHgZoP8fzEbCC27agrgOSgMuvmHW/eTNa1lJ u253aVjevBoBuuV1r4HQTVNN/83/8u+kxxfunHzSccPzG+LaaXfNkyVPlB6sisgyThvr rLx+3jDnSFGXl2rrwgP0gSHvxLbSZSu3E0VQMJpf3t+pTt8KEr+Gw1ENvF3kjlMGJWtA 1oGMsY44zD7fkH8/jtaxhD0+WaMoisGoAMZF7Elf177aK6UErQx1OK971yeK3yHltLjR +PAFYArOV+htE6D9j3Xf2t98YvDc+b/7+htXHnoE2YojvBCxChGqkwclkiL6Cgf8Z+nD J2Hg== X-Gm-Message-State: AKwxytdk/LtaF7Lf+gUe1DCFzaNOx+MhXRpCmV2lCyXgR7qWtSMn0grG SUYoCOrA0yhivs1lsAxjfXosUV78Pvg= X-Received: by 10.107.164.134 with SMTP id d6mr29196470ioj.176.1517293907416; Mon, 29 Jan 2018 22:31:47 -0800 (PST) Received: from mail-io0-f179.google.com (mail-io0-f179.google.com. [209.85.223.179]) by smtp.gmail.com with ESMTPSA id v41sm5445481iov.3.2018.01.29.22.31.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jan 2018 22:31:46 -0800 (PST) Received: by mail-io0-f179.google.com with SMTP id b198so10242617iof.6 for ; Mon, 29 Jan 2018 22:31:46 -0800 (PST) X-Received: by 10.107.136.76 with SMTP id k73mr29420994iod.301.1517293905914; Mon, 29 Jan 2018 22:31:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.79.241.9 with HTTP; Mon, 29 Jan 2018 22:31:25 -0800 (PST) In-Reply-To: References: <20180126060216.147918-1-acourbot@chromium.org> From: Alexandre Courbot Date: Tue, 30 Jan 2018 15:31:25 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 0/8] [media] Request API, take three To: Hans Verkuil Cc: Mauro Carvalho Chehab , Laurent Pinchart , Pawel Osciak , Marek Szyprowski , Tomasz Figa , Sakari Ailus , Gustavo Padovan , Linux Media Mailing List , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Hans, On Mon, Jan 29, 2018 at 8:21 PM, Hans Verkuil wrote: > On 01/26/2018 07:02 AM, Alexandre Courbot wrote: >> Howdy. Here is your bi-weekly request API redesign! ;) >> >> Again, this is a simple version that only implements the flow of requests, >> without applying controls. The intent is to get an agreement on a base to work >> on, since the previous versions went straight back to the redesign board. >> >> Highlights of this version: >> >> * As requested by Hans, request-bound buffers are now passed earlier to drivers, >> as early as the request itself is submitted. Doing it earlier is not be useful >> since the driver would not know the state of the request, and thus cannot do >> anything with the buffer. Drivers are now responsible for applying request >> parameters themselves. >> >> * As a consequence, there is no such thing as a "request queue" anymore. The >> flow of buffers decides the order in which requests are processed. Individual >> devices of the same pipeline can implement synchronization if needed, but this >> is beyond this first version. >> >> * VB2 code is still a bit shady. Some of it will interfere with the fences >> series, so I am waiting for the latter to land to do it properly. >> >> * Requests that are not yet submitted effectively act as fences on the buffers >> they own, resulting in the buffer queue being blocked until the request is >> submitted. An alternate design would be to only block the >> not-submitted-request's buffer and let further buffers pass before it, but since >> buffer order is becoming increasingly important I have decided to just block the >> queue. This is open to discussion though. > > I don't think we should mess with the order. Agreed, let's keep it that way then. > >> >> * Documentation! Also described usecases for codec and simple (i.e. not part of >> a complex pipeline) capture device. > > I'll concentrate on reviewing that. > >> >> Still remaining to do: >> >> * As pointed out by Hans on the previous revision, do not assume that drivers >> using v4l2_fh have a per-handle state. I have not yet found a good way to >> differenciate both usages. > > I suspect we need to add a flag or something for this. I hope we don't need to, let's see if I can find a pattern... > >> * Integrate Hans' patchset for control handling: as said above, this is futile >> unless we can agree on the basic design, which I hope we can do this time. >> Chrome OS needs this really badly now and will have to move forward no matter >> what, so I hope this will be considered good enough for a common base of work. > > I am not sure there is any reason to not move forward with the control handling. > You need this anyway IMHO, regardless of any public API considerations. Only reasons are my lazyness and because I wanted to focus on the request flow first. But you're right. I have a version with your control framework changes integrated (they worked on the first attempt btw! :)), let me create a clean patchset from this and send another RFC. > >> A few thoughts/questions that emerged when writing this patchset: >> >> * Since requests are exposed as file descriptors, we could easily move the >> MEDIA_REQ_CMD_SUBMIT and MEDIA_REQ_CMD_REININT commands as ioctls on the >> requests themselves, instead of having to perform them on the media device that >> provided the request in the first place. That would add a bit more flexibility >> if/when passing requests around and means the media device only needs to handle >> MEDIA_REQ_CMD_ALLOC. Conceptually speaking, this seems to make sense to me. >> Any comment for/against that? > > Makes sense IMHO. Glad to hear it, that was my preferred design. :) > >> * For the codec usecase, I have experimented a bit marking CAPTURE buffers with >> the request FD that produced them (vim2m acts that way). This seems to work >> well, however FDs are process-local and could be closed before the CAPTURE >> buffer is dequeued, rendering that information less meaningful, if not >> dangerous. > > I don't follow this. Once the fd is passed to the kernel its refcount should be > increased so the data it represents won't be released if userspace closes the fd. The refcount of the request is increased. The refcount of the FD is not, since it is only a userspace reference to the request. > > Obviously if userspace closes the fd it cannot do anything with it anymore, but > it shouldn't be 'dangerous' AFAICT. It userspace later gets that closed FD back from a DQBUF call, and decides to use it again, then we would have a problem. I agree that it is userspace responsibility to be careful here, but making things foolproof never hurts. > >> Wouldn't it be better/safer to use a global request ID for >> such information instead? That ID would be returned upon MEDIA_REQ_CMD_ALLOC so >> user-space knows which request ID a FD refers to. > > I think it is not a good idea to have both an fd and an ID to refer to the > same object. That's going to be very confusing I think. IDs would not refer to the object, they would just be a way to identify it. FDs would be the actual reference. If we drop the idea of returning request FDs to userspace after the initial allocation (which is the only time we can be sure that a returned FD is valid), then this is not a problem anymore, but I think it may be useful to mark CAPTURE buffers with the request that generated them. > >> * Using the media node to provide requests makes absolute sense for complex >> camera devices, but is tedious for codec devices which work on one node and >> require to protect request/media related code with #ifdef >> CONFIG_MEDIA_CONTROLLER. > > Why? They would now depend on MEDIA_CONTROLLER (i.e. they won't appear in the > menuconfig unless MEDIA_CONTROLLER is set). No need for an #ifdef. Ah, if we make them depend on MEDIA_CONTROLLER, then indeed. But do we want to do this for e.g. vim2m and vivid? > > For these devices, the sole role of the media node is >> to produce the request, and that's it (since request submission could be moved >> to the request FD as explained above). That's a modest use that hardly justifies >> bringing in the whole media framework IMHO. With a bit of extra abstraction, it >> should be possible to decouple the base requests from the media controller >> altogether, and propose two kinds of requests implementations: one simpler >> implementation that works directly with a single V4L2 node (useful for codecs), >> and another one that works on a media node and can control all its entities >> (good for camera). This would allow codecs to use the request API without >> forcing the media controller, and would considerably simplify the use-case. Any >> objection to that? IIRC the earlier design documents mentioned this possibility. > > I think this is an interesting idea, but I would postpone making a decision on > this until later. We need this MC support regardless, so let's start off with that. > > Once that's working we can discuss if we should or should not create a shortcut > for codecs. Trying to decide this now would only confuse the process. Sounds good, as long as we make a decision before merging. Thanks, Alex.