From patchwork Sat Feb 13 04:21:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 11270 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 A1BFDBD160 for ; Sat, 13 Feb 2021 04:21:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6E1C76379C; Sat, 13 Feb 2021 05:21:57 +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="F+XTiskZ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A0063601B5 for ; Sat, 13 Feb 2021 05:21:56 +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 CC7B2564; Sat, 13 Feb 2021 05:21:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1613190116; bh=GxefxIu9ca3pEvL0EXu4uR85bO3gYt38u/mytUDU+oc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F+XTiskZzPQubi2pB8Hi2J0PT/OJ+2tqhTI2tH+tizKwrv2ZXxq9N6KEdGR94jdtA IdJgldcfCdT8WQywD0nrm9QpO9xeG6iajX2/ul0s7Z5hF0aCcVWIjBsk0ulUOo3Fc9 rK3CbPvmiwEbnfiPDU1B3TG9cstHjIlMxy4okVLs= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Sat, 13 Feb 2021 13:21:35 +0900 Message-Id: <20210213042143.112361-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210213042143.112361-1-paul.elder@ideasonboard.com> References: <20210213042143.112361-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 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 --- No change in v8 Changes in v7: - log cache status to Debug instead of Info - fix doc wording - pass const reference to isCached instead of const pointer - simplify isCached implementation New in v6 --- .../libcamera/internal/control_serializer.h | 2 ++ src/libcamera/control_serializer.cpp | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/libcamera/internal/control_serializer.h b/include/libcamera/internal/control_serializer.h index 0ab29d9a..7d4426c9 100644 --- a/include/libcamera/internal/control_serializer.h +++ b/include/libcamera/internal/control_serializer.h @@ -33,6 +33,8 @@ 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..09744413 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -173,6 +173,12 @@ void ControlSerializer::store(const ControlInfo &info, ByteStreamBuffer &buffer) int ControlSerializer::serialize(const ControlInfoMap &infoMap, ByteStreamBuffer &buffer) { + if (isCached(infoMap)) { + LOG(Serializer, Debug) + << "Skipping already serialized ControlInfoMap"; + return 0; + } + /* Compute entries and data required sizes. */ size_t entriesSize = infoMap.size() * sizeof(struct ipa_control_info_entry); @@ -347,6 +353,12 @@ ControlInfoMap ControlSerializer::deserialize(ByteStreamBuffer & return {}; } + auto iter = infoMaps_.find(hdr->handle); + if (iter != infoMaps_.end()) { + LOG(Serializer, Debug) << "Use cached ControlInfoMap"; + return iter->second; + } + if (hdr->version != IPA_CONTROLS_FORMAT_VERSION) { LOG(Serializer, Error) << "Unsupported controls format version " @@ -485,4 +497,18 @@ ControlList ControlSerializer::deserialize(ByteStreamBuffer &buffer return ctrls; } +/** + * \brief Check if a 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 false otherwise + */ +bool ControlSerializer::isCached(const ControlInfoMap &infoMap) +{ + return infoMapHandles_.count(&infoMap); +} + } /* namespace libcamera */