anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

Blame 0046-cxl-add-health-information-to-cxl-list.patch

Jeff Moyer 2c91dc
From f5d1e2133c54c1f420a0c3cf45fa633f097823be Mon Sep 17 00:00:00 2001
Jeff Moyer 2c91dc
From: Vishal Verma <vishal.l.verma@intel.com>
Jeff Moyer 2c91dc
Date: Thu, 7 Oct 2021 02:21:39 -0600
Jeff Moyer 2c91dc
Subject: [PATCH 046/217] cxl: add health information to cxl-list
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
Add JSON output for fields from the 'GET_HEALTH_INFO' mailbox command
Jeff Moyer 2c91dc
to memory device listings.
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
Cc: Dan Williams <dan.j.williams@intel.com>
Jeff Moyer 2c91dc
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Jeff Moyer 2c91dc
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Jeff Moyer 2c91dc
---
Jeff Moyer 2c91dc
 Documentation/cxl/cxl-list.txt |  38 +++++++
Jeff Moyer 2c91dc
 cxl/list.c                     |   5 +
Jeff Moyer 2c91dc
 util/json.c                    | 179 +++++++++++++++++++++++++++++++++
Jeff Moyer 2c91dc
 util/json.h                    |   1 +
Jeff Moyer 2c91dc
 4 files changed, 223 insertions(+)
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt
Jeff Moyer 2c91dc
index 370d5b8..c8d10fb 100644
Jeff Moyer 2c91dc
--- a/Documentation/cxl/cxl-list.txt
Jeff Moyer 2c91dc
+++ b/Documentation/cxl/cxl-list.txt
Jeff Moyer 2c91dc
@@ -48,6 +48,44 @@ OPTIONS
Jeff Moyer 2c91dc
 --idle::
Jeff Moyer 2c91dc
 	Include idle (not enabled / zero-sized) devices in the listing
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
+-H::
Jeff Moyer 2c91dc
+--health::
Jeff Moyer 2c91dc
+	Include health information in the memdev listing. Example listing:
Jeff Moyer 2c91dc
+----
Jeff Moyer 2c91dc
+# cxl list -m mem0 -H
Jeff Moyer 2c91dc
+[
Jeff Moyer 2c91dc
+  {
Jeff Moyer 2c91dc
+    "memdev":"mem0",
Jeff Moyer 2c91dc
+    "pmem_size":268435456,
Jeff Moyer 2c91dc
+    "ram_size":268435456,
Jeff Moyer 2c91dc
+    "health":{
Jeff Moyer 2c91dc
+      "maintenance_needed":true,
Jeff Moyer 2c91dc
+      "performance_degraded":true,
Jeff Moyer 2c91dc
+      "hw_replacement_needed":true,
Jeff Moyer 2c91dc
+      "media_normal":false,
Jeff Moyer 2c91dc
+      "media_not_ready":false,
Jeff Moyer 2c91dc
+      "media_persistence_lost":false,
Jeff Moyer 2c91dc
+      "media_data_lost":true,
Jeff Moyer 2c91dc
+      "media_powerloss_persistence_loss":false,
Jeff Moyer 2c91dc
+      "media_shutdown_persistence_loss":false,
Jeff Moyer 2c91dc
+      "media_persistence_loss_imminent":false,
Jeff Moyer 2c91dc
+      "media_powerloss_data_loss":false,
Jeff Moyer 2c91dc
+      "media_shutdown_data_loss":false,
Jeff Moyer 2c91dc
+      "media_data_loss_imminent":false,
Jeff Moyer 2c91dc
+      "ext_life_used":"normal",
Jeff Moyer 2c91dc
+      "ext_temperature":"critical",
Jeff Moyer 2c91dc
+      "ext_corrected_volatile":"warning",
Jeff Moyer 2c91dc
+      "ext_corrected_persistent":"normal",
Jeff Moyer 2c91dc
+      "life_used_percent":15,
Jeff Moyer 2c91dc
+      "temperature":25,
Jeff Moyer 2c91dc
+      "dirty_shutdowns":10,
Jeff Moyer 2c91dc
+      "volatile_errors":20,
Jeff Moyer 2c91dc
+      "pmem_errors":30
Jeff Moyer 2c91dc
+    }
Jeff Moyer 2c91dc
+  }
Jeff Moyer 2c91dc
+]
Jeff Moyer 2c91dc
+----
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
 include::human-option.txt[]
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
 include::verbose-option.txt[]
Jeff Moyer 2c91dc
diff --git a/cxl/list.c b/cxl/list.c
Jeff Moyer 2c91dc
index 043d20c..b1468b7 100644
Jeff Moyer 2c91dc
--- a/cxl/list.c
Jeff Moyer 2c91dc
+++ b/cxl/list.c
Jeff Moyer 2c91dc
@@ -16,6 +16,7 @@ static struct {
Jeff Moyer 2c91dc
 	bool memdevs;
Jeff Moyer 2c91dc
 	bool idle;
Jeff Moyer 2c91dc
 	bool human;
Jeff Moyer 2c91dc
+	bool health;
Jeff Moyer 2c91dc
 } list;
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
 static unsigned long listopts_to_flags(void)
Jeff Moyer 2c91dc
@@ -26,6 +27,8 @@ static unsigned long listopts_to_flags(void)
Jeff Moyer 2c91dc
 		flags |= UTIL_JSON_IDLE;
Jeff Moyer 2c91dc
 	if (list.human)
Jeff Moyer 2c91dc
 		flags |= UTIL_JSON_HUMAN;
Jeff Moyer 2c91dc
+	if (list.health)
Jeff Moyer 2c91dc
+		flags |= UTIL_JSON_HEALTH;
Jeff Moyer 2c91dc
 	return flags;
Jeff Moyer 2c91dc
 }
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
@@ -57,6 +60,8 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
Jeff Moyer 2c91dc
 		OPT_BOOLEAN('i', "idle", &list.idle, "include idle devices"),
Jeff Moyer 2c91dc
 		OPT_BOOLEAN('u', "human", &list.human,
Jeff Moyer 2c91dc
 				"use human friendly number formats "),
Jeff Moyer 2c91dc
+		OPT_BOOLEAN('H', "health", &list.health,
Jeff Moyer 2c91dc
+				"include memory device health information "),
Jeff Moyer 2c91dc
 		OPT_END(),
Jeff Moyer 2c91dc
 	};
Jeff Moyer 2c91dc
 	const char * const u[] = {
Jeff Moyer 2c91dc
diff --git a/util/json.c b/util/json.c
Jeff Moyer 2c91dc
index 3be3a92..f97cf07 100644
Jeff Moyer 2c91dc
--- a/util/json.c
Jeff Moyer 2c91dc
+++ b/util/json.c
Jeff Moyer 2c91dc
@@ -1442,6 +1442,180 @@ struct json_object *util_badblock_rec_to_json(u64 block, u64 count,
Jeff Moyer 2c91dc
 	return NULL;
Jeff Moyer 2c91dc
 }
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
+static struct json_object *util_cxl_memdev_health_to_json(
Jeff Moyer 2c91dc
+		struct cxl_memdev *memdev, unsigned long flags)
Jeff Moyer 2c91dc
+{
Jeff Moyer 2c91dc
+	struct json_object *jhealth;
Jeff Moyer 2c91dc
+	struct json_object *jobj;
Jeff Moyer 2c91dc
+	struct cxl_cmd *cmd;
Jeff Moyer 2c91dc
+	u32 field;
Jeff Moyer 2c91dc
+	int rc;
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	jhealth = json_object_new_object();
Jeff Moyer 2c91dc
+	if (!jhealth)
Jeff Moyer 2c91dc
+		return NULL;
Jeff Moyer 2c91dc
+	if (!memdev)
Jeff Moyer 2c91dc
+		goto err_jobj;
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	cmd = cxl_cmd_new_get_health_info(memdev);
Jeff Moyer 2c91dc
+	if (!cmd)
Jeff Moyer 2c91dc
+		goto err_jobj;
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = cxl_cmd_submit(cmd);
Jeff Moyer 2c91dc
+	if (rc < 0)
Jeff Moyer 2c91dc
+		goto err_cmd;
Jeff Moyer 2c91dc
+	rc = cxl_cmd_get_mbox_status(cmd);
Jeff Moyer 2c91dc
+	if (rc != 0)
Jeff Moyer 2c91dc
+		goto err_cmd;
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	/* health_status fields */
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_maintenance_needed(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "maintenance_needed", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_performance_degraded(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "performance_degraded", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_hw_replacement_needed(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "hw_replacement_needed", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	/* media_status fields */
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_media_normal(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "media_normal", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_media_not_ready(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "media_not_ready", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_media_persistence_lost(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "media_persistence_lost", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_media_data_lost(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "media_data_lost", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_media_powerloss_persistence_loss(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "media_powerloss_persistence_loss", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_media_shutdown_persistence_loss(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "media_shutdown_persistence_loss", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_media_persistence_loss_imminent(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "media_persistence_loss_imminent", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_media_powerloss_data_loss(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "media_powerloss_data_loss", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_media_shutdown_data_loss(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "media_shutdown_data_loss", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	rc = cxl_cmd_health_info_get_media_data_loss_imminent(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_boolean(rc);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "media_data_loss_imminent", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	/* ext_status fields */
Jeff Moyer 2c91dc
+	if (cxl_cmd_health_info_get_ext_life_used_normal(cmd))
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("normal");
Jeff Moyer 2c91dc
+	else if (cxl_cmd_health_info_get_ext_life_used_warning(cmd))
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("warning");
Jeff Moyer 2c91dc
+	else if (cxl_cmd_health_info_get_ext_life_used_critical(cmd))
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("critical");
Jeff Moyer 2c91dc
+	else
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("unknown");
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "ext_life_used", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	if (cxl_cmd_health_info_get_ext_temperature_normal(cmd))
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("normal");
Jeff Moyer 2c91dc
+	else if (cxl_cmd_health_info_get_ext_temperature_warning(cmd))
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("warning");
Jeff Moyer 2c91dc
+	else if (cxl_cmd_health_info_get_ext_temperature_critical(cmd))
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("critical");
Jeff Moyer 2c91dc
+	else
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("unknown");
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "ext_temperature", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	if (cxl_cmd_health_info_get_ext_corrected_volatile_normal(cmd))
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("normal");
Jeff Moyer 2c91dc
+	else if (cxl_cmd_health_info_get_ext_corrected_volatile_warning(cmd))
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("warning");
Jeff Moyer 2c91dc
+	else
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("unknown");
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "ext_corrected_volatile", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	if (cxl_cmd_health_info_get_ext_corrected_persistent_normal(cmd))
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("normal");
Jeff Moyer 2c91dc
+	else if (cxl_cmd_health_info_get_ext_corrected_persistent_warning(cmd))
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("warning");
Jeff Moyer 2c91dc
+	else
Jeff Moyer 2c91dc
+		jobj = json_object_new_string("unknown");
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "ext_corrected_persistent", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	/* other fields */
Jeff Moyer 2c91dc
+	field = cxl_cmd_health_info_get_life_used(cmd);
Jeff Moyer 2c91dc
+	if (field != 0xff) {
Jeff Moyer 2c91dc
+		jobj = json_object_new_int(field);
Jeff Moyer 2c91dc
+		if (jobj)
Jeff Moyer 2c91dc
+			json_object_object_add(jhealth, "life_used_percent", jobj);
Jeff Moyer 2c91dc
+	}
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	field = cxl_cmd_health_info_get_temperature(cmd);
Jeff Moyer 2c91dc
+	if (field != 0xffff) {
Jeff Moyer 2c91dc
+		jobj = json_object_new_int(field);
Jeff Moyer 2c91dc
+		if (jobj)
Jeff Moyer 2c91dc
+			json_object_object_add(jhealth, "temperature", jobj);
Jeff Moyer 2c91dc
+	}
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	field = cxl_cmd_health_info_get_dirty_shutdowns(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_int64(field);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "dirty_shutdowns", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	field = cxl_cmd_health_info_get_volatile_errors(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_int64(field);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "volatile_errors", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	field = cxl_cmd_health_info_get_pmem_errors(cmd);
Jeff Moyer 2c91dc
+	jobj = json_object_new_int64(field);
Jeff Moyer 2c91dc
+	if (jobj)
Jeff Moyer 2c91dc
+		json_object_object_add(jhealth, "pmem_errors", jobj);
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+	cxl_cmd_unref(cmd);
Jeff Moyer 2c91dc
+	return jhealth;
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
+err_cmd:
Jeff Moyer 2c91dc
+	cxl_cmd_unref(cmd);
Jeff Moyer 2c91dc
+err_jobj:
Jeff Moyer 2c91dc
+	json_object_put(jhealth);
Jeff Moyer 2c91dc
+	return NULL;
Jeff Moyer 2c91dc
+}
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
 struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
Jeff Moyer 2c91dc
 		unsigned long flags)
Jeff Moyer 2c91dc
 {
Jeff Moyer 2c91dc
@@ -1464,5 +1638,10 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
Jeff Moyer 2c91dc
 	if (jobj)
Jeff Moyer 2c91dc
 		json_object_object_add(jdev, "ram_size", jobj);
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
+	if (flags & UTIL_JSON_HEALTH) {
Jeff Moyer 2c91dc
+		jobj = util_cxl_memdev_health_to_json(memdev, flags);
Jeff Moyer 2c91dc
+		if (jobj)
Jeff Moyer 2c91dc
+			json_object_object_add(jdev, "health", jobj);
Jeff Moyer 2c91dc
+	}
Jeff Moyer 2c91dc
 	return jdev;
Jeff Moyer 2c91dc
 }
Jeff Moyer 2c91dc
diff --git a/util/json.h b/util/json.h
Jeff Moyer 2c91dc
index 91918c8..ce575e6 100644
Jeff Moyer 2c91dc
--- a/util/json.h
Jeff Moyer 2c91dc
+++ b/util/json.h
Jeff Moyer 2c91dc
@@ -19,6 +19,7 @@ enum util_json_flags {
Jeff Moyer 2c91dc
 	UTIL_JSON_CONFIGURED	= (1 << 7),
Jeff Moyer 2c91dc
 	UTIL_JSON_FIRMWARE	= (1 << 8),
Jeff Moyer 2c91dc
 	UTIL_JSON_DAX_MAPPINGS	= (1 << 9),
Jeff Moyer 2c91dc
+	UTIL_JSON_HEALTH	= (1 << 10),
Jeff Moyer 2c91dc
 };
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
 struct json_object;
Jeff Moyer 2c91dc
-- 
Jeff Moyer 2c91dc
2.27.0
Jeff Moyer 2c91dc