Skip to content

Commit 2d02bf8

Browse files
vaibhav92mpe
authored andcommitted
powerpc/papr_scm: Fetch nvdimm performance stats from PHYP
Update papr_scm.c to query dimm performance statistics from PHYP via H_SCM_PERFORMANCE_STATS hcall and export them to user-space as PAPR specific NVDIMM attribute 'perf_stats' in sysfs. The patch also provide a sysfs ABI documentation for the stats being reported and their meanings. During NVDIMM probe time in papr_scm_nvdimm_init() a special variant of H_SCM_PERFORMANCE_STATS hcall is issued to check if collection of performance statistics is supported or not. If successful then a PHYP returns a maximum possible buffer length needed to read all performance stats. This returned value is stored in a per-nvdimm attribute 'stat_buffer_len'. The layout of request buffer for reading NVDIMM performance stats from PHYP is defined in 'struct papr_scm_perf_stats' and 'struct papr_scm_perf_stat'. These structs are used in newly introduced drc_pmem_query_stats() that issues the H_SCM_PERFORMANCE_STATS hcall. The sysfs access function perf_stats_show() uses value 'stat_buffer_len' to allocate a buffer large enough to hold all possible NVDIMM performance stats and passes it to drc_pmem_query_stats() to populate. Finally statistics reported in the buffer are formatted into the sysfs access function output buffer. Signed-off-by: Vaibhav Jain <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d947fb4 commit 2d02bf8

File tree

2 files changed

+177
-0
lines changed

2 files changed

+177
-0
lines changed

Documentation/ABI/testing/sysfs-bus-papr-pmem

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,30 @@ Description:
2525
NVDIMM have been scrubbed.
2626
* "locked" : Indicating that NVDIMM contents cant
2727
be modified until next power cycle.
28+
29+
What: /sys/bus/nd/devices/nmemX/papr/perf_stats
30+
Date: May, 2020
31+
KernelVersion: v5.9
32+
Contact: linuxppc-dev <[email protected]>, [email protected],
33+
Description:
34+
(RO) Report various performance stats related to papr-scm NVDIMM
35+
device. Each stat is reported on a new line with each line
36+
composed of a stat-identifier followed by it value. Below are
37+
currently known dimm performance stats which are reported:
38+
39+
* "CtlResCt" : Controller Reset Count
40+
* "CtlResTm" : Controller Reset Elapsed Time
41+
* "PonSecs " : Power-on Seconds
42+
* "MemLife " : Life Remaining
43+
* "CritRscU" : Critical Resource Utilization
44+
* "HostLCnt" : Host Load Count
45+
* "HostSCnt" : Host Store Count
46+
* "HostSDur" : Host Store Duration
47+
* "HostLDur" : Host Load Duration
48+
* "MedRCnt " : Media Read Count
49+
* "MedWCnt " : Media Write Count
50+
* "MedRDur " : Media Read Duration
51+
* "MedWDur " : Media Write Duration
52+
* "CchRHCnt" : Cache Read Hit Count
53+
* "CchWHCnt" : Cache Write Hit Count
54+
* "FastWCnt" : Fast Write Count

arch/powerpc/platforms/pseries/papr_scm.c

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@
6464
PAPR_PMEM_HEALTH_FATAL | \
6565
PAPR_PMEM_HEALTH_UNHEALTHY)
6666

67+
#define PAPR_SCM_PERF_STATS_EYECATCHER __stringify(SCMSTATS)
68+
#define PAPR_SCM_PERF_STATS_VERSION 0x1
69+
70+
/* Struct holding a single performance metric */
71+
struct papr_scm_perf_stat {
72+
u8 stat_id[8];
73+
__be64 stat_val;
74+
} __packed;
75+
76+
/* Struct exchanged between kernel and PHYP for fetching drc perf stats */
77+
struct papr_scm_perf_stats {
78+
u8 eye_catcher[8];
79+
/* Should be PAPR_SCM_PERF_STATS_VERSION */
80+
__be32 stats_version;
81+
/* Number of stats following */
82+
__be32 num_statistics;
83+
/* zero or more performance matrics */
84+
struct papr_scm_perf_stat scm_statistic[];
85+
} __packed;
86+
6787
/* private struct associated with each region */
6888
struct papr_scm_priv {
6989
struct platform_device *pdev;
@@ -92,6 +112,9 @@ struct papr_scm_priv {
92112

93113
/* Health information for the dimm */
94114
u64 health_bitmap;
115+
116+
/* length of the stat buffer as expected by phyp */
117+
size_t stat_buffer_len;
95118
};
96119

97120
static LIST_HEAD(papr_nd_regions);
@@ -200,6 +223,79 @@ static int drc_pmem_query_n_bind(struct papr_scm_priv *p)
200223
return drc_pmem_bind(p);
201224
}
202225

226+
/*
227+
* Query the Dimm performance stats from PHYP and copy them (if returned) to
228+
* provided struct papr_scm_perf_stats instance 'stats' that can hold atleast
229+
* (num_stats + header) bytes.
230+
* - If buff_stats == NULL the return value is the size in byes of the buffer
231+
* needed to hold all supported performance-statistics.
232+
* - If buff_stats != NULL and num_stats == 0 then we copy all known
233+
* performance-statistics to 'buff_stat' and expect to be large enough to
234+
* hold them.
235+
* - if buff_stats != NULL and num_stats > 0 then copy the requested
236+
* performance-statistics to buff_stats.
237+
*/
238+
static ssize_t drc_pmem_query_stats(struct papr_scm_priv *p,
239+
struct papr_scm_perf_stats *buff_stats,
240+
unsigned int num_stats)
241+
{
242+
unsigned long ret[PLPAR_HCALL_BUFSIZE];
243+
size_t size;
244+
s64 rc;
245+
246+
/* Setup the out buffer */
247+
if (buff_stats) {
248+
memcpy(buff_stats->eye_catcher,
249+
PAPR_SCM_PERF_STATS_EYECATCHER, 8);
250+
buff_stats->stats_version =
251+
cpu_to_be32(PAPR_SCM_PERF_STATS_VERSION);
252+
buff_stats->num_statistics =
253+
cpu_to_be32(num_stats);
254+
255+
/*
256+
* Calculate the buffer size based on num-stats provided
257+
* or use the prefetched max buffer length
258+
*/
259+
if (num_stats)
260+
/* Calculate size from the num_stats */
261+
size = sizeof(struct papr_scm_perf_stats) +
262+
num_stats * sizeof(struct papr_scm_perf_stat);
263+
else
264+
size = p->stat_buffer_len;
265+
} else {
266+
/* In case of no out buffer ignore the size */
267+
size = 0;
268+
}
269+
270+
/* Do the HCALL asking PHYP for info */
271+
rc = plpar_hcall(H_SCM_PERFORMANCE_STATS, ret, p->drc_index,
272+
buff_stats ? virt_to_phys(buff_stats) : 0,
273+
size);
274+
275+
/* Check if the error was due to an unknown stat-id */
276+
if (rc == H_PARTIAL) {
277+
dev_err(&p->pdev->dev,
278+
"Unknown performance stats, Err:0x%016lX\n", ret[0]);
279+
return -ENOENT;
280+
} else if (rc != H_SUCCESS) {
281+
dev_err(&p->pdev->dev,
282+
"Failed to query performance stats, Err:%lld\n", rc);
283+
return -EIO;
284+
285+
} else if (!size) {
286+
/* Handle case where stat buffer size was requested */
287+
dev_dbg(&p->pdev->dev,
288+
"Performance stats size %ld\n", ret[0]);
289+
return ret[0];
290+
}
291+
292+
/* Successfully fetched the requested stats from phyp */
293+
dev_dbg(&p->pdev->dev,
294+
"Performance stats returned %d stats\n",
295+
be32_to_cpu(buff_stats->num_statistics));
296+
return 0;
297+
}
298+
203299
/*
204300
* Issue hcall to retrieve dimm health info and populate papr_scm_priv with the
205301
* health information.
@@ -637,6 +733,48 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc,
637733
return 0;
638734
}
639735

736+
static ssize_t perf_stats_show(struct device *dev,
737+
struct device_attribute *attr, char *buf)
738+
{
739+
int index, rc;
740+
struct seq_buf s;
741+
struct papr_scm_perf_stat *stat;
742+
struct papr_scm_perf_stats *stats;
743+
struct nvdimm *dimm = to_nvdimm(dev);
744+
struct papr_scm_priv *p = nvdimm_provider_data(dimm);
745+
746+
if (!p->stat_buffer_len)
747+
return -ENOENT;
748+
749+
/* Allocate the buffer for phyp where stats are written */
750+
stats = kzalloc(p->stat_buffer_len, GFP_KERNEL);
751+
if (!stats)
752+
return -ENOMEM;
753+
754+
/* Ask phyp to return all dimm perf stats */
755+
rc = drc_pmem_query_stats(p, stats, 0);
756+
if (rc)
757+
goto free_stats;
758+
/*
759+
* Go through the returned output buffer and print stats and
760+
* values. Since stat_id is essentially a char string of
761+
* 8 bytes, simply use the string format specifier to print it.
762+
*/
763+
seq_buf_init(&s, buf, PAGE_SIZE);
764+
for (index = 0, stat = stats->scm_statistic;
765+
index < be32_to_cpu(stats->num_statistics);
766+
++index, ++stat) {
767+
seq_buf_printf(&s, "%.8s = 0x%016llX\n",
768+
stat->stat_id,
769+
be64_to_cpu(stat->stat_val));
770+
}
771+
772+
free_stats:
773+
kfree(stats);
774+
return rc ? rc : seq_buf_used(&s);
775+
}
776+
DEVICE_ATTR_RO(perf_stats);
777+
640778
static ssize_t flags_show(struct device *dev,
641779
struct device_attribute *attr, char *buf)
642780
{
@@ -682,6 +820,7 @@ DEVICE_ATTR_RO(flags);
682820
/* papr_scm specific dimm attributes */
683821
static struct attribute *papr_nd_attributes[] = {
684822
&dev_attr_flags.attr,
823+
&dev_attr_perf_stats.attr,
685824
NULL,
686825
};
687826

@@ -702,6 +841,7 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)
702841
struct nd_region_desc ndr_desc;
703842
unsigned long dimm_flags;
704843
int target_nid, online_nid;
844+
ssize_t stat_size;
705845

706846
p->bus_desc.ndctl = papr_scm_ndctl;
707847
p->bus_desc.module = THIS_MODULE;
@@ -769,6 +909,16 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)
769909
list_add_tail(&p->region_list, &papr_nd_regions);
770910
mutex_unlock(&papr_ndr_lock);
771911

912+
/* Try retriving the stat buffer and see if its supported */
913+
stat_size = drc_pmem_query_stats(p, NULL, 0);
914+
if (stat_size > 0) {
915+
p->stat_buffer_len = stat_size;
916+
dev_dbg(&p->pdev->dev, "Max perf-stat size %lu-bytes\n",
917+
p->stat_buffer_len);
918+
} else {
919+
dev_info(&p->pdev->dev, "Dimm performance stats unavailable\n");
920+
}
921+
772922
return 0;
773923

774924
err: nvdimm_bus_unregister(p->bus);

0 commit comments

Comments
 (0)