Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Clark" <james.clark@linaro.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 2/2] perf test cs-etm: Test thread attribution
Date: Tue, 26 May 2026 12:13:46 +0000	[thread overview]
Message-ID: <20260526121347.D28651F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260526-james-cs-context-tracking-fix-v1-2-ebd602e18287@linaro.org>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Unused pipe file descriptors are not closed after `fork()`, which creates a deadlock risk that can hang the test suite indefinitely.
- [Medium] The test script `context_switch_thread.sh` hardcodes greps for the exact symbol names `thread1` and `thread2`, but the functions are declared as `static`. Under Link-Time Optimization (LTO) or when local symbols are stripped, these symbols may be renamed or dropped, causing the test to fail.
- [Low] The user-space test tool incorrectly includes the kernel-specific header `<linux/compiler.h>` to use the `noinline` macro.
--

commit 5c37aa232ad92e715b665569c8d8414545369de0
Author: James Clark <james.clark@linaro.org>

perf test cs-etm: Test thread attribution

Add a workload that creates two threads reading and writing to a pipe to
verify processor trace attributes symbols correctly across context switches.

> diff --git a/tools/perf/tests/shell/coresight/context_switch_loop/context_switch_loop.c b/tools/perf/tests/shell/coresight/context_switch_loop/context_switch_loop.c
> new file mode 100644
> index 0000000000000..6b7cd11952a2f
> --- /dev/null
> +++ b/tools/perf/tests/shell/coresight/context_switch_loop/context_switch_loop.c
> @@ -0,0 +1,83 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/compiler.h>

[Severity: Low]
Is it safe to include the kernel-specific header <linux/compiler.h> in this
user-space test tool to use the noinline macro?

If the test is compiled standalone outside of the perf Makefile tree, the
build might fail to find the header. Would using the standard compiler
attribute __attribute__((noinline)) be a more robust approach here?

> +#include <stdio.h>
> +#include <stdlib.h>

[ ... ]

> +static noinline void thread1(int in_fd, int out_fd)

[Severity: Medium]
Could these static declarations cause the test to fail under Link-Time
Optimization (LTO) or if local symbols are stripped?

The companion script context_switch_thread.sh hardcodes greps for the exact
symbol names thread1 and thread2. Since they are declared with internal
linkage, the compiler or linker might suffix the symbols (e.g.,
thread1.lto_priv.0), inline them despite noinline, or omit them from the
symbol table entirely. If omitted, the greps will fail.

Would removing the static keyword ensure they have external linkage and
their symbol names are strictly preserved?

> +{
> +	for (int i = 0; i < loops; i++) {
> +		read_block(in_fd);
> +		work += i * 3;
> +		write_block(out_fd);
> +	}
> +}
> +
> +static noinline void thread2(int in_fd, int out_fd)
> +{

[ ... ]

> +	thread1_pid = fork();
> +	if (thread1_pid < 0) {
> +		perror("Fork error");
> +		return 1;
> +	}
> +
> +	if (!thread1_pid) {
> +		prctl(PR_SET_NAME, "thread1", 0, 0, 0);
> +		thread1(b_to_a[0], a_to_b[1]);
> +		exit(0);
> +	}
> +
> +	prctl(PR_SET_NAME, "thread2", 0, 0, 0);
> +	thread2(a_to_b[0], b_to_a[1]);

[Severity: Medium]
Does this process setup risk deadlocking the automated test suite?

After fork(), both parent and child processes inherit all four file
descriptors for the two pipes, but neither process closes the unused ends
of the pipes (e.g., the child leaves a_to_b[0] open and the parent leaves
a_to_b[1] open).

If one process exits prematurely, for example via exit(1) upon an
unexpected read or write failure, will the surviving process block
indefinitely in read_block()? It will never receive an EOF because it
still holds a write end of the pipe open itself, which could hang the perf
record command waiting on the workload.

> +
> +	if (waitpid(thread1_pid, &status, 0) != thread1_pid || !WIFEXITED(status) ||
> +	    WEXITSTATUS(status))
> +		return 1;
> +
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260526-james-cs-context-tracking-fix-v1-0-ebd602e18287@linaro.org?part=2

  reply	other threads:[~2026-05-26 12:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 11:14 [PATCH 0/2] perf cs-etm: Queue context packets for frontend James Clark
2026-05-26 11:14 ` [PATCH 1/2] " James Clark
2026-05-26 11:53   ` sashiko-bot
2026-05-26 11:14 ` [PATCH 2/2] perf test cs-etm: Test thread attribution James Clark
2026-05-26 12:13   ` sashiko-bot [this message]
2026-05-29 14:55 ` [PATCH 0/2] perf cs-etm: Queue context packets for frontend Arnaldo Carvalho de Melo
2026-05-29 14:58   ` James Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260526121347.D28651F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=james.clark@linaro.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox