From patchwork Fri Nov 13 06:38:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10415 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 AFFB9BE086 for ; Fri, 13 Nov 2020 06:38:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7E408631B6; Fri, 13 Nov 2020 07:38:25 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qzOEkz4Q"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BC42763149 for ; Fri, 13 Nov 2020 07:38:23 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 36A9F31A for ; Fri, 13 Nov 2020 07:38:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1605249503; bh=Xe7ANk361kpda4hf4DZb74y0h87EO+aEUpfv8VB6hNY=; h=From:To:Subject:Date:From; b=qzOEkz4QSOA3DwmSGjaLvS9dGjdEXA3xy2RzDhpbOrUaZ/klpxk/iG41cAMAweoGo rKIWckQJTllGxnAKEKIkfkUPKSx6FFX6dQyJK1Ahwsyy+LDikiAwmnzxf6lCtBjYzb YaTjvyWGmM6DNQ5IEvtdNrFpx7DeCl2vpxohHBpc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 13 Nov 2020 08:38:10 +0200 Message-Id: <20201113063815.10288-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 0/5] cam: Move request processing to main thread 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" Hello, This patch series improves the cam application by moving request processing to the main thread to avoid blocking the camera manager thread (in which the request completion signal is emitted) for extended periods of time. This helps meeting the realtime constraints of pipeline handlers. Note that move requesting processing to a different thread isn't a magical solution, if the average processing time for a request is larger than the frame interval, a request queue underrun will still occur. It however helps handling random delays in request processing. Included in the series is a move to libevent to implement the cam event loop. The event loop is currently based on the libcamera event dispatcher for historical reasons. The event dispatcher API exposed by libcamera is incomplete, as thread support is internal to libcamera. Instead of reimplementing the missing parts in the cam event loop, or exposing thread support in the libcamera public API, moving to libevent allows making the event dispatcher implementation fully private (in patch 3/5). It isn't the job of libcamera to provide such generic APIs. Laurent Pinchart (5): test: Get event dispatcher from current thread cam: Use libevent to implement event loop libcamera: Move EventDispatcher to internal API cam: event_loop: Add deferred calls support cam: Move request processing to main thread include/libcamera/camera_manager.h | 4 -- .../{ => internal}/event_dispatcher.h | 0 .../internal/event_dispatcher_poll.h | 2 +- .../libcamera/{ => internal}/event_notifier.h | 0 include/libcamera/internal/meson.build | 3 + include/libcamera/{ => internal}/timer.h | 0 include/libcamera/meson.build | 3 - src/cam/capture.cpp | 9 +++ src/cam/capture.h | 1 + src/cam/event_loop.cpp | 63 ++++++++++++++++--- src/cam/event_loop.h | 24 ++++--- src/cam/main.cpp | 16 ++--- src/cam/meson.build | 13 +++- src/libcamera/camera_manager.cpp | 44 +------------ src/libcamera/device_enumerator_udev.cpp | 3 +- src/libcamera/event_dispatcher.cpp | 2 +- src/libcamera/event_dispatcher_poll.cpp | 5 +- src/libcamera/event_notifier.cpp | 4 +- src/libcamera/ipc_unixsocket.cpp | 3 +- src/libcamera/pipeline/rkisp1/timeline.h | 3 +- src/libcamera/process.cpp | 3 +- .../proxy/worker/ipa_proxy_linux_worker.cpp | 2 +- src/libcamera/thread.cpp | 3 +- src/libcamera/timer.cpp | 4 +- src/libcamera/v4l2_device.cpp | 3 +- src/libcamera/v4l2_videodevice.cpp | 2 +- test/camera/buffer_import.cpp | 8 +-- test/camera/capture.cpp | 9 ++- test/event-dispatcher.cpp | 5 +- test/event-thread.cpp | 5 +- test/event.cpp | 7 +-- test/hotplug-cameras.cpp | 4 +- test/ipa/ipa_interface_test.cpp | 6 +- test/ipc/unixsocket.cpp | 5 +- test/log/log_process.cpp | 4 +- test/object-invoke.cpp | 2 +- test/process/process_test.cpp | 5 +- test/timer-thread.cpp | 5 +- test/timer.cpp | 5 +- test/v4l2_videodevice/buffer_sharing.cpp | 4 +- test/v4l2_videodevice/capture_async.cpp | 4 +- test/v4l2_videodevice/v4l2_m2mdevice.cpp | 4 +- 42 files changed, 159 insertions(+), 142 deletions(-) rename include/libcamera/{ => internal}/event_dispatcher.h (100%) rename include/libcamera/{ => internal}/event_notifier.h (100%) rename include/libcamera/{ => internal}/timer.h (100%)