{"id":19105,"url":"https://patchwork.libcamera.org/api/1.1/patches/19105/?format=json","web_url":"https://patchwork.libcamera.org/patch/19105/","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":"<20231006132000.23504-4-naush@raspberrypi.com>","date":"2023-10-06T13:19:43","name":"[libcamera-devel,03/20] pipeline: rpi: Add SharedMemObject class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"d95a40edc775e71ac7913c4c8ecb8008ed43068d","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19105/mbox/","series":[{"id":4047,"url":"https://patchwork.libcamera.org/api/1.1/series/4047/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4047","date":"2023-10-06T13:19:40","name":"Raspberry Pi: Preliminary PiSP support","version":1,"mbox":"https://patchwork.libcamera.org/series/4047/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19105/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19105/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 51EF1C32B7\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Oct 2023 13:20:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9812C6296F;\n\tFri,  6 Oct 2023 15:20:02 +0200 (CEST)","from mail-wr1-x433.google.com (mail-wr1-x433.google.com\n\t[IPv6:2a00:1450:4864:20::433])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3815461DDF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Oct 2023 15:20:00 +0200 (CEST)","by mail-wr1-x433.google.com with SMTP id\n\tffacd0b85a97d-3231dff4343so1329432f8f.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 06 Oct 2023 06:20:00 -0700 (PDT)","from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tm8-20020a056000180800b00321773bb933sm1639478wrh.77.2023.10.06.06.19.58\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 06 Oct 2023 06:19:58 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1696598402;\n\tbh=MrbguUUhWoJ3mvBKCag4gOOpqwweJsmOEDY+C/5I+lA=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=C+Xw2CN3DDx4MBd30F0D49A3hV1oH4eynB05XZfX8RRkhKbWGyPh4OpMT6sxtWJui\n\tA8Q0Oyks7x4rYNOsGVfnRwNoc/1a1fXK1MNqZOC/KF//PnkIyqFAgcdNnss5KjgrPy\n\tQW3CKAs3aT895hxtvmpP7dKSniYXbUlHMAiKe3huDvx0dTnOTn1lccI3Nx9S9kb9kU\n\tOiRsrL7Z0AUV937Wr+3Erhu8ZQrh+z1F3b/gY/L87ydCE4NRU2HEtRPehtqHBND7rU\n\t+WriGWwFWpzGt/2HgDn7HZ9G7Tufb1VsaEehJ/l5WxDKDv+T6RZhb3XVAE8o2V+Moo\n\tUlSiOVx2WiOdQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1696598399; x=1697203199;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=Mfz7taO4zHPB6ZKI/hoU5uhlW/mJ3kymDVPfQGARFmo=;\n\tb=b1/TcgLS+Vv7ucOnboZ0A2yKMEj+JAyirPZ5jpn71lj0cEMDhxy/p/vi7XzyAfT+TB\n\teyKpo2VXOFtPUpEMXE4eSKuTdqqNBXeq/EiMpECJ7dt5ok15ZwFB9isSyeQGaxYggsy7\n\tnIicaYlX5cF5ZEGdtdNMOzs9/viZ2AVrDsoj4vzJbDu0X9IsEJ3KOu4ETEkQO0R8aGOu\n\t4CCEI9VnOdYQzU4h//xhrhAmPg4f/aT/0JfAMawLgfh7i7cipI190WItBBNisJboOKHA\n\tPdqvqPLKBeYRMFwdD9XV6YJC5EsGxAtiaKt3p90BJvW7Jygz7MMpOPbd5+sYf9U/M3tE\n\tVnuA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"b1/TcgLS\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1696598399; x=1697203199;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=Mfz7taO4zHPB6ZKI/hoU5uhlW/mJ3kymDVPfQGARFmo=;\n\tb=ClgR4U330U+QfftNuUCVPklb/PUlkh69hqx9e4dupXgXQSXPyQTHacunousnckEPLs\n\t7sPrtSbBafpWhIS3xU+vim2EsIBlg7hPkpv7buHzASjHDWh4vP/7cGAwJyo4PPlsDhPQ\n\tIshLtKv24D4SIRPsOlCR8tbMNlrYlsKSlZooSVt95rCy6tuKka+ys9KDJNEeH1nKt2dn\n\tb52/6eMwQIkNVsTiHoRoNNznxLwlE44xmE66F3lKR/XjA+GoDNaCo+kiwK2OO5KqTVT9\n\t15c5IUkedZ4ylq0eTACXRFs8EcgqZNTXYYDrOUM7/UquVrrD4bcptpfC5F450Nisq/9g\n\tkiHA==","X-Gm-Message-State":"AOJu0YzPFghpix+r6DcEnOBDWlLaQOC9++1bgH9jjGwJoGh5H+g9W9PH\n\t44QdKfZ/3Mgol9ADiOTXHNYb0zJNsu0NcNZ17SLrLQ==","X-Google-Smtp-Source":"AGHT+IEabilBkvqh33c9tOG7dqXMMyZgFS3aPGRW/p3+IQiBm59gL01aN1cnkXG+miD43C3VqqpxTQ==","X-Received":"by 2002:a5d:55c7:0:b0:321:6339:f523 with SMTP id\n\ti7-20020a5d55c7000000b003216339f523mr4762413wrw.22.1696598399692; \n\tFri, 06 Oct 2023 06:19:59 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  6 Oct 2023 14:19:43 +0100","Message-Id":"<20231006132000.23504-4-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20231006132000.23504-1-naush@raspberrypi.com>","References":"<20231006132000.23504-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 03/20] pipeline: rpi: Add SharedMemObject\n\tclass","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>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add new SharedMemObject class that wraps a memfd memory allocation and\nconstructs a templated object in the memory. With appropriate locking,\nthis object can then be shared across different processes using the\nassociated allocation file handle.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n .../pipeline/rpi/common/shared_mem_object.h   | 118 ++++++++++++++++++\n 1 file changed, 118 insertions(+)\n create mode 100644 src/libcamera/pipeline/rpi/common/shared_mem_object.h","diff":"diff --git a/src/libcamera/pipeline/rpi/common/shared_mem_object.h b/src/libcamera/pipeline/rpi/common/shared_mem_object.h\nnew file mode 100644\nindex 000000000000..69051ecc3f52\n--- /dev/null\n+++ b/src/libcamera/pipeline/rpi/common/shared_mem_object.h\n@@ -0,0 +1,118 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2023, Raspberry Pi Ltd\n+ *\n+ * shared_mem_object.h - Helper class for shared memory allocations\n+ */\n+#pragma once\n+\n+#include <fcntl.h>\n+#include <string>\n+#include <sys/mman.h>\n+#include <sys/stat.h>\n+#include <unistd.h>\n+\n+#include <libcamera/base/class.h>\n+#include <libcamera/base/shared_fd.h>\n+\n+namespace libcamera {\n+\n+namespace RPi {\n+\n+template<class T>\n+class SharedMemObject\n+{\n+public:\n+\tstatic constexpr std::size_t SIZE = sizeof(T);\n+\n+\tSharedMemObject()\n+\t\t: obj_(nullptr)\n+\t{\n+\t}\n+\n+\ttemplate<class... Args>\n+\tSharedMemObject(const std::string &name, Args &&...args)\n+\t\t: name_(name), obj_(nullptr)\n+\t{\n+\t\tvoid *mem;\n+\t\tint ret;\n+\n+\t\tret = memfd_create(name_.c_str(), MFD_CLOEXEC);\n+\t\tif (ret < 0)\n+\t\t\treturn;\n+\n+\t\tfd_ = SharedFD(std::move(ret));\n+\t\tif (!fd_.isValid())\n+\t\t\treturn;\n+\n+\t\tret = ftruncate(fd_.get(), SIZE);\n+\t\tif (ret < 0)\n+\t\t\treturn;\n+\n+\t\tmem = mmap(nullptr, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,\n+\t\t\t   fd_.get(), 0);\n+\t\tif (mem == MAP_FAILED)\n+\t\t\treturn;\n+\n+\t\tobj_ = new (mem) T(std::forward<Args>(args)...);\n+\t}\n+\n+\t~SharedMemObject()\n+\t{\n+\t\tif (obj_) {\n+\t\t\tobj_->~T();\n+\t\t\tmunmap(obj_, SIZE);\n+\t\t}\n+\t}\n+\n+\t/* Make SharedMemObject non-copyable for now. */\n+\tLIBCAMERA_DISABLE_COPY(SharedMemObject)\n+\n+\tSharedMemObject<T> &operator=(SharedMemObject<T> &&rhs)\n+\t{\n+\t\tthis->name_ = std::move(rhs.name_);\n+\t\tthis->fd_ = std::move(rhs.fd_);\n+\t\tthis->obj_ = rhs.obj_;\n+\t\trhs.obj_ = nullptr;\n+\t\treturn *this;\n+\t}\n+\n+\tT *operator->()\n+\t{\n+\t\treturn obj_;\n+\t}\n+\n+\tconst T *operator->() const\n+\t{\n+\t\treturn obj_;\n+\t}\n+\n+\tT &operator*()\n+\t{\n+\t\treturn *obj_;\n+\t}\n+\n+\tconst T &operator*() const\n+\t{\n+\t\treturn *obj_;\n+\t}\n+\n+\tconst SharedFD &fd() const\n+\t{\n+\t\treturn fd_;\n+\t}\n+\n+\texplicit operator bool() const\n+\t{\n+\t\treturn !!obj_;\n+\t}\n+\n+private:\n+\tstd::string name_;\n+\tSharedFD fd_;\n+\tT *obj_;\n+};\n+\n+} /* namespace RPi */\n+\n+} /* namespace libcamera */\n","prefixes":["libcamera-devel","03/20"]}