Patch Detail
Show a patch.
GET /api/patches/22456/?format=api
{ "id": 22456, "url": "https://patchwork.libcamera.org/api/patches/22456/?format=api", "web_url": "https://patchwork.libcamera.org/patch/22456/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20250107144141.3416094-1-chenghaoyang@chromium.org>", "date": "2025-01-07T14:41:37", "name": "[v2] Thread: Fix setThreadAffinity race condition in start", "commit_ref": "d49a84a4f3aa63efc900564ff32558e4f5d85b04", "pull_url": null, "state": "accepted", "archived": false, "hash": "0cd427fef2f78475a1c6a33b504877ac9a479b53", "submitter": { "id": 117, "url": "https://patchwork.libcamera.org/api/people/117/?format=api", "name": "Cheng-Hao Yang", "email": "chenghaoyang@chromium.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/22456/mbox/", "series": [ { "id": 4931, "url": "https://patchwork.libcamera.org/api/series/4931/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4931", "date": "2025-01-07T14:41:37", "name": "[v2] Thread: Fix setThreadAffinity race condition in start", "version": 2, "mbox": "https://patchwork.libcamera.org/series/4931/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/22456/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/22456/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 309EEC32DC\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 7 Jan 2025 14:41:51 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2BD9B684E2;\n\tTue, 7 Jan 2025 15:41:50 +0100 (CET)", "from mail-pl1-x631.google.com (mail-pl1-x631.google.com\n\t[IPv6:2607:f8b0:4864:20::631])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 59D2B684CD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 7 Jan 2025 15:41:48 +0100 (CET)", "by mail-pl1-x631.google.com with SMTP id\n\td9443c01a7336-21649a7bcdcso222336925ad.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 07 Jan 2025 06:41:48 -0800 (PST)", "from chenghaoyang-low.c.googlers.com.com\n\t(21.160.199.104.bc.googleusercontent.com. [104.199.160.21])\n\tby smtp.gmail.com with ESMTPSA id\n\td9443c01a7336-219dc96e867sm313355965ad.71.2025.01.07.06.41.45\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 07 Jan 2025 06:41:46 -0800 (PST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"lkdjYUMc\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1736260906; x=1736865706;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=lEJs8QbGX1h8G/RP+rIHsVRX37JJ+I5a9diiDBxG02E=;\n\tb=lkdjYUMcmOu5G+lpRGvfbC7kyEkx1ZrtAaJI5/wLcVNKCFI6Xaq5O85rq3JF34+Buf\n\tUZNoP7sHIv+850oQiCozvTc8iu6bcwHBy/N7PTPMz7VMxdDCk3XaGZMnURQ6Mvn1OFtD\n\tr/FqCCFi5PRR4cQsH/uZmKJ10mejyYj3v11c8=", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1736260906; x=1736865706;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=lEJs8QbGX1h8G/RP+rIHsVRX37JJ+I5a9diiDBxG02E=;\n\tb=uNw2UIA+d8SLoBJyy88H8BwpRBd1N9VafK31fpiKb4OgRK7Xtg/tCcQ9XY4BuL2t7+\n\tC5hHIjt/AaPD50gWHgnCCWi1zbLQY8MkO67Jv4u25J1hAVgc4qMNgcfgxhIJPhxKzLly\n\txxUky/dgWVgSLQzE4zoNIfy2CWbrnDYTvK0wJXP9CmLH5aDGqCQJxSWr0UKgKEuWKOvz\n\tmMZjI8Imwubddw7LRMFedzoHQNpw5dCNpgcQNCQ9nvEJeOP2iBsBTWckblxZ8B/Y8YXu\n\t5Evvoy31rZ0MIbtvJtR+sqXkRZmdGxlp6B625veSHonkT/s7bt1lgPZRrNj26VouX0jA\n\t9c4w==", "X-Gm-Message-State": "AOJu0Yys3vQDeEC0TZ8coGKAzZW6nsGsuz3ROxb2rQ7p+pjwZlhJ08Ie\n\tX+eVFcgS6O4NVi0KLQ8IULu/s6sLCmsIywxyLZhjA3B5Ll8RI+xKDn7HiFWGVSnAj8l7/M4PADU\n\t=", "X-Gm-Gg": "ASbGncsckBmOjhbH8k32OBvdEKqi1O/j3krtJoF6BVSoxM/OSfMWpKHfgAaJGPhaTdC\n\tehOuE+fuIZ0bPSo2BDpEMj+FmG9U2HCJMA60crWKpJwIxCAAL2sH+mWaZV3+AE0fy4SnQJd/6Oz\n\tlFy0EeyCxdIH/taklQFN/ieS2R+loL489ye1hiYBhxK1QTbtZ6ddHkxhX+jC+Oh6/DDEc1CX0tM\n\twA47xXNTxPY73zyGbQo82ddNZvLKt6rvJL2iOQ92bF2Qij8lBD4F2xd/W+mK8WV8DkF7v5pE/cA\n\tN2Jxv2ynflETWBThNs4A1EbbCs9xbiw/BCr6XFmYr7MMkDlKygZ3AJLQ6sLFduE=", "X-Google-Smtp-Source": "AGHT+IEao42DQFq+Br6SSZ2i+cLJegtZROqMJQVXEGVWuQf4D+Uo1vV/Qcpq43O41o6oUUZhWZFeSg==", "X-Received": "by 2002:a17:902:e5cc:b0:215:577b:ab77 with SMTP id\n\td9443c01a7336-219e70bf185mr889076745ad.39.1736260906575; \n\tTue, 07 Jan 2025 06:41:46 -0800 (PST)", "From": "Harvey Yang <chenghaoyang@chromium.org>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Harvey Yang <chenghaoyang@chromium.org>", "Subject": "[PATCH v2] Thread: Fix setThreadAffinity race condition in start", "Date": "Tue, 7 Jan 2025 14:41:37 +0000", "Message-ID": "<20250107144141.3416094-1-chenghaoyang@chromium.org>", "X-Mailer": "git-send-email 2.47.1.613.gc27f4b7a9f-goog", "MIME-Version": "1.0", "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>" }, "content": "Previously we call Thread::setThreadAffinityInternal in\nThread::startThread. The purpose was to avoid the main workload being\nrun on incorrect CPUs. This leads to a race condition of setting\n`Thread::thread_` in `Thread::start()` and accessing\n`Thread::setThreadAffinityInternal` though.\n\nThis patch moves the call after the construction of std::thread to avoid\nthe race condition. The downside is that the first tasks, if any, upon\nstarting a thread might be run on incorrect CPUs.\n\nFixes: 4d9db06d6690 (\"libcamera: add method to set thread affinity\")\nSigned-off-by: Harvey Yang <chenghaoyang@chromium.org>\n---\n src/libcamera/base/thread.cpp | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)", "diff": "diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp\nindex f6322fe3108b..319bfda9ae98 100644\n--- a/src/libcamera/base/thread.cpp\n+++ b/src/libcamera/base/thread.cpp\n@@ -257,6 +257,8 @@ void Thread::start()\n \tdata_->exit_.store(false, std::memory_order_relaxed);\n \n \tthread_ = std::thread(&Thread::startThread, this);\n+\n+\tsetThreadAffinityInternal();\n }\n \n void Thread::startThread()\n@@ -284,8 +286,6 @@ void Thread::startThread()\n \tdata_->tid_ = syscall(SYS_gettid);\n \tcurrentThreadData = data_;\n \n-\tsetThreadAffinityInternal();\n-\n \trun();\n }\n \n", "prefixes": [ "v2" ] }