powertop registers quite some perf events per cpu.
I get a misleading error message pointing to wrong kernel settings if
the file descriptors run out.

This improves the error message to:
Registered 1021 perf events, failed due to file descriptor limits
Try again with increased limit: ulimit -n <limit>

Signed-off-by: Thomas Renninger <[email protected]>

diff --git a/perf/perf.cpp b/perf/perf.cpp
index 73682aa..e0eef9d 100644
--- a/perf/perf.cpp
+++ b/perf/perf.cpp
@@ -72,6 +72,7 @@ void perf_event::create_perf_event(char *eventname, int _cpu)
 {
        struct perf_event_attr attr;
        int ret;
+       static int file_count = 0;
 
        struct {
                __u64 count;
@@ -108,9 +109,14 @@ void perf_event::create_perf_event(char *eventname, int 
_cpu)
 
        if (perf_fd < 0) {
                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 (errno == 24) {
+                       fprintf(stderr, _("Registered %d perf events, failed 
due to file descriptor limits\n"), file_count);
+                       fprintf(stderr, _("Try again with increased limit: 
ulimit -n <limit>\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) {
@@ -137,7 +143,7 @@ void perf_event::create_perf_event(char *eventname, int 
_cpu)
        pc = (perf_event_mmap_page *)perf_mmap;
        data_mmap = (unsigned char *)perf_mmap + getpagesize();
 
-
+       file_count++;
 }
 
 void perf_event::set_event_name(const char *event_name)

_______________________________________________
Power mailing list
[email protected]
http://www.bughost.org/mailman/listinfo/power

Reply via email to