krishnanadh / rpms / rasdaemon

Forked from rpms/rasdaemon a year ago
Clone
d9e469
From 0a31d938cf29e065e96de1206a7d35042962e02a Mon Sep 17 00:00:00 2001
d9e469
From: Mauro Carvalho Chehab <mchehab@redhat.com>
d9e469
Date: Fri, 31 May 2013 14:18:24 -0300
d9e469
Subject: [PATCH 07/32] Add support to store MCE events at the database
d9e469
d9e469
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
d9e469
---
d9e469
 ras-mce-handler.c |    5 +++
d9e469
 ras-record.c      |  104 +++++++++++++++++++++++++++++++++++++++++++++++++++-
d9e469
 ras-record.h      |    9 +++++
d9e469
 3 files changed, 116 insertions(+), 2 deletions(-)
d9e469
d9e469
diff --git a/ras-mce-handler.c b/ras-mce-handler.c
d9e469
index 614a0eb..59e8d05 100644
d9e469
--- a/ras-mce-handler.c
d9e469
+++ b/ras-mce-handler.c
d9e469
@@ -396,5 +396,10 @@ int ras_mce_event_handler(struct trace_seq *s,
d9e469
 		return rc;
d9e469
 
d9e469
 	report_mce_event(ras, record, s, &e);
d9e469
+
d9e469
+#ifdef HAVE_SQLITE3
d9e469
+	ras_store_mce_record(ras, &e);
d9e469
+#endif
d9e469
+
d9e469
 	return 0;
d9e469
 }
d9e469
diff --git a/ras-record.c b/ras-record.c
d9e469
index cb302ce..daa3cb1 100644
d9e469
--- a/ras-record.c
d9e469
+++ b/ras-record.c
d9e469
@@ -27,6 +27,7 @@
d9e469
 #include "ras-events.h"
d9e469
 #include "ras-mc-handler.h"
d9e469
 #include "ras-aer-handler.h"
d9e469
+#include "ras-mce-handler.h"
d9e469
 #include "ras-logger.h"
d9e469
 
d9e469
 /* #define DEBUG_SQL 1 */
d9e469
@@ -135,7 +136,7 @@ int ras_store_aer_event(struct ras_events *ras, struct ras_aer_event *ev)
d9e469
 
d9e469
 	if (!priv || !priv->stmt_aer_event)
d9e469
 		return 0;
d9e469
-	log(TERM, LOG_INFO, "mc_event store: %p\n", priv->stmt_aer_event);
d9e469
+	log(TERM, LOG_INFO, "aer_event store: %p\n", priv->stmt_aer_event);
d9e469
 
d9e469
 	sqlite3_bind_text(priv->stmt_aer_event,  1, ev->timestamp, -1, NULL);
d9e469
 	sqlite3_bind_text(priv->stmt_aer_event,  3, ev->error_type, -1, NULL);
d9e469
@@ -156,6 +157,98 @@ int ras_store_aer_event(struct ras_events *ras, struct ras_aer_event *ev)
d9e469
 }
d9e469
 #endif
d9e469
 
d9e469
+
d9e469
+/*
d9e469
+ * Table and functions to handle mce:mce_record
d9e469
+ */
d9e469
+
d9e469
+#ifdef HAVE_MCE
d9e469
+static const struct db_fields mce_record_fields[] = {
d9e469
+		{ .name="id",			.type="INTEGER PRIMARY KEY" },
d9e469
+		{ .name="timestamp",		.type="TEXT" },
d9e469
+
d9e469
+		/* MCE registers */
d9e469
+		{ .name="mcgcap",		.type="INTEGER" },
d9e469
+		{ .name="mcgstatus",		.type="INTEGER" },
d9e469
+		{ .name="status",		.type="INTEGER" },
d9e469
+		{ .name="addr",			.type="INTEGER" }, // 5
d9e469
+		{ .name="misc",			.type="INTEGER" },
d9e469
+		{ .name="ip",			.type="INTEGER" },
d9e469
+		{ .name="tsc",			.type="INTEGER" },
d9e469
+		{ .name="walltime",		.type="INTEGER" },
d9e469
+		{ .name="cpu",			.type="INTEGER" }, // 10
d9e469
+		{ .name="cpuid",		.type="INTEGER" },
d9e469
+		{ .name="apicid",		.type="INTEGER" },
d9e469
+		{ .name="socketid",		.type="INTEGER" },
d9e469
+		{ .name="cs",			.type="INTEGER" },
d9e469
+		{ .name="bank",			.type="INTEGER" }, //15
d9e469
+		{ .name="cpuvendor",		.type="INTEGER" },
d9e469
+
d9e469
+		/* Parsed data - will likely change */
d9e469
+		{ .name="bank_name",		.type="TEXT" },
d9e469
+		{ .name="error_msg",		.type="TEXT" },
d9e469
+		{ .name="mcgstatus_msg",	.type="TEXT" },
d9e469
+		{ .name="mcistatus_msg",	.type="TEXT" }, // 20
d9e469
+		{ .name="user_action",		.type="TEXT" },
d9e469
+		{ .name="mc_location",		.type="TEXT" },
d9e469
+};
d9e469
+
d9e469
+static const struct db_table_descriptor mce_record_tab = {
d9e469
+	.name = "mce_record",
d9e469
+	.fields = mce_record_fields,
d9e469
+	.num_fields = ARRAY_SIZE(mce_record_fields),
d9e469
+};
d9e469
+
d9e469
+int ras_store_mce_record(struct ras_events *ras, struct mce_event *ev)
d9e469
+{
d9e469
+	int rc;
d9e469
+	struct sqlite3_priv *priv = ras->db_priv;
d9e469
+
d9e469
+	if (!priv || !priv->stmt_mce_record)
d9e469
+		return 0;
d9e469
+	log(TERM, LOG_INFO, "mce_record store: %p\n", priv->stmt_mce_record);
d9e469
+
d9e469
+	sqlite3_bind_text(priv->stmt_mce_record,  1, ev->timestamp, -1, NULL);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record,  2, ev->mcgcap);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record,  3, ev->mcgstatus);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record,  4, ev->status);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record,  5, ev->addr);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record,  6, ev->misc);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record,  7, ev->ip);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record,  8, ev->tsc);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record,  9, ev->walltime);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record, 10, ev->cpu);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record, 11, ev->cpuid);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record, 12, ev->apicid);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record, 13, ev->socketid);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record, 14, ev->cs);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record, 15, ev->bank);
d9e469
+	sqlite3_bind_int (priv->stmt_mce_record, 16, ev->cpuvendor);
d9e469
+
d9e469
+	sqlite3_bind_text(priv->stmt_mce_record, 17, ev->bank_name, -1, NULL);
d9e469
+	sqlite3_bind_text(priv->stmt_mce_record, 18, ev->error_msg, -1, NULL);
d9e469
+	sqlite3_bind_text(priv->stmt_mce_record, 19, ev->mcgstatus_msg, -1, NULL);
d9e469
+	sqlite3_bind_text(priv->stmt_mce_record, 20, ev->mcistatus_msg, -1, NULL);
d9e469
+	sqlite3_bind_text(priv->stmt_mce_record, 21, ev->mcastatus_msg, -1, NULL);
d9e469
+	sqlite3_bind_text(priv->stmt_mce_record, 22, ev->user_action, -1, NULL);
d9e469
+	sqlite3_bind_text(priv->stmt_mce_record, 23, ev->mc_location, -1, NULL);
d9e469
+
d9e469
+	rc = sqlite3_step(priv->stmt_mce_record);
d9e469
+	if (rc != SQLITE_OK && rc != SQLITE_DONE)
d9e469
+		log(TERM, LOG_ERR,
d9e469
+		    "Failed to do mce_record step on sqlite: error = %d\n", rc);
d9e469
+	rc = sqlite3_reset(priv->stmt_mce_record);
d9e469
+	if (rc != SQLITE_OK && rc != SQLITE_DONE)
d9e469
+		log(TERM, LOG_ERR,
d9e469
+		    "Failed reset mce_record on sqlite: error = %d\n",
d9e469
+		    rc);
d9e469
+	log(TERM, LOG_INFO, "register inserted at db\n");
d9e469
+
d9e469
+	return rc;
d9e469
+}
d9e469
+#endif
d9e469
+
d9e469
+
d9e469
 /*
d9e469
  * Generic code
d9e469
  */
d9e469
@@ -291,6 +384,13 @@ int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras)
d9e469
 					 &aer_event_tab);
d9e469
 #endif
d9e469
 
d9e469
-	ras->db_priv = priv;
d9e469
+#ifdef HAVE_MCE
d9e469
+	rc = ras_mc_create_table(priv, &mce_record_tab);
d9e469
+	if (rc == SQLITE_OK)
d9e469
+		rc = ras_mc_prepare_stmt(priv, &priv->stmt_mce_record,
d9e469
+					 &mce_record_tab);
d9e469
+#endif
d9e469
+
d9e469
+		ras->db_priv = priv;
d9e469
 	return 0;
d9e469
 }
d9e469
diff --git a/ras-record.h b/ras-record.h
d9e469
index 5008906..6f146a8 100644
d9e469
--- a/ras-record.h
d9e469
+++ b/ras-record.h
d9e469
@@ -40,6 +40,10 @@ struct ras_aer_event {
d9e469
 	const char *msg;
d9e469
 };
d9e469
 
d9e469
+struct ras_mc_event;
d9e469
+struct ras_aer_event;
d9e469
+struct mce_event;
d9e469
+
d9e469
 #ifdef HAVE_SQLITE3
d9e469
 
d9e469
 #include <sqlite3.h>
d9e469
@@ -50,16 +54,21 @@ struct sqlite3_priv {
d9e469
 #ifdef HAVE_AER
d9e469
 	sqlite3_stmt	*stmt_aer_event;
d9e469
 #endif
d9e469
+#ifdef HAVE_MCE
d9e469
+	sqlite3_stmt	*stmt_mce_record;
d9e469
+#endif
d9e469
 };
d9e469
 
d9e469
 int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras);
d9e469
 int ras_store_mc_event(struct ras_events *ras, struct ras_mc_event *ev);
d9e469
 int ras_store_aer_event(struct ras_events *ras, struct ras_aer_event *ev);
d9e469
+int ras_store_mce_record(struct ras_events *ras, struct mce_event *ev);
d9e469
 
d9e469
 #else
d9e469
 static inline int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras) { return 0; };
d9e469
 static inline int ras_store_mc_event(struct ras_events *ras, struct ras_mc_event *ev) { return 0; };
d9e469
 static inline int ras_store_aer_event(struct ras_events *ras, struct ras_aer_event *ev) { return 0; };
d9e469
+static inline int ras_store_mce_record(struct ras_events *ras, struct mce_event *ev) { return 0; };
d9e469
 
d9e469
 #endif
d9e469
 
d9e469
-- 
d9e469
1.7.1
d9e469