From patchwork Wed Apr 6 12:35:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15631 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 BD0EDC3260 for ; Wed, 6 Apr 2022 12:36:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 72A8C6564B; Wed, 6 Apr 2022 14:36:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1649248563; bh=kKNc5Avk2FwJqil3H/Ajhco1kcD2GEiIOR6YERdfC3w=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ACtARnAiQamw9OrgsXnyS/xwL7s+maSKnYrg2odyj3Yn98jrdnvnE794XvGP2Ugab 61T/+jL+oo2ATvqvRmfG6NZscIu12W4HEsbdD5WGB1yj0mZt22d60ckZMjnBPGa/gS cbuMPnOTwbcnMpWFJ+Vch4SuisrZQhpdpauEBGlBc0GdCmmm7A4wMzJuQiCIfjnv2i VPLRh0owEjUfvLf5vDd8Aq2DDIYKRvJGtWTiPH1oneF0lDK0vIoZ4TcWlt08jEs0n0 s38UUjKaM/3igay+XFCeZlXA1ijKjfu6iSUTThYpznxpqCExKXeG3wFhE0rsePCnaJ d/tPzJia8E0Xw== Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D18806563F for ; Wed, 6 Apr 2022 14:36:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="FwG4CY0x"; dkim-atps=neutral Received: by mail-wr1-x432.google.com with SMTP id h4so2951855wrc.13 for ; Wed, 06 Apr 2022 05:36:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aUJNEmkQe0GZ1+awdCYosUGZvagdGaLqZ5bpdZXMy/A=; b=FwG4CY0xbNhpGMIAdY+csElcjE44wRQSnc3mXeCWvtZC7LoJbVaAppyHVfc1xMe95A BpYUqq6j5juv88DdrVvxwbfxOtU7MwgpjaiAz5e1K5g9hS6X8pfI+Fd6nd0Aci7LRt9v TM/Qrt19RUR+zy4tIGuLlgVPi1ny8apB3GgiduNZ3OurJjMwO+aQ3N90PTx3td4f+ALG mv18JcyIIqtfrgH5gQzgqyB5HNogCQgbKPQK50u7oHS9m7USw2jmbONDC1FnNmazWueS 75JXYUFkjqS4ht9z3QYOL2YbAvuLYuBROGnS7ddgEYmMSzFF/N54WdHqvOhVKTP+8sUS 7SXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aUJNEmkQe0GZ1+awdCYosUGZvagdGaLqZ5bpdZXMy/A=; b=TC3kcEyHTFZqrxsnc7Iyy9HlaOX4VhIYLicBFL94DDF15lj9t+Z2/0+lHYPX6qbYfs BfTbxi0vSmrv4Ssty0IVQxXDEexg9w9nHtBIQaW+O8Jew+ysn7ORcIBzAAuQe2AmWF/H ErWU6Nj1hMHiRaznkcsMORRDIQR52PgM5ab1jNkW4++ITzUcg+/XqPSackG/EXtv9M+Q Lw33T+DJvMCbwrjP0UiXoDxyGAbcxcUdBjar5cWidg5Cb71mvVHXwpcet4oLz3YmepP3 a1aGmwEkM/hcd0OVQVufzs4fDWwTkGfPa8vgaKO44fO+T9XY5liYVmBEZvAH7kg+enj3 4D5Q== X-Gm-Message-State: AOAM531MFyEhMeAEV3BaaouCc16z9KzjfT9UYbBzJVFcLNU7ssCNr7Y0 uVGQvIehtRGiNULF+oz1qw3HnDV6IsHWTA== X-Google-Smtp-Source: ABdhPJyrIM6tMur4XOLwlsA+DBms++eBgHtNPEAmligcVWCrS+TSBtdcfGWEq4xDBZK7NGDsMc9sAw== X-Received: by 2002:a5d:44ca:0:b0:206:893:6b5c with SMTP id z10-20020a5d44ca000000b0020608936b5cmr6528487wrr.145.1649248561095; Wed, 06 Apr 2022 05:36:01 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:8464:e7f5:f44c:ee9f]) by smtp.gmail.com with ESMTPSA id p8-20020a5d59a8000000b00204178688d3sm16712490wrr.100.2022.04.06.05.35.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:36:00 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Apr 2022 13:35:52 +0100 Message-Id: <20220406123554.4042163-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220406123554.4042163-1-naush@raspberrypi.com> References: <20220406123554.4042163-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 1/3] libcamera: v4l2_videodevice: Add a dequeue timer 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: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a timer that gets reset on every buffer dequeue event. If the timeout expires, optionally call a slot in the pipeline handler to handle this condition. This may be useful in detecting and handling stalls in either the hardware or device driver. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_videodevice.h | 10 ++++ src/libcamera/v4l2_videodevice.cpp | 53 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index cfeae7bd6c52..9c9493cc16ed 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include #include @@ -217,6 +219,9 @@ public: int streamOn(); int streamOff(); + void setDequeueTimeout(utils::Duration timeout); + Signal<> dequeueTimeout; + static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); @@ -253,6 +258,8 @@ private: void bufferAvailable(); FrameBuffer *dequeueBuffer(); + void watchdogExpired(); + V4L2Capability caps_; V4L2DeviceFormat format_; const PixelFormatInfo *formatInfo_; @@ -266,6 +273,9 @@ private: EventNotifier *fdBufferNotifier_; State state_; + + Timer watchdog_; + utils::Duration watchdogDuration_; }; class V4L2M2MDevice diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 0830be80c553..c3a1b6c42e19 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -539,6 +539,7 @@ V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode) V4L2VideoDevice::V4L2VideoDevice(const MediaEntity *entity) : V4L2VideoDevice(entity->deviceNode()) { + watchdog_.timeout.connect(this, &V4L2VideoDevice::watchdogExpired); } V4L2VideoDevice::~V4L2VideoDevice() @@ -1726,6 +1727,9 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() return nullptr; } + if (watchdogDuration_.count()) + watchdog_.start(std::chrono::duration_cast(watchdogDuration_)); + cache_->put(buf.index); FrameBuffer *buffer = it->second; @@ -1828,6 +1832,8 @@ int V4L2VideoDevice::streamOn() } state_ = State::Streaming; + if (watchdogDuration_.count()) + watchdog_.start(std::chrono::duration_cast(watchdogDuration_)); return 0; } @@ -1852,6 +1858,9 @@ int V4L2VideoDevice::streamOff() if (state_ != State::Streaming && queuedBuffers_.empty()) return 0; + if (watchdogDuration_.count()) + watchdog_.stop(); + ret = ioctl(VIDIOC_STREAMOFF, &bufferType_); if (ret < 0) { LOG(V4L2, Error) @@ -1879,6 +1888,50 @@ int V4L2VideoDevice::streamOff() return 0; } +/** + * \brief Set the dequeue timeout value + * \param[in] timeout The timeout value to be used + * + * Sets a timeout value, given by \a timeout, that will be used by a watchdog + * timer to ensure buffer dequeue events are periodically occurring when the + * device is streaming. The watchdog timer is only active when the device is + * streaming, so it is not necessary to disable it when the device stops + * streaming. The timeout value can be safely updated at any time. + * + * If the timer expires, the \ref V4L2VideoDevice::dequeueTimeout signal is + * emitted. This can typically be used by pipeline handlers to be notified of + * stalled devices. + * + * Set \a timeout to 0 to disable the watchdog timer. + */ +void V4L2VideoDevice::setDequeueTimeout(utils::Duration timeout) +{ + watchdogDuration_ = timeout; + + watchdog_.stop(); + if (watchdogDuration_.count() && state_ == State::Streaming) + watchdog_.start(std::chrono::duration_cast(timeout)); +} + +/** + * \var V4L2VideoDevice::dequeueTimeout + * \brief A Signal emitted when the dequeue watchdog timer expires + */ + +/** + * \brief Slot to handle an expired dequeue timer + * + * When this slot is called, the time between successive dequeue events is over + * the required timeout. Emit the \ref V4L2VideoDevice::dequeueTimeout signal. + */ +void V4L2VideoDevice::watchdogExpired() +{ + LOG(V4L2, Warning) + << "Dequeue timer of " << watchdogDuration_ << " has expired!"; + + dequeueTimeout.emit(); +} + /** * \brief Create a new video device instance from \a entity in media device * \a media