Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp840302ybh; Wed, 11 Mar 2020 11:54:20 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsyt1CBMpr6mixPE2nOASgUAk5xxknewWU9HSz6+djeUj46cAFzffe3PPJazji26hbfQkm9 X-Received: by 2002:a9d:e84:: with SMTP id 4mr3582846otj.346.1583952860710; Wed, 11 Mar 2020 11:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583952860; cv=none; d=google.com; s=arc-20160816; b=C4CLfPeZxJKhbmd89nug3Na4O39zaz5AWT0bPC9ydKl/1+c3q4WEVCg4O3GLdyS8AF 7yL2WcTRhS7gA58HJGk9QK2EcUa9Wgxy35xq0zAP6xKgrklwe3fh8PWLMTCcwReEMtvJ 85JY0tQDNPFFFxbq+IX/VmAFxU4LZvZqVYdTtfdHTf5esnL6bpt5geKb7pSg5d/2t0v/ MiQMt60ePOso4d9sXYyIVMlXesyp+y52ze5OE8NzEMEl/GPuTyZZoopjHjKCo1a6VGEh 0GWqTrc4dIzeijipHfjEDlVQo5iNGg9IBVYyAwYZKg8tAZbxpPv753TnYcKl5EtTEyus waoQ== 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:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=/dNPHeH2JZmJ2dMMclVWXH5FnCXDvSk9raw7HY/zLIQ=; b=rqMnxHnr08Oe9erMo8P+uGm0PTrUzvmLb54tg5zshsNoP8yinTEhMtZ+WqMHByytW0 5t+oEjllYFPb+FwuLaME+uG8ICDdzm9Q27uUnmUCbNiK+xelwfY48w9C8Z+dDeWkadxu tjqZ0ewdBSBCfK4a2Yya3PAEOo3DnRsKMSi6taDdOMok7jOQzDPTUENuGct73aC2ESCN +zVOGxyfVnXSGptsF5X2TMEGj4hS0KAHZVeMOTsMMbNT0l4Ac06+RlUdVqI9vjJrsdfJ 34mcdV5TttKU/G9vXUxWEzNHJICiFhYSMrC0Q+i9fCmWDKuqsxcH9e1ux3Rh010qStMe xqcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ndufresne-ca.20150623.gappssmtp.com header.s=20150623 header.b=ygDsOdtY; 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 r13si1422893otd.167.2020.03.11.11.54.07; Wed, 11 Mar 2020 11:54:20 -0700 (PDT) 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=@ndufresne-ca.20150623.gappssmtp.com header.s=20150623 header.b=ygDsOdtY; 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 S1730892AbgCKSxn (ORCPT + 99 others); Wed, 11 Mar 2020 14:53:43 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:33386 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730705AbgCKSxn (ORCPT ); Wed, 11 Mar 2020 14:53:43 -0400 Received: by mail-qk1-f194.google.com with SMTP id p62so3192528qkb.0 for ; Wed, 11 Mar 2020 11:53:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ndufresne-ca.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=/dNPHeH2JZmJ2dMMclVWXH5FnCXDvSk9raw7HY/zLIQ=; b=ygDsOdtY6QApFOfgyPzrx2YcP1OlBPCDu+mbKNx62lxfET7c++bIcIv7VAPT7xD+AM HBLi/TBK9SQzFp6tSZ1apwYr4NEZtIjQKrVdleubLxSXTK9HiMiJ6OTmZt3eDFFoy9Mo 66tCLtaGGmTijrMelKjuDHFOas9Rl6fYaBH5AfQR8a4FgZAx8dUSt0aGPAfgkn/4FDL7 eKhzvpKLREUjx5S1Hh3hSJakrnOsra+GKMUeE510a9zYDWmO3GmJYrD6U5m2cewGd7N/ SkzHDu/3OQzW47rJkLahb0aKEACA0ITGxh1SMrT0N5r3CvGCNeggcird9UZZBL4QWxDg mEXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=/dNPHeH2JZmJ2dMMclVWXH5FnCXDvSk9raw7HY/zLIQ=; b=CoRHY/yP42YJhjFvw9VtZK5cp+CU2nHfddLywVkLpYJ1nyEnzAiGOUgSGeNJkJ5DhB DlZBnMBg2K22VWIPWm3NgTa+i01uIO2eRBQfd+NYyLeWRMj6LYtyZ+CyCIOqDfWZWCEH 7Cb6y7N04du3wkhErn81IoYyS5BB+bvcP/r+vCTH2lcuedn9FK4g0o0JRsJk5hrDejA1 TZpkbyEsdKxASev/Ak9ki30gRlLKR7LrXRjT9BRoJu4xUa+JGRZyWZjlfeuY01AQwWFP Frad+xFWVwbtcCQ1l/cNeShylFodVq1R5LMJmubT065MnhMEaiaTE2zh81GCZSqChE/x 0CWw== X-Gm-Message-State: ANhLgQ0bdNQvLaBuP46RNWdAF70GUO31jwJ/QerBBzzvFYbXjnKIlKQ2 Pd/eMfyncgf0Ft+lUP9iBYnQig== X-Received: by 2002:a37:b304:: with SMTP id c4mr4250035qkf.348.1583952820524; Wed, 11 Mar 2020 11:53:40 -0700 (PDT) Received: from nicolas-tpx395.localdomain ([2610:98:8005::527]) by smtp.gmail.com with ESMTPSA id f13sm21354104qkm.42.2020.03.11.11.53.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 11:53:39 -0700 (PDT) Message-ID: <7b0e33f9c66dd87904b787218389c3d639f7469a.camel@ndufresne.ca> Subject: Re: [PATCH 1/6] v4l2-mem2mem: return CAPTURE buffer first From: Nicolas Dufresne To: Ezequiel Garcia , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Tomasz Figa , kernel@collabora.com, Jonas Karlman , Heiko Stuebner , Hans Verkuil , Alexandre Courbot , Jeffrey Kardatzke Date: Wed, 11 Mar 2020 14:53:37 -0400 In-Reply-To: <20200311174300.19407-2-ezequiel@collabora.com> References: <20200311174300.19407-1-ezequiel@collabora.com> <20200311174300.19407-2-ezequiel@collabora.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.4 (3.34.4-1.fc31) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le mercredi 11 mars 2020 à 14:42 -0300, Ezequiel Garcia a écrit : > When the request API is used, typically an OUTPUT (src) buffer > will be part of a request. A userspace process will be typically > blocked, waiting on the request file descriptor. > > Returning the OUTPUT (src) buffer will wake-up such processes, > who will immediately attempt to dequeue the CAPTURE buffer, > only to find it's still unavailable. > > Therefore, change v4l2_m2m_buf_done_and_job_finish returning > the CAPTURE (dst) buffer first, to avoid signalling the request > file descriptor prematurely, i.e. before the CAPTURE buffer is done. > > When the request API is not used, this change should have > no impact. > > Signed-off-by: Ezequiel Garcia This was tested with upcoming GStreamer element with O_NONBLOCK flag passed when opening the video node. Before this change, EAGAIN would from time to time be returned when DQBUF(CAPTURE) was called. gst-launch-1.0 filesrc location=somefile.mp4 ! parsebin ! v4l2slh264dec ! fakevideosink https://gitlab.freedesktop.org/ndufresne/gst-plugins-bad/-/blob/v4l2codecs-hantro-v3/sys/v4l2codecs/gstv4l2decoder.c#L139 Tested-by: Nicolas Dufresne > --- > drivers/media/v4l2-core/v4l2-mem2mem.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2- > core/v4l2-mem2mem.c > index 8986c31176e9..62ac9424c92a 100644 > --- a/drivers/media/v4l2-core/v4l2-mem2mem.c > +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c > @@ -504,12 +504,21 @@ void v4l2_m2m_buf_done_and_job_finish(struct > v4l2_m2m_dev *m2m_dev, > > if (WARN_ON(!src_buf || !dst_buf)) > goto unlock; > - v4l2_m2m_buf_done(src_buf, state); > dst_buf->is_held = src_buf->flags & V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF; > if (!dst_buf->is_held) { > v4l2_m2m_dst_buf_remove(m2m_ctx); > v4l2_m2m_buf_done(dst_buf, state); > } > + /* > + * If the request API is being used, returning the OUTPUT > + * (src) buffer will wake-up any process waiting on the > + * request file descriptor. > + * > + * Therefore, return the CAPTURE (dst) buffer first, > + * to avoid signalling the request file descriptor > + * before the CAPTURE buffer is done. > + */ > + v4l2_m2m_buf_done(src_buf, state); > schedule_next = _v4l2_m2m_job_finish(m2m_dev, m2m_ctx); > unlock: > spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);