From patchwork Tue Apr 6 08:51:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11840 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 26240C0DA3 for ; Tue, 6 Apr 2021 08:52:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AC0D3687A1; Tue, 6 Apr 2021 10:52:06 +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="G7Z3eFdo"; dkim-atps=neutral Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5F4C360517 for ; Tue, 6 Apr 2021 10:52:02 +0200 (CEST) Received: by mail-pg1-x529.google.com with SMTP id t22so2714646pgu.0 for ; Tue, 06 Apr 2021 01:52:02 -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=jfeyZ2yvrHTGMVCEciDVuNQQtKjTpqBhEM2MU+DjD78=; b=G7Z3eFdo5SZ1bdUSsW2DK9l7xWVlgOrw/+m/bcqaGqbXatPzltg+GPhXCq//aSCGd5 twfeCTaeKxF25jfhs0FN8kQlKeMakv+ax7WwuusrD2equtGU0VdMocAr0CLGFXOjvGP9 qlYz6Mq8hALb+MUzErVUEEpvCPCoNzKngN0Bc= 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=jfeyZ2yvrHTGMVCEciDVuNQQtKjTpqBhEM2MU+DjD78=; b=rFHaUZKAbZK6fgQbblIvEm+c3MgkNTmshDg2+XJvl2fbMMudvlTx/geIqXyd3WZiVV SMOP7tCILNPB+iV/d0FZT9ZoZpVwENqwtCMlCEzNA7Deyx/Q8YfMx23DYgBWQV1Nc8/B wa8LnQvWZczIlkSrgQXY0/EmFJXRMzRlI9h6Aa8CgJHMboiCxQR0SBCVPpYosQc4EqNI 5iSjBo8oThJrOZpl1WfH1hzSjtR9PxbpPlC7qcjmVsAHszElfohx2wJOUlJyjSwvedUd H6Yz2wng+1/r4CxQS+q5lKSfaF+gWQDPLrPlZ/PTnT3XdfJyT+HowjS+uEkhkb1SGP0W /ViA== X-Gm-Message-State: AOAM531o1KxaDbGwytE/njLjzngWEtWvlaLGs/nbPBCh54MaS/JRB6kc 589pDBAcujTqzqqxqcD9cUc16b4vTkf7RQ== X-Google-Smtp-Source: ABdhPJzHRJ/6cYo8ZQ17dQ2eexqlYq3aiIv9gOBa8nsSfYmCiiecPIZy7zK3gFatn3qmeC6x6reyQA== X-Received: by 2002:aa7:900d:0:b029:230:2d6a:2940 with SMTP id m13-20020aa7900d0000b02902302d6a2940mr24676496pfo.23.1617699120395; Tue, 06 Apr 2021 01:52:00 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:4180:40db:6f79:a143]) by smtp.gmail.com with ESMTPSA id y7sm18070135pfq.70.2021.04.06.01.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 01:52:00 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 6 Apr 2021 17:51:52 +0900 Message-Id: <20210406085153.3818580-2-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog In-Reply-To: <20210406085153.3818580-1-hiroh@chromium.org> References: <20210406085153.3818580-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 --- src/libcamera/pipeline/ipu3/ipu3.cpp | 58 ++++++++++++++++++---------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 519cad4f..c73e4f7c 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -66,6 +66,7 @@ public: void cio2BufferReady(FrameBuffer *buffer); void paramBufferReady(FrameBuffer *buffer); void statBufferReady(FrameBuffer *buffer); + int queuePendingRequests(); CIO2Device cio2_; ImgUDevice *imgu_; @@ -84,6 +85,7 @@ public: std::unique_ptr ipa_; + std::queue pendingRequests_; private: void queueFrameAction(unsigned int id, const ipa::ipu3::IPU3Action &action); @@ -764,6 +766,8 @@ void PipelineHandlerIPU3::stop(Camera *camera) IPU3CameraData *data = cameraData(camera); int ret = 0; + data->pendingRequests_ = {}; + data->ipa_->stop(); ret |= data->imgu_->stop(); @@ -774,36 +778,48 @@ void PipelineHandlerIPU3::stop(Camera *camera) freeBuffers(camera); } -int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request) +int IPU3CameraData::queuePendingRequests() { - IPU3CameraData *data = cameraData(camera); + while (!pendingRequests_.empty()) { + Request *request = pendingRequests_.front(); - IPU3Frames::Info *info = data->frameInfos_.create(request); - if (!info) - return -ENOBUFS; + 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(&data->rawStream_); - FrameBuffer *rawBuffer = data->cio2_.queueBuffer(request, reqRawBuffer); - if (!rawBuffer) { - data->frameInfos_.remove(info); - return -ENOMEM; - } + /* + * 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); + if (!rawBuffer) { + frameInfos_.remove(info); + break; + } - info->rawBuffer = rawBuffer; + info->rawBuffer = rawBuffer; - ipa::ipu3::IPU3Event ev; - ev.op = ipa::ipu3::EventProcessControls; - ev.frame = info->id; - ev.controls = request->controls(); - data->ipa_->processEvent(ev); + ipa::ipu3::IPU3Event ev; + ev.op = ipa::ipu3::EventProcessControls; + ev.frame = info->id; + ev.controls = request->controls(); + ipa_->processEvent(ev); + + pendingRequests_.pop(); + } return 0; } +int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request) +{ + IPU3CameraData *data = cameraData(camera); + data->pendingRequests_.emplace(request); + return data->queuePendingRequests(); +} + bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator) { int ret; From patchwork Tue Apr 6 08:51:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11841 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 C83C1C0DA3 for ; Tue, 6 Apr 2021 08:52:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 198DC68797; Tue, 6 Apr 2021 10:52:07 +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="fkTqdv5q"; dkim-atps=neutral Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 638DA60517 for ; Tue, 6 Apr 2021 10:52:03 +0200 (CEST) Received: by mail-pg1-x52f.google.com with SMTP id y32so6677772pga.11 for ; Tue, 06 Apr 2021 01:52:03 -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=AlMFdpjld/thmoA4QQbI8zwGsWKIYqW7MNGUakZcOnM=; b=fkTqdv5qS2pkEoy51RqTpWga1ZkEC/qjphtdVWgUW0McOD65f7kLsgBcCdO/Th7wtA 8uo5y8mXNwkSZISRyGouxO2Gqo7rTvh4c4uF/KMsA6CJYpVZRhnbic0znGpOrtSjW2Xi 4Ffpx8kJkdt9NzRvghSuR7EN5AmrxyR7zhx44= 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=AlMFdpjld/thmoA4QQbI8zwGsWKIYqW7MNGUakZcOnM=; b=pfP+1V0T5jbyPSsnUUHBeOuKJMTT5xDptQmBa8WGx6cKr0nDna8PHKcc00oNnj0Pw1 YKmWfyIfdNqg8n2Fgfz/E4oRNezsIAuKwSwZgkWqVdNXNa5zreapBjkh14uF9RxnNGmf DNX7ZibSCD8V3Htry/ap0UnLLOOnptpCH/AIGcoatj5qgH7dObv1/8zxKimJN26lq2FK wmglG+D+2SbmiuO0f+UG1VoBYNBfquJLfPvm0MI4UIqJPrtD1t9oHtVHy/ESUN5BhGxp UEOd1fKGIA/HIJ4ZTa2YJ3fqrGkkKK7vn1QnssPMG+dD5Hdl0aKsNfBXITtUJufCx15q /4ZA== X-Gm-Message-State: AOAM533GoVVNQ4PW4Ss5NDqoHMZztGtXjs1Q3VI0+vujZ/zslFrQK3e4 fD7w1GfIFcVx8ZanqW1lLoI/LVDkLKAF+A== X-Google-Smtp-Source: ABdhPJwjVBCBMEINL0QauX1/QGGQ6HLe+qF5vCpOVo7g/ElkGuDrwf1Cra4ktDBibK4kZA/yS08OsA== X-Received: by 2002:a62:e805:0:b029:1f8:16ba:4518 with SMTP id c5-20020a62e8050000b02901f816ba4518mr26364558pfi.37.1617699121796; Tue, 06 Apr 2021 01:52:01 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:4180:40db:6f79:a143]) by smtp.gmail.com with ESMTPSA id y7sm18070135pfq.70.2021.04.06.01.52.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 01:52:01 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 6 Apr 2021 17:51:53 +0900 Message-Id: <20210406085153.3818580-3-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog In-Reply-To: <20210406085153.3818580-1-hiroh@chromium.org> References: <20210406085153.3818580-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 --- src/libcamera/pipeline/ipu3/cio2.cpp | 4 +++- src/libcamera/pipeline/ipu3/cio2.h | 3 +++ src/libcamera/pipeline/ipu3/frames.cpp | 6 ++++-- src/libcamera/pipeline/ipu3/frames.h | 5 +++++ src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 3cd777d1..6490fd46 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; } @@ -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..8f37ee35 100644 --- a/src/libcamera/pipeline/ipu3/cio2.h +++ b/src/libcamera/pipeline/ipu3/cio2.h @@ -54,6 +54,7 @@ public: FrameBuffer *queueBuffer(Request *request, FrameBuffer *rawBuffer); void tryReturnBuffer(FrameBuffer *buffer); Signal &bufferReady() { return output_->bufferReady; } + Signal<> &bufferAvailable() { return bufferAvailable_; } Signal &frameStart() { return csi2_->frameStart; } private: @@ -65,6 +66,8 @@ private: std::unique_ptr csi2_; std::unique_ptr output_; + Signal<> bufferAvailable_; + std::vector> buffers_; std::queue availableBuffers_; }; diff --git a/src/libcamera/pipeline/ipu3/frames.cpp b/src/libcamera/pipeline/ipu3/frames.cpp index 03e8131c..58a47f98 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; } @@ -86,6 +86,8 @@ void IPU3Frames::remove(IPU3Frames::Info *info) /* Delete the extended frame information. */ frameInfo_.erase(info->id); + + bufferAvailable_.emit(); } bool IPU3Frames::tryComplete(IPU3Frames::Info *info) diff --git a/src/libcamera/pipeline/ipu3/frames.h b/src/libcamera/pipeline/ipu3/frames.h index 4acdf48e..d2e5fbb9 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,10 +51,13 @@ public: Info *find(unsigned int id); Info *find(FrameBuffer *buffer); + Signal<> &bufferAvailable() { return bufferAvailable_; } private: std::queue availableParamBuffers_; std::queue availableStatBuffers_; + Signal<> bufferAvailable_; + std::map> frameInfo_; }; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index c73e4f7c..462a0d9b 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -699,6 +699,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; } @@ -1123,6 +1125,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(),