linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] perf test record.sh: Raise limit of open file descriptors
@ 2024-08-14 15:17 vmolnaro
  2024-08-14 15:32 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 11+ messages in thread
From: vmolnaro @ 2024-08-14 15:17 UTC (permalink / raw)
  To: linux-perf-users, acme, acme
  Cc: adrian.hunter, atrajeev, irogers, jolsa, kjain, mpetlan, rstoyano

From: Veronika Molnarova <vmolnaro@redhat.com>

Subtest for system-wide record with '--threads=cpu' option fails due
to a limit of open file descriptors on systems with 128 or more CPUs
as the default limit is set to 1024.

The number of open file descriptors should be slightly above
nmb_events*nmb_cpus + nmb_cpus(for perf.data.n) + 4*nmb_cpus(for pipes),
which equals 8*nmb_cpus. Therefore, temporarily raise the limit to
16*nmb_cpus for the test.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Radostin Stoyanov <rstoyano@redhat.com>
Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
---
v2: Rebase the patch to apply upstream
v3: Fix shellcheck warnings
---
 tools/perf/tests/shell/record.sh | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
index 3d1a7759a7b2..c1160d36311a 100755
--- a/tools/perf/tests/shell/record.sh
+++ b/tools/perf/tests/shell/record.sh
@@ -22,6 +22,21 @@ cpu_pmu_dir="/sys/bus/event_source/devices/cpu*"
 br_cntr_file="/caps/branch_counter_nr"
 br_cntr_output="branch stack counters"
 
+ulimit_supported=false
+# With option --threads=cpu the number of open file descriptors should be
+# equal to sum of:    nmb_cpus * nmb_events (2+dummy),
+#                     nmb_threads for perf.data.n (equal to nmb_cpus) and
+#                     2*nmb_cpus of pipes = 4*nmb_cpus (each pipe has 2 ends)
+# All together it needs 8*nmb_cpus file descriptors plus some are also used
+# outside of testing, thus raising the limit to 16*nmb_cpus
+min_fd_limit=$(($(getconf _NPROCESSORS_ONLN) * 16))
+
+# shellcheck disable=SC3045 # ulimit is required for testing --threads option
+default_fd_limit=$(ulimit -Sn)
+if [ $? -eq 0 ]; then
+  ulimit_supported=true
+fi
+
 cleanup() {
   rm -rf "${perfdata}"
   rm -rf "${perfdata}".old
@@ -107,6 +122,11 @@ test_register_capture() {
 
 test_system_wide() {
   echo "Basic --system-wide mode test"
+  if [ ! $ulimit_supported ] && [ $min_fd_limit -gt 1024 ]
+  then
+    echo "Limited file descriptors for --threads option [Skipped not available]"
+    return
+  fi
   if ! perf record -aB --synth=no -o "${perfdata}" ${testprog} 2> /dev/null
   then
     echo "System-wide record [Skipped not supported]"
@@ -190,11 +210,23 @@ test_branch_counter() {
   echo "Basic branch counter test [Success]"
 }
 
+# raise the limit of file descriptors to required minimum
+if [ $ulimit_supported ] && [ $default_fd_limit -lt $min_fd_limit ]; then
+  # shellcheck disable=SC3045 # ulimit is required for testing --threads option
+  ulimit -Sn $min_fd_limit
+fi
+
 test_per_thread
 test_register_capture
 test_system_wide
 test_workload
 test_branch_counter
 
+# restore the default value
+if [ $ulimit_supported ]; then
+  # shellcheck disable=SC3045 # ulimit is required for testing --threads option
+  ulimit -Sn $default_fd_limit
+fi
+
 cleanup
 exit $err
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [PATCH v3] perf test record.sh: Raise limit of open file descriptors
@ 2024-08-14 15:47 vmolnaro
  0 siblings, 0 replies; 11+ messages in thread
From: vmolnaro @ 2024-08-14 15:47 UTC (permalink / raw)
  To: linux-perf-users, acme, acme
  Cc: adrian.hunter, atrajeev, irogers, jolsa, kjain, mpetlan, rstoyano

From: Veronika Molnarova <vmolnaro@redhat.com>

Subtest for system-wide record with '--threads=cpu' option fails due
to a limit of open file descriptors on systems with 128 or more CPUs
as the default limit is set to 1024.

The number of open file descriptors should be slightly above
nmb_events*nmb_cpus + nmb_cpus(for perf.data.n) + 4*nmb_cpus(for pipes),
which equals 8*nmb_cpus. Therefore, temporarily raise the limit to
16*nmb_cpus for the test.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Radostin Stoyanov <rstoyano@redhat.com>
Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
---
v2: Rebase the patch to apply upstream
v3: Switch to bash to fix shellcheck warnings
---
 tools/perf/tests/shell/record.sh | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
index 3d1a7759a7b2..02b706792737 100755
--- a/tools/perf/tests/shell/record.sh
+++ b/tools/perf/tests/shell/record.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 # perf record tests
 # SPDX-License-Identifier: GPL-2.0
 
@@ -22,6 +22,15 @@ cpu_pmu_dir="/sys/bus/event_source/devices/cpu*"
 br_cntr_file="/caps/branch_counter_nr"
 br_cntr_output="branch stack counters"
 
+# With option --threads=cpu the number of open file descriptors should be
+# equal to sum of:    nmb_cpus * nmb_events (2+dummy),
+#                     nmb_threads for perf.data.n (equal to nmb_cpus) and
+#                     2*nmb_cpus of pipes = 4*nmb_cpus (each pipe has 2 ends)
+# All together it needs 8*nmb_cpus file descriptors plus some are also used
+# outside of testing, thus raising the limit to 16*nmb_cpus
+min_fd_limit=$(($(getconf _NPROCESSORS_ONLN) * 16))
+default_fd_limit=$(ulimit -Sn)
+
 cleanup() {
   rm -rf "${perfdata}"
   rm -rf "${perfdata}".old
@@ -190,11 +199,19 @@ test_branch_counter() {
   echo "Basic branch counter test [Success]"
 }
 
+# raise the limit of file descriptors to required minimum
+if [ $default_fd_limit -lt $min_fd_limit ]; then
+  ulimit -Sn $min_fd_limit
+fi
+
 test_per_thread
 test_register_capture
 test_system_wide
 test_workload
 test_branch_counter
 
+# restore the default value
+ulimit -Sn $default_fd_limit
+
 cleanup
 exit $err
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-08-14 16:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-14 15:17 [PATCH v3] perf test record.sh: Raise limit of open file descriptors vmolnaro
2024-08-14 15:32 ` Arnaldo Carvalho de Melo
2024-08-14 15:35   ` Arnaldo Carvalho de Melo
2024-08-14 15:42     ` Veronika Molnarova
2024-08-14 15:54       ` Arnaldo Carvalho de Melo
2024-08-14 15:56         ` Arnaldo Carvalho de Melo
2024-08-14 16:04           ` Veronika Molnarova
2024-08-14 16:39             ` Arnaldo Carvalho de Melo
2024-08-14 15:58         ` Veronika Molnarova
2024-08-14 15:53     ` Arnaldo Carvalho de Melo
  -- strict thread matches above, loose matches on Subject: below --
2024-08-14 15:47 vmolnaro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).