From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2E8B37E2F2 for ; Tue, 9 Jun 2026 14:40:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781016041; cv=none; b=IYMtSqI+xcZcADbz41lNR0FZamsGBTq5i1ayrApbc4Y3a8w318uqJiyQIiDcRyJvQmCMkqBwlVkj9gzWTezi/Sl+qnJaZAOD2ki72nBSxGTASfq9dTYfl0TPiWJark89fNYYkEy/3RCyhuvdb37GGynwF9Xz5Q0c601BOwiiTDA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781016041; c=relaxed/simple; bh=WCF37Je8MxyyOE4gwzCHUUj3VQznGEyT8txE/wxHMAU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YXJmqfR5QdYcZjbWE/QKI1yK4Urp+4haJg3hQW7pkHDXb0B9zCgXx2zXLwyNefSxwnzVrBbQYtDUUkyu7Fznvir9pXO1kwGSYFeB/Uw4XV/AZdvdPtS1z3Rw7XuAoJc8Dzz1XNuo2dcoHtuy/sohCcveTqtSAv3gjC4SIHHfTzs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=BWE8ptwy; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="BWE8ptwy" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-490bb83a3f6so46652735e9.0 for ; Tue, 09 Jun 2026 07:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1781016036; x=1781620836; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=4f1wgMP8HKBDMVa7qiKIEB8ImxwlPbZld8s+b9RAewo=; b=BWE8ptwyTTxLW+lcRvDNTuEqbrhO8I8a+anTBI533VYwxdhiDCHhEIz4LXkBKKt+Hy 2bdhdhnJakrV65h/KRnpSI7b2yRYQi6RBpmCaPuXgBXMDLIe9BLrNvCgRbzXzwZoWmqm VoNbATd2ZwmAD1Vj1OfHAeUcklOd8yazA+DFaSdBDuz9VGMvFFzzuSISitc6y7A2TCWG TL2IicLqINQOQwSIeYypFhDtaz7QCKgaeO7ZXfBcd+iKx1oR1Cb582EyFTpfilaTvt1R tEJ4hi48YZIzJUHXilDnSMTwOCJvHjh4Puf8YStf2LMmf/mcD/WqzwJpdchXLQ8HL2SB ltPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781016036; x=1781620836; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=4f1wgMP8HKBDMVa7qiKIEB8ImxwlPbZld8s+b9RAewo=; b=VtaNKoCDlmoAb3qMXm2fcEZ91A7T1Y9Bd9yZbHKwqQ8eKLHMktAYfWLMh8FeL9BSEy 5m/lvWCrYfVEv+ypR8fZjgfOiCXFOXgIK27rG95r8uPHrBl0NIDEEq+UcN31zn0w4nPH BEaS2Ksl3UkB3kavrAw45RLqp+okke721Hu5ugcH0oOEKzggEaAnLnLv6GUUtxPpECR1 Hbv5e4LJqcRMdSrNBNxTmvja8/B+K1cdG3nvw2kkG08Itv8iHJUQfaAUWNQWQNThwPev hOSODlxz80Z+ol1EQVd6Dy4UoCGLZKt56rZ+HErlqPaFl7l97Gzz+3GWulHzg/uy+o7g 9Guw== X-Forwarded-Encrypted: i=1; AFNElJ9Mj6/Gbk8HjeNe7UXysERykxdWpQyDidGm4mCtC5P0jkk/me5s5F6RRrQ2pt4e/jq7YQPzITmYqzXwc4k=@vger.kernel.org X-Gm-Message-State: AOJu0YxmP3gerhreZrA8F+njzWKGmauGx0eCIP8vD1KDbX3DgwJ95+rn KYMibZ/iR8MznwrEgyjETQIjrDP868NQ6QJIOnezYn4gS9+0z1wmpuoJfa2zi48olHc= X-Gm-Gg: Acq92OG0amB+ulMGzR2wnXqu6xf3zI5QyOahyrqFSVqeFXny8cJs09rDAHHUobPATwb cMBaIeAIRvfOKVwcs5B9HOSfpU1Zyqm8x8wEaj9J5kKrXdA+IBrxygh1VQWbnZWOL4FWpyNEihF GtFCozuLtqnRiOijQOUyL2EXJiHwGhOnXvnnuNONrxdlHvmTDc4HK0Nccb5T1Loku+OsaCNiJLb DV8+dHdg8mVvZ081+p/f/8PYrVtg/vGfHQb3pG88YY4OnENrEDSREeGl23MhrzlmpP+way9n+ir VRrPNzSVWLhjjMM1nta6V+6oAz4CcSkIWW6bsOWlhh5uiEYqXgaz4lQqR07S3k91+drerGsQKDl Rixk4wHWrK6HlnMWvwKR8T9YmDw8k6ev1+VKEo0CrU5qsZxwctMvTsNLMarj3EuqTi+1RuE8nhC vzF9NA6SIt2hW4vl5wGM7hssINU2wQ3tpLOVY0GCYNqag= X-Received: by 2002:a05:600d:8444:20b0:490:48b7:c1ff with SMTP id 5b1f17b1804b1-490d72239damr30304245e9.17.1781016036424; Tue, 09 Jun 2026 07:40:36 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.77.170]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3c1149sm428411935e9.4.2026.06.09.07.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2026 07:40:35 -0700 (PDT) From: James Clark Date: Tue, 09 Jun 2026 15:40:14 +0100 Subject: [PATCH v5 09/19] perf test: Add named_threads workload Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260609-james-cs-context-tracking-fix-v5-9-d53a7d096a19@linaro.org> References: <20260609-james-cs-context-tracking-fix-v5-0-d53a7d096a19@linaro.org> In-Reply-To: <20260609-james-cs-context-tracking-fix-v5-0-d53a7d096a19@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , Arnaldo Carvalho de Melo , Namhyung Kim , Jiri Olsa , Ian Rogers , Amir Ayupov , Jonathan Corbet , Shuah Khan , Paschalis Mpeis Cc: coresight@lists.linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, James Clark X-Mailer: b4 0.14.0 Add a workload that runs X threads that run a unique function named "named_threads_thread[x]" which performs a multiplication in a loop for Y loops. Each thread sets its name to "thread[x]". This can be used to test that processor trace decoding handles concurrent threads correctly and the correct symbols and thread names are assigned to samples. Signed-off-by: James Clark --- tools/perf/Documentation/perf-test.txt | 5 +- tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/tests.h | 1 + tools/perf/tests/workloads/Build | 1 + tools/perf/tests/workloads/named_threads.c | 109 +++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-test.txt b/tools/perf/Documentation/perf-test.txt index c50a4b2d2d29..81c8525f5946 100644 --- a/tools/perf/Documentation/perf-test.txt +++ b/tools/perf/Documentation/perf-test.txt @@ -57,7 +57,7 @@ OPTIONS --workload=:: Run a built-in workload, to list them use '--list-workloads', current ones include: noploop, thloop, leafloop, sqrtloop, brstack, datasym, - context_switch_loop, deterministic and landlock. + context_switch_loop, deterministic, named_threads and landlock. Used with the shell script regression tests. @@ -66,6 +66,9 @@ OPTIONS seconds: leafloop, noploop, sqrtloop, thloop nrloops: brstack, context_switch_loop + 'named_threads' accepts the number of threads and the number of loops to + do in each thread. + The datasym, landlock and deterministic workloads don't accept any. --list-workloads:: diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index ef7e3f52a383..afc06cec4954 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -155,6 +155,7 @@ static struct test_suite *generic_tests[] = { static struct test_workload *workloads[] = { &workload__noploop, &workload__thloop, + &workload__named_threads, &workload__leafloop, &workload__sqrtloop, &workload__brstack, diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index bcfe9c33fc66..7cedf05be544 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -237,6 +237,7 @@ struct test_workload workload__##work = { \ /* The list of test workloads */ DECLARE_WORKLOAD(noploop); DECLARE_WORKLOAD(thloop); +DECLARE_WORKLOAD(named_threads); DECLARE_WORKLOAD(leafloop); DECLARE_WORKLOAD(sqrtloop); DECLARE_WORKLOAD(brstack); diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build index 90f2d8aa4941..75b377934a0e 100644 --- a/tools/perf/tests/workloads/Build +++ b/tools/perf/tests/workloads/Build @@ -2,6 +2,7 @@ perf-test-y += noploop.o perf-test-y += thloop.o +perf-test-y += named_threads.o perf-test-y += leafloop.o perf-test-y += sqrtloop.o perf-test-y += brstack.o diff --git a/tools/perf/tests/workloads/named_threads.c b/tools/perf/tests/workloads/named_threads.c new file mode 100644 index 000000000000..d051d41a3cfe --- /dev/null +++ b/tools/perf/tests/workloads/named_threads.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include "../tests.h" + +#define MAX_THREADS 25 + +static int iterations = 500; +int named_threads_work = 1234; + +typedef void *(*thread_fn_t)(void *); + +#define DEFINE_THREAD(n) \ +noinline void *named_threads_thread##n(void *arg __maybe_unused) \ +{ \ + pthread_setname_np(pthread_self(), "thread" #n); \ + for (int i = 0; i < iterations; i++) \ + named_threads_work += 3; \ + \ + return NULL; \ +} + +#define THREAD_LIST(macro) \ + macro(1) \ + macro(2) \ + macro(3) \ + macro(4) \ + macro(5) \ + macro(6) \ + macro(7) \ + macro(8) \ + macro(9) \ + macro(10) \ + macro(11) \ + macro(12) \ + macro(13) \ + macro(14) \ + macro(15) \ + macro(16) \ + macro(17) \ + macro(18) \ + macro(19) \ + macro(20) \ + macro(21) \ + macro(22) \ + macro(23) \ + macro(24) \ + macro(25) + +#define DECLARE_THREAD(n) void *named_threads_thread##n(void *arg); + +THREAD_LIST(DECLARE_THREAD) +THREAD_LIST(DEFINE_THREAD) + +#define THREAD_ENTRY(n) named_threads_thread##n, + +static thread_fn_t thread_fns[MAX_THREADS] = { + THREAD_LIST(THREAD_ENTRY) +}; + +/* + * Creates argv[0] threads that run a unique function named "thread[x]" which performs + * a multiplication in a loop for argv[1] loops. + */ +static int named_threads(int argc, const char **argv) +{ + pthread_t threads[MAX_THREADS]; + int nr_threads = 1; + int err = 0; + + if (argc > 0) + nr_threads = atoi(argv[0]); + + if (nr_threads <= 0 || nr_threads > MAX_THREADS) { + fprintf(stderr, "Error: num threads must be 1 - %d\n", MAX_THREADS); + return 1; + } + + if (argc > 1) + iterations = atoi(argv[1]); + + if (iterations < 0) { + fprintf(stderr, "Error: iterations must be non-negative\n"); + return 1; + } + + for (int i = 0; i < nr_threads; i++) { + int ret; + + ret = pthread_create(&threads[i], NULL, thread_fns[i], NULL); + if (ret) { + fprintf(stderr, "Error: failed to create thread%d: %s\n", + i + 1, strerror(ret)); + return 1; + } + } + + for (int i = 0; i < nr_threads; i++) + pthread_join(threads[i], NULL); + + return err; +} + +DEFINE_WORKLOAD(named_threads); -- 2.34.1