perf test workload noploop: Name the noploop process
Ian Rogers
reviewerPATCH v2 1/2 perf test workload noploop: Name the noploop process
Name the noploop process "perf-noploop" so that tests can easily check for its existence.
--- tools/perf/tests/workloads/noploop.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/tests/workloads/noploop.c +3 -0
@@ -2,6 +2,8 @@#include <stdlib.h> #include <signal.h> #include <unistd.h> +#include <linux/prctl.h> +#include <sys/prctl.h> #include <linux/compiler.h> #include "../tests.h"
@@ -16,6 +18,7 @@ static int noploop(int argc, const char **argv) {int sec =1 ; +prctl (PR_SET_NAME ,"perf-noploop" );if (argc >0 ) sec =atoi (argv[0 ]);
Signature · 1 line
2.50.0.rc2.701.gf1e915cc24-goog
Ian Rogers
reviewerPATCH v2 2/2 perf test: Add sched latency and script shell tests
Add shell tests covering the perf sched latency and perf sched script commands. The test creates 2 noploop processes on the same forced CPU, it then checks that the process appears in the perf sched output.
---
v2: Skip the test if not root due to permissions.
--- tools/perf/tests/shell/sched.sh | 91 +++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 tools/perf/tests/shell/sched.sh
tools/perf/tests/shell/sched.sh new file +91 -0
@@ -0,0 +1,91 @@ +#!/bin/bash +# perf sched tests +# SPDX-License-Identifier: GPL-2.0 + +set -e + +if [ "$(id -u)" != 0 ]; then + echo "[Skip] No root permission" + exit 2 +fi + +err=0 +perfdata=$(mktemp /tmp/__perf_test_sched.perf.data.XXXXX) +PID1=0 +PID2=0 + +cleanup() { + rm -f "${perfdata}" + rm -f "${perfdata}".old + + trap - EXIT TERM INT +} + +trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +start_noploops() { + # Start two noploop workloads on CPU0 to trigger scheduling. + taskset -c 0 perf test -w noploop 10 & + PID1=$! + taskset -c 0 perf test -w noploop 10 & + PID2=$! + + if ! grep -q 'Cpus_allowed_list:\s*0$' "/proc/$PID1/status" + then + echo "Sched [Error taskset did not work for the 1st noploop ($PID1)]" + grep Cpus_allowed /proc/$PID1/status + err=1 + fi + + if ! grep -q 'Cpus_allowed_list:\s*0$' "/proc/$PID2/status" + then + echo "Sched [Error taskset did not work for the 2nd noploop ($PID2)]" + grep Cpus_allowed /proc/$PID2/status + err=1 + fi +} + +cleanup_noploops() { + kill "$PID1" "$PID2" +} + +test_sched_latency() { + echo "Sched latency" + + start_noploops + + perf sched record --no-inherit -o "${perfdata}" sleep 1 + if ! perf sched latency -i "${perfdata}" | grep -q perf-noploop + then + echo "Sched latency [Failed missing output]" + err=1 + fi + + cleanup_noploops +} + +test_sched_script() { + echo "Sched script" + + start_noploops + + perf sched record --no-inherit -o "${perfdata}" sleep 1 + if ! perf sched script -i "${perfdata}" | grep -q perf-noploop + then + echo "Sched script [Failed missing output]" + err=1 + fi + + cleanup_noploops +} + +test_sched_latency +test_sched_script + +cleanup +exit $err
Signature · 1 line
2.50.0.rc2.701.gf1e915cc24-goog
Re: [PATCH v2 2/2] perf test: Add sched latency and script shell tests
Quoted 47 lines · Ian Rogers
Add shell tests covering the
perf sched latencyandperf sched scriptcommands. The test creates 2 noploop processes on the same forced CPU, it then checks that the process appears in theperf schedoutput.Signed-off-by Ian Rogers <[email protected]>---
v2: Skip the test if not root due to permissions.--- tools/perf/tests/shell/sched.sh | 91 +++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)create mode 100755
tools/perf/tests/shell/sched.shtools/perf/tests/shell/sched.sh new file +28
-0@@ -0,0 +1,91 @@ +#!/bin/bash +# perf sched tests +# SPDX-License-Identifier: GPL-2.0 + +set -e + +if [ "$(id -u)" != 0 ]; then + echo "[Skip] No root permission" + exit 2 +fi + +err=0 +perfdata=$(mktemp /tmp/__perf_test_sched.perf.data.XXXXX) +PID1=0 +PID2=0 + +cleanup() { + rm -f "${perfdata}" + rm -f "${perfdata}".old + + trap - EXIT TERM INT +} + +trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +}
tools/perf/tests/shell/sched.sh line 38
Quoted 10 lines
tools/perf/tests/shell/sched.sh new file +10
-0+trap trap_cleanup EXIT TERM INT + +start_noploops() { + # Start two noploop workloads on CPU0 to trigger scheduling. + taskset -c 0 perf test -w noploop 10 & + PID1=$! + taskset -c 0 perf test -w noploop 10 & + PID2=$! + + if ! grep -q 'Cpus_allowed_list:\s*0$' "/proc/$PID1/status"
Hi Ian,
Because taskset is also run in the background it's possible to grep the proc file before it's managed to re-pin itself. I saw some intermittent failures of the test because of this.
I think you'd need to run noploop in the background but taskset in the foreground and give it the pid of noploop to make sure it finishes before grepping.
Other than that the test seems ok:
Thanks
James
Quoted 53 lines
tools/perf/tests/shell/sched.sh new file +53
-0+ then + echo "Sched [Error taskset did not work for the 1st noploop ($PID1)]" + grep Cpus_allowed /proc/$PID1/status + err=1 + fi + + if ! grep -q 'Cpus_allowed_list:\s*0$' "/proc/$PID2/status" + then + echo "Sched [Error taskset did not work for the 2nd noploop ($PID2)]" + grep Cpus_allowed /proc/$PID2/status + err=1 + fi +} + +cleanup_noploops() { + kill "$PID1" "$PID2" +} + +test_sched_latency() { + echo "Sched latency" + + start_noploops + + perf sched record --no-inherit -o "${perfdata}" sleep 1 + if ! perf sched latency -i "${perfdata}" | grep -q perf-noploop + then + echo "Sched latency [Failed missing output]" + err=1 + fi + + cleanup_noploops +} + +test_sched_script() { + echo "Sched script" + + start_noploops + + perf sched record --no-inherit -o "${perfdata}" sleep 1 + if ! perf sched script -i "${perfdata}" | grep -q perf-noploop + then + echo "Sched script [Failed missing output]" + err=1 + fi + + cleanup_noploops +} + +test_sched_latency +test_sched_script + +cleanup +exit $err
Namhyung Kim
maintainerRe: [PATCH v2 2/2] perf test: Add sched latency and script shell tests
In reply to Ian RogersQuoted 45 lines · Ian Rogers
Add shell tests covering the
perf sched latencyandperf sched scriptcommands. The test creates 2 noploop processes on the same forced CPU, it then checks that the process appears in theperf schedoutput.Signed-off-by Ian Rogers <[email protected]>---
v2: Skip the test if not root due to permissions.--- tools/perf/tests/shell/sched.sh | 91 +++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 tools/perf/tests/shell/sched.shtools/perf/tests/shell/sched.sh new file +26
-0@@ -0,0 +1,91 @@ +#!/bin/bash +# perf sched tests +# SPDX-License-Identifier: GPL-2.0 + +set -e + +if [ "$(id -u)" != 0 ]; then + echo "[Skip] No root permission" + exit 2 +fi + +err=0 +perfdata=$(mktemp /tmp/__perf_test_sched.perf.data.XXXXX) +PID1=0 +PID2=0 + +cleanup() { + rm -f "${perfdata}" + rm -f "${perfdata}".old + + trap - EXIT TERM INT +} + +trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup
tools/perf/tests/shell/sched.sh line 36
Quoted 10 lines
tools/perf/tests/shell/sched.sh new file +10
-0+ exit 1 +} +trap trap_cleanup EXIT TERM INT + +start_noploops() { + # Start two noploop workloads on CPU0 to trigger scheduling. + taskset -c 0 perf test -w noploop 10 & + PID1=$! + taskset -c 0 perf test -w noploop 10 & + PID2=$!
You can use 'thloop' workload which runs 2 threads at the same time. Then you don't need to handle the background processes and run it directly with perf test.
Thanks,
Namhyung
Quoted 58 lines
tools/perf/tests/shell/sched.sh new file +55
-0+ + if ! grep -q 'Cpus_allowed_list:\s*0$' "/proc/$PID1/status" + then + echo "Sched [Error taskset did not work for the 1st noploop ($PID1)]" + grep Cpus_allowed /proc/$PID1/status + err=1 + fi + + if ! grep -q 'Cpus_allowed_list:\s*0$' "/proc/$PID2/status" + then + echo "Sched [Error taskset did not work for the 2nd noploop ($PID2)]" + grep Cpus_allowed /proc/$PID2/status + err=1 + fi +} + +cleanup_noploops() { + kill "$PID1" "$PID2" +} + +test_sched_latency() { + echo "Sched latency" + + start_noploops + + perf sched record --no-inherit -o "${perfdata}" sleep 1 + if ! perf sched latency -i "${perfdata}" | grep -q perf-noploop + then + echo "Sched latency [Failed missing output]" + err=1 + fi + + cleanup_noploops +} + +test_sched_script() { + echo "Sched script" + + start_noploops + + perf sched record --no-inherit -o "${perfdata}" sleep 1 + if ! perf sched script -i "${perfdata}" | grep -q perf-noploop + then + echo "Sched script [Failed missing output]" + err=1 + fi + + cleanup_noploops +} + +test_sched_latency +test_sched_script + +cleanup +exit $errSignature · 1 line
2.50.0.rc2.701.gf1e915cc24-goog
Ian Rogers
reviewerRe: [PATCH v2 2/2] perf test: Add sched latency and script shell tests
Quoted 3 lines · Namhyung Kim
You can use 'thloop' workload which runs 2 threads at the same time. Then you don't need to handle the background processes and run it directly with perf test.
v3 sent. I held off changing noploop to thloop as I think 2 separate processes is a little clearer:
https://lore.kernel.org/lkml/[email protected]/
Thanks,
Ian
Quoted 22 lines · Ian Rogers
Name the noploop process "perf-noploop" so that tests can easily check for its existence.
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/tests/workloads/noploop.c | 3 +++ 1 file changed, 3 insertions(+)tools/perf/tests/workloads/noploop.c +2
-0@@ -2,6 +2,8 @@#include <stdlib.h> #include <signal.h> #include <unistd.h> +#include <linux/prctl.h> +#include <sys/prctl.h> #include <linux/compiler.h> #include "../tests.h"
tools/perf/tests/workloads/noploop.c static int noploop(int argc, const char **argv) · line 24
Quoted 7 lines
tools/perf/tests/workloads/noploop.c +1
-0@@ -16,6 +18,7 @@ static int noploop(int argc, const char **argv) {int sec =1 ; +prctl (PR_SET_NAME ,"perf-noploop" );if (argc >0 ) sec =atoi (argv[0 ]);
Namhyung Kim
maintainerHi Ian,
Quoted 13 lines · Ian Rogers
Name the noploop process "perf-noploop" so that tests can easily check for its existence.
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/tests/workloads/noploop.c | 3 +++ 1 file changed, 3 insertions(+)tools/perf/tests/workloads/noploop.c +0
-0
tools/perf/tests/workloads/noploop.c line 6
Quoted 5 lines
tools/perf/tests/workloads/noploop.c +2
-0@@ -2,6 +2,8 @@#include <stdlib.h> #include <signal.h> #include <unistd.h> +#include <linux/prctl.h> +#include <sys/prctl.h>
I'm afraid it'd introduce a build failure on musl. Please see
https://lore.kernel.org/linux-perf-users/[email protected]/
I think <sys/prctl.h> would be enough.
Thanks,
Namhyung
Quoted 14 lines
tools/perf/tests/workloads/noploop.c +1
-0#include <linux/compiler.h> #include "../tests.h" @@ -16,6 +18,7 @@ static int noploop(int argc, const char **argv) {int sec =1 ; +prctl (PR_SET_NAME ,"perf-noploop" );if (argc >0 ) sec =atoi (argv[0 ]);Signature · 1 line
2.50.0.rc2.701.gf1e915cc24-goog
Ian Rogers
reviewerQuoted 25 lines · Namhyung Kim
Hi Ian,
Quoted 13 lines · Ian Rogers
Name the noploop process "perf-noploop" so that tests can easily check for its existence.
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/tests/workloads/noploop.c | 3 +++ 1 file changed, 3 insertions(+)tools/perf/tests/workloads/noploop.c +0
-0tools/perf/tests/workloads/noploop.c line 6
Quoted 5 lines
tools/perf/tests/workloads/noploop.c +2
-0@@ -2,6 +2,8 @@#include <stdlib.h> #include <signal.h> #include <unistd.h> +#include <linux/prctl.h> +#include <sys/prctl.h> I'm afraid it'd introduce a build failure on musl. Please see
Quoted 3 lines
https://lore.kernel.org/linux-perf-users/[email protected]/
I think <
sys/prctl.h> would be enough.
Hi Namhyung,
we could do that but in the glibc man page it says:
https://man7.org/linux/man-pages/man2/prctl.2.html
``` #include <linux/prctl.h> /* Definition of PR_* constants */ #include <sys/prctl.h> ```
So wouldn't the PR_SET_NAME definition potentially be missing then? We could fill in the missing definition with #ifndef PR_SET_NAME it seems sub-optimal - I see this is what was done in the linked to changes. Perhaps we need something like a tools/perf/util/prctl.h, and a feature test, then in that we have something like:
``` /* A header file to work around musl libc breakages caused conflicting definitions in linux/prctl.h . */ #ifndef HAVE_SENSIBLE_PRCTL # include <linux/prctl.h> # include <sys/prctl.h> #else // !HAVE_SENSIBLE_PRCTL # include <sys/prctl.h> # ifndef PR_SET_NAME # define PR_SET_NAME 15 # endif // PR_SET_NAME # ifndef PR_FUTEX_HASH # define PR_FUTEX_HASH 78 # define PR_FUTEX_HASH_SET_SLOTS 1 # define FH_FLAG_IMMUTABLE (1ULL << 0) # define PR_FUTEX_HASH_GET_SLOTS 2 # define PR_FUTEX_HASH_GET_IMMUTABLE 3 # endif // PR_FUTEX_HASH #endif // HAVE_SENSIBLE_PRCTL ```
The feature test would just be to include the two headers and see if the build breaks.
It'd be nice to think musl was slowly getting fixed. I notice we're carrying two comments in the code about working around musl, but I suspect we do this kind of thing in a lot of places (just knowing the issues that come up from yourself and Arnaldo when trying to integrate patches). It'd be nice if perf's code could keep close to what the man page, or whatever, is saying the standard should be, rather than doing some kind of adhoc linux/prctl.h rewrite (or if we are doing that, make the code more explicit that it's what we're doing).
It'd be nice to think that the perf code could be clean wrt analyses like "include what you use" [1], but strategically removing #includes to try to work around musl issues seems like the opposite of this.
Thanks,
Ian
[1] https://github.com/include-what-you-use/include-what-you-use
Quoted 18 lines
Thanks,
NamhyungQuoted 14 lines
tools/perf/tests/workloads/noploop.c +1
-1#include <linux/compiler.h> #include "../tests.h" @@ -16,6 +18,7 @@ static int noploop(int argc, const char **argv) {int sec =1 ; +prctl (PR_SET_NAME ,"perf-noploop" );if (argc >0 ) sec =atoi (argv[0 ]); --2.50.0.rc2.701.gf1e915cc24-goog
Arnaldo Carvalho de Melo
maintainerQuoted 7 lines · Ian Rogers
Quoted 5 lines · Namhyung Kim
I'm afraid it'd introduce a build failure on musl. Please see
https://lore.kernel.org/linux-perf-users/[email protected]/
I think <
sys/prctl.h> would be enough.
Quoted 8 lines
we could do that but in the glibc man page it says:
https://man7.org/linux/man-pages/man2/prctl.2.html``` #include <linux/prctl.h> /* Definition of PR_* constants */ #include <sys/prctl.h> ```It'd be nice to think musl was slowly getting fixed. I notice we're
Sebastian reported on the musl libc, its maintainer replied:
https://www.openwall.com/lists/musl/2025/06/12/11
- ARnaldo
Ian Rogers
reviewerQuoted 16 lines · Arnaldo Carvalho de Melo
Quoted 13 lines · Ian Rogers
Quoted 5 lines · Namhyung Kim
I'm afraid it'd introduce a build failure on musl. Please see
https://lore.kernel.org/linux-perf-users/[email protected]/
I think <
sys/prctl.h> would be enough.we could do that but in the glibc man page it says:
https://man7.org/linux/man-pages/man2/prctl.2.html``` #include <linux/prctl.h> /* Definition of PR_* constants */ #include <sys/prctl.h> ```
Quoted 5 lines
Quoted 1 line
It'd be nice to think musl was slowly getting fixed. I notice we're
Sebastian reported on the musl libc, its maintainer replied:
Ugh. I'm not sure how we're expected to resolve this and have glibc and musl be happy without basically not trusting libc.
Thanks,
Ian
Namhyung Kim
maintainerQuoted 18 lines · Ian Rogers
Quoted 16 lines · Arnaldo Carvalho de Melo
Quoted 13 lines · Ian Rogers
Quoted 5 lines · Namhyung Kim
I'm afraid it'd introduce a build failure on musl. Please see
https://lore.kernel.org/linux-perf-users/[email protected]/
I think <
sys/prctl.h> would be enough.we could do that but in the glibc man page it says:
https://man7.org/linux/man-pages/man2/prctl.2.html``` #include <linux/prctl.h> /* Definition of PR_* constants */ #include <sys/prctl.h> ```
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
It'd be nice to think musl was slowly getting fixed. I notice we're
Sebastian reported on the musl libc, its maintainer replied:
Ugh. I'm not sure how we're expected to resolve this and have glibc and musl be happy without basically not trusting libc.
Maybe pthread_setname_np()? It seems musl also implemented it.
Thanks,
Namhyung
Arnaldo Carvalho de Melo
maintainerQuoted 19 lines · Namhyung Kim
Quoted 17 lines · Ian Rogers
Quoted 16 lines · Arnaldo Carvalho de Melo
Quoted 15 lines · Ian Rogers
Quoted 5 lines · Namhyung Kim
I'm afraid it'd introduce a build failure on musl. Please see
https://lore.kernel.org/linux-perf-users/[email protected]/
I think <
sys/prctl.h> would be enough.we could do that but in the glibc man page it says:
https://man7.org/linux/man-pages/man2/prctl.2.html``` #include <linux/prctl.h> /* Definition of PR_* constants */ #include <sys/prctl.h> ```It'd be nice to think musl was slowly getting fixed. I notice we're
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Sebastian reported on the musl libc, its maintainer replied:
Ugh. I'm not sure how we're expected to resolve this and have glibc and musl be happy without basically not trusting libc.
Maybe
pthread_setname_np()? It seems musl also implemented it.
⬢ [acme@toolbx perf-tools-next]$ git diff
tools/perf/tests/workloads/noploop.c +2 -3
@@ -1,9 +1,8 @@/* SPDX-License-Identifier: GPL-2.0 */ +#include <pthread.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> -#include <linux/prctl.h> -#include <sys/prctl.h> #include <linux/compiler.h> #include "../tests.h"
@@ -18,7 +17,7 @@ static int noploop(int argc, const char **argv) {int sec =1 ; -prctl (PR_SET_NAME ,"perf-noploop" ); +pthread_setname_np (pthread_self (),"perf-noploop" );if (argc >0 ) sec =atoi (argv[0 ]);
⬢ [acme@toolbx perf-tools-next]$
⬢ [acme@toolbx perf-tools-next]$ perf test -w noploop &
[1] 1179763
⬢ [acme@toolbx perf-tools-next]$ ps
PID TTY TIME CMD
3935 pts/1 00:00:00 bash 4053 pts/1 00:00:00 toolbox 4222 pts/1 00:00:28 podman 971900 pts/1 00:00:00 bash 1100453 pts/1 00:00:00 tail 1160346 pts/1 00:00:00 bash 1179763 pts/1 00:00:00 perf-noploop 1179765 pts/1 00:00:00 ps
⬢ [acme@toolbx perf-tools-next]$
And then on one of the Alpine Linux containers:
make: Leaving directory '/tmp/perf-6.16.0-rc3/tools/perf' /tmp/perf-6.16.0-rc3 $ cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.18.12
PRETTY_NAME="Alpine Linux v3.18" HOME_URL="https://alpinelinux.org/" BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues" /tmp/perf-6.16.0-rc3 $ tools/perf/perf test -w noploop & /tmp/perf-6.16.0-rc3 $ ps
PID USER TIME COMMAND
1 toolsbui 0:00 /bin/sh
5693 toolsbui 0:00 {perf-noploop} tools/perf/perf test -w noploop
5694 toolsbui 0:00 ps/tmp/perf-6.16.0-rc3 $
[1]+ Done tools/perf/perf test -w noploop/tmp/perf-6.16.0-rc3
There are more direct use of prctl() to set the name in tools/perf/, using pthread_setname_np() seems cleaner :-)
- Arnaldo
Ian Rogers
reviewerQuoted 87 lines · Arnaldo Carvalho de Melo
Quoted 19 lines · Namhyung Kim
Quoted 17 lines · Ian Rogers
Quoted 16 lines · Arnaldo Carvalho de Melo
Quoted 15 lines · Ian Rogers
Quoted 5 lines · Namhyung Kim
I'm afraid it'd introduce a build failure on musl. Please see
https://lore.kernel.org/linux-perf-users/[email protected]/
I think <
sys/prctl.h> would be enough.we could do that but in the glibc man page it says:
https://man7.org/linux/man-pages/man2/prctl.2.html``` #include <linux/prctl.h> /* Definition of PR_* constants */ #include <sys/prctl.h> ```It'd be nice to think musl was slowly getting fixed. I notice we're
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Sebastian reported on the musl libc, its maintainer replied:
Ugh. I'm not sure how we're expected to resolve this and have glibc and musl be happy without basically not trusting libc.
Maybe
pthread_setname_np()? It seems musl also implemented it.⬢ [acme@toolbx perf-tools-next]$ git diff
tools/perf/tests/workloads/noploop.c +2
-3@@ -1,9 +1,8 @@/* SPDX-License-Identifier: GPL-2.0 */ +#include <pthread.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> -#include <linux/prctl.h> -#include <sys/prctl.h> #include <linux/compiler.h> #include "../tests.h" @@ -18,7 +17,7 @@ static int noploop(int argc, const char **argv) {int sec =1 ; -prctl (PR_SET_NAME ,"perf-noploop" ); +pthread_setname_np (pthread_self (),"perf-noploop" );if (argc >0 ) sec =atoi (argv[0 ]);⬢ [acme@toolbx perf-tools-next]$
⬢ [acme@toolbx perf-tools-next]$ perf test -w noploop &
[1] 1179763
⬢ [acme@toolbx perf-tools-next]$ ps
PID TTY TIME CMD3935 pts/1 00:00:00 bash 4053 pts/1 00:00:00 toolbox 4222 pts/1 00:00:28 podman 971900 pts/1 00:00:00 bash 1100453 pts/1 00:00:00 tail 1160346 pts/1 00:00:00 bash 1179763 pts/1 00:00:00 perf-noploop 1179765 pts/1 00:00:00 ps⬢ [acme@toolbx perf-tools-next]$
And then on one of the Alpine Linux containers:
make: Leaving directory '
/tmp/perf-6.16.0-rc3/tools/perf'/tmp/perf-6.16.0-rc3$ cat/etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.18.12
PRETTY_NAME="Alpine Linux v3.18" HOME_URL="https://alpinelinux.org/" BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"/tmp/perf-6.16.0-rc3$tools/perf/perftest -w noploop &/tmp/perf-6.16.0-rc3$ ps
PID USER TIME COMMAND1 toolsbui 0:00 /bin/sh 5693 toolsbui 0:00 {perf-noploop} tools/perf/perf test -w noploop 5694 toolsbui 0:00 ps
Quoted 6 lines
/tmp/perf-6.16.0-rc3$
[1]+ Donetools/perf/perftest -w noploop/tmp/perf-6.16.0-rc3There are more direct use of
prctl()to set the name intools/perf/, usingpthread_setname_np()seems cleaner :-)
Yeah, I wanted to set the program name rather than a thread name for the sake of seeing the process name in ps - hence reaching for prctl. PR_SET_NAME is documented as setting the thread name and so no difference to pthread_setname_np. It's still frustrating to get bogged down in working around musl when typing the literal code from the prctl man page. Do you need me to re-send the patch?
Thanks,
Ian
Quoted 1 line
- Arnaldo
Namhyung Kim
maintainerQuoted 93 lines · Ian Rogers
Quoted 91 lines · Arnaldo Carvalho de Melo
Quoted 19 lines · Namhyung Kim
Quoted 17 lines · Ian Rogers
Quoted 16 lines · Arnaldo Carvalho de Melo
Quoted 15 lines · Ian Rogers
Quoted 5 lines · Namhyung Kim
I'm afraid it'd introduce a build failure on musl. Please see
https://lore.kernel.org/linux-perf-users/[email protected]/
I think <
sys/prctl.h> would be enough.we could do that but in the glibc man page it says:
https://man7.org/linux/man-pages/man2/prctl.2.html``` #include <linux/prctl.h> /* Definition of PR_* constants */ #include <sys/prctl.h> ```It'd be nice to think musl was slowly getting fixed. I notice we're
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Sebastian reported on the musl libc, its maintainer replied:
Ugh. I'm not sure how we're expected to resolve this and have glibc and musl be happy without basically not trusting libc.
Maybe
pthread_setname_np()? It seems musl also implemented it.⬢ [acme@toolbx perf-tools-next]$ git diff
tools/perf/tests/workloads/noploop.c +2
-3@@ -1,9 +1,8 @@/* SPDX-License-Identifier: GPL-2.0 */ +#include <pthread.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> -#include <linux/prctl.h> -#include <sys/prctl.h> #include <linux/compiler.h> #include "../tests.h" @@ -18,7 +17,7 @@ static int noploop(int argc, const char **argv) {int sec =1 ; -prctl (PR_SET_NAME ,"perf-noploop" ); +pthread_setname_np (pthread_self (),"perf-noploop" );if (argc >0 ) sec =atoi (argv[0 ]);⬢ [acme@toolbx perf-tools-next]$
⬢ [acme@toolbx perf-tools-next]$ perf test -w noploop &
[1] 1179763
⬢ [acme@toolbx perf-tools-next]$ ps
PID TTY TIME CMD3935 pts/1 00:00:00 bash 4053 pts/1 00:00:00 toolbox 4222 pts/1 00:00:28 podman 971900 pts/1 00:00:00 bash 1100453 pts/1 00:00:00 tail 1160346 pts/1 00:00:00 bash 1179763 pts/1 00:00:00 perf-noploop 1179765 pts/1 00:00:00 ps⬢ [acme@toolbx perf-tools-next]$
And then on one of the Alpine Linux containers:
make: Leaving directory '
/tmp/perf-6.16.0-rc3/tools/perf'/tmp/perf-6.16.0-rc3$ cat/etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.18.12
PRETTY_NAME="Alpine Linux v3.18" HOME_URL="https://alpinelinux.org/" BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"/tmp/perf-6.16.0-rc3$tools/perf/perftest -w noploop &/tmp/perf-6.16.0-rc3$ ps
PID USER TIME COMMAND1 toolsbui 0:00 /bin/sh 5693 toolsbui 0:00 {perf-noploop} tools/perf/perf test -w noploop 5694 toolsbui 0:00 ps
/tmp/perf-6.16.0-rc3$
[1]+ Donetools/perf/perftest -w noploop/tmp/perf-6.16.0-rc3
Quoted 9 lines
Quoted 2 lines
There are more direct use of
prctl()to set the name intools/perf/, usingpthread_setname_np()seems cleaner :-)Yeah, I wanted to set the program name rather than a thread name for the sake of seeing the process name in ps - hence reaching for prctl.
PR_SET_NAMEis documented as setting the thread name and so no difference topthread_setname_np. It's still frustrating to get bogged down in working around musl when typing the literal code from the prctl man page. Do you need me to re-send the patch?
Yes please. And address comments in the patch 2 as well.
Thanks,
Namhyung