linux-cxl.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Verma, Vishal L" <vishal.l.verma@intel.com>
To: "linux-cxl@vger.kernel.org" <linux-cxl@vger.kernel.org>
Cc: "Williams, Dan J" <dan.j.williams@intel.com>,
	"Widawsky, Ben" <ben.widawsky@intel.com>,
	"nvdimm@lists.linux.dev" <nvdimm@lists.linux.dev>
Subject: Re: [ndctl PATCH v4 17/17] cxl: add health information to cxl-list
Date: Mon, 11 Oct 2021 22:07:27 +0000	[thread overview]
Message-ID: <8144d0576ce15828456a0ba0c8461162f604bc38.camel@intel.com> (raw)
In-Reply-To: <20211007082139.3088615-18-vishal.l.verma@intel.com>

On Thu, 2021-10-07 at 02:21 -0600, Vishal Verma wrote:
> Add JSON output for fields from the 'GET_HEALTH_INFO' mailbox command
> to memory device listings.
> 
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
> ---
>  Documentation/cxl/cxl-list.txt |   4 +
>  util/json.h                    |   1 +
>  cxl/list.c                     |   5 +
>  util/json.c                    | 189 +++++++++++++++++++++++++++++++++
>  4 files changed, 199 insertions(+)
> 
> diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt
> index bd377b3..dc86651 100644
> --- a/Documentation/cxl/cxl-list.txt
> +++ b/Documentation/cxl/cxl-list.txt
> @@ -53,6 +53,10 @@ OPTIONS
>  --idle::
>  	Include idle (not enabled / zero-sized) devices in the listing
>  
> +-H::
> +--health::
> +	Include health information in the memdev listing
> +
>  include::human-option.txt[]
>  
>  include::verbose-option.txt[]
> diff --git a/util/json.h b/util/json.h
> index 91918c8..ce575e6 100644
> --- a/util/json.h
> +++ b/util/json.h
> @@ -19,6 +19,7 @@ enum util_json_flags {
>  	UTIL_JSON_CONFIGURED	= (1 << 7),
>  	UTIL_JSON_FIRMWARE	= (1 << 8),
>  	UTIL_JSON_DAX_MAPPINGS	= (1 << 9),
> +	UTIL_JSON_HEALTH	= (1 << 10),
>  };
>  
>  struct json_object;
> diff --git a/cxl/list.c b/cxl/list.c
> index 3dea73f..2fa155a 100644
> --- a/cxl/list.c
> +++ b/cxl/list.c
> @@ -16,6 +16,7 @@ static struct {
>  	bool memdevs;
>  	bool idle;
>  	bool human;
> +	bool health;
>  } list;
>  
>  static unsigned long listopts_to_flags(void)
> @@ -26,6 +27,8 @@ static unsigned long listopts_to_flags(void)
>  		flags |= UTIL_JSON_IDLE;
>  	if (list.human)
>  		flags |= UTIL_JSON_HUMAN;
> +	if (list.health)
> +		flags |= UTIL_JSON_HEALTH;
>  	return flags;
>  }
>  
> @@ -57,6 +60,8 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
>  		OPT_BOOLEAN('i', "idle", &list.idle, "include idle devices"),
>  		OPT_BOOLEAN('u', "human", &list.human,
>  				"use human friendly number formats "),
> +		OPT_BOOLEAN('H', "health", &list.health,
> +				"include memory device health information "),
>  		OPT_END(),
>  	};
>  	const char * const u[] = {
> diff --git a/util/json.c b/util/json.c
> index 3be3a92..dfc7b8e 100644
> --- a/util/json.c
> +++ b/util/json.c
> @@ -1442,6 +1442,190 @@ struct json_object *util_badblock_rec_to_json(u64 block, u64 count,
>  	return NULL;
>  }
>  
> +static struct json_object *util_cxl_memdev_health_to_json(
> +		struct cxl_memdev *memdev, unsigned long flags)
> +{
> +	const char *devname = cxl_memdev_get_devname(memdev);
> +	struct json_object *jhealth;
> +	struct json_object *jobj;
> +	struct cxl_cmd *cmd;
> +	u32 field;
> +	int rc;
> +
> +	jhealth = json_object_new_object();
> +	if (!jhealth)
> +		return NULL;
> +	if (!memdev)
> +		goto err_jobj;
> +
> +	cmd = cxl_cmd_new_get_health_info(memdev);
> +	if (!cmd)
> +		goto err_jobj;
> +
> +	rc = cxl_cmd_submit(cmd);
> +	/* ENOTTY - command not supported by the memdev */
> +	if (rc == -ENOTTY)
> +		goto err_cmd;
> +	if (rc < 0) {
> +		fprintf(stderr, "%s: cmd submission failed: %s\n", devname,
> +		    strerror(-rc));
> +		goto err_cmd;
> +	}
> +	rc = cxl_cmd_get_mbox_status(cmd);
> +	if (rc != 0) {
> +		fprintf(stderr, "%s: firmware status: %d\n", devname, rc);
> +		rc = -ENXIO;
> +		goto err_cmd;
> +	}
> +
> +	/* health_status fields */
> +	rc = cxl_cmd_health_info_get_maintenance_needed(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "maintenance_needed", jobj);
> +
> +	rc = cxl_cmd_health_info_get_performance_degraded(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "performance_degraded", jobj);
> +
> +	rc = cxl_cmd_health_info_get_hw_replacement_needed(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "hw_replacement_needed", jobj);
> +
> +	/* media_status fields */
> +	rc = cxl_cmd_health_info_get_media_normal(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "media_normal", jobj);
> +
> +	rc = cxl_cmd_health_info_get_media_not_ready(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "media_not_ready", jobj);
> +
> +	rc = cxl_cmd_health_info_get_media_persistence_lost(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "media_persistence_lost", jobj);
> +
> +	rc = cxl_cmd_health_info_get_media_data_lost(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "media_data_lost", jobj);
> +
> +	rc = cxl_cmd_health_info_get_media_powerloss_persistence_loss(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "media_powerloss_persistence_loss", jobj);
> +
> +	rc = cxl_cmd_health_info_get_media_shutdown_persistence_loss(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "media_shutdown_persistence_loss", jobj);
> +
> +	rc = cxl_cmd_health_info_get_media_persistence_loss_imminent(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "media_persistence_loss_imminent", jobj);
> +
> +	rc = cxl_cmd_health_info_get_media_powerloss_data_loss(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "media_powerloss_data_loss", jobj);
> +
> +	rc = cxl_cmd_health_info_get_media_shutdown_data_loss(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "media_shutdown_data_loss", jobj);
> +
> +	rc = cxl_cmd_health_info_get_media_data_loss_imminent(cmd);
> +	jobj = json_object_new_boolean(rc);
> +	if (jobj)
> +		json_object_object_add(jhealth, "media_data_loss_imminent", jobj);
> +
> +	/* ext_status fields */
> +	if (cxl_cmd_health_info_get_ext_life_used_normal(cmd))
> +		jobj = json_object_new_string("normal");
> +	else if (cxl_cmd_health_info_get_ext_life_used_warning(cmd))
> +		jobj = json_object_new_string("warning");
> +	else if (cxl_cmd_health_info_get_ext_life_used_critical(cmd))
> +		jobj = json_object_new_string("critical");
> +	else
> +		jobj = json_object_new_string("unknown");
> +	if (jobj)
> +		json_object_object_add(jhealth, "ext_life_used", jobj);
> +
> +	if (cxl_cmd_health_info_get_ext_temperature_normal(cmd))
> +		jobj = json_object_new_string("normal");
> +	else if (cxl_cmd_health_info_get_ext_temperature_warning(cmd))
> +		jobj = json_object_new_string("warning");
> +	else if (cxl_cmd_health_info_get_ext_temperature_critical(cmd))
> +		jobj = json_object_new_string("critical");
> +	else
> +		jobj = json_object_new_string("unknown");
> +	if (jobj)
> +		json_object_object_add(jhealth, "ext_temperature", jobj);
> +
> +	if (cxl_cmd_health_info_get_ext_corrected_volatile_normal(cmd))
> +		jobj = json_object_new_string("normal");
> +	else if (cxl_cmd_health_info_get_ext_corrected_volatile_warning(cmd))
> +		jobj = json_object_new_string("warning");
> +	else
> +		jobj = json_object_new_string("unknown");
> +	if (jobj)
> +		json_object_object_add(jhealth, "ext_corrected_volatile", jobj);
> +
> +	if (cxl_cmd_health_info_get_ext_corrected_persistent_normal(cmd))
> +		jobj = json_object_new_string("normal");
> +	else if (cxl_cmd_health_info_get_ext_corrected_persistent_warning(cmd))
> +		jobj = json_object_new_string("warning");
> +	else
> +		jobj = json_object_new_string("unknown");
> +	if (jobj)
> +		json_object_object_add(jhealth, "ext_corrected_persistent", jobj);
> +
> +	/* other fields */
> +	field = cxl_cmd_health_info_get_life_used(cmd);
> +	if (field != 0xff) {
> +		jobj = json_object_new_int(field);
> +		if (jobj)
> +			json_object_object_add(jhealth, "life_used_percent", jobj);
> +	}
> +
> +	field = cxl_cmd_health_info_get_temperature(cmd);
> +	if (field != 0xffff) {
> +		jobj = json_object_new_int(field);
> +		if (jobj)
> +			json_object_object_add(jhealth, "temperature", jobj);
> +	}
> +
> +	field = cxl_cmd_health_info_get_dirty_shutdowns(cmd);
> +	jobj = json_object_new_uint64(field);
> +	if (jobj)
> +		json_object_object_add(jhealth, "dirty_shutdowns", jobj);
> +
> +	field = cxl_cmd_health_info_get_volatile_errors(cmd);
> +	jobj = json_object_new_uint64(field);
> +	if (jobj)
> +		json_object_object_add(jhealth, "volatile_errors", jobj);
> +
> +	field = cxl_cmd_health_info_get_pmem_errors(cmd);
> +	jobj = json_object_new_uint64(field);

json_object_new_uint64() seems to be a relatively new interface in
json-c - Some Ubuntu LTS and CentOS 8 distros dont' have a recent
enough json-c to have this.

I'm thinking I'll switch these three above to json_object_new_int64.
I'd originally chosen the uint64 variant because that seemsed to be the
only unsigned int option available. The fields we're trying to print
are all u32's. So I think using int64 should be sufficient that we
won't end up with spurious negative listings.

Thoughts?

> +	if (jobj)
> +		json_object_object_add(jhealth, "pmem_errors", jobj);
> +
> +	cxl_cmd_unref(cmd);
> +	return jhealth;
> +
> +err_cmd:
> +	cxl_cmd_unref(cmd);
> +err_jobj:
> +	json_object_put(jhealth);
> +	return NULL;
> +}
> +
>  struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
>  		unsigned long flags)
>  {
> @@ -1464,5 +1648,10 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
>  	if (jobj)
>  		json_object_object_add(jdev, "ram_size", jobj);
>  
> +	if (flags & UTIL_JSON_HEALTH) {
> +		jobj = util_cxl_memdev_health_to_json(memdev, flags);
> +		if (jobj)
> +			json_object_object_add(jdev, "health", jobj);
> +	}
>  	return jdev;
>  }


  reply	other threads:[~2021-10-11 22:07 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07  8:21 [ndctl PATCH v4 00/17] Initial CXL support Vishal Verma
2021-10-07  8:21 ` [ndctl PATCH v4 01/17] ndctl: add .clang-format Vishal Verma
2021-10-07  8:21 ` [ndctl PATCH v4 02/17] cxl: add a cxl utility and libcxl library Vishal Verma
2021-10-07  8:21 ` [ndctl PATCH v4 03/17] cxl: add a local copy of the cxl_mem UAPI header Vishal Verma
2021-10-07  8:21 ` [ndctl PATCH v4 04/17] util: add the struct_size() helper from the kernel Vishal Verma
2021-10-14  2:40   ` Dan Williams
2021-10-07  8:21 ` [ndctl PATCH v4 05/17] libcxl: add support for command query and submission Vishal Verma
2021-10-14  2:53   ` Dan Williams
2021-10-07  8:21 ` [ndctl PATCH v4 06/17] libcxl: add support for the 'Identify Device' command Vishal Verma
2021-10-07  8:21 ` [ndctl PATCH v4 07/17] libcxl: add GET_HEALTH_INFO mailbox command and accessors Vishal Verma
2021-10-14 16:01   ` Dan Williams
2021-11-02 20:22     ` Verma, Vishal L
2021-11-02 20:27       ` Dan Williams
2021-10-07  8:21 ` [ndctl PATCH v4 08/17] libcxl: add support for the 'GET_LSA' command Vishal Verma
2021-10-14 16:35   ` Dan Williams
2021-10-14 20:06     ` Verma, Vishal L
2021-10-14 20:55       ` Dan Williams
2021-10-07  8:21 ` [ndctl PATCH v4 09/17] util/hexdump: Add a util helper to print a buffer in hex Vishal Verma
2021-10-14 16:48   ` Dan Williams
2021-10-14 20:33     ` Verma, Vishal L
2021-10-14 22:39       ` Dan Williams
2021-11-02 20:25         ` Verma, Vishal L
2021-10-07  8:21 ` [ndctl PATCH v4 10/17] libcxl: add label_size to cxl_memdev, and an API to retrieve it Vishal Verma
2021-10-14 18:24   ` Dan Williams
2021-10-14 21:50     ` Verma, Vishal L
2021-10-07  8:21 ` [ndctl PATCH v4 11/17] libcxl: add a stub interface to determine whether a memdev is active Vishal Verma
2021-10-14 19:59   ` Dan Williams
2021-10-07  8:21 ` [ndctl PATCH v4 12/17] libcxl: add interfaces for label operations Vishal Verma
2021-10-14 21:27   ` Dan Williams
2021-10-14 22:18     ` Verma, Vishal L
2021-10-14 22:24     ` Verma, Vishal L
2021-10-14 22:45       ` Dan Williams
2021-10-07  8:21 ` [ndctl PATCH v4 13/17] cxl: add commands to read, write, and zero labels Vishal Verma
2021-10-14 22:34   ` Dan Williams
2021-10-07  8:21 ` [ndctl PATCH v4 14/17] Documentation/cxl: add library API documentation Vishal Verma
2021-10-14 23:31   ` Dan Williams
2021-11-05 18:58   ` Dan Williams
2021-10-07  8:21 ` [ndctl PATCH v4 15/17] ndctl: Add CXL packages to the RPM spec Vishal Verma
2021-10-14 23:33   ` Dan Williams
2021-10-07  8:21 ` [ndctl PATCH v4 16/17] cxl-cli: add bash completion Vishal Verma
2021-10-14 23:34   ` Dan Williams
2021-10-07  8:21 ` [ndctl PATCH v4 17/17] cxl: add health information to cxl-list Vishal Verma
2021-10-11 22:07   ` Verma, Vishal L [this message]
2021-10-15  0:09     ` Dan Williams
2021-10-14 23:42   ` Verma, Vishal L
2021-10-15 21:15     ` Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8144d0576ce15828456a0ba0c8461162f604bc38.camel@intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=ben.widawsky@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --subject='Re: [ndctl PATCH v4 17/17] cxl: add health information to cxl-list' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).