Patch Detail
Show a patch.
GET /api/1.1/patches/2943/?format=api
{ "id": 2943, "url": "https://patchwork.libcamera.org/api/1.1/patches/2943/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2943/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200229164254.23604-27-laurent.pinchart@ideasonboard.com>", "date": "2020-02-29T16:42:49", "name": "[libcamera-devel,26/31] libcamera: control_serializer: Use zero-copy ByteStreamBuffer::read()", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "b5d63b7c735589447a380d5ede9ec0b8814a0dc1", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/2943/mbox/", "series": [ { "id": 696, "url": "https://patchwork.libcamera.org/api/1.1/series/696/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=696", "date": "2020-02-29T16:42:23", "name": "libcamera: Add support for array controls", "version": 1, "mbox": "https://patchwork.libcamera.org/series/696/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2943/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2943/checks/", "tags": {}, "headers": { "Return-Path": "<laurent.pinchart@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6E4376278C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 29 Feb 2020 17:43:31 +0100 (CET)", "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1205D33E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 29 Feb 2020 17:43:31 +0100 (CET)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1582994611;\n\tbh=FbhM2pKsf9zAPJD/WdkQfCaXmIBrLIK1B+8/o/+OiWo=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=DWHl/Y+AyZWzwQULaMbSlIwXkoCVEhrgRRebolpCDKWsD9SG9JDhidxV6wNaUEWX8\n\tpvkvohK+jMElq0mWymyfKfmAAI9TMpNfGYnO4uSEdr3j1zeP6+4jOK/nqJi/4EfwD1\n\tbupk/qBKA5gMoQpDHpe+Waw8BwZZyPpq5q6F0wPU=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 29 Feb 2020 18:42:49 +0200", "Message-Id": "<20200229164254.23604-27-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.24.1", "In-Reply-To": "<20200229164254.23604-1-laurent.pinchart@ideasonboard.com>", "References": "<20200229164254.23604-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 26/31] libcamera: control_serializer: Use\n\tzero-copy ByteStreamBuffer::read()", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "X-List-Received-Date": "Sat, 29 Feb 2020 16:43:36 -0000" }, "content": "Use the zero-copy variant of ByteStreamBuffer::read() to read packet\nhaders and control entries. This enhance performance of ControlList and\nControlInfoMap deserialization.\n\nDeserialization of the actual ControlValue is untouched for now and will\nbe optimized later.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/control_serializer.cpp | 74 +++++++++++++++++-----------\n 1 file changed, 44 insertions(+), 30 deletions(-)", "diff": "diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp\nindex dc87b96f384b..6cac70739468 100644\n--- a/src/libcamera/control_serializer.cpp\n+++ b/src/libcamera/control_serializer.cpp\n@@ -364,39 +364,46 @@ ControlRange ControlSerializer::load<ControlRange>(ControlType type,\n template<>\n ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &buffer)\n {\n-\tstruct ipa_controls_header hdr;\n-\tbuffer.read(&hdr);\n+\tconst struct ipa_controls_header *hdr = buffer.read<decltype(*hdr)>();\n+\tif (!hdr) {\n+\t\tLOG(Serializer, Error) << \"Out of data\";\n+\t\treturn {};\n+\t}\n \n-\tif (hdr.version != IPA_CONTROLS_FORMAT_VERSION) {\n+\tif (hdr->version != IPA_CONTROLS_FORMAT_VERSION) {\n \t\tLOG(Serializer, Error)\n \t\t\t<< \"Unsupported controls format version \"\n-\t\t\t<< hdr.version;\n+\t\t\t<< hdr->version;\n \t\treturn {};\n \t}\n \n-\tByteStreamBuffer entries = buffer.carveOut(hdr.data_offset - sizeof(hdr));\n-\tByteStreamBuffer values = buffer.carveOut(hdr.size - hdr.data_offset);\n+\tByteStreamBuffer entries = buffer.carveOut(hdr->data_offset - sizeof(*hdr));\n+\tByteStreamBuffer values = buffer.carveOut(hdr->size - hdr->data_offset);\n \n \tif (buffer.overflow()) {\n-\t\tLOG(Serializer, Error) << \"Serialized packet too small\";\n+\t\tLOG(Serializer, Error) << \"Out of data\";\n \t\treturn {};\n \t}\n \n \tControlInfoMap::Map ctrls;\n \n-\tfor (unsigned int i = 0; i < hdr.entries; ++i) {\n-\t\tstruct ipa_control_range_entry entry;\n-\t\tentries.read(&entry);\n+\tfor (unsigned int i = 0; i < hdr->entries; ++i) {\n+\t\tconst struct ipa_control_range_entry *entry =\n+\t\t\tentries.read<decltype(*entry)>();\n+\t\tif (!entry) {\n+\t\t\tLOG(Serializer, Error) << \"Out of data\";\n+\t\t\treturn {};\n+\t\t}\n \n \t\t/* Create and cache the individual ControlId. */\n-\t\tControlType type = static_cast<ControlType>(entry.type);\n+\t\tControlType type = static_cast<ControlType>(entry->type);\n \t\t/**\n \t\t * \\todo Find a way to preserve the control name for debugging\n \t\t * purpose.\n \t\t */\n-\t\tcontrolIds_.emplace_back(std::make_unique<ControlId>(entry.id, \"\", type));\n+\t\tcontrolIds_.emplace_back(std::make_unique<ControlId>(entry->id, \"\", type));\n \n-\t\tif (entry.offset != values.offset()) {\n+\t\tif (entry->offset != values.offset()) {\n \t\t\tLOG(Serializer, Error)\n \t\t\t\t<< \"Bad data, entry offset mismatch (entry \"\n \t\t\t\t<< i << \")\";\n@@ -412,8 +419,8 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &\n \t * Create the ControlInfoMap in the cache, and store the map to handle\n \t * association.\n \t */\n-\tControlInfoMap &map = infoMaps_[hdr.handle] = std::move(ctrls);\n-\tinfoMapHandles_[&map] = hdr.handle;\n+\tControlInfoMap &map = infoMaps_[hdr->handle] = std::move(ctrls);\n+\tinfoMapHandles_[&map] = hdr->handle;\n \n \treturn map;\n }\n@@ -430,21 +437,24 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &\n template<>\n ControlList ControlSerializer::deserialize<ControlList>(ByteStreamBuffer &buffer)\n {\n-\tstruct ipa_controls_header hdr;\n-\tbuffer.read(&hdr);\n+\tconst struct ipa_controls_header *hdr = buffer.read<decltype(*hdr)>();\n+\tif (!hdr) {\n+\t\tLOG(Serializer, Error) << \"Out of data\";\n+\t\treturn {};\n+\t}\n \n-\tif (hdr.version != IPA_CONTROLS_FORMAT_VERSION) {\n+\tif (hdr->version != IPA_CONTROLS_FORMAT_VERSION) {\n \t\tLOG(Serializer, Error)\n \t\t\t<< \"Unsupported controls format version \"\n-\t\t\t<< hdr.version;\n+\t\t\t<< hdr->version;\n \t\treturn {};\n \t}\n \n-\tByteStreamBuffer entries = buffer.carveOut(hdr.data_offset - sizeof(hdr));\n-\tByteStreamBuffer values = buffer.carveOut(hdr.size - hdr.data_offset);\n+\tByteStreamBuffer entries = buffer.carveOut(hdr->data_offset - sizeof(*hdr));\n+\tByteStreamBuffer values = buffer.carveOut(hdr->size - hdr->data_offset);\n \n \tif (buffer.overflow()) {\n-\t\tLOG(Serializer, Error) << \"Serialized packet too small\";\n+\t\tLOG(Serializer, Error) << \"Out of data\";\n \t\treturn {};\n \t}\n \n@@ -456,10 +466,10 @@ ControlList ControlSerializer::deserialize<ControlList>(ByteStreamBuffer &buffer\n \t * use the global control::control idmap.\n \t */\n \tconst ControlInfoMap *infoMap;\n-\tif (hdr.handle) {\n+\tif (hdr->handle) {\n \t\tauto iter = std::find_if(infoMapHandles_.begin(), infoMapHandles_.end(),\n \t\t\t\t\t [&](decltype(infoMapHandles_)::value_type &entry) {\n-\t\t\t\t\t\t return entry.second == hdr.handle;\n+\t\t\t\t\t\t return entry.second == hdr->handle;\n \t\t\t\t\t });\n \t\tif (iter == infoMapHandles_.end()) {\n \t\t\tLOG(Serializer, Error)\n@@ -474,19 +484,23 @@ ControlList ControlSerializer::deserialize<ControlList>(ByteStreamBuffer &buffer\n \n \tControlList ctrls(infoMap ? infoMap->idmap() : controls::controls);\n \n-\tfor (unsigned int i = 0; i < hdr.entries; ++i) {\n-\t\tstruct ipa_control_value_entry entry;\n-\t\tentries.read(&entry);\n+\tfor (unsigned int i = 0; i < hdr->entries; ++i) {\n+\t\tconst struct ipa_control_value_entry *entry =\n+\t\t\tentries.read<decltype(*entry)>();\n+\t\tif (!entry) {\n+\t\t\tLOG(Serializer, Error) << \"Out of data\";\n+\t\t\treturn {};\n+\t\t}\n \n-\t\tif (entry.offset != values.offset()) {\n+\t\tif (entry->offset != values.offset()) {\n \t\t\tLOG(Serializer, Error)\n \t\t\t\t<< \"Bad data, entry offset mismatch (entry \"\n \t\t\t\t<< i << \")\";\n \t\t\treturn {};\n \t\t}\n \n-\t\tControlType type = static_cast<ControlType>(entry.type);\n-\t\tctrls.set(entry.id, load<ControlValue>(type, values));\n+\t\tControlType type = static_cast<ControlType>(entry->type);\n+\t\tctrls.set(entry->id, load<ControlValue>(type, values));\n \t}\n \n \treturn ctrls;\n", "prefixes": [ "libcamera-devel", "26/31" ] }