[SRU][Jammy][PATCH 1/1] tools/power turbostat: Increase the limit for fd opened
Matthew Ruffell
matthew.ruffell at canonical.com
Tue Aug 27 00:42:06 UTC 2024
From: Wyes Karny <wyes.karny at amd.com>
BugLink: https://bugs.launchpad.net/bugs/2069961
When running turbostat, a system with 512 cpus reaches the limit for
maximum number of file descriptors that can be opened. To solve this
problem, the limit is raised to 2^15, which is a large enough number.
Below data is collected from AMD server systems while running turbostat:
|-----------+-------------------------------|
| # of cpus | # of opened fds for turbostat |
|-----------+-------------------------------|
| 128 | 260 |
|-----------+-------------------------------|
| 192 | 388 |
|-----------+-------------------------------|
| 512 | 1028 |
|-----------+-------------------------------|
So, the new max limit would be sufficient up to 2^14 cpus (but this
also depends on how many counters are enabled).
Reviewed-by: Doug Smythies <dsmythies at telus.net>
Tested-by: Doug Smythies <dsmythies at telus.net>
Signed-off-by: Wyes Karny <wyes.karny at amd.com>
Signed-off-by: Len Brown <len.brown at intel.com>
(backported from commit 3ac1d14d0583a2de75d49a5234d767e2590384dd)
[mruffell: minor context adjustment in first hunk]
Signed-off-by: Matthew Ruffell <matthew.ruffell at canonical.com>
---
tools/power/x86/turbostat/turbostat.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 550c6dfc4f04..84a138266ed7 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -166,6 +166,8 @@ int ignore_stdin;
#define NAME_BYTES 20
#define PATH_BYTES 128
+#define MAX_NOFILE 0x8000
+
int backwards_count;
char *progname;
@@ -6430,6 +6432,22 @@ void cmdline(int argc, char **argv)
}
}
+void set_rlimit(void)
+{
+ struct rlimit limit;
+
+ if (getrlimit(RLIMIT_NOFILE, &limit) < 0)
+ err(1, "Failed to get rlimit");
+
+ if (limit.rlim_max < MAX_NOFILE)
+ limit.rlim_max = MAX_NOFILE;
+ if (limit.rlim_cur < MAX_NOFILE)
+ limit.rlim_cur = MAX_NOFILE;
+
+ if (setrlimit(RLIMIT_NOFILE, &limit) < 0)
+ err(1, "Failed to set rlimit");
+}
+
int main(int argc, char **argv)
{
outf = stderr;
@@ -6440,6 +6458,9 @@ int main(int argc, char **argv)
probe_sysfs();
+ if (!getuid())
+ set_rlimit();
+
turbostat_init();
/* dump counters and exit */
--
2.45.2
More information about the kernel-team
mailing list