[{"id":1781,"web_url":"https://patchwork.libcamera.org/comment/1781/","msgid":"<20190606100313.GF12825@pendragon.ideasonboard.com>","date":"2019-06-06T10:03:13","subject":"Re: [libcamera-devel] [RFC PATCH 06/10] libcamera: ipa_manager: add\n\tshims","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Wed, Jun 05, 2019 at 06:18:13PM -0400, Paul Elder wrote:\n> Make IPAManager load shim shared objects in addition to IPA module\n> shared objects, and keep them in a shims list. When requested for an\n> IPA, if the IPA requires isolation, wrap the IPA in the first shim that\n> is available.\n\nI think we need to start documenting this somewhere. It deals with the\nlibcamera architecture, so Documentation/ could be an option. Otherwise\nthe file block at the top of ipa_manager.cpp is another candidate.\n\nI also think that we should take a bit of time to evaluate the other\navailable options. Reading you patch I was wondering if we should build\nthe shims in libcamera instead of loading them dynamically. I'm not\nsaying it is a better option, but we should evaluate the pros and cons.\nOne point that we should keep in mind is that which shim to load will\nlikely come from a configuration file, but it could also be useful if we\ncould detect automatically which shims are or are not suitable for the\nplatform (for instance to automatically use the Android shim on\nAndroid).\n\n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> ---\n>  src/libcamera/include/ipa_manager.h |  1 +\n>  src/libcamera/ipa_manager.cpp       | 34 +++++++++++++++++++++++++++--\n>  2 files changed, 33 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/include/ipa_manager.h b/src/libcamera/include/ipa_manager.h\n> index 310ce7c..a0fb8ad 100644\n> --- a/src/libcamera/include/ipa_manager.h\n> +++ b/src/libcamera/include/ipa_manager.h\n> @@ -28,6 +28,7 @@ public:\n>  \n>  private:\n>  \tstd::vector<IPAModule *> modules_;\n> +\tstd::vector<IPAModule *> shims_;\n>  \n>  \tIPAManager();\n>  \t~IPAManager();\n> diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp\n> index f689aa6..3648ea6 100644\n> --- a/src/libcamera/ipa_manager.cpp\n> +++ b/src/libcamera/ipa_manager.cpp\n> @@ -110,7 +110,10 @@ int IPAManager::addDir(const char *libDir)\n>  \t\t\tcontinue;\n>  \t\t}\n>  \n> -\t\tmodules_.push_back(ipaModule);\n> +\t\tif (!strncmp(ipaModule->info().pipelineName, \"Shim\", 4))\n> +\t\t\tshims_.push_back(ipaModule);\n> +\t\telse\n> +\t\t\tmodules_.push_back(ipaModule);\n>  \t\tcount++;\n>  \t}\n>  \n> @@ -132,6 +135,7 @@ std::unique_ptr<IPAInterface> IPAManager::createIPA(PipelineHandler *pipe,\n>  \t\t\t\t\t\t    uint32_t minVersion)\n>  {\n>  \tIPAModule *m = nullptr;\n> +\tIPAModule *shim = nullptr;\n\nYou can declare this variable below when assigning it.\n\n>  \n>  \tfor (IPAModule *module : modules_) {\n>  \t\tif (module->match(pipe, minVersion, maxVersion)) {\n> @@ -140,7 +144,33 @@ std::unique_ptr<IPAInterface> IPAManager::createIPA(PipelineHandler *pipe,\n>  \t\t}\n>  \t}\n>  \n> -\tif (!m || !m->load())\n> +\tif (!m)\n> +\t\treturn nullptr;\n> +\n> +\tif (m->info().isolate) {\n> +\t\tif (shims_.empty()) {\n> +\t\t\tLOG(IPAManager, Error) << \"No shims available\";\n> +\t\t\treturn nullptr;\n> +\t\t}\n> +\n> +\t\tshim = shims_.front();\n> +\t\tif (!shim || !shim->load()) {\n\nI don't think shim can be nullptr here, otherwise the shims_.empty()\ncheck above would have triggered.\n\n> +\t\t\tLOG(IPAManager, Error) << \"Failed to obtain shim\";\n> +\t\t\treturn nullptr;\n> +\t\t}\n> +\n> +\t\tauto shimIPAIntf = shim->createInstance();\n\nWe usually try to type out types explicitly instead of using auto,\nexcept when it would be very inconvenient.\n\n\t\tstd::unique_ptr<IPAInterface> shimIPAIntf = shim->createInstance();\n\ndoesn't look that bad. And I think I would even name the variable just\nintf (or interface).\n\n> +\t\tif (!shimIPAIntf) {\n> +\t\t\tLOG(IPAManager, Error) << \"Failed to load shim\";\n> +\t\t\treturn nullptr;\n> +\t\t}\n> +\n> +\t\tshimIPAIntf->init(m->path());\n> +\n> +\t\treturn shimIPAIntf;\n> +\t}\n> +\n> +\tif (!m->load())\n>  \t\treturn nullptr;\n>  \n>  \treturn m->createInstance();","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 E363D67BC8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  6 Jun 2019 12:03:27 +0200 (CEST)","from pendragon.ideasonboard.com (unknown\n\t[IPv6:2a02:a03f:44f0:8500:ca05:8177:199c:fed4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8B4FD33B;\n\tThu,  6 Jun 2019 12:03:27 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1559815407;\n\tbh=8tlRZxtOwxcUtVHS0KDy6aCMU4O7eUU3n/t/Z3kYcdo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=eHzV2y1AAE6MNN1Lr4wW1fK/nyglfzC1692H87F+ovOYluoerAQWM5PUpNcqK8ZOb\n\teSC+K8Lt1ZSBIspsFGdThVFntfDwtLMXKC34tBaPe/582fqmFTzjQ6HiF2PnMyPhPZ\n\tip6/RUwcdqfSchj5qx9Z+gIc2jfmpfH9+XdXq/Uc=","Date":"Thu, 6 Jun 2019 13:03:13 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190606100313.GF12825@pendragon.ideasonboard.com>","References":"<20190605221817.966-1-paul.elder@ideasonboard.com>\n\t<20190605221817.966-7-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190605221817.966-7-paul.elder@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [RFC PATCH 06/10] libcamera: ipa_manager: add\n\tshims","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Thu, 06 Jun 2019 10:03:28 -0000"}}]