From patchwork Tue Jul 1 04:58:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 23696 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 9B910C3237 for ; Tue, 1 Jul 2025 04:58:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6162F68E0E; Tue, 1 Jul 2025 06:58:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="ocQqqCv6"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1C43161524 for ; Tue, 1 Jul 2025 06:58:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=8lpcsVU2/8nvPxz6mt5TdzX3rdo0vrIYA1xtGdiqkFY=; b=ocQqqCv6b9oTn+96LTpTHLWuH9 jW8ONnLGi5M2jjburv0oxeJEMsQNJ83CrrpUIQYnE2koHJxYA4HDPh/KN3t6ZO3azhWYEqXNGyHKr KcE905mAZod2Duo6SsV0ySAkMMt7N6+TC73cro3a8dOoDgLuc/SIjwdfpzikKPOVJGO6x8gRKDS73 r3ONDY6RmV6AJdY4IhbdKdukyb+mSHTkdPM6hN5YGu1sw28EOrowagU5PnTvzFxGMwfMO6iM4fNn4 msKzFK/oauZpIVXntJ9YUzO2bpEhGUooYyAu9CHyVdd6CcSngVUhINY/J9ZmPGMg5HXzpHqHvDGYO 7DJoYSoQ==; Received: from [49.36.69.141] (helo=uajain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uWT4I-00AoPg-IL; Tue, 01 Jul 2025 06:58:07 +0200 From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Umang Jain Subject: [PATCH] libcamera: pipeline_hander: Return -EAGAIN if pipeline is saturated Date: Tue, 1 Jul 2025 10:28:05 +0530 Message-ID: <20250701045805.15201-1-uajain@igalia.com> X-Mailer: git-send-email 2.50.0 MIME-Version: 1.0 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" PipelineHandler::queueRequestDevice() returns a negative error code if the request fails to get queued to the underlying hardware. One such case would be if the hardware is saturated with requests beyond its limits, in which case queueRequestDevice() should return -EAGAIN. This way, each pipeline handler can keep their limits internal and decide to start returning -EAGAIN if they foresee their pipelines queues getting over-saturated with requests. Hence, returns error codes from doQueueRequest() so that doQueueRequests() can make an inform decision whether to pop off the requests from the internal waiting queue or not. Signed-off-by: Umang Jain --- include/libcamera/internal/pipeline_handler.h | 2 +- src/libcamera/pipeline_handler.cpp | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index 972a2fa6..35252e3a 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -88,7 +88,7 @@ private: void mediaDeviceDisconnected(MediaDevice *media); virtual void disconnect(); - void doQueueRequest(Request *request); + int doQueueRequest(Request *request); void doQueueRequests(); std::vector> mediaDevices_; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index d84dff3c..2ce093ff 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -452,8 +452,10 @@ void PipelineHandler::queueRequest(Request *request) /** * \brief Queue one requests to the device */ -void PipelineHandler::doQueueRequest(Request *request) +int PipelineHandler::doQueueRequest(Request *request) { + int ret; + LIBCAMERA_TRACEPOINT(request_device_queue, request); Camera *camera = request->_d()->camera(); @@ -464,12 +466,14 @@ void PipelineHandler::doQueueRequest(Request *request) if (request->_d()->cancelled_) { completeRequest(request); - return; + return -ECANCELED; } - int ret = queueRequestDevice(camera, request); - if (ret) + ret = queueRequestDevice(camera, request); + if (ret && ret != -EAGAIN) cancelRequest(request); + + return ret; } /** @@ -485,7 +489,9 @@ void PipelineHandler::doQueueRequests() if (!request->_d()->prepared_) break; - doQueueRequest(request); + if (doQueueRequest(request) == -EAGAIN) + break; + waitingRequests_.pop(); } } @@ -502,6 +508,10 @@ void PipelineHandler::doQueueRequests() * parameters will be applied to the frames captured in the buffers provided in * the request. * + * If the underlying hardware pipeline is saturated with requests, this + * function returns -EAGAIN, so that the \a request stays in the internal + * waiting queue. + * * \context This function is called from the CameraManager thread. * * \return 0 on success or a negative error code otherwise