{"id":3000,"url":"https://patchwork.libcamera.org/api/1.1/patches/3000/?format=json","web_url":"https://patchwork.libcamera.org/patch/3000/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200306160002.30549-29-laurent.pinchart@ideasonboard.com>","date":"2020-03-06T15:59:58","name":"[libcamera-devel,v2,28/32] libcamera: control_serializer: Use zero-copy ByteStreamBuffer::read()","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"b5d63b7c735589447a380d5ede9ec0b8814a0dc1","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3000/mbox/","series":[{"id":703,"url":"https://patchwork.libcamera.org/api/1.1/series/703/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=703","date":"2020-03-06T15:59:30","name":"libcamera: Add support for array controls","version":2,"mbox":"https://patchwork.libcamera.org/series/703/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3000/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3000/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 20C6C628DF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Mar 2020 17:00:27 +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 B084024B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Mar 2020 17:00:26 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1583510426;\n\tbh=L3GkoxDy2u5cprwdKxL8JS9B3xvdJtsEZwIpKK1Jeqg=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=TByOm/HRlkoLU/FEmMzplIORcpZLV9wn3TO+yHTRmRq7Fa2kzWae27UHMd72CHFSP\n\tSDvWTa2CuVdZqplS8+KR6VcEimZGJZeHgFllHYHpUw/isjg4F1V5t5OgUSsMYuzs7f\n\tQlJ8MI9yquEZE5ul+wbZAMgNjdZM+ShPSpUdp5aQ=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  6 Mar 2020 17:59:58 +0200","Message-Id":"<20200306160002.30549-29-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.24.1","In-Reply-To":"<20200306160002.30549-1-laurent.pinchart@ideasonboard.com>","References":"<20200306160002.30549-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 28/32] libcamera: control_serializer:\n\tUse zero-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":"Fri, 06 Mar 2020 16:00:28 -0000"},"content":"Use the zero-copy variant of ByteStreamBuffer::read() to read packet\nheaders and control entries. This enhances the performance of\nControlList and ControlInfoMap 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>\nReviewed-by: Kieran Bingham <kieran.binghm@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 997e87bec817..b4c1ed410b92 100644\n--- a/src/libcamera/control_serializer.cpp\n+++ b/src/libcamera/control_serializer.cpp\n@@ -366,39 +366,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@@ -414,8 +421,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@@ -432,21 +439,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@@ -458,10 +468,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@@ -476,19 +486,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","v2","28/32"]}