Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1876901imm; Tue, 22 May 2018 10:44:45 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqDhSaF9jG1wDmFPOPKNx+KZCWqbE3oTarJ+TEarFAAOWcT4TOytIwU5N9Am26Ivn0pMmvC X-Received: by 2002:a63:6a08:: with SMTP id f8-v6mr20013850pgc.363.1527011085855; Tue, 22 May 2018 10:44:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527011085; cv=none; d=google.com; s=arc-20160816; b=dXHt/GGd/TDH50OALRaBpeYYWTI6IWSOW8P6YF7ZYwpqPdaAGwjkmS3Y0bkSM3xSRk RVxByZhE5MbJmxpEZid+EuAai9TBHimwL8cUgEyf8lqZJW/Mp7C5gpy3qulqPEIY0yhb V4EOXNSFIIkFtlkZlJGWOF9KoheO57PRW+Fv1PxmnpXkYwuobd3DODhoR16h3BXSapRO fZt9cQsopy2HLsdAq/QpGLr3C7ejPCX0nWA2OC9VHdcnsAgL95X5KxELlbw9nP5gCwFg mFMrWr+EhFScly6e0jNRgbHyeaHpteHJOAreskkfza/k6+eWhwOqEFWI6mJcZle4GBjS 3Szg== 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 :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=6elKXsaEDMNEijOW/v3LfnOcg2qe32QZFxjE1RNboGc=; b=VPIiku5I/62oi69+A9jOZ9LQ+WAl8KII8Qa5PFKggf/oOE/anIcx4FBT9irftIv/KR 1X2BsMqOys6OtB/sJJaALOZ5/birn7dosk2DEiLu2aveVl85uFEvd+1hWTTvX8tKPihD 4iXbw5tHqSqskj9fVT88sWs/WR0Pb2Z6qbFXEzd3AigtQeTsxiv4K1WUDXrm8eygGVAN RfhHkQMKXI0HoCzmZccnpfI4RoMasgMafB6ZNxyo10HtUt+6hfzVee0p/m+eK6yoZbci wBpGpd1o59YQETM0aBCALPUg+GJxQz383U3QUkFOgwg4qrzYmQenNTb9FNfi0kZql2PD 4r/w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3-v6si16604662plb.246.2018.05.22.10.44.31; Tue, 22 May 2018 10:44:45 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751493AbeEVRnN (ORCPT + 99 others); Tue, 22 May 2018 13:43:13 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:33838 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751240AbeEVRnL (ORCPT ); Tue, 22 May 2018 13:43:11 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id 954CF27338D Message-ID: <9836ca80e08574c6e77f45d069514c28f8867cb1.camel@collabora.com> Subject: Re: [PATCH v10 12/16] vb2: add in-fence support to QBUF From: Ezequiel Garcia To: Hans Verkuil , linux-media@vger.kernel.org Cc: kernel@collabora.com, Mauro Carvalho Chehab , Shuah Khan , Pawel Osciak , Alexandre Courbot , Sakari Ailus , Brian Starkey , linux-kernel@vger.kernel.org, Gustavo Padovan Date: Tue, 22 May 2018 14:41:29 -0300 In-Reply-To: <8848cdb3-73cf-2122-4c50-a57fcd83e151@xs4all.nl> References: <20180521165946.11778-1-ezequiel@collabora.com> <20180521165946.11778-13-ezequiel@collabora.com> <7462919b-ad6f-eb8c-7389-ef0ff6e9d1a2@xs4all.nl> <062e8128491e63927f4669ad08c40d29dfbb4141.camel@collabora.com> <8848cdb3-73cf-2122-4c50-a57fcd83e151@xs4all.nl> Organization: Collabora Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-05-22 at 18:48 +0200, Hans Verkuil wrote: > On 22/05/18 18:22, Ezequiel Garcia wrote: > > > > @@ -1615,7 +1762,12 @@ static void __vb2_dqbuf(struct vb2_buffer *vb) > > > > return; > > > > > > > > vb->state = VB2_BUF_STATE_DEQUEUED; > > > > - > > > > + if (vb->in_fence) { > > > > + if (dma_fence_remove_callback(vb->in_fence, &vb->fence_cb)) > > > > + __vb2_buffer_put(vb); > > > > + dma_fence_put(vb->in_fence); > > > > + vb->in_fence = NULL; > > > > + } > > > > /* unmap DMABUF buffer */ > > > > if (q->memory == VB2_MEMORY_DMABUF) > > > > for (i = 0; i < vb->num_planes; ++i) { > > > > @@ -1653,7 +1805,7 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb, > > > > if (pindex) > > > > *pindex = vb->index; > > > > > > > > - /* Fill buffer information for the userspace */ > > > > + /* Fill buffer information for userspace */ > > > > if (pb) > > > > call_void_bufop(q, fill_user_buffer, vb, pb); > > > > > > > > @@ -1700,8 +1852,8 @@ static void __vb2_queue_cancel(struct vb2_queue *q) > > > > if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { > > > > for (i = 0; i < q->num_buffers; ++i) > > > > if (q->bufs[i]->state == VB2_BUF_STATE_ACTIVE) { > > > > - pr_warn("driver bug: stop_streaming operation is leaving buf %p in active > > > > state\n", > > > > - q->bufs[i]); > > > > + pr_warn("driver bug: stop_streaming operation is leaving buf[%d] 0x%p in active > > > > state\n", > > > > + q->bufs[i]->index, q->bufs[i]); > > > > vb2_buffer_done(q->bufs[i], VB2_BUF_STATE_ERROR); > > > > } > > > > > > Shouldn't any pending fences be canceled here? > > > > > > > No, we don't have to flush -- that's the reason of the refcount :) > > The qbuf_work won't do anything if all the buffers are returned > > by the driver (with error or done state), and if !streaming. > > > > Also, note that's why qbuf_work checks for the queued state, and not > > for the error state. > > > > > I feel uncomfortable with the refcounting of buffers, I'd rather that when we > > > cancel the queue all fences for buffers are removed/canceled/whatever. > > > > > > Is there any reason for refcounting if we cancel all pending fences here? > > > > > > Note that besides canceling fences you also need to cancel/flush __qbuf_work. > > > > > > > > > > Like I said above, I'm trying to avoid cancel/flushing the workqueue. > > Currently, I believe it works fine without any flushing, provided we refcount > > the buffers. > > > > The problem with cancelling the workqueue, is that you need to unlock the queue > > lock, to avoid a deadlock. It seemed to me that having a refcount is more natural. > > > > Thoughts? > > > > I'll take another look tomorrow morning. Do you have a public git tree containing > this series that I can browse? > > Sure, there you go http://git.infradead.org/users/ezequielg/linux/shortlog/refs/heads/fences_v10_v4.17-rc1