[{"id":36697,"web_url":"https://patchwork.libcamera.org/comment/36697/","msgid":"<5425a43d-e94d-4e17-b59b-04e194e2e280@ideasonboard.com>","date":"2025-11-05T09:08:34","subject":"Re: [PATCH v2] Thread: Add name parameter","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"content":"Hi Kieran\n\nOn 04/11/2025 18:50, Kieran Bingham wrote:\n> From: \"Schulz, Andreas\" <andreas.schulz2@karlstorz.com>\n> \n> For debugging purposes, threads can be assigned a name, which eases\n> distinguishing between them in e.g. htop or gdb. This uses a\n> Linux-specific API for now which is limited to 15 characters (+ null\n> terminator), so truncation is done and names for existing thread\n> instantiations were chosen to be consise.\n> \n> [Kieran: Apply checkstyle suggestions, rebase on proxy rework]\n> Signed-off-by: Schulz, Andreas <andreas.schulz2@karlstorz.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n\nI like the idea. Is there value in warning where users pass a thread name greater than 15 \ncharacters? Either way:\n\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n\n> v2:\n>   - Simplify default name initialiser\n>   - Wrap dmaHeap_\n>   - Add in the VirtualCamera thread\n> \n> Testing on RKISP1:\n> \n> root@debix-som:~# cam -c1 -C^C\n> \n> root@debix-som:~# ps -T -p `pidof cam`\n>      PID    SPID TTY          TIME CMD\n>      332     332 pts/0    00:00:00 cam\n>      332     333 pts/0    00:00:00 CameraManager\n>      332     334 pts/0    00:00:00 IPAProxyRkISP1\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>   include/libcamera/base/thread.h                       |  4 +++-\n>   src/libcamera/base/thread.cpp                         | 11 +++++++++--\n>   src/libcamera/camera_manager.cpp                      |  2 +-\n>   src/libcamera/pipeline/virtual/virtual.cpp            |  2 +-\n>   src/libcamera/software_isp/software_isp.cpp           |  3 ++-\n>   .../libcamera_templates/module_ipa_proxy.cpp.tmpl     |  2 +-\n>   6 files changed, 17 insertions(+), 7 deletions(-)\n> \n> diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h\n> index dc1aca275e23..6aa36fa1bfb0 100644\n> --- a/include/libcamera/base/thread.h\n> +++ b/include/libcamera/base/thread.h\n> @@ -8,6 +8,7 @@\n>   #pragma once\n>   \n>   #include <memory>\n> +#include <string>\n>   #include <sys/types.h>\n>   #include <thread>\n>   \n> @@ -30,7 +31,7 @@ class ThreadMain;\n>   class Thread\n>   {\n>   public:\n> -\tThread();\n> +\tThread(std::string name = {});\n>   \tvirtual ~Thread();\n>   \n>   \tvoid start();\n> @@ -74,6 +75,7 @@ private:\n>   \tvoid moveObject(Object *object, ThreadData *currentData,\n>   \t\t\tThreadData *targetData);\n>   \n> +\tstd::string name_;\n>   \tstd::thread thread_;\n>   \tstd::unique_ptr<ThreadData> data_;\n>   };\n> diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp\n> index 338cbcc260c8..39209ec8ad0d 100644\n> --- a/src/libcamera/base/thread.cpp\n> +++ b/src/libcamera/base/thread.cpp\n> @@ -10,6 +10,7 @@\n>   #include <atomic>\n>   #include <list>\n>   #include <optional>\n> +#include <pthread.h>\n>   #include <sys/syscall.h>\n>   #include <sys/types.h>\n>   #include <unistd.h>\n> @@ -144,6 +145,7 @@ class ThreadMain : public Thread\n>   {\n>   public:\n>   \tThreadMain()\n> +\t\t: Thread(\"libcamera-main\")\n>   \t{\n>   \t\tdata_->running_ = true;\n>   \t}\n> @@ -234,8 +236,9 @@ ThreadData *ThreadData::current()\n>   /**\n>    * \\brief Create a thread\n>    */\n> -Thread::Thread()\n> -\t: data_(std::make_unique<ThreadData>(this))\n> +Thread::Thread(std::string name)\n> +\t: name_(std::move(name)),\n> +\t  data_(std::make_unique<ThreadData>(this))\n>   {\n>   }\n>   \n> @@ -288,6 +291,10 @@ void Thread::startThread()\n>   \tdata_->tid_ = syscall(SYS_gettid);\n>   \tcurrentThreadData = data_.get();\n>   \n> +\tif (!name_.empty())\n> +\t\tpthread_setname_np(thread_.native_handle(),\n> +\t\t\t\t   name_.substr(0, 15).c_str());\n> +\n>   \trun();\n>   }\n>   \n> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\n> index c203b08f7de3..83510e062fae 100644\n> --- a/src/libcamera/camera_manager.cpp\n> +++ b/src/libcamera/camera_manager.cpp\n> @@ -39,7 +39,7 @@ LOG_DEFINE_CATEGORY(Camera)\n>   \n>   #ifndef __DOXYGEN_PUBLIC__\n>   CameraManager::Private::Private()\n> -\t: initialized_(false)\n> +\t: Thread(\"CameraManager\"), initialized_(false)\n>   {\n>   \tipaManager_ = std::make_unique<IPAManager>(this->configuration());\n>   }\n> diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp\n> index 23eae852f79b..09e0afc956fd 100644\n> --- a/src/libcamera/pipeline/virtual/virtual.cpp\n> +++ b/src/libcamera/pipeline/virtual/virtual.cpp\n> @@ -115,7 +115,7 @@ private:\n>   \n>   VirtualCameraData::VirtualCameraData(PipelineHandler *pipe,\n>   \t\t\t\t     const std::vector<Resolution> &supportedResolutions)\n> -\t: Camera::Private(pipe)\n> +\t: Camera::Private(pipe), Thread(\"VirtualCamera\")\n>   {\n>   \tconfig_.resolutions = supportedResolutions;\n>   \tfor (const auto &resolution : config_.resolutions) {\n> diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> index fdadf79e1966..341c0352cf0c 100644\n> --- a/src/libcamera/software_isp/software_isp.cpp\n> +++ b/src/libcamera/software_isp/software_isp.cpp\n> @@ -75,7 +75,8 @@ LOG_DEFINE_CATEGORY(SoftwareIsp)\n>    */\n>   SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n>   \t\t\t ControlInfoMap *ipaControls)\n> -\t: dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n> +\t: ispWorkerThread_(\"SWIspWorker\"),\n> +\t  dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n>   \t\t   DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n>   \t\t   DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n>   {\n> diff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> index 0d03c1df0dd9..e6e19b3030b9 100644\n> --- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> +++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> @@ -46,7 +46,7 @@ namespace {{ns}} {\n>   {%- endif %}\n>   \n>   {{proxy_name}}Threaded::{{proxy_name}}Threaded(IPAModule *ipam, const GlobalConfiguration &configuration)\n> -\t: {{proxy_name}}(ipam, configuration)\n> +\t: {{proxy_name}}(ipam, configuration), thread_(\"{{proxy_name}}\")\n>   {\n>   \tLOG(IPAProxy, Debug)\n>   \t\t<< \"initializing {{module_name}} proxy in thread: loading IPA from \"","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 DB89EBDE4C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Nov 2025 09:08:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5C5E260A80;\n\tWed,  5 Nov 2025 10:08:39 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3A6F8608CF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Nov 2025 10:08:38 +0100 (CET)","from [192.168.0.43]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B2B8E78E;\n\tWed,  5 Nov 2025 10:06:43 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"q0xTecaE\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762333603;\n\tbh=sL+XSt26WFaeyVxiPRqNcDjRcU9mV3U/vcDpe8J5b8o=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=q0xTecaEeB8w5M/GzVszJbYV0+fWDjuF3749oV38U2NH6VviwlMD+FTgmFhyioewT\n\tSkkAaMHOGqbM7KOB0E5gTS8mnMMamlYabb7HHNOnpFBM5PNoWsSw2xbltoEhvBENiZ\n\t1GZfOq9dTf5OrKCh1CjglKTeb0LYsVB6w/OhSAAE=","Message-ID":"<5425a43d-e94d-4e17-b59b-04e194e2e280@ideasonboard.com>","Date":"Wed, 5 Nov 2025 09:08:34 +0000","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2] Thread: Add name parameter","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Cc":"\"Schulz, Andreas\" <andreas.schulz2@karlstorz.com>","References":"<20251104185002.2337556-1-kieran.bingham@ideasonboard.com>","Content-Language":"en-US","From":"Dan Scally <dan.scally@ideasonboard.com>","In-Reply-To":"<20251104185002.2337556-1-kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":36698,"web_url":"https://patchwork.libcamera.org/comment/36698/","msgid":"<176233398698.3742839.12867751989435051163@ping.linuxembedded.co.uk>","date":"2025-11-05T09:13:06","subject":"Re: [PATCH v2] Thread: Add name parameter","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Dan Scally (2025-11-05 09:08:34)\n> Hi Kieran\n> \n> On 04/11/2025 18:50, Kieran Bingham wrote:\n> > From: \"Schulz, Andreas\" <andreas.schulz2@karlstorz.com>\n> > \n> > For debugging purposes, threads can be assigned a name, which eases\n> > distinguishing between them in e.g. htop or gdb. This uses a\n> > Linux-specific API for now which is limited to 15 characters (+ null\n> > terminator), so truncation is done and names for existing thread\n> > instantiations were chosen to be consise.\n> > \n> > [Kieran: Apply checkstyle suggestions, rebase on proxy rework]\n> > Signed-off-by: Schulz, Andreas <andreas.schulz2@karlstorz.com>\n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > \n> > ---\n> \n> I like the idea. Is there value in warning where users pass a thread name greater than 15 \n> characters? Either way:\n\nPossibly - but it's hardcoded at the moment, and if someone adds it then\nit's likely they're looking for it so they'll see.\n\n--\nKieran\n\n> \n> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n\nThanks\n\n\n> \n> > v2:\n> >   - Simplify default name initialiser\n> >   - Wrap dmaHeap_\n> >   - Add in the VirtualCamera thread\n> > \n> > Testing on RKISP1:\n> > \n> > root@debix-som:~# cam -c1 -C^C\n> > \n> > root@debix-som:~# ps -T -p `pidof cam`\n> >      PID    SPID TTY          TIME CMD\n> >      332     332 pts/0    00:00:00 cam\n> >      332     333 pts/0    00:00:00 CameraManager\n> >      332     334 pts/0    00:00:00 IPAProxyRkISP1\n> > \n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > ---\n> >   include/libcamera/base/thread.h                       |  4 +++-\n> >   src/libcamera/base/thread.cpp                         | 11 +++++++++--\n> >   src/libcamera/camera_manager.cpp                      |  2 +-\n> >   src/libcamera/pipeline/virtual/virtual.cpp            |  2 +-\n> >   src/libcamera/software_isp/software_isp.cpp           |  3 ++-\n> >   .../libcamera_templates/module_ipa_proxy.cpp.tmpl     |  2 +-\n> >   6 files changed, 17 insertions(+), 7 deletions(-)\n> > \n> > diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h\n> > index dc1aca275e23..6aa36fa1bfb0 100644\n> > --- a/include/libcamera/base/thread.h\n> > +++ b/include/libcamera/base/thread.h\n> > @@ -8,6 +8,7 @@\n> >   #pragma once\n> >   \n> >   #include <memory>\n> > +#include <string>\n> >   #include <sys/types.h>\n> >   #include <thread>\n> >   \n> > @@ -30,7 +31,7 @@ class ThreadMain;\n> >   class Thread\n> >   {\n> >   public:\n> > -     Thread();\n> > +     Thread(std::string name = {});\n> >       virtual ~Thread();\n> >   \n> >       void start();\n> > @@ -74,6 +75,7 @@ private:\n> >       void moveObject(Object *object, ThreadData *currentData,\n> >                       ThreadData *targetData);\n> >   \n> > +     std::string name_;\n> >       std::thread thread_;\n> >       std::unique_ptr<ThreadData> data_;\n> >   };\n> > diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp\n> > index 338cbcc260c8..39209ec8ad0d 100644\n> > --- a/src/libcamera/base/thread.cpp\n> > +++ b/src/libcamera/base/thread.cpp\n> > @@ -10,6 +10,7 @@\n> >   #include <atomic>\n> >   #include <list>\n> >   #include <optional>\n> > +#include <pthread.h>\n> >   #include <sys/syscall.h>\n> >   #include <sys/types.h>\n> >   #include <unistd.h>\n> > @@ -144,6 +145,7 @@ class ThreadMain : public Thread\n> >   {\n> >   public:\n> >       ThreadMain()\n> > +             : Thread(\"libcamera-main\")\n> >       {\n> >               data_->running_ = true;\n> >       }\n> > @@ -234,8 +236,9 @@ ThreadData *ThreadData::current()\n> >   /**\n> >    * \\brief Create a thread\n> >    */\n> > -Thread::Thread()\n> > -     : data_(std::make_unique<ThreadData>(this))\n> > +Thread::Thread(std::string name)\n> > +     : name_(std::move(name)),\n> > +       data_(std::make_unique<ThreadData>(this))\n> >   {\n> >   }\n> >   \n> > @@ -288,6 +291,10 @@ void Thread::startThread()\n> >       data_->tid_ = syscall(SYS_gettid);\n> >       currentThreadData = data_.get();\n> >   \n> > +     if (!name_.empty())\n> > +             pthread_setname_np(thread_.native_handle(),\n> > +                                name_.substr(0, 15).c_str());\n> > +\n> >       run();\n> >   }\n> >   \n> > diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\n> > index c203b08f7de3..83510e062fae 100644\n> > --- a/src/libcamera/camera_manager.cpp\n> > +++ b/src/libcamera/camera_manager.cpp\n> > @@ -39,7 +39,7 @@ LOG_DEFINE_CATEGORY(Camera)\n> >   \n> >   #ifndef __DOXYGEN_PUBLIC__\n> >   CameraManager::Private::Private()\n> > -     : initialized_(false)\n> > +     : Thread(\"CameraManager\"), initialized_(false)\n> >   {\n> >       ipaManager_ = std::make_unique<IPAManager>(this->configuration());\n> >   }\n> > diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp\n> > index 23eae852f79b..09e0afc956fd 100644\n> > --- a/src/libcamera/pipeline/virtual/virtual.cpp\n> > +++ b/src/libcamera/pipeline/virtual/virtual.cpp\n> > @@ -115,7 +115,7 @@ private:\n> >   \n> >   VirtualCameraData::VirtualCameraData(PipelineHandler *pipe,\n> >                                    const std::vector<Resolution> &supportedResolutions)\n> > -     : Camera::Private(pipe)\n> > +     : Camera::Private(pipe), Thread(\"VirtualCamera\")\n> >   {\n> >       config_.resolutions = supportedResolutions;\n> >       for (const auto &resolution : config_.resolutions) {\n> > diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> > index fdadf79e1966..341c0352cf0c 100644\n> > --- a/src/libcamera/software_isp/software_isp.cpp\n> > +++ b/src/libcamera/software_isp/software_isp.cpp\n> > @@ -75,7 +75,8 @@ LOG_DEFINE_CATEGORY(SoftwareIsp)\n> >    */\n> >   SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n> >                        ControlInfoMap *ipaControls)\n> > -     : dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n> > +     : ispWorkerThread_(\"SWIspWorker\"),\n> > +       dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n> >                  DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n> >                  DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n> >   {\n> > diff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> > index 0d03c1df0dd9..e6e19b3030b9 100644\n> > --- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> > +++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> > @@ -46,7 +46,7 @@ namespace {{ns}} {\n> >   {%- endif %}\n> >   \n> >   {{proxy_name}}Threaded::{{proxy_name}}Threaded(IPAModule *ipam, const GlobalConfiguration &configuration)\n> > -     : {{proxy_name}}(ipam, configuration)\n> > +     : {{proxy_name}}(ipam, configuration), thread_(\"{{proxy_name}}\")\n> >   {\n> >       LOG(IPAProxy, Debug)\n> >               << \"initializing {{module_name}} proxy in thread: loading IPA from \"\n>","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 DDB83C3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Nov 2025 09:13:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DAA0C60A80;\n\tWed,  5 Nov 2025 10:13:11 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 294EC608CF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Nov 2025 10:13:10 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CDCFC7E0;\n\tWed,  5 Nov 2025 10:11:15 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"eWxDgdBN\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762333875;\n\tbh=ZyVSm4OCHaTANenpRu65lYAgmDj+5eWMj8/HrDAu9gs=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=eWxDgdBN7rZDAXTmLDk38wKE5RjAIjk7Mf+rTiGfFb5n7T0VSNstuW0lLAQC04K50\n\t7pGacM+Q7dwD4Ha2VGxiIr5cBlA2SDsjB7TTgIfnl+2HHKwywicThkS7NopMcQ0xZ4\n\tXsDnSWITtUFQOsEVVfBkDMdA4v/Jf1hJpTuuY834=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<5425a43d-e94d-4e17-b59b-04e194e2e280@ideasonboard.com>","References":"<20251104185002.2337556-1-kieran.bingham@ideasonboard.com>\n\t<5425a43d-e94d-4e17-b59b-04e194e2e280@ideasonboard.com>","Subject":"Re: [PATCH v2] Thread: Add name parameter","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"\"Schulz, Andreas\" <andreas.schulz2@karlstorz.com>","To":"Dan Scally <dan.scally@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Wed, 05 Nov 2025 09:13:06 +0000","Message-ID":"<176233398698.3742839.12867751989435051163@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":36701,"web_url":"https://patchwork.libcamera.org/comment/36701/","msgid":"<25f543d9-6d7e-4458-acb8-a8669afddaff@ideasonboard.com>","date":"2025-11-05T09:40:07","subject":"Re: [PATCH v2] Thread: Add name parameter","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2025. 11. 04. 19:50 keltezéssel, Kieran Bingham írta:\n> From: \"Schulz, Andreas\" <andreas.schulz2@karlstorz.com>\n> \n> For debugging purposes, threads can be assigned a name, which eases\n> distinguishing between them in e.g. htop or gdb. This uses a\n> Linux-specific API for now which is limited to 15 characters (+ null\n> terminator), so truncation is done and names for existing thread\n> instantiations were chosen to be consise.\n> \n> [Kieran: Apply checkstyle suggestions, rebase on proxy rework]\n> Signed-off-by: Schulz, Andreas <andreas.schulz2@karlstorz.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> v2:\n>   - Simplify default name initialiser\n>   - Wrap dmaHeap_\n>   - Add in the VirtualCamera thread\n> \n> Testing on RKISP1:\n> \n> root@debix-som:~# cam -c1 -C^C\n> \n> root@debix-som:~# ps -T -p `pidof cam`\n>      PID    SPID TTY          TIME CMD\n>      332     332 pts/0    00:00:00 cam\n>      332     333 pts/0    00:00:00 CameraManager\n>      332     334 pts/0    00:00:00 IPAProxyRkISP1\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>   include/libcamera/base/thread.h                       |  4 +++-\n>   src/libcamera/base/thread.cpp                         | 11 +++++++++--\n>   src/libcamera/camera_manager.cpp                      |  2 +-\n>   src/libcamera/pipeline/virtual/virtual.cpp            |  2 +-\n>   src/libcamera/software_isp/software_isp.cpp           |  3 ++-\n>   .../libcamera_templates/module_ipa_proxy.cpp.tmpl     |  2 +-\n>   6 files changed, 17 insertions(+), 7 deletions(-)\n> \n> diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h\n> index dc1aca275e23..6aa36fa1bfb0 100644\n> --- a/include/libcamera/base/thread.h\n> +++ b/include/libcamera/base/thread.h\n> @@ -8,6 +8,7 @@\n>   #pragma once\n>   \n>   #include <memory>\n> +#include <string>\n>   #include <sys/types.h>\n>   #include <thread>\n>   \n> @@ -30,7 +31,7 @@ class ThreadMain;\n>   class Thread\n>   {\n>   public:\n> -\tThread();\n> +\tThread(std::string name = {});\n>   \tvirtual ~Thread();\n>   \n>   \tvoid start();\n> @@ -74,6 +75,7 @@ private:\n>   \tvoid moveObject(Object *object, ThreadData *currentData,\n>   \t\t\tThreadData *targetData);\n>   \n> +\tstd::string name_;\n>   \tstd::thread thread_;\n>   \tstd::unique_ptr<ThreadData> data_;\n>   };\n> diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp\n> index 338cbcc260c8..39209ec8ad0d 100644\n> --- a/src/libcamera/base/thread.cpp\n> +++ b/src/libcamera/base/thread.cpp\n> @@ -10,6 +10,7 @@\n>   #include <atomic>\n>   #include <list>\n>   #include <optional>\n> +#include <pthread.h>\n>   #include <sys/syscall.h>\n>   #include <sys/types.h>\n>   #include <unistd.h>\n> @@ -144,6 +145,7 @@ class ThreadMain : public Thread\n>   {\n>   public:\n>   \tThreadMain()\n> +\t\t: Thread(\"libcamera-main\")\n\nThis is differently styled than the other names.\n\n\n>   \t{\n>   \t\tdata_->running_ = true;\n>   \t}\n> @@ -234,8 +236,9 @@ ThreadData *ThreadData::current()\n>   /**\n>    * \\brief Create a thread\n>    */\n> -Thread::Thread()\n> -\t: data_(std::make_unique<ThreadData>(this))\n> +Thread::Thread(std::string name)\n> +\t: name_(std::move(name)),\n> +\t  data_(std::make_unique<ThreadData>(this))\n>   {\n>   }\n>   \n> @@ -288,6 +291,10 @@ void Thread::startThread()\n>   \tdata_->tid_ = syscall(SYS_gettid);\n>   \tcurrentThreadData = data_.get();\n>   \n> +\tif (!name_.empty())\n> +\t\tpthread_setname_np(thread_.native_handle(),\n> +\t\t\t\t   name_.substr(0, 15).c_str());\n\nI would've still liked some kind of prefix like \"lc:\" or such.\n\nBut nonetheless\n\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\n\n\n> +\n>   \trun();\n>   }\n>   \n> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\n> index c203b08f7de3..83510e062fae 100644\n> --- a/src/libcamera/camera_manager.cpp\n> +++ b/src/libcamera/camera_manager.cpp\n> @@ -39,7 +39,7 @@ LOG_DEFINE_CATEGORY(Camera)\n>   \n>   #ifndef __DOXYGEN_PUBLIC__\n>   CameraManager::Private::Private()\n> -\t: initialized_(false)\n> +\t: Thread(\"CameraManager\"), initialized_(false)\n>   {\n>   \tipaManager_ = std::make_unique<IPAManager>(this->configuration());\n>   }\n> diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp\n> index 23eae852f79b..09e0afc956fd 100644\n> --- a/src/libcamera/pipeline/virtual/virtual.cpp\n> +++ b/src/libcamera/pipeline/virtual/virtual.cpp\n> @@ -115,7 +115,7 @@ private:\n>   \n>   VirtualCameraData::VirtualCameraData(PipelineHandler *pipe,\n>   \t\t\t\t     const std::vector<Resolution> &supportedResolutions)\n> -\t: Camera::Private(pipe)\n> +\t: Camera::Private(pipe), Thread(\"VirtualCamera\")\n>   {\n>   \tconfig_.resolutions = supportedResolutions;\n>   \tfor (const auto &resolution : config_.resolutions) {\n> diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> index fdadf79e1966..341c0352cf0c 100644\n> --- a/src/libcamera/software_isp/software_isp.cpp\n> +++ b/src/libcamera/software_isp/software_isp.cpp\n> @@ -75,7 +75,8 @@ LOG_DEFINE_CATEGORY(SoftwareIsp)\n>    */\n>   SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n>   \t\t\t ControlInfoMap *ipaControls)\n> -\t: dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n> +\t: ispWorkerThread_(\"SWIspWorker\"),\n> +\t  dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n>   \t\t   DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n>   \t\t   DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n>   {\n> diff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> index 0d03c1df0dd9..e6e19b3030b9 100644\n> --- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> +++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl\n> @@ -46,7 +46,7 @@ namespace {{ns}} {\n>   {%- endif %}\n>   \n>   {{proxy_name}}Threaded::{{proxy_name}}Threaded(IPAModule *ipam, const GlobalConfiguration &configuration)\n> -\t: {{proxy_name}}(ipam, configuration)\n> +\t: {{proxy_name}}(ipam, configuration), thread_(\"{{proxy_name}}\")\n>   {\n>   \tLOG(IPAProxy, Debug)\n>   \t\t<< \"initializing {{module_name}} proxy in thread: loading IPA from \"","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 B0AE0BDE4C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Nov 2025 09:40:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A9C5960A80;\n\tWed,  5 Nov 2025 10:40:13 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 04D2F608CF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Nov 2025 10:40:11 +0100 (CET)","from [192.168.33.40] (185.221.140.239.nat.pool.zt.hu\n\t[185.221.140.239])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 47FA06F3;\n\tWed,  5 Nov 2025 10:38:17 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"DEPMCU9n\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762335497;\n\tbh=3OeBe9/tUYfY2ZHh5XIaLfexvuivi+lvxT5vlArzT3E=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=DEPMCU9nJqV5uabO6OTgtzHIUualVdP4wfhCEDBK5piPSFO32V/OoU/XBZTm98Wft\n\tt45QupcMxrK4cC7qVjZ9lsYVKJ4UwISQ/xXaTbn5wn/uTDu8LNTMoRv2bzcGBUrqW9\n\tVFDEEpP5cqf9Kl2wx3rgMhcPfyyTSWbFfiFko2b0=","Message-ID":"<25f543d9-6d7e-4458-acb8-a8669afddaff@ideasonboard.com>","Date":"Wed, 5 Nov 2025 10:40:07 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2] Thread: Add name parameter","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Cc":"\"Schulz, Andreas\" <andreas.schulz2@karlstorz.com>","References":"<20251104185002.2337556-1-kieran.bingham@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20251104185002.2337556-1-kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]