From patchwork Thu Dec 24 08:15:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 10715 X-Patchwork-Delegate: paul.elder@ideasonboard.com 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 1A23DC0F1A for ; Thu, 24 Dec 2020 08:15:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DC123615B4; Thu, 24 Dec 2020 09:15:48 +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="AyOwCy1s"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2053560525 for ; Thu, 24 Dec 2020 09:15:48 +0100 (CET) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8D1B0A1D; Thu, 24 Dec 2020 09:15:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1608797747; bh=Oo57KEscQYkvO1BeJ3JHiP5sQ75O5M/j/iEKTTTXWsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AyOwCy1sTcZBRyeN1KDRogdl1VU+5QImd+KlFyPRqi3aDOlhP6R/zgKpaG3nK6slH cvg4rjCl1Zap2s2VbGvjLvZAzLNC8TjI3buFhIUujMoo1d7hFAbjERh6u1oWIcMDMi 74VcfxbSwFz78FQvOO0PqPXCOzAoClp0Luf+YMdU= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Dec 2020 17:15:26 +0900 Message-Id: <20201224081534.41601-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201224081534.41601-1-paul.elder@ideasonboard.com> References: <20201224081534.41601-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 1/9] libcamera: control_serializer: Save serialized ControlInfoMap in a cache 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" The ControlSerializer saves all ControlInfoMaps that it has already (de)serialized, in order to (de)serialize ControlLists that contain the ControlInfoMaps. Leverage this to cache ControlInfoMaps, such that the ControlSerializer will not re-(de)serialize a ControlInfoMap that it has previously (de)serialized. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- New in v6 --- .../libcamera/internal/control_serializer.h | 1 + src/libcamera/control_serializer.cpp | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/libcamera/internal/control_serializer.h b/include/libcamera/internal/control_serializer.h index 0ab29d9a..76cb3c10 100644 --- a/include/libcamera/internal/control_serializer.h +++ b/include/libcamera/internal/control_serializer.h @@ -33,6 +33,7 @@ public: template T deserialize(ByteStreamBuffer &buffer); + bool isCached(const ControlInfoMap *infoMap); private: static size_t binarySize(const ControlValue &value); static size_t binarySize(const ControlInfo &info); diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp index 258db6df..4cf1c720 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -173,6 +173,11 @@ void ControlSerializer::store(const ControlInfo &info, ByteStreamBuffer &buffer) int ControlSerializer::serialize(const ControlInfoMap &infoMap, ByteStreamBuffer &buffer) { + if (isCached(&infoMap)) { + LOG(Serializer, Info) << "Serializing ControlInfoMap from cache"; + return 0; + } + /* Compute entries and data required sizes. */ size_t entriesSize = infoMap.size() * sizeof(struct ipa_control_info_entry); @@ -347,6 +352,12 @@ ControlInfoMap ControlSerializer::deserialize(ByteStreamBuffer & return {}; } + auto iter = infoMaps_.find(hdr->handle); + if (iter != infoMaps_.end()) { + LOG(Serializer, Info) << "Deserializing ControlInfoMap from cache"; + return iter->second; + } + if (hdr->version != IPA_CONTROLS_FORMAT_VERSION) { LOG(Serializer, Error) << "Unsupported controls format version " @@ -485,4 +496,23 @@ ControlList ControlSerializer::deserialize(ByteStreamBuffer &buffer return ctrls; } +/** + * \brief Check if some ControlInfoMap is cached + * \param[in] infoMap The ControlInfoMap to check + * + * The ControlSerializer caches all ControlInfoMaps that it has (de)serialized. + * This function checks if \a infoMap is in the cache. + * + * \return True if \a infoMap is in the cache or if \a infoMap is + * controls::controls, false otherwise + */ +bool ControlSerializer::isCached(const ControlInfoMap *infoMap) +{ + if (!infoMap) + return true; + + auto iter = infoMapHandles_.find(infoMap); + return iter != infoMapHandles_.end(); +} + } /* namespace libcamera */