New version of unlimit-fds patch

- Fixed error message if FDs limit is reached (by fd-limit-err patch)
This commit is contained in:
Jaroslav Škarvada 2013-10-10 12:22:39 +02:00
parent 895093e85e
commit c76e0cb9d7
3 changed files with 86 additions and 34 deletions

View File

@ -0,0 +1,38 @@
diff -up powertop-2.4/src/perf/perf.cpp.orig powertop-2.4/src/perf/perf.cpp
--- powertop-2.4/src/perf/perf.cpp.orig 2013-01-31 16:39:27.000000000 -0500
+++ powertop-2.4/src/perf/perf.cpp 2013-09-19 10:36:02.298839248 -0400
@@ -26,6 +26,7 @@
#include <iostream>
#include <fstream>
+#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
@@ -72,6 +73,7 @@ void perf_event::create_perf_event(char
{
struct perf_event_attr attr;
int ret;
+ int err;
struct {
__u64 count;
@@ -107,10 +109,15 @@ void perf_event::create_perf_event(char
perf_fd = sys_perf_event_open(&attr, -1, _cpu, -1, 0);
if (perf_fd < 0) {
+ err = errno;
reset_display();
- fprintf(stderr, _("PowerTOP %s needs the kernel to support the 'perf' subsystem\n"), POWERTOP_VERSION);
- fprintf(stderr, _("as well as support for trace points in the kernel:\n"));
- fprintf(stderr, "CONFIG_PERF_EVENTS=y\nCONFIG_PERF_COUNTERS=y\nCONFIG_TRACEPOINTS=y\nCONFIG_TRACING=y\n");
+ if (err == EMFILE)
+ fprintf(stderr, _("Too many open files, please increase the limit of open file descriptors.\n"));
+ else {
+ fprintf(stderr, _("PowerTOP %s needs the kernel to support the 'perf' subsystem\n"), POWERTOP_VERSION);
+ fprintf(stderr, _("as well as support for trace points in the kernel:\n"));
+ fprintf(stderr, "CONFIG_PERF_EVENTS=y\nCONFIG_PERF_COUNTERS=y\nCONFIG_TRACEPOINTS=y\nCONFIG_TRACING=y\n");
+ }
exit(EXIT_FAILURE);
}
if (read(perf_fd, &read_data, sizeof(read_data)) == -1) {

View File

@ -1,33 +1,16 @@
From 4cbb957605818dc7e4b7932dafac0aad5ed0b87a Mon Sep 17 00:00:00 2001
From: Youquan Song <youquan.song@linux.intel.com>
Date: Tue, 4 Jun 2013 17:31:23 -0400
Subject: [PATCH] Fix running failure when > 69 CPUs for open file limitation
Powertop 2.3 fails to run on machine with > 69 CPUs because system open files
limitation of one process is 1024 default, While powertop will open one file
for every monitored perf_event (at least 15) each CPU.
Like on 80 CPUs Westmere-EX machine, powertop will fail to run with below:
PowerTOP v2.3 needs the kernel to support the 'perf' subsystem
as well as support for trace points in the kernel:
CONFIG_PERF_EVENTS=y
CONFIG_PERF_COUNTERS=y
CONFIG_TRACEPOINTS=y
CONFIG_TRACING=y
This patch is to change RLIMIT_NOFILE from default (1024) to max limition.
Signed-off-by: Youquan Song <youquan.song@intel.com>
---
src/main.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/main.cpp b/src/main.cpp
index 46466b0..e74890f 100644
index 0883424..16b1613 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,6 +36,7 @@
@@ -28,6 +28,7 @@
* Arjan van de Ven <arjan@linux.intel.com>
*/
#include <iostream>
+#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
@@ -36,6 +37,7 @@
#include <getopt.h>
#include <unistd.h>
#include <locale.h>
@ -35,7 +18,35 @@ index 46466b0..e74890f 100644
#include "cpu/cpu.h"
#include "process/process.h"
@@ -283,11 +284,17 @@ static void powertop_init(void)
@@ -60,6 +62,8 @@
#define DEBUGFS_MAGIC 0x64626720
+#define NR_OPEN_DEF 1024 * 1024
+
int debug_learning = 0;
unsigned time_out = 20;
int leave_powertop = 0;
@@ -278,16 +282,35 @@ static void checkroot() {
}
+static int get_nr_open(void) {
+ int nr_open = NR_OPEN_DEF;
+ ifstream file;
+
+ file.open("/proc/sys/fs/nr_open", ios::in);
+ if (file) {
+ file >> nr_open;
+ if (!file)
+ nr_open = NR_OPEN_DEF;
+ file.close();
+ }
+ return nr_open;
+}
+
static void powertop_init(void)
{
static char initialized = 0;
int ret;
struct statfs st_fs;
@ -46,13 +57,9 @@ index 46466b0..e74890f 100644
checkroot();
+
+ getrlimit (RLIMIT_NOFILE, &rlmt);
+ rlmt.rlim_cur = rlmt.rlim_max;
+ rlmt.rlim_cur = rlmt.rlim_max = get_nr_open();
+ setrlimit (RLIMIT_NOFILE, &rlmt);
+
ret = system("/sbin/modprobe cpufreq_stats > /dev/null 2>&1");
ret = system("/sbin/modprobe msr > /dev/null 2>&1");
statfs("/sys/kernel/debug", &st_fs);
--
1.8.4

View File

@ -1,6 +1,6 @@
Name: powertop
Version: 2.4
Release: 4%{?dist}
Release: 5%{?dist}
Summary: Power consumption monitor
Group: Applications/System
@ -16,6 +16,8 @@ Patch1: powertop-2.3-man-fix.patch
Patch2: powertop-2.3-ondemand-check.patch
# Accepted upstream
Patch3: powertop-2.4-unlimit-fds.patch
# Accepted upstream
Patch4: powertop-2.4-fd-limit-err.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: gettext, ncurses-devel, pciutils-devel, zlib-devel, libnl3-devel
Requires(post): coreutils
@ -30,6 +32,7 @@ computer use more power than necessary while it is idle.
%patch1 -p1 -b .man-fix
%patch2 -p1 -b .ondemand-check
%patch3 -p1 -b .unlimit-fds
%patch4 -p1 -b .fd-limit-err
# remove left over object files
find . -name "*.o" -exec rm {} \;
@ -62,6 +65,10 @@ rm -rf %{buildroot}
%{_mandir}/man8/powertop.8*
%changelog
* Thu Oct 10 2013 Jaroslav Škarvada <jskarvad@redhat.com> - 2.4-5
- New version of unlimit-fds patch
- Fixed error message if FDs limit is reached (by fd-limit-err patch)
* Fri Sep 20 2013 Jaroslav Škarvada <jskarvad@redhat.com> - 2.4-4
- Unlimit FDs (by unlimit-fds patch) and dropped the fd-limit-err patch