From: Mauro Carvalho Chehab Date: Tue, 26 Feb 2013 12:15:30 +0000 (-0300) Subject: Add logic to enable/disable RAS events X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=50b1e9679970423f1078a005d5a1bcabd762e7a6;p=users%2Fmchehab%2Fedactool.git Add logic to enable/disable RAS events Signed-off-by: Mauro Carvalho Chehab --- diff --git a/edactool.c b/edactool.c index 59143ee..eeedaf6 100644 --- a/edactool.c +++ b/edactool.c @@ -30,6 +30,8 @@ #include #include #include +#include "kbuffer.h" +#include "event-parse.h" #define PAGE_SIZE 0x400 /* Test for a little-endian machine */ @@ -39,14 +41,52 @@ #define ENDIAN KBUFFER_ENDIAN_BIG #endif -#include "kbuffer.h" -#include "event-parse.h" +#define DEBUGFS "/sys/kernel/debug/" + +#define ENABLE_RAS_MC_EVENT "ras:mc_event\n" +#define DISABLE_RAS_MC_EVENT "!" ENABLE_RAS_MC_EVENT /* - * Tracing read code + * Tracing enable/disable code */ +static int toggle_ras_mc_event(int enable) +{ + int fd, rc; + + /* Enable RAS events */ + fd = open(DEBUGFS "tracing/set_event", O_RDWR | O_APPEND); + if (fd < 0) { + perror("Open set_event"); + return errno; + } + if (enable) + rc = write(fd, ENABLE_RAS_MC_EVENT, + sizeof(ENABLE_RAS_MC_EVENT)); + else + rc = write(fd, DISABLE_RAS_MC_EVENT, + sizeof(DISABLE_RAS_MC_EVENT)); + if (rc < 0) { + perror("can't write to set_event"); + close(fd); + return rc; + } + close(fd); + if (!rc) { + fprintf(stderr, "nothing was written on set_event\n"); + return EIO; + } + if (enable) + printf("RAS events enabled\n"); + else + printf("RAS events disabled\n"); + return 0; +} + +/* + * Tracing read code + */ static void parse_ras_data(struct pevent *pevent, struct kbuffer *kbuf, void *data, unsigned long long time_stamp) { struct pevent_record record; @@ -104,7 +144,7 @@ static int handle_ras_events_cpu(struct pevent *pevent, int cpu) } /* FIXME: use select to open for all CPUs */ - fd = open("/sys/kernel/debug/tracing/per_cpu/cpu0/trace_pipe_raw", + fd = open(DEBUGFS "tracing/per_cpu/cpu0/trace_pipe_raw", O_RDONLY); if (fd < 0) { perror("Can't open trace_pipe_raw"); @@ -127,16 +167,19 @@ static int handle_ras_events(void) struct pevent *pevent; void *page; + /* Enable RAS events */ + rc = toggle_ras_mc_event(1); + pevent = pevent_alloc(); if (!pevent) { perror("Can't allocate pevent"); return errno; } - fd = open("/sys/kernel/debug/tracing/events/ras/mc_event/format", + fd = open(DEBUGFS "tracing/events/ras/mc_event/format", O_RDONLY); if (fd < 0) { - perror("open ras format"); + perror("Open ras format"); rc = errno; goto free_pevent; } @@ -183,7 +226,7 @@ const char *argp_program_version = TOOL_NAME " " VERSION; const char *argp_program_bug_address = "Mauro Carvalho Chehab "; struct arguments { - int handle_events; + int handle_events, enable_ras; }; static error_t parse_opt(int k, char *arg, struct argp_state *state) @@ -194,6 +237,12 @@ static error_t parse_opt(int k, char *arg, struct argp_state *state) case 'r': args->handle_events++; break; + case 'e': + args->enable_ras++; + break; + case 'd': + args->enable_ras--; + break; default: return ARGP_ERR_UNKNOWN; } @@ -205,7 +254,10 @@ int main(int argc, char *argv[]) struct arguments args; int idx = -1; const struct argp_option options[] = { - {"read", 'r', 0, 0, "read RAS events", 0}, + {"read", 'r', 0, 0, "read RAS events", 0}, + {"enable", 'e', 0, 0, "enable RAS events", 0}, + {"disable", 'd', 0, 0, "disable RAS events", 0}, + { 0, 0, 0, 0, 0, 0 } }; const struct argp argp = { @@ -224,6 +276,11 @@ int main(int argc, char *argv[]) return -1; } + if (args.enable_ras > 0) + toggle_ras_mc_event(1); + else if (args.enable_ras < 0) + toggle_ras_mc_event(0); + if (args.handle_events) handle_ras_events();