public inbox for linux-nvdimm@lists.01.org
 help / color / mirror / Atom feed
From: Vaibhav Jain <vaibhav@linux.ibm.com>
To: linux-nvdimm@lists.01.org
Cc: Vaibhav Jain <vaibhav@linux.ibm.com>,
	"Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>
Subject: [ndctl RFC-PATCH 4/4] papr_scm: Implement dimm op 'get_stat'
Date: Mon, 18 May 2020 16:50:23 +0530	[thread overview]
Message-ID: <20200518112023.147139-5-vaibhav@linux.ibm.com> (raw)
In-Reply-To: <20200518112023.147139-1-vaibhav@linux.ibm.com>

Previous patches implemented functionality to fetch the dimm-stats
from kernel by implementing dimm-op 'new_stats'. However in absence of
dimm-op 'get_stat' the fetched dimm-stats are never passed on to ndctl
json presentation layer.

This patch implements dimm-op 'get_stat' as function papr_get_stat()
that incremently returns populated 'struct ndctl_dimm_stat' instances
back to ndctl json util function util_dimm_stats_to_json() which then
creates a json-object out of them.

In order to keep track of last returned dimm-stat, papr_get_stat()
utilizes ndctl_cmd.private_data to store the next index of 'struct
nd_pdsm_perf_stat' to be returned from array dimm_priv.perf_stats.

Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
---
 ndctl/lib/papr_scm.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/ndctl/lib/papr_scm.c b/ndctl/lib/papr_scm.c
index d27bacaa7d2c..46f8992508b2 100644
--- a/ndctl/lib/papr_scm.c
+++ b/ndctl/lib/papr_scm.c
@@ -551,6 +551,41 @@ static struct ndctl_cmd * papr_new_stats(struct ndctl_dimm * dimm)
 	return cmd;
 }
 
+/* Return a single dimm-stat from the command until ret */
+static int papr_get_stat(struct ndctl_cmd *cmd, struct ndctl_dimm_stat * stat)
+{
+	/* Store the next stat index in stat->provider_private */
+	int next_index;
+	struct dimm_priv * p = cmd->dimm->dimm_user_data;
+	struct nd_pdsm_cmd_pkg *pcmd;
+	const struct dimm_stat *stat_desc;
+
+	if (!stat || !cmd)
+		return -EINVAL;
+
+	pcmd = nd_to_pdsm_cmd_pkg(cmd->pkg);
+	if (pcmd_to_pdsm(pcmd) != PAPR_SCM_PDSM_READ_PERF_STATS)
+		return -EINVAL;
+
+	/* Fetch the next_index from cmd and check bounds */
+	next_index = (cmd->private_data - (void*)0);
+	if (next_index >= p->count_perf_stats)
+		return -ENOENT;
+
+	stat_desc = get_dimm_stat_desc(p->perf_stats[next_index].id);
+	if (!stat_desc)
+		return -EINVAL;
+
+	/* populate theprovided struct */
+	stat->name = stat_desc->name;
+	stat->type = stat_desc->type;
+	stat->val.int64_val = p->perf_stats[next_index].val;
+
+	/* update the stored next index in the struct ndctl_cmd */
+	cmd->private_data = (void*)0 + next_index + 1;
+	return 0;
+}
+
 struct ndctl_dimm_ops * const papr_scm_dimm_ops = &(struct ndctl_dimm_ops) {
 	.cmd_is_supported = papr_cmd_is_supported,
 	.dimm_init = papr_dimm_init,
@@ -561,4 +596,5 @@ struct ndctl_dimm_ops * const papr_scm_dimm_ops = &(struct ndctl_dimm_ops) {
 	.smart_get_health = papr_smart_get_health,
 	.smart_get_shutdown_state = papr_smart_get_shutdown_state,
 	.new_stats = papr_new_stats,
+	.get_stat = papr_get_stat,
 };
-- 
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

      parent reply	other threads:[~2020-05-18 11:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-18 11:20 [ndctl RFC-PATCH 0/4] Add support for reporting PAPR NVDIMM Statistics Vaibhav Jain
2020-05-18 11:20 ` [ndctl RFC-PATCH 1/4] ndctl,libndctl: Implement new dimm-ops 'new_stats' and 'get_stat' Vaibhav Jain
2020-05-18 11:20 ` [ndctl RFC-PATCH 2/4] papr_scm: Add support for fetching dimm-stats Vaibhav Jain
2020-05-18 11:20 ` [ndctl RFC-PATCH 3/4] papr_scm: Implement parsing and clean-up for fetched dimm stats Vaibhav Jain
2020-05-18 11:20 ` Vaibhav Jain [this message]

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=20200518112023.147139-5-vaibhav@linux.ibm.com \
    --to=vaibhav@linux.ibm.com \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=linux-nvdimm@lists.01.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox