From patchwork Thu May 13 02:29:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12257 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BEA40C1D12 for ; Thu, 13 May 2021 02:29:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4BEBE6891A; Thu, 13 May 2021 04:29:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="a785MDA2"; dkim-atps=neutral Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8A19961538 for ; Thu, 13 May 2021 04:29:54 +0200 (CEST) Received: by mail-pg1-x52c.google.com with SMTP id s22so19893075pgk.6 for ; Wed, 12 May 2021 19:29:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xOJ+v1Pkn4CaBBnLJFL78g5tgqEuNDo694T4tDXiVIE=; b=a785MDA21gPG+5pKDFIxjdHhs2eO8LQd6FZMaSZzN33MWWQThQwItJF20sg1ljz74z 2CaNQr0bc9Hjh8bI+UCxegcSNetV02H5kJ+9sNcOBDMRxmHW65ONquuvzwG8VUn4YOGa Rch7wzYcW+dRzq75Q12/eAkzXUjrdZnxOGZE0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xOJ+v1Pkn4CaBBnLJFL78g5tgqEuNDo694T4tDXiVIE=; b=sL9TgxPQ3K0vJfHaGDx2rWMJHThKfCLVf7VKtLLZbBwJposQRUktOQ7PhqIf4mfu9b ksxGQPnD5rN3yAda7Ij48CloBzYinTNC8SVqplMN3x3USHiGJozs1MuacI8AjkU7VfHd 8rKH8HfVVV8kM2fGTKRwVqoQorFwUEKxgGyoZF4ic7KxSxhSwObGWolPrfyOYkS0rW3e t6s6AONN2/ak/uRmpeorQdPKSktZJJwBDCMfjlh+luc0uKcSXVGp2s2Dnx12ND+m5Ls4 iHyXHkg8bfV5KRxNj2caj6MSOYzxeb2pVnR2ABQppjJN4fl9FU4E4cbhTwDdkxVf+i23 MWDA== X-Gm-Message-State: AOAM530mESDq+6rLrotIq2aNLldje5SoAi7PZXxAM1vKmFPhdhUrdcJW bybWJIjNgP0LBNudtKpWdf9sWVvEIKYTeA== X-Google-Smtp-Source: ABdhPJwD6VmRpogQcO9+KZX66cCv6LoX5kIZpJl9tMwR7DTDpDE/mTxVlt7FU0mzLsHbJ7HDAvEujw== X-Received: by 2002:a17:90a:1382:: with SMTP id i2mr42990705pja.176.1620872992349; Wed, 12 May 2021 19:29:52 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:90f6:be0f:1d8a:d075]) by smtp.gmail.com with ESMTPSA id d23sm864358pfo.80.2021.05.12.19.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 19:29:51 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 13 May 2021 11:29:45 +0900 Message-Id: <20210513022946.2194341-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 1/2] pipeline: ipu3: Store requests in the case a buffer shortage X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" PipelineHandlerIPU3 returns -ENOBUFS and -ENOMEM on queueing a request when there are not sufficient buffers for the request. Since the request will be successful if it is queued later when enough buffers are available. The requests failed due to a buffer shortage should be stored and retried later in the FIFO order. This introduces the queue in IPU3CameraData to do that. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/cio2.cpp | 2 +- src/libcamera/pipeline/ipu3/frames.cpp | 4 +- src/libcamera/pipeline/ipu3/ipu3.cpp | 80 +++++++++++++++++++------- 3 files changed, 63 insertions(+), 23 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 3cd777d1..8bbef174 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -272,7 +272,7 @@ FrameBuffer *CIO2Device::queueBuffer(Request *request, FrameBuffer *rawBuffer) /* If no buffer is provided in the request, use an internal one. */ if (!buffer) { if (availableBuffers_.empty()) { - LOG(IPU3, Error) << "CIO2 buffer underrun"; + LOG(IPU3, Debug) << "CIO2 buffer underrun"; return nullptr; } diff --git a/src/libcamera/pipeline/ipu3/frames.cpp b/src/libcamera/pipeline/ipu3/frames.cpp index d0f55ab9..29d9aafc 100644 --- a/src/libcamera/pipeline/ipu3/frames.cpp +++ b/src/libcamera/pipeline/ipu3/frames.cpp @@ -44,12 +44,12 @@ IPU3Frames::Info *IPU3Frames::create(Request *request) unsigned int id = request->sequence(); if (availableParamBuffers_.empty()) { - LOG(IPU3, Error) << "Parameters buffer underrun"; + LOG(IPU3, Debug) << "Parameters buffer underrun"; return nullptr; } if (availableStatBuffers_.empty()) { - LOG(IPU3, Error) << "Statistics buffer underrun"; + LOG(IPU3, Debug) << "Statistics buffer underrun"; return nullptr; } diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index ade8ffbd..6961d498 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -66,6 +66,8 @@ public: void cio2BufferReady(FrameBuffer *buffer); void paramBufferReady(FrameBuffer *buffer); void statBufferReady(FrameBuffer *buffer); + void queuePendingRequests(); + void cancelPendingRequests(); CIO2Device cio2_; ImgUDevice *imgu_; @@ -84,6 +86,8 @@ public: std::unique_ptr ipa_; + std::queue pendingRequests_; + private: void queueFrameAction(unsigned int id, const ipa::ipu3::IPU3Action &action); @@ -764,6 +768,8 @@ void PipelineHandlerIPU3::stop(Camera *camera) IPU3CameraData *data = cameraData(camera); int ret = 0; + data->cancelPendingRequests(); + data->ipa_->stop(); ret |= data->imgu_->stop(); @@ -774,32 +780,66 @@ void PipelineHandlerIPU3::stop(Camera *camera) freeBuffers(camera); } -int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request) +void IPU3CameraData::cancelPendingRequests() { - IPU3CameraData *data = cameraData(camera); + while (!pendingRequests_.empty()) { + Request *request = pendingRequests_.front(); - IPU3Frames::Info *info = data->frameInfos_.create(request); - if (!info) - return -ENOBUFS; + for (auto it : request->buffers()) { + FrameBuffer *buffer = it.second; + buffer->cancel(); + pipe_->completeBuffer(request, buffer); + } - /* - * Queue a buffer on the CIO2, using the raw stream buffer provided in - * the request, if any, or a CIO2 internal buffer otherwise. - */ - FrameBuffer *reqRawBuffer = request->findBuffer(&data->rawStream_); - FrameBuffer *rawBuffer = data->cio2_.queueBuffer(request, reqRawBuffer); - if (!rawBuffer) { - data->frameInfos_.remove(info); - return -ENOMEM; + pipe_->completeRequest(request); + pendingRequests_.pop(); } +} - info->rawBuffer = rawBuffer; +void IPU3CameraData::queuePendingRequests() +{ + while (!pendingRequests_.empty()) { + Request *request = pendingRequests_.front(); - ipa::ipu3::IPU3Event ev; - ev.op = ipa::ipu3::EventProcessControls; - ev.frame = info->id; - ev.controls = request->controls(); - data->ipa_->processEvent(ev); + IPU3Frames::Info *info = frameInfos_.create(request); + if (!info) + break; + + /* + * Queue a buffer on the CIO2, using the raw stream buffer + * provided in the request, if any, or a CIO2 internal buffer + * otherwise. + */ + FrameBuffer *reqRawBuffer = request->findBuffer(&rawStream_); + FrameBuffer *rawBuffer = cio2_.queueBuffer(request, reqRawBuffer); + /* + * \todo If queueBuffer fails in queuing a buffer to the device, + * report the request as error by cancelling the request and + * calling PipelineHandler::completeRequest(). + */ + if (!rawBuffer) { + frameInfos_.remove(info); + break; + } + + info->rawBuffer = rawBuffer; + + ipa::ipu3::IPU3Event ev; + ev.op = ipa::ipu3::EventProcessControls; + ev.frame = info->id; + ev.controls = request->controls(); + ipa_->processEvent(ev); + + pendingRequests_.pop(); + } +} + +int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request) +{ + IPU3CameraData *data = cameraData(camera); + + data->pendingRequests_.push(request); + data->queuePendingRequests(); return 0; } From patchwork Thu May 13 02:29:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12258 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 08BDBC1D12 for ; Thu, 13 May 2021 02:29:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B313B6890C; Thu, 13 May 2021 04:29:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="G+2X2RIC"; dkim-atps=neutral Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5D3DC61538 for ; Thu, 13 May 2021 04:29:55 +0200 (CEST) Received: by mail-pg1-x536.google.com with SMTP id l70so5213271pga.1 for ; Wed, 12 May 2021 19:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oMa7Vy9hAg4h3M6ksclEDRx2X0pK1VHQzHhYJOvclkI=; b=G+2X2RIC1NLK9z9FlMU0AZMS+MlcinpTHyVWp/Hxh783XPLdFwIzycp+FVTqaWlPZw 2a0wvkBS9agJHSuL5IvlC/ZQDopnqJJ6/QiZPTargX/txEc1QpdHZx/auvp2asmjy+AW At5a9YYHw38idVqKmD6uLeF8uTpFknXcn68UE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oMa7Vy9hAg4h3M6ksclEDRx2X0pK1VHQzHhYJOvclkI=; b=hmALgcdFNczmXtkyrFZY16x7y39cOJgCcoCjMf8MxhNwqcggKAQQSs62kC86f3tGnC Q7DFpHynGf5qSBPzOt5d4ESUGJAjBVrXRx2XbtlFabZPKXhEVEKIly9OGsleF0Kj8zRE 7f29dSot4GlM3888v9lpcSD/m0iu3zICqEBBmC48Qg6DSJODaIiivJkM9r6T6LCRwstg nf3M8VDw1bPcGKs5edKs/wsgyA0oqpQy32d9kLshRGKZWP3KVihjz067zeztRL8fckr7 qh1ROscJcZO+YUMtxKFuCLPY2Y4YNAwhzO2y0ir4TrVIPQ/aUkByalHKfJdRv7TI3zur Loug== X-Gm-Message-State: AOAM532vl+ASB93sx7SabM3SvKobHEnHF+fyM+UEx77vJgVi2fL4Af+J hnsz/6Wb7qanEbOOGNnDaYLPw/w8lEDFug== X-Google-Smtp-Source: ABdhPJzEFO5pSORlLGiTcphtGDn10Xco33xwPUIQc7S3kJuJ6kPoXCIMZts1s0JQ7e2ux6z6Nisp9A== X-Received: by 2002:a17:90b:4a4e:: with SMTP id lb14mr1906031pjb.115.1620872993746; Wed, 12 May 2021 19:29:53 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:90f6:be0f:1d8a:d075]) by smtp.gmail.com with ESMTPSA id d23sm864358pfo.80.2021.05.12.19.29.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 19:29:53 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 13 May 2021 11:29:46 +0900 Message-Id: <20210513022946.2194341-2-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210513022946.2194341-1-hiroh@chromium.org> References: <20210513022946.2194341-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 2/2] libcamera: ipu3: Try queuing pending requests if a buffer is available X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" IPU3CameraData stores requests that have been failed due to a buffer shortage. The requests should be retried once enough buffers are available. This sets the retry function as signal to CIO2Device and IPU3Frame, and invokes it from CIO2Device::tryReturnBuffer() and IPU3Frame::remove(). Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/cio2.cpp | 2 ++ src/libcamera/pipeline/ipu3/cio2.h | 2 ++ src/libcamera/pipeline/ipu3/frames.cpp | 2 ++ src/libcamera/pipeline/ipu3/frames.h | 4 ++++ src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++++ 5 files changed, 14 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 8bbef174..1be2cbcd 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -302,6 +302,8 @@ void CIO2Device::tryReturnBuffer(FrameBuffer *buffer) break; } } + + bufferAvailable.emit(); } void CIO2Device::freeBuffers() diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h index 5ecc4f47..d8d4a181 100644 --- a/src/libcamera/pipeline/ipu3/cio2.h +++ b/src/libcamera/pipeline/ipu3/cio2.h @@ -56,6 +56,8 @@ public: Signal &bufferReady() { return output_->bufferReady; } Signal &frameStart() { return csi2_->frameStart; } + Signal<> bufferAvailable; + private: void freeBuffers(); diff --git a/src/libcamera/pipeline/ipu3/frames.cpp b/src/libcamera/pipeline/ipu3/frames.cpp index 29d9aafc..d9a2249b 100644 --- a/src/libcamera/pipeline/ipu3/frames.cpp +++ b/src/libcamera/pipeline/ipu3/frames.cpp @@ -103,6 +103,8 @@ bool IPU3Frames::tryComplete(IPU3Frames::Info *info) remove(info); + bufferAvailable.emit(); + return true; } diff --git a/src/libcamera/pipeline/ipu3/frames.h b/src/libcamera/pipeline/ipu3/frames.h index 4acdf48e..59e64e81 100644 --- a/src/libcamera/pipeline/ipu3/frames.h +++ b/src/libcamera/pipeline/ipu3/frames.h @@ -12,6 +12,8 @@ #include #include +#include + namespace libcamera { class FrameBuffer; @@ -49,6 +51,8 @@ public: Info *find(unsigned int id); Info *find(FrameBuffer *buffer); + Signal<> bufferAvailable; + private: std::queue availableParamBuffers_; std::queue availableStatBuffers_; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 6961d498..8ae47c6d 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -701,6 +701,8 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera) data->ipa_->mapBuffers(ipaBuffers_); data->frameInfos_.init(imgu->paramBuffers_, imgu->statBuffers_); + data->frameInfos_.bufferAvailable.connect( + data, &IPU3CameraData::queuePendingRequests); return 0; } @@ -1147,6 +1149,8 @@ int PipelineHandlerIPU3::registerCameras() */ data->cio2_.bufferReady().connect(data.get(), &IPU3CameraData::cio2BufferReady); + data->cio2_.bufferAvailable.connect( + data.get(), &IPU3CameraData::queuePendingRequests); data->imgu_->input_->bufferReady.connect(&data->cio2_, &CIO2Device::tryReturnBuffer); data->imgu_->output_->bufferReady.connect(data.get(),