Skip to contentSkip to conversation

perf bench sched pipe: Add -G/--cgroups option

PATCH Applied Namhyung Kim 2 participants 4 messages Oct 17, 2023 – Oct 26, 2023 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH v4 1/1 perf bench sched pipe: Add -G/--cgroups option

The -G/--cgroups option is to put sender and receiver in different cgroups in order to measure cgroup context switch overheads.

Users need to make sure the cgroups exist and accessible. The following example should the effect of this change. Please don't forget taskset before the perf bench to measure cgroup switches properly. Otherwise each task would run on a different CPU and generate cgroup switches regardless of this change.

  # perf stat -e context-switches,cgroup-switches \
Quoted 1 line

taskset -c 0 perf bench sched pipe -l 10000 > /dev/null

Performance counter stats for 'taskset -c 0 perf bench sched pipe -l 10000':

              20,001      context-switches
                   2      cgroup-switches

         0.053449651 seconds time elapsed

         0.011286000 seconds user
         0.041869000 seconds sys
  # perf stat -e context-switches,cgroup-switches \
Quoted 1 line

taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB > /dev/null

Performance counter stats for 'taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB':

              20,001      context-switches
              20,001      cgroup-switches

         0.052768627 seconds time elapsed

         0.006284000 seconds user
         0.046266000 seconds sys

---
* update hint for non-root usage
* initialize cgroup_failed properly
* describe taskset usage in the commit log

 tools/perf/Documentation/perf-bench.txt |  19 ++++
 tools/perf/bench/sched-pipe.c           | 132 +++++++++++++++++++++++-
 2 files changed, 147 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-bench.txt +19 -0
index ca5789625cd2..8331bd28b10e 100644
@@ -124,6 +124,14 @@ Options of *pipe*
 --loop=::
 Specify number of loops.
 
+-G::
+--cgroups=::
+Names of cgroups for sender and receiver, separated by a comma.
+This is useful to check cgroup context switching overhead.
+Note that perf doesn't create nor delete the cgroups, so users should
+make sure that the cgroups exist and are accessible before use.
+
+
 Example of *pipe*
 ^^^^^^^^^^^^^^^^^
 
@@ -141,6 +149,17 @@ Example of *pipe*
         Total time:0.016 sec
                 16.948000 usecs/op
                 59004 ops/sec
+
+% perf bench sched pipe -G AAA,BBB
+(executing 1000000 pipe operations between cgroups)
+# Running 'sched/pipe' benchmark:
+# Executed 1000000 pipe operations between two processes
+
+     Total time: 6.886 [sec]
+
+       6.886208 usecs/op
+         145217 ops/sec
+
 ---------------------
 
 SUITES FOR 'syscall'
tools/perf/bench/sched-pipe.c +128 -4

197 lines not on this page · raw message

Signature · 1 line
2.42.0.655.g421f12c284-goog
maintainer Tested-by on v4 1/1
#1 lore raw

Em Tue, Oct 17, 2023 at 01:23:42PM -0700, Namhyung Kim escreveu:

Quoted 2 lines

The -G/--cgroups option is to put sender and receiver in different cgroups in order to measure cgroup context switch overheads.

<SNIP>

Quoted 6 lines
Quoted 1 line

taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB > /dev/null

Performance counter stats for 'taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB':

              20,001      context-switches
              20,001      cgroup-switches

[root@five ~]# perf stat -e context-switches,cgroup-switches taskset -c 0 perf bench sched pipe -l 10000 # Running 'sched/pipe' benchmark:
# Executed 10000 pipe operations between two processes

     Total time: 0.063 [sec]

       6.367500 usecs/op
         157047 ops/sec

Performance counter stats for 'taskset -c 0 perf bench sched pipe -l 10000':

            20,004      context-switches
                 4      cgroup-switches

       0.084191842 seconds time elapsed

       0.008332000 seconds user
       0.067193000 seconds sys

[root@five ~]# perf stat -e context-switches,cgroup-switches taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB # Running 'sched/pipe' benchmark:
no access to cgroup /sys/fs/cgroup/BBB
Failed to open cgroup file in BBB
Hint: create the cgroup first, like 'mkdir /sys/fs/cgroup/BBB'
no access to cgroup /sys/fs/cgroup/AAA
Failed to open cgroup file in AAA
Hint: create the cgroup first, like 'mkdir /sys/fs/cgroup/AAA'

Performance counter stats for 'taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB':

                 2      context-switches
                 1      cgroup-switches

       0.010356533 seconds time elapsed

       0.003209000 seconds user
       0.007122000 seconds sys

[root@five ~]# vim /tmp/bla
[root@five ~]#
[root@five ~]# mkdir /sys/fs/cgroup/BBB /sys/fs/cgroup/AAA
[root@five ~]# perf stat -e context-switches,cgroup-switches taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB # Running 'sched/pipe' benchmark:
# Executed 10000 pipe operations between two processes

     Total time: 0.079 [sec]

       7.987800 usecs/op
         125190 ops/sec

Performance counter stats for 'taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB':

            20,008      context-switches
            20,007      cgroup-switches

       0.089361029 seconds time elapsed

       0.009004000 seconds user
       0.065376000 seconds sys

[root@five ~]#

author maintainer
#2 lore raw
Quoted 5 lines · Arnaldo Carvalho de Melo

Em Tue, Oct 17, 2023 at 01:23:42PM -0700, Namhyung Kim escreveu:

Quoted 2 lines

The -G/--cgroups option is to put sender and receiver in different cgroups in order to measure cgroup context switch overheads.

<SNIP>

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB > /dev/null

Performance counter stats for 'taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB':

              20,001      context-switches
              20,001      cgroup-switches

Thanks a lot Arnaldo!

Ingo, can I keep you Acked-by here? (forgot to add in v4, sorry!)

Thanks,
Namhyung

Quoted 65 lines

[root@five ~]# perf stat -e context-switches,cgroup-switches taskset -c 0 perf bench sched pipe -l 10000 # Running 'sched/pipe' benchmark:
# Executed 10000 pipe operations between two processes

     Total time: 0.063 [sec]

       6.367500 usecs/op
         157047 ops/sec

Performance counter stats for 'taskset -c 0 perf bench sched pipe -l 10000':

            20,004      context-switches
                 4      cgroup-switches

       0.084191842 seconds time elapsed

       0.008332000 seconds user
       0.067193000 seconds sys

[root@five ~]# perf stat -e context-switches,cgroup-switches taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB # Running 'sched/pipe' benchmark:
no access to cgroup /sys/fs/cgroup/BBB
Failed to open cgroup file in BBB
Hint: create the cgroup first, like 'mkdir /sys/fs/cgroup/BBB'
no access to cgroup /sys/fs/cgroup/AAA
Failed to open cgroup file in AAA
Hint: create the cgroup first, like 'mkdir /sys/fs/cgroup/AAA'

Performance counter stats for 'taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB':

                 2      context-switches
                 1      cgroup-switches

       0.010356533 seconds time elapsed

       0.003209000 seconds user
       0.007122000 seconds sys

[root@five ~]# vim /tmp/bla
[root@five ~]#
[root@five ~]# mkdir /sys/fs/cgroup/BBB /sys/fs/cgroup/AAA
[root@five ~]# perf stat -e context-switches,cgroup-switches taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB # Running 'sched/pipe' benchmark:
# Executed 10000 pipe operations between two processes

     Total time: 0.079 [sec]

       7.987800 usecs/op
         125190 ops/sec

Performance counter stats for 'taskset -c 0 perf bench sched pipe -l 10000 -G AAA,BBB':

            20,008      context-switches
            20,007      cgroup-switches

       0.089361029 seconds time elapsed

       0.009004000 seconds user
       0.065376000 seconds sys

[root@five ~]#

author maintainer Applied
#3 lore raw
In reply to Namhyung Kim
Quoted 10 lines · Namhyung Kim

The -G/--cgroups option is to put sender and receiver in different cgroups in order to measure cgroup context switch overheads.

Users need to make sure the cgroups exist and accessible. The following example should the effect of this change. Please don't forget taskset before the perf bench to measure cgroup switches properly. Otherwise each task would run on a different CPU and generate cgroup switches regardless of this change.

[...]

Applied to perf-tools-next, thanks!