[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-edac
Subject:    [PATCH 03/10] rasd: add trace event support
From:       Jean Pihet <jean.pihet () linaro ! org>
Date:       2014-09-25 9:55:54
Message-ID: 1411638961-8112-3-git-send-email-jean.pihet () linaro ! org
[Download RAW message or body]

The added functionality is:
- look for a specific tracepoint in debugfs,
- extract the id value from the tracepoint and fill in the
  perf_event_attr fields accordingly,
- fill in the rasd_event struct for future use: format parsing etc.

Signed-off-by: Jean Pihet <jean.pihet@linaro.org>
---
 include/trace_event.h |  6 ++++++
 src/Makefile          |  2 ++
 src/trace_event.c     | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+)
 create mode 100644 include/trace_event.h
 create mode 100644 src/trace_event.c

diff --git a/include/trace_event.h b/include/trace_event.h
new file mode 100644
index 0000000..577d54d
--- /dev/null
+++ b/include/trace_event.h
@@ -0,0 +1,6 @@
+#include <linux/perf_event.h>
+
+#define EVENTS_DIR_MAX_LENGTH	4096
+
+int setup_event_tp(struct perf_event_attr *attr, char *sys, char *name,
+		   struct rasd_event *re);
diff --git a/src/Makefile b/src/Makefile
index f400583..c6110a7 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -33,6 +33,7 @@ HEADERS += $(HPFX)/strlist.h
 HEADERS += $(HPFX)/symbol.h
 HEADERS += $(HPFX)/target.h
 HEADERS += $(HPFX)/thread_map.h
+HEADERS += $(HPFX)/trace_event.h
 HEADERS += $(HPFX)/xyarray.h
 
 OBJS += cpumap.o
@@ -48,6 +49,7 @@ OBJS += rblist.o
 OBJS += rbtree.o
 OBJS += strlist.o
 OBJS += thread_map.o
+OBJS += trace_event.o
 OBJS += util.o
 OBJS += xyarray.o
 
diff --git a/src/trace_event.c b/src/trace_event.c
new file mode 100644
index 0000000..53dbc55
--- /dev/null
+++ b/src/trace_event.c
@@ -0,0 +1,58 @@
+#include <sys/stat.h>
+
+#include "debug.h"
+#include "debugfs.h"
+#include "trace_event.h"
+
+#define EVENTS_DIR_SUFFIX	"tracing/events"
+#define EVENT_ID		"id"
+
+
+/*
+ * Find the tracepoint event by the name and fill in the attr struct
+ * Fill in the rasd_event struct for future use
+ */
+int setup_event_tp(struct perf_event_attr *attr, char *sys, char *name,
+		   struct rasd_event *re)
+{
+	char event_id_path[EVENTS_DIR_MAX_LENGTH];
+	struct stat file_status;
+	FILE *fd;
+	int id;
+
+	snprintf(event_id_path, EVENTS_DIR_MAX_LENGTH,
+		 "%s/" EVENTS_DIR_SUFFIX "/%s/%s/" EVENT_ID,
+		 debugfs_mountpoint, sys, name);
+
+	/*
+	 * Open the event id file and retrieve the value
+	 *
+	 * attr->type is already set to PERF_TYPE_TRACEPOINT when creating
+	 * the evsel entry (in perf_evsel__newtp_idx).
+	 */
+	if ((stat(event_id_path, &file_status) == 0) &&
+	    (S_ISREG(file_status.st_mode))) {
+		fd = fopen(event_id_path, "r");
+		if ((fd != NULL) && (fscanf(fd, "%d", &id) != EOF)) {
+			/* Assign event path */
+			re->event_path = zalloc(EVENTS_DIR_MAX_LENGTH);
+			if (!re->event_path)
+				return -ENOMEM;
+
+			snprintf(re->event_path, EVENTS_DIR_MAX_LENGTH,
+				 "%s/" EVENTS_DIR_SUFFIX "/%s/%s",
+				 debugfs_mountpoint, sys, name);
+
+			/* Assign id */
+			attr->config = id;
+			re->id = id;
+		} else {
+			return -ENODEV;
+		}
+		fclose(fd);
+	} else {
+		return -EINVAL;
+	}
+
+	return 0;
+}
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-edac" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic