[{"id":35409,"web_url":"https://patchwork.libcamera.org/comment/35409/","msgid":"<bb057b8c-e599-41b4-ba11-d0ed603dae1e@ideasonboard.com>","date":"2025-08-14T13:16:49","subject":"Re: [PATCH] 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. 08. 14. 15:05 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\nI think this is useful, and I have thought about adding this on multiple occasions.\n\n\n> \n> [Kieran: Apply checkstyle suggestions]\n> Signed-off-by: Schulz, Andreas <andreas.schulz2@karlstorz.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>   include/libcamera/base/thread.h                           | 4 +++-\n>   src/libcamera/base/thread.cpp                             | 8 +++++++-\n>   src/libcamera/camera_manager.cpp                          | 2 +-\n>   src/libcamera/software_isp/software_isp.cpp               | 6 +++---\n>   .../libcamera_templates/module_ipa_proxy.cpp.tmpl         | 2 +-\n>   5 files changed, 15 insertions(+), 7 deletions(-)\n> \n> diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h\n> index b9284c2c0556..56055261e920 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 = std::string());\n\n  = {}\n\n?\n\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>   \tThreadData *data_;\n>   };\n> diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp\n> index d8fe0d6971ec..d016f352a783 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> @@ -140,6 +141,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> @@ -230,7 +232,8 @@ ThreadData *ThreadData::current()\n>   /**\n>    * \\brief Create a thread\n>    */\n> -Thread::Thread()\n> +Thread::Thread(std::string name)\n> +\t: name_(std::move(name))\n>   {\n>   \tdata_ = new ThreadData;\n>   \tdata_->thread_ = this;\n> @@ -286,6 +289,9 @@ void Thread::startThread()\n>   \tdata_->tid_ = syscall(SYS_gettid);\n>   \tcurrentThreadData = data_;\n>   \n> +\tif (!name_.empty())\n> +\t\tpthread_setname_np(thread_.native_handle(), name_.substr(0, 15).c_str());\n\nI am not sure but I believe enforcing short prefix, e.g. \"lc:\", would be very useful. E.g.\n\n   char n[16] = {};\n   snprintf(n, sizeof(n), \"lc:%.12s\", name_.c_str());\n   pthread_setname_np(...);\n\n\nAnother small question is whether the availability of `pthread_setname_np` should be checked.\n\n\nRegards,\nBarnabás Pőcze\n\n\n> +\n>   \trun();\n>   }\n>   \n> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\n> index f81794bfd6fe..a42835c18739 100644\n> --- a/src/libcamera/camera_manager.cpp\n> +++ b/src/libcamera/camera_manager.cpp\n> @@ -38,7 +38,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>();\n>   }\n> diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> index 28e2a360e7e6..b2f6cf61b646 100644\n> --- a/src/libcamera/software_isp/software_isp.cpp\n> +++ b/src/libcamera/software_isp/software_isp.cpp\n> @@ -75,9 +75,9 @@ 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\t   DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n> -\t\t   DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n> +\t: ispWorkerThread_(\"SWIspWorker\"), dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n> +\t\t\t\t\t\t    DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n> +\t\t\t\t\t\t    DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n>   {\n>   \t/*\n>   \t * debayerParams_ must be initialized because the initial value is used for\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 beb646e2d157..7d2d510f5a79 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}}::{{proxy_name}}(IPAModule *ipam, bool isolate)\n> -\t: IPAProxy(ipam), isolate_(isolate),\n> +\t: IPAProxy(ipam), thread_(\"{{proxy_name}}\"), isolate_(isolate),\n>   \t  controlSerializer_(ControlSerializer::Role::Proxy), seq_(0)\n>   {\n>   \tLOG(IPAProxy, Debug)","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 75286BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 14 Aug 2025 13:16:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 594F469254;\n\tThu, 14 Aug 2025 15:16:54 +0200 (CEST)","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 17E6861444\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 14 Aug 2025 15:16:53 +0200 (CEST)","from [192.168.33.15] (185.221.141.188.nat.pool.zt.hu\n\t[185.221.141.188])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 769776DF;\n\tThu, 14 Aug 2025 15:15:58 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"qGx1Xk2V\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755177358;\n\tbh=SB3f2S3uzE9PXmjXrZfWB3k9FCsBNYKmexlRQYT/5Gs=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=qGx1Xk2Veb5xCqCv7q49fbRrkPuntFYdsZav35HbywRMhvRA+1LYWRhkXcgbcOGWj\n\tKqIoouKIPa341dc5e8enAt4ohh++hs74pEEa8V4i8/gpne7cukuvg4eP4TG1h9lmPT\n\thDKTll6ATt188P0whN/uHthYqcjs/9xCIKcAom84=","Message-ID":"<bb057b8c-e599-41b4-ba11-d0ed603dae1e@ideasonboard.com>","Date":"Thu, 14 Aug 2025 15:16:49 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] 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":"<20250814130534.1125903-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":"<20250814130534.1125903-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>"}},{"id":35414,"web_url":"https://patchwork.libcamera.org/comment/35414/","msgid":"<20250814151707.GB23634@pendragon.ideasonboard.com>","date":"2025-08-14T15:17:07","subject":"Re: [PATCH] Thread: Add name parameter","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Thu, Aug 14, 2025 at 03:16:49PM +0200, Barnabás Pőcze wrote:\n> 2025. 08. 14. 15:05 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> I think this is useful, and I have thought about adding this on\n> multiple occasions.\n> \n> > [Kieran: Apply checkstyle suggestions]\n> > Signed-off-by: Schulz, Andreas <andreas.schulz2@karlstorz.com>\n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > ---\n> >   include/libcamera/base/thread.h                           | 4 +++-\n> >   src/libcamera/base/thread.cpp                             | 8 +++++++-\n> >   src/libcamera/camera_manager.cpp                          | 2 +-\n> >   src/libcamera/software_isp/software_isp.cpp               | 6 +++---\n> >   .../libcamera_templates/module_ipa_proxy.cpp.tmpl         | 2 +-\n> >   5 files changed, 15 insertions(+), 7 deletions(-)\n> > \n> > diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h\n> > index b9284c2c0556..56055261e920 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 = std::string());\n> \n>   = {}\n> \n> ?\n> \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> >   \tThreadData *data_;\n> >   };\n> > diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp\n> > index d8fe0d6971ec..d016f352a783 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> > @@ -140,6 +141,7 @@ class ThreadMain : public Thread\n> >   {\n> >   public:\n> >   \tThreadMain()\n> > +\t\t: Thread(\"libcamera-main\")\n\nThis will never appear anywhere, so I wouldn't give it a name.\n\n> >   \t{\n> >   \t\tdata_->running_ = true;\n> >   \t}\n> > @@ -230,7 +232,8 @@ ThreadData *ThreadData::current()\n> >   /**\n> >    * \\brief Create a thread\n> >    */\n> > -Thread::Thread()\n> > +Thread::Thread(std::string name)\n> > +\t: name_(std::move(name))\n> >   {\n> >   \tdata_ = new ThreadData;\n> >   \tdata_->thread_ = this;\n> > @@ -286,6 +289,9 @@ void Thread::startThread()\n> >   \tdata_->tid_ = syscall(SYS_gettid);\n> >   \tcurrentThreadData = data_;\n> >   \n> > +\tif (!name_.empty())\n> > +\t\tpthread_setname_np(thread_.native_handle(), name_.substr(0, 15).c_str());\n\nIsn't name.substr(0, 15).c_str() unsafe ?\n\n> I am not sure but I believe enforcing short prefix, e.g. \"lc:\", would\n> be very useful. E.g.\n> \n>    char n[16] = {};\n>    snprintf(n, sizeof(n), \"lc:%.12s\", name_.c_str());\n>    pthread_setname_np(...);\n\nI'd be tempted to use\n\n\t\"lc:%.12s\", typeid(*this).name()\n\n(probably stripping the \"struct\" or \"class\" prefixes) to make all this\nautomatic. Names could get too long though.\n\n> Another small question is whether the availability of\n> `pthread_setname_np` should be checked.\n\nWe already use pthread_setaffinity_np(), I suppose that either both or\nnone would be available ?\n\n> > +\n> >   \trun();\n> >   }\n> >   \n> > diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\n> > index f81794bfd6fe..a42835c18739 100644\n> > --- a/src/libcamera/camera_manager.cpp\n> > +++ b/src/libcamera/camera_manager.cpp\n> > @@ -38,7 +38,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>();\n> >   }\n> > diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> > index 28e2a360e7e6..b2f6cf61b646 100644\n> > --- a/src/libcamera/software_isp/software_isp.cpp\n> > +++ b/src/libcamera/software_isp/software_isp.cpp\n> > @@ -75,9 +75,9 @@ 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\t   DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n> > -\t\t   DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n> > +\t: ispWorkerThread_(\"SWIspWorker\"), dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n> > +\t\t\t\t\t\t    DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n> > +\t\t\t\t\t\t    DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n\nLine wrap before dmaHeap_.\n\n> >   {\n> >   \t/*\n> >   \t * debayerParams_ must be initialized because the initial value is used for\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 beb646e2d157..7d2d510f5a79 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}}::{{proxy_name}}(IPAModule *ipam, bool isolate)\n> > -\t: IPAProxy(ipam), isolate_(isolate),\n> > +\t: IPAProxy(ipam), thread_(\"{{proxy_name}}\"), isolate_(isolate),\n> >   \t  controlSerializer_(ControlSerializer::Role::Proxy), seq_(0)\n> >   {\n> >   \tLOG(IPAProxy, Debug)","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 27EA4BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 14 Aug 2025 15:17:30 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 20AD369254;\n\tThu, 14 Aug 2025 17:17:29 +0200 (CEST)","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 71C6E61444\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 14 Aug 2025 17:17:27 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 928066DF;\n\tThu, 14 Aug 2025 17:16:32 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"iNxgOmxp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755184592;\n\tbh=iWIBQ739qVceZZqQYFY3yn2vUZ+sbNGwmFI+4UNndSw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=iNxgOmxpmKrtGPGPqSSDA2ptBbPkz5plJ9IA0HJvH7f76HfJE7/f/JLSJkLyfdL4y\n\tsY5AazCyD7rQdosm2T19ihOhXSTrgDWa7GKdRIqcwoPS80W8gq9rbPn9u+tCzcOwFM\n\t5uDnJthOE6ZYcDMawk8jeSInu+rZWX4Ta8ArS2kg=","Date":"Thu, 14 Aug 2025 18:17:07 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>,\n\t\"Schulz, Andreas\" <andreas.schulz2@karlstorz.com>","Subject":"Re: [PATCH] Thread: Add name parameter","Message-ID":"<20250814151707.GB23634@pendragon.ideasonboard.com>","References":"<20250814130534.1125903-1-kieran.bingham@ideasonboard.com>\n\t<bb057b8c-e599-41b4-ba11-d0ed603dae1e@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<bb057b8c-e599-41b4-ba11-d0ed603dae1e@ideasonboard.com>","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":35415,"web_url":"https://patchwork.libcamera.org/comment/35415/","msgid":"<0c4baf2f-f983-4fae-894f-2aaa044165e6@ideasonboard.com>","date":"2025-08-14T15:30:09","subject":"Re: [PATCH] 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":"2025. 08. 14. 17:17 keltezéssel, Laurent Pinchart írta:\n> On Thu, Aug 14, 2025 at 03:16:49PM +0200, Barnabás Pőcze wrote:\n>> 2025. 08. 14. 15:05 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>> I think this is useful, and I have thought about adding this on\n>> multiple occasions.\n>>\n>>> [Kieran: Apply checkstyle suggestions]\n>>> Signed-off-by: Schulz, Andreas <andreas.schulz2@karlstorz.com>\n>>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>>> ---\n>>>    include/libcamera/base/thread.h                           | 4 +++-\n>>>    src/libcamera/base/thread.cpp                             | 8 +++++++-\n>>>    src/libcamera/camera_manager.cpp                          | 2 +-\n>>>    src/libcamera/software_isp/software_isp.cpp               | 6 +++---\n>>>    .../libcamera_templates/module_ipa_proxy.cpp.tmpl         | 2 +-\n>>>    5 files changed, 15 insertions(+), 7 deletions(-)\n>>>\n>>> diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h\n>>> index b9284c2c0556..56055261e920 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 = std::string());\n>>\n>>    = {}\n>>\n>> ?\n>>\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>>>    \tThreadData *data_;\n>>>    };\n>>> diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp\n>>> index d8fe0d6971ec..d016f352a783 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>>> @@ -140,6 +141,7 @@ class ThreadMain : public Thread\n>>>    {\n>>>    public:\n>>>    \tThreadMain()\n>>> +\t\t: Thread(\"libcamera-main\")\n> \n> This will never appear anywhere, so I wouldn't give it a name.\n\nI suppose it could still be useful when manually inspecting the object\nin a debugger.\n\n\n> \n>>>    \t{\n>>>    \t\tdata_->running_ = true;\n>>>    \t}\n>>> @@ -230,7 +232,8 @@ ThreadData *ThreadData::current()\n>>>    /**\n>>>     * \\brief Create a thread\n>>>     */\n>>> -Thread::Thread()\n>>> +Thread::Thread(std::string name)\n>>> +\t: name_(std::move(name))\n>>>    {\n>>>    \tdata_ = new ThreadData;\n>>>    \tdata_->thread_ = this;\n>>> @@ -286,6 +289,9 @@ void Thread::startThread()\n>>>    \tdata_->tid_ = syscall(SYS_gettid);\n>>>    \tcurrentThreadData = data_;\n>>>    \n>>> +\tif (!name_.empty())\n>>> +\t\tpthread_setname_np(thread_.native_handle(), name_.substr(0, 15).c_str());\n> \n> Isn't name.substr(0, 15).c_str() unsafe ?\n\nI don't think so. `std::string::substr()` creates a temporary string, but that is only\ndestroyed at the end of the full expression, so it will be valid during the pthread call.\n\n\n> \n>> I am not sure but I believe enforcing short prefix, e.g. \"lc:\", would\n>> be very useful. E.g.\n>>\n>>     char n[16] = {};\n>>     snprintf(n, sizeof(n), \"lc:%.12s\", name_.c_str());\n>>     pthread_setname_np(...);\n> \n> I'd be tempted to use\n> \n> \t\"lc:%.12s\", typeid(*this).name()\n> \n> (probably stripping the \"struct\" or \"class\" prefixes) to make all this\n> automatic. Names could get too long though.\n\nI feel like an explicit name could be better in certain cases, especially\nin a more complex inheritance hierarchy with templates. I suppose the type\nid could be the fallback.\n\n\n> \n>> Another small question is whether the availability of\n>> `pthread_setname_np` should be checked.\n> \n> We already use pthread_setaffinity_np(), I suppose that either both or\n> none would be available ?\n\nAhh, ok, then I guess it's fine.\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 f81794bfd6fe..a42835c18739 100644\n>>> --- a/src/libcamera/camera_manager.cpp\n>>> +++ b/src/libcamera/camera_manager.cpp\n>>> @@ -38,7 +38,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>();\n>>>    }\n>>> diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n>>> index 28e2a360e7e6..b2f6cf61b646 100644\n>>> --- a/src/libcamera/software_isp/software_isp.cpp\n>>> +++ b/src/libcamera/software_isp/software_isp.cpp\n>>> @@ -75,9 +75,9 @@ 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\t   DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n>>> -\t\t   DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n>>> +\t: ispWorkerThread_(\"SWIspWorker\"), dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n>>> +\t\t\t\t\t\t    DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n>>> +\t\t\t\t\t\t    DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n> \n> Line wrap before dmaHeap_.\n> \n>>>    {\n>>>    \t/*\n>>>    \t * debayerParams_ must be initialized because the initial value is used for\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 beb646e2d157..7d2d510f5a79 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}}::{{proxy_name}}(IPAModule *ipam, bool isolate)\n>>> -\t: IPAProxy(ipam), isolate_(isolate),\n>>> +\t: IPAProxy(ipam), thread_(\"{{proxy_name}}\"), isolate_(isolate),\n>>>    \t  controlSerializer_(ControlSerializer::Role::Proxy), seq_(0)\n>>>    {\n>>>    \tLOG(IPAProxy, Debug)\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 03A10BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 14 Aug 2025 15:30:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CC9B269254;\n\tThu, 14 Aug 2025 17:30:13 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F18CC61444\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 14 Aug 2025 17:30:12 +0200 (CEST)","from [192.168.33.15] (185.221.141.188.nat.pool.zt.hu\n\t[185.221.141.188])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 215746DF;\n\tThu, 14 Aug 2025 17:29:18 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"IydP2Ve+\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755185358;\n\tbh=lCU1mQ9tT00D57iEK3pUEaGgQn8lGzWP/9HicQOnnE0=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=IydP2Ve+jaSZM5hVswtVw/kg96Dpi3uzReQAq1VD/SikCk1CdEvR7Idqhenyao2N2\n\t2f89N+CNJg42rkL09mfuLIZjHCTBmyabGTQ8eS+y+5R2zFB8zFezW4Fu/9ffRrFzAe\n\tPozei5tg+weLTt+AzBQMeGAegoqPD/a7fkeSnzyo=","Message-ID":"<0c4baf2f-f983-4fae-894f-2aaa044165e6@ideasonboard.com>","Date":"Thu, 14 Aug 2025 17:30:09 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] Thread: Add name parameter","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>,\n\t\"Schulz, Andreas\" <andreas.schulz2@karlstorz.com>","References":"<20250814130534.1125903-1-kieran.bingham@ideasonboard.com>\n\t<bb057b8c-e599-41b4-ba11-d0ed603dae1e@ideasonboard.com>\n\t<20250814151707.GB23634@pendragon.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":"<20250814151707.GB23634@pendragon.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>"}},{"id":36689,"web_url":"https://patchwork.libcamera.org/comment/36689/","msgid":"<176227968983.3742839.8311910983622107609@ping.linuxembedded.co.uk>","date":"2025-11-04T18:08:09","subject":"Re: [PATCH] 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 Barnabás Pőcze (2025-08-14 16:30:09)\n> 2025. 08. 14. 17:17 keltezéssel, Laurent Pinchart írta:\n> > On Thu, Aug 14, 2025 at 03:16:49PM +0200, Barnabás Pőcze wrote:\n> >> 2025. 08. 14. 15:05 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> >> I think this is useful, and I have thought about adding this on\n> >> multiple occasions.\n> >>\n> >>> [Kieran: Apply checkstyle suggestions]\n> >>> Signed-off-by: Schulz, Andreas <andreas.schulz2@karlstorz.com>\n> >>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> >>> ---\n> >>>    include/libcamera/base/thread.h                           | 4 +++-\n> >>>    src/libcamera/base/thread.cpp                             | 8 +++++++-\n> >>>    src/libcamera/camera_manager.cpp                          | 2 +-\n> >>>    src/libcamera/software_isp/software_isp.cpp               | 6 +++---\n> >>>    .../libcamera_templates/module_ipa_proxy.cpp.tmpl         | 2 +-\n> >>>    5 files changed, 15 insertions(+), 7 deletions(-)\n> >>>\n> >>> diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h\n> >>> index b9284c2c0556..56055261e920 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 = std::string());\n> >>\n> >>    = {}\n> >>\n> >> ?\n\nDone.\n\n> >>\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> >>>     ThreadData *data_;\n> >>>    };\n> >>> diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp\n> >>> index d8fe0d6971ec..d016f352a783 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> >>> @@ -140,6 +141,7 @@ class ThreadMain : public Thread\n> >>>    {\n> >>>    public:\n> >>>     ThreadMain()\n> >>> +           : Thread(\"libcamera-main\")\n> > \n> > This will never appear anywhere, so I wouldn't give it a name.\n> \n> I suppose it could still be useful when manually inspecting the object\n> in a debugger.\n\nI'd like to keep this one in too.\n\n> \n> \n> > \n> >>>     {\n> >>>             data_->running_ = true;\n> >>>     }\n> >>> @@ -230,7 +232,8 @@ ThreadData *ThreadData::current()\n> >>>    /**\n> >>>     * \\brief Create a thread\n> >>>     */\n> >>> -Thread::Thread()\n> >>> +Thread::Thread(std::string name)\n> >>> +   : name_(std::move(name))\n> >>>    {\n> >>>     data_ = new ThreadData;\n> >>>     data_->thread_ = this;\n> >>> @@ -286,6 +289,9 @@ void Thread::startThread()\n> >>>     data_->tid_ = syscall(SYS_gettid);\n> >>>     currentThreadData = data_;\n> >>>    \n> >>> +   if (!name_.empty())\n> >>> +           pthread_setname_np(thread_.native_handle(), name_.substr(0, 15).c_str());\n> > \n> > Isn't name.substr(0, 15).c_str() unsafe ?\n> \n> I don't think so. `std::string::substr()` creates a temporary string, but that is only\n> destroyed at the end of the full expression, so it will be valid during the pthread call.\n> \n> \n> > \n> >> I am not sure but I believe enforcing short prefix, e.g. \"lc:\", would\n> >> be very useful. E.g.\n> >>\n> >>     char n[16] = {};\n> >>     snprintf(n, sizeof(n), \"lc:%.12s\", name_.c_str());\n> >>     pthread_setname_np(...);\n> > \n> > I'd be tempted to use\n> > \n> >       \"lc:%.12s\", typeid(*this).name()\n> > \n> > (probably stripping the \"struct\" or \"class\" prefixes) to make all this\n> > automatic. Names could get too long though.\n> \n> I feel like an explicit name could be better in certain cases, especially\n> in a more complex inheritance hierarchy with templates. I suppose the type\n> id could be the fallback.\n\nI liked the idea of automatically populating the thread name from the\nobject - but I don't think it's going to be helpful:\n\n[367:48:04.502587188] [2207769] ERROR Thread thread.cpp:306 Setting thread name to N9libcamera13Ca from N9libcamera13CameraManager7PrivateE\n\n\nThat might be difficult to demangle in a generic way that will always\nget a short and obvious type...\n\nAny suggestions? Otherwise I think I would only set them if supplied.\n\n\n> >> Another small question is whether the availability of\n> >> `pthread_setname_np` should be checked.\n> > \n> > We already use pthread_setaffinity_np(), I suppose that either both or\n> > none would be available ?\n> \n> Ahh, ok, then I guess it's fine.\n> \n> \n> > \n> >>> +\n> >>>     run();\n> >>>    }\n> >>>    \n> >>> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\n> >>> index f81794bfd6fe..a42835c18739 100644\n> >>> --- a/src/libcamera/camera_manager.cpp\n> >>> +++ b/src/libcamera/camera_manager.cpp\n> >>> @@ -38,7 +38,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>();\n> >>>    }\n> >>> diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\n> >>> index 28e2a360e7e6..b2f6cf61b646 100644\n> >>> --- a/src/libcamera/software_isp/software_isp.cpp\n> >>> +++ b/src/libcamera/software_isp/software_isp.cpp\n> >>> @@ -75,9 +75,9 @@ LOG_DEFINE_CATEGORY(SoftwareIsp)\n> >>>     */\n> >>>    SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n> >>>                      ControlInfoMap *ipaControls)\n> >>> -   : dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n> >>> -              DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n> >>> -              DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n> >>> +   : ispWorkerThread_(\"SWIspWorker\"), dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n> >>> +                                               DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n> >>> +                                               DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n> > \n> > Line wrap before dmaHeap_.\n\nAck.\n\n--\nKieran\n\n\n> > \n> >>>    {\n> >>>     /*\n> >>>      * debayerParams_ must be initialized because the initial value is used for\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 beb646e2d157..7d2d510f5a79 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}}::{{proxy_name}}(IPAModule *ipam, bool isolate)\n> >>> -   : IPAProxy(ipam), isolate_(isolate),\n> >>> +   : IPAProxy(ipam), thread_(\"{{proxy_name}}\"), isolate_(isolate),\n> >>>       controlSerializer_(ControlSerializer::Role::Proxy), seq_(0)\n> >>>    {\n> >>>     LOG(IPAProxy, Debug)\n> > \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 EC25FC3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  4 Nov 2025 18:08:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2D0FC60A9D;\n\tTue,  4 Nov 2025 19:08:14 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 63B996069A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  4 Nov 2025 19:08:13 +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 73EC71771;\n\tTue,  4 Nov 2025 19:06:19 +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=\"vSynC/1d\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762279579;\n\tbh=bSNyVLSU/o3Ot6fD2ovhbHakw0xYOJbVs9vVBSjKAf8=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=vSynC/1dzi928tX/D6eUReTP8kgOnsJZGpS+V6ydpCGkXbhDYBvvRMIQ5jLoXNue1\n\t13ufUyKQ+aKycc8uM2oyVSm5tk4r99yGGsrp7FUU1AqmPyQpMIoKV5ZuvQ/p+i4HoN\n\twowmSmqowR2VrVIT6PxYjVNnLVSfXEXdbl7vek+8=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<0c4baf2f-f983-4fae-894f-2aaa044165e6@ideasonboard.com>","References":"<20250814130534.1125903-1-kieran.bingham@ideasonboard.com>\n\t<bb057b8c-e599-41b4-ba11-d0ed603dae1e@ideasonboard.com>\n\t<20250814151707.GB23634@pendragon.ideasonboard.com>\n\t<0c4baf2f-f983-4fae-894f-2aaa044165e6@ideasonboard.com>","Subject":"Re: [PATCH] Thread: Add name parameter","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>, \"Schulz,\n\tAndreas\" <andreas.schulz2@karlstorz.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","Date":"Tue, 04 Nov 2025 18:08:09 +0000","Message-ID":"<176227968983.3742839.8311910983622107609@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":36690,"web_url":"https://patchwork.libcamera.org/comment/36690/","msgid":"<e9ca45c4-5326-4505-a10e-f799d2f3ae69@ideasonboard.com>","date":"2025-11-04T18:15:51","subject":"Re: [PATCH] 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":"2025. 11. 04. 19:08 keltezéssel, Kieran Bingham írta:\n> Quoting Barnabás Pőcze (2025-08-14 16:30:09)\n>> 2025. 08. 14. 17:17 keltezéssel, Laurent Pinchart írta:\n>>> On Thu, Aug 14, 2025 at 03:16:49PM +0200, Barnabás Pőcze wrote:\n>>>> 2025. 08. 14. 15:05 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>>>> I think this is useful, and I have thought about adding this on\n>>>> multiple occasions.\n>>>>\n>>>>> [Kieran: Apply checkstyle suggestions]\n>>>>> Signed-off-by: Schulz, Andreas <andreas.schulz2@karlstorz.com>\n>>>>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>>>>> ---\n>>>>>     include/libcamera/base/thread.h                           | 4 +++-\n>>>>>     src/libcamera/base/thread.cpp                             | 8 +++++++-\n>>>>>     src/libcamera/camera_manager.cpp                          | 2 +-\n>>>>>     src/libcamera/software_isp/software_isp.cpp               | 6 +++---\n>>>>>     .../libcamera_templates/module_ipa_proxy.cpp.tmpl         | 2 +-\n>>>>>     5 files changed, 15 insertions(+), 7 deletions(-)\n>>>>>\n> [...]\n>>>>> -Thread::Thread()\n>>>>> +Thread::Thread(std::string name)\n>>>>> +   : name_(std::move(name))\n>>>>>     {\n>>>>>      data_ = new ThreadData;\n>>>>>      data_->thread_ = this;\n>>>>> @@ -286,6 +289,9 @@ void Thread::startThread()\n>>>>>      data_->tid_ = syscall(SYS_gettid);\n>>>>>      currentThreadData = data_;\n>>>>>     \n>>>>> +   if (!name_.empty())\n>>>>> +           pthread_setname_np(thread_.native_handle(), name_.substr(0, 15).c_str());\n>>>\n>>> Isn't name.substr(0, 15).c_str() unsafe ?\n>>\n>> I don't think so. `std::string::substr()` creates a temporary string, but that is only\n>> destroyed at the end of the full expression, so it will be valid during the pthread call.\n>>\n>>\n>>>\n>>>> I am not sure but I believe enforcing short prefix, e.g. \"lc:\", would\n>>>> be very useful. E.g.\n>>>>\n>>>>      char n[16] = {};\n>>>>      snprintf(n, sizeof(n), \"lc:%.12s\", name_.c_str());\n>>>>      pthread_setname_np(...);\n>>>\n>>> I'd be tempted to use\n>>>\n>>>        \"lc:%.12s\", typeid(*this).name()\n>>>\n>>> (probably stripping the \"struct\" or \"class\" prefixes) to make all this\n>>> automatic. Names could get too long though.\n>>\n>> I feel like an explicit name could be better in certain cases, especially\n>> in a more complex inheritance hierarchy with templates. I suppose the type\n>> id could be the fallback.\n> \n> I liked the idea of automatically populating the thread name from the\n> object - but I don't think it's going to be helpful:\n> \n> [367:48:04.502587188] [2207769] ERROR Thread thread.cpp:306 Setting thread name to N9libcamera13Ca from N9libcamera13CameraManager7PrivateE\n> \n> \n> That might be difficult to demangle in a generic way that will always\n> get a short and obvious type...\n> \n> Any suggestions? Otherwise I think I would only set them if supplied.\n> [...]\n\nI am not really proposing this, but there is `__cxxabiv1::__cxa_demangle()`\nin the c++ runtime to demangle names. But still, the length constraint probably\nmakes anything automatic but still simple not too useful. I was thinking about\nusing the address of the object in absence of a name, but not entirely sure\nabout the implications.\n\n\nRegards,\nBarnabás Pőcze","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 19383BDE4C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  4 Nov 2025 18:15:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 56CF760856;\n\tTue,  4 Nov 2025 19:15:58 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1F1D66069A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  4 Nov 2025 19:15:56 +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 A579B1838;\n\tTue,  4 Nov 2025 19:14:01 +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=\"Hh7j2rmM\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762280041;\n\tbh=OUP9ZVY+ZPhLpeAH2LZ/SRrCfont8RVtxHLYE6IxRBg=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=Hh7j2rmMtse5yTZXAvwYtKjBUhh+SAXsh1mMc5N5MVUPobed3My29OEg6doL7Cktu\n\t7PXvb1ytgD+hdsEfVWCnA4CuoV5lzRxDyeW4BDTri9I+AywlpH4au08mtLMiXCTSud\n\tpSzGYuBRQEA7l+1NRCsd35fxCzg4R8HxOEd2KuPY=","Message-ID":"<e9ca45c4-5326-4505-a10e-f799d2f3ae69@ideasonboard.com>","Date":"Tue, 4 Nov 2025 19:15:51 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] Thread: Add name parameter","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>,\n\t\"Schulz, Andreas\" <andreas.schulz2@karlstorz.com>","References":"<20250814130534.1125903-1-kieran.bingham@ideasonboard.com>\n\t<bb057b8c-e599-41b4-ba11-d0ed603dae1e@ideasonboard.com>\n\t<20250814151707.GB23634@pendragon.ideasonboard.com>\n\t<0c4baf2f-f983-4fae-894f-2aaa044165e6@ideasonboard.com>\n\t<176227968983.3742839.8311910983622107609@ping.linuxembedded.co.uk>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<176227968983.3742839.8311910983622107609@ping.linuxembedded.co.uk>","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>"}}]