From: Mauro Carvalho Chehab Date: Tue, 26 Feb 2013 12:35:10 +0000 (-0300) Subject: Get the number of CPUs, according with the per_cpu tracing X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=eb18ed48ae503f6c442f74964a9f52abef34065e;p=users%2Fmchehab%2Fedactool.git Get the number of CPUs, according with the per_cpu tracing Signed-off-by: Mauro Carvalho Chehab --- diff --git a/edactool.c b/edactool.c index eeedaf6..1be5078 100644 --- a/edactool.c +++ b/edactool.c @@ -21,15 +21,16 @@ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include #include +#include +#include #include -#include +#include #include +#include #include -#include #include -#include +#include #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);