From patchwork Thu Feb 11 07:17:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 11212 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 05EC0BD16C for ; Thu, 11 Feb 2021 07:18:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B368861646; Thu, 11 Feb 2021 08:18:18 +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="lgtrROOc"; 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 E7417602FD for ; Thu, 11 Feb 2021 08:18:17 +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 272DE41; Thu, 11 Feb 2021 08:18:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1613027897; bh=IOlR6n0a1eflcpQUlZ87GJO5iUDXGsWgfritr/jLdeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lgtrROOcONtX0w7EW36h7JzOppv6CweoMyjepVjtwngSFnMnCfXI0Rx3WE7gCkeyu JHKnCJS5xhl/y3+CBOmEtjtjDgjuKek5p0gfSVzR6qrocgEkysHs8uo5AMJG6P6o2G 7YTaAJatq/V+Pz7Xaq0B3unj2e37BktVaNAmQ4Uw= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Thu, 11 Feb 2021 16:17:56 +0900 Message-Id: <20210211071805.34963-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210211071805.34963-1-paul.elder@ideasonboard.com> References: <20210211071805.34963-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 01/10] 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 --- 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 */