]> www.infradead.org Git - users/mchehab/edactool.git/commitdiff
Get the number of CPUs, according with the per_cpu tracing
authorMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 26 Feb 2013 12:35:10 +0000 (09:35 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 26 Feb 2013 12:49:04 +0000 (09:49 -0300)
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
edactool.c

index eeedaf6127fe206bbc63d13b7a66ef03b4bb970b..1be507837ad8e6e6f5cbdaf0718127d86e7cdf53 100644 (file)
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <stdio.h>
 #include <argp.h>
+#include <dirent.h>
+#include <errno.h>
 #include <fcntl.h>
-#include <string.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
-#include <sys/types.h>
 #include <sys/stat.h>
-#include <errno.h>
+#include <sys/types.h>
 #include "kbuffer.h"
 #include "event-parse.h"
 
@@ -124,6 +125,26 @@ static int read_ras_event(int fd, struct pevent *pevent, struct kbuffer *kbuf, v
        return 0;
 }
 
+static int get_num_cpus(void)
+{
+       int num_cpus = 0;
+
+       DIR             *dir;
+       struct dirent   *entry;
+
+       dir = opendir(DEBUGFS "tracing/per_cpu/");
+       if (!dir)
+               return -1;
+
+       for (entry = readdir(dir); entry; entry = readdir(dir)) {
+               if (strstr(entry->d_name, "cpu"))
+                       num_cpus++;
+       }
+       closedir(dir);
+
+       return num_cpus;
+}
+
 static int handle_ras_events_cpu(struct pevent *pevent, int cpu)
 {
        int rc, fd;
@@ -143,6 +164,9 @@ static int handle_ras_events_cpu(struct pevent *pevent, int cpu)
                return errno;
        }
 
+       printf("Number of CPUs: %d. For now, opening just cpu0\n",
+              get_num_cpus());
+
        /* FIXME: use select to open for all CPUs */
        fd = open(DEBUGFS "tracing/per_cpu/cpu0/trace_pipe_raw",
                  O_RDONLY);