All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vaibhav Jain <vaibhav@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org, linux-nvdimm@lists.01.org
Cc: Vaibhav Jain <vaibhav@linux.ibm.com>,
	"Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>
Subject: [RFC PATCH 4/4] powerpc/papr_scm: Add support for PDSM GET_PERF_STAT
Date: Mon, 18 May 2020 16:38:14 +0530	[thread overview]
Message-ID: <20200518110814.145644-5-vaibhav@linux.ibm.com> (raw)
In-Reply-To: <20200518110814.145644-1-vaibhav@linux.ibm.com>

This patch adds support for retrieving a singled NVDIMM performance
stat from PHYP via PDSM GET_PERF_STAT_VERSION. A new uapi 'struct
nd_pdsm_get_perf_stat' is introduced that holds a single performance
stat and is populated by newly introduced papr_scm_get_perf_stat() by
issuing an H_SCM_PERFORMANCE_STATS to PHYP.

Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
---
 arch/powerpc/include/uapi/asm/papr_scm_pdsm.h | 12 +++
 arch/powerpc/platforms/pseries/papr_scm.c     | 74 +++++++++++++++++++
 2 files changed, 86 insertions(+)

diff --git a/arch/powerpc/include/uapi/asm/papr_scm_pdsm.h b/arch/powerpc/include/uapi/asm/papr_scm_pdsm.h
index 2db4ffdff285..473c4bbddb2f 100644
--- a/arch/powerpc/include/uapi/asm/papr_scm_pdsm.h
+++ b/arch/powerpc/include/uapi/asm/papr_scm_pdsm.h
@@ -116,6 +116,7 @@ enum papr_scm_pdsm {
 	PAPR_SCM_PDSM_HEALTH,
 	PAPR_SCM_PDSM_FETCH_PERF_STATS,
 	PAPR_SCM_PDSM_READ_PERF_STATS,
+	PAPR_SCM_PDSM_GET_PERF_STAT,
 	PAPR_SCM_PDSM_MAX,
 };
 
@@ -218,4 +219,15 @@ struct nd_pdsm_read_perf_stats_v1 {
 #define nd_pdsm_read_perf_stats nd_pdsm_read_perf_stats_v1
 #define ND_PDSM_READ_PERF_STATS_VERSION 1
 
+/*
+ * Fetch the value of single nvdimm performance stat id of which is
+ * stored in 'stat.id'
+ */
+struct nd_pdsm_get_perf_stat_v1 {
+	struct nd_pdsm_perf_stat stat;
+} __packed;
+
+#define nd_pdsm_get_perf_stat nd_pdsm_get_perf_stat_v1
+#define ND_PDSM_GET_PERF_STAT_VERSION 1
+
 #endif /* _UAPI_ASM_POWERPC_PAPR_SCM_PDSM_H_ */
diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index 06744d7fe727..284d04f0a094 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -525,6 +525,77 @@ static int is_cmd_valid(struct nvdimm *nvdimm, unsigned int cmd, void *buf,
 	return 0;
 }
 
+static int papr_scm_get_perf_stat(struct papr_scm_priv *p,
+				  struct nd_pdsm_cmd_pkg *pkg)
+{
+	int rc;
+	struct nd_pdsm_get_perf_stat *stat =
+		(struct nd_pdsm_get_perf_stat *)pdsm_cmd_to_payload(pkg);
+	const size_t copysize = sizeof(struct nd_pdsm_get_perf_stat);
+	struct papr_scm_perf_stats *stats_req;
+	ssize_t stat_size;
+
+	/*
+	 * If the requested payload version is greater than one we know
+	 * about, return the payload version we know about and let
+	 * caller/userspace handle.
+	 */
+	if (pkg->payload_version > ND_PDSM_GET_PERF_STAT_VERSION)
+		pkg->payload_version = ND_PDSM_GET_PERF_STAT_VERSION;
+
+	if (pkg->hdr.nd_size_out < copysize) {
+		dev_dbg(&p->pdev->dev, "Truncated payload (%u). Expected (%lu)",
+			pkg->hdr.nd_size_out, copysize);
+		rc = -ENOSPC;
+		goto out;
+	}
+
+	if (!READ_ONCE(p->len_stat_buffer)) {
+		dev_dbg(&p->pdev->dev, "Perf stat: req for unsupported device");
+		rc = -ENOENT;
+		goto out;
+	}
+
+	/* Allocate and setup a PERFORMANCE_STATS request buffer */
+	stat_size = sizeof(struct papr_scm_perf_stats) +
+		sizeof(struct papr_scm_perf_stat);
+	stats_req = kzalloc(stat_size, GFP_KERNEL);
+	if (!stats_req) {
+		dev_err(&p->pdev->dev, "Perf stat: Unable to allocate memory\n");
+		rc = -ENOMEM;
+		goto out;
+	}
+
+	/* Copy the single request statistic_id into the request buffer */
+	memcpy(&stats_req->scm_statistics[0].statistic_id, &stat->stat.id,
+	       sizeof(stats_req->scm_statistics[0].statistic_id));
+
+	/* Fetch the stat from PHYP */
+	rc = drc_pmem_query_stats(p, stats_req, stat_size, 1, NULL);
+	if (rc)
+		goto out;
+
+	/* Copy the value of stat to the return payload */
+	memcpy(&stat->stat.id, &stats_req->scm_statistics[0].statistic_id,
+	       sizeof(stat->stat.id));
+	stat->stat.val = stats_req->scm_statistics[0].statistic_value;
+
+	pkg->hdr.nd_fw_size = copysize;
+
+	dev_dbg(&p->pdev->dev, "Copying payload size=%u version=0x%x\n",
+		pkg->hdr.nd_fw_size, pkg->payload_version);
+
+out:
+	/*
+	 * Put the error in out package and return success from function
+	 * so that errors if any are propogated back to userspace.
+	 */
+	pkg->cmd_status = rc;
+	dev_dbg(&p->pdev->dev, "completion code = %d\n", rc);
+
+	return 0;
+}
+
 /*
  * Read the contents of dimm performance statistics buffer at the given
  * 'in_offset' and copy 'in_length' number of bytes to the pkg payload.
@@ -755,6 +826,9 @@ static int papr_scm_service_pdsm(struct papr_scm_priv *p,
 	case PAPR_SCM_PDSM_READ_PERF_STATS:
 		return papr_scm_read_perf_stats(p, call_pkg);
 
+	case PAPR_SCM_PDSM_GET_PERF_STAT:
+		return papr_scm_get_perf_stat(p, call_pkg);
+
 	default:
 		dev_dbg(&p->pdev->dev, "Unsupported PDSM request 0x%llx\n",
 			call_pkg->hdr.nd_command);
-- 
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

WARNING: multiple messages have this Message-ID (diff)
From: Vaibhav Jain <vaibhav@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org, linux-nvdimm@lists.01.org
Cc: Santosh Sivaraj <santosh@fossix.org>,
	Oliver O'Halloran <oohall@gmail.com>,
	"Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>,
	Vaibhav Jain <vaibhav@linux.ibm.com>,
	Dan Williams <dan.j.williams@intel.com>
Subject: [RFC PATCH 4/4] powerpc/papr_scm: Add support for PDSM GET_PERF_STAT
Date: Mon, 18 May 2020 16:38:14 +0530	[thread overview]
Message-ID: <20200518110814.145644-5-vaibhav@linux.ibm.com> (raw)
In-Reply-To: <20200518110814.145644-1-vaibhav@linux.ibm.com>

This patch adds support for retrieving a singled NVDIMM performance
stat from PHYP via PDSM GET_PERF_STAT_VERSION. A new uapi 'struct
nd_pdsm_get_perf_stat' is introduced that holds a single performance
stat and is populated by newly introduced papr_scm_get_perf_stat() by
issuing an H_SCM_PERFORMANCE_STATS to PHYP.

Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
---
 arch/powerpc/include/uapi/asm/papr_scm_pdsm.h | 12 +++
 arch/powerpc/platforms/pseries/papr_scm.c     | 74 +++++++++++++++++++
 2 files changed, 86 insertions(+)

diff --git a/arch/powerpc/include/uapi/asm/papr_scm_pdsm.h b/arch/powerpc/include/uapi/asm/papr_scm_pdsm.h
index 2db4ffdff285..473c4bbddb2f 100644
--- a/arch/powerpc/include/uapi/asm/papr_scm_pdsm.h
+++ b/arch/powerpc/include/uapi/asm/papr_scm_pdsm.h
@@ -116,6 +116,7 @@ enum papr_scm_pdsm {
 	PAPR_SCM_PDSM_HEALTH,
 	PAPR_SCM_PDSM_FETCH_PERF_STATS,
 	PAPR_SCM_PDSM_READ_PERF_STATS,
+	PAPR_SCM_PDSM_GET_PERF_STAT,
 	PAPR_SCM_PDSM_MAX,
 };
 
@@ -218,4 +219,15 @@ struct nd_pdsm_read_perf_stats_v1 {
 #define nd_pdsm_read_perf_stats nd_pdsm_read_perf_stats_v1
 #define ND_PDSM_READ_PERF_STATS_VERSION 1
 
+/*
+ * Fetch the value of single nvdimm performance stat id of which is
+ * stored in 'stat.id'
+ */
+struct nd_pdsm_get_perf_stat_v1 {
+	struct nd_pdsm_perf_stat stat;
+} __packed;
+
+#define nd_pdsm_get_perf_stat nd_pdsm_get_perf_stat_v1
+#define ND_PDSM_GET_PERF_STAT_VERSION 1
+
 #endif /* _UAPI_ASM_POWERPC_PAPR_SCM_PDSM_H_ */
diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index 06744d7fe727..284d04f0a094 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -525,6 +525,77 @@ static int is_cmd_valid(struct nvdimm *nvdimm, unsigned int cmd, void *buf,
 	return 0;
 }
 
+static int papr_scm_get_perf_stat(struct papr_scm_priv *p,
+				  struct nd_pdsm_cmd_pkg *pkg)
+{
+	int rc;
+	struct nd_pdsm_get_perf_stat *stat =
+		(struct nd_pdsm_get_perf_stat *)pdsm_cmd_to_payload(pkg);
+	const size_t copysize = sizeof(struct nd_pdsm_get_perf_stat);
+	struct papr_scm_perf_stats *stats_req;
+	ssize_t stat_size;
+
+	/*
+	 * If the requested payload version is greater than one we know
+	 * about, return the payload version we know about and let
+	 * caller/userspace handle.
+	 */
+	if (pkg->payload_version > ND_PDSM_GET_PERF_STAT_VERSION)
+		pkg->payload_version = ND_PDSM_GET_PERF_STAT_VERSION;
+
+	if (pkg->hdr.nd_size_out < copysize) {
+		dev_dbg(&p->pdev->dev, "Truncated payload (%u). Expected (%lu)",
+			pkg->hdr.nd_size_out, copysize);
+		rc = -ENOSPC;
+		goto out;
+	}
+
+	if (!READ_ONCE(p->len_stat_buffer)) {
+		dev_dbg(&p->pdev->dev, "Perf stat: req for unsupported device");
+		rc = -ENOENT;
+		goto out;
+	}
+
+	/* Allocate and setup a PERFORMANCE_STATS request buffer */
+	stat_size = sizeof(struct papr_scm_perf_stats) +
+		sizeof(struct papr_scm_perf_stat);
+	stats_req = kzalloc(stat_size, GFP_KERNEL);
+	if (!stats_req) {
+		dev_err(&p->pdev->dev, "Perf stat: Unable to allocate memory\n");
+		rc = -ENOMEM;
+		goto out;
+	}
+
+	/* Copy the single request statistic_id into the request buffer */
+	memcpy(&stats_req->scm_statistics[0].statistic_id, &stat->stat.id,
+	       sizeof(stats_req->scm_statistics[0].statistic_id));
+
+	/* Fetch the stat from PHYP */
+	rc = drc_pmem_query_stats(p, stats_req, stat_size, 1, NULL);
+	if (rc)
+		goto out;
+
+	/* Copy the value of stat to the return payload */
+	memcpy(&stat->stat.id, &stats_req->scm_statistics[0].statistic_id,
+	       sizeof(stat->stat.id));
+	stat->stat.val = stats_req->scm_statistics[0].statistic_value;
+
+	pkg->hdr.nd_fw_size = copysize;
+
+	dev_dbg(&p->pdev->dev, "Copying payload size=%u version=0x%x\n",
+		pkg->hdr.nd_fw_size, pkg->payload_version);
+
+out:
+	/*
+	 * Put the error in out package and return success from function
+	 * so that errors if any are propogated back to userspace.
+	 */
+	pkg->cmd_status = rc;
+	dev_dbg(&p->pdev->dev, "completion code = %d\n", rc);
+
+	return 0;
+}
+
 /*
  * Read the contents of dimm performance statistics buffer at the given
  * 'in_offset' and copy 'in_length' number of bytes to the pkg payload.
@@ -755,6 +826,9 @@ static int papr_scm_service_pdsm(struct papr_scm_priv *p,
 	case PAPR_SCM_PDSM_READ_PERF_STATS:
 		return papr_scm_read_perf_stats(p, call_pkg);
 
+	case PAPR_SCM_PDSM_GET_PERF_STAT:
+		return papr_scm_get_perf_stat(p, call_pkg);
+
 	default:
 		dev_dbg(&p->pdev->dev, "Unsupported PDSM request 0x%llx\n",
 			call_pkg->hdr.nd_command);
-- 
2.26.2


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

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-18 11:08 [RFC PATCH 0/4] powerpc/papr_scm: Add support for reporting NVDIMM performance statistics Vaibhav Jain
2020-05-18 11:08 ` Vaibhav Jain
2020-05-18 11:08 ` [RFC PATCH 1/4] powerpc/papr_scm: Fetch nvdimm performance stats from PHYP Vaibhav Jain
2020-05-18 11:08   ` Vaibhav Jain
2020-05-18 11:08 ` [RFC PATCH 2/4] powerpc/papr_scm: Add support for PAPR_SCM_PDSM_FETCH_PERF_STATS Vaibhav Jain
2020-05-18 11:08   ` Vaibhav Jain
2020-05-18 11:08 ` [RFC PATCH 3/4] powerpc/papr_scm: Implement support for PAPR_SCM_PDSM_READ_PERF_STATS Vaibhav Jain
2020-05-18 11:08   ` Vaibhav Jain
2020-05-18 11:08 ` Vaibhav Jain [this message]
2020-05-18 11:08   ` [RFC PATCH 4/4] powerpc/papr_scm: Add support for PDSM GET_PERF_STAT Vaibhav Jain
2020-10-21 16:52 ` [RFC PATCH 0/4] powerpc/papr_scm: Add support for reporting NVDIMM performance statistics Michal Suchánek
2020-10-21 16:52   ` Michal Suchánek

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=20200518110814.145644-5-vaibhav@linux.ibm.com \
    --to=vaibhav@linux.ibm.com \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=linux-nvdimm@lists.01.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.