Skip to content

Commit ed78f56

Browse files
vaibhav92mpe
authored andcommitted
powerpc/papr_scm: Make 'perf_stats' invisible if perf-stats unavailable
In case performance stats for an nvdimm are not available, reading the 'perf_stats' sysfs file returns an -ENOENT error. A better approach is to make the 'perf_stats' file entirely invisible to indicate that performance stats for an nvdimm are unavailable. So this patch updates 'papr_nd_attribute_group' to add a 'is_visible' callback implemented as newly introduced 'papr_nd_attribute_visible()' that returns an appropriate mode in case performance stats aren't supported in a given nvdimm. Also the initialization of 'papr_scm_priv.stat_buffer_len' is moved from papr_scm_nvdimm_init() to papr_scm_probe() so that it value is available when 'papr_nd_attribute_visible()' is called during nvdimm initialization. Even though 'perf_stats' attribute is available since v5.9, there are no known user-space tools/scripts that are dependent on presence of its sysfs file. Hence I dont expect any user-space breakage with this patch. Fixes: 2d02bf8 ("powerpc/papr_scm: Fetch nvdimm performance stats from PHYP") Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com> Reviewed-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20210513092349.285021-1-vaibhav@linux.ibm.com
1 parent 511eea5 commit ed78f56

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ KernelVersion: v5.9
3939
Contact: linuxppc-dev <linuxppc-dev@lists.ozlabs.org>, nvdimm@lists.linux.dev,
4040
Description:
4141
(RO) Report various performance stats related to papr-scm NVDIMM
42-
device. Each stat is reported on a new line with each line
43-
composed of a stat-identifier followed by it value. Below are
44-
currently known dimm performance stats which are reported:
42+
device. This attribute is only available for NVDIMM devices
43+
that support reporting NVDIMM performance stats. Each stat is
44+
reported on a new line with each line composed of a
45+
stat-identifier followed by it value. Below are currently known
46+
dimm performance stats which are reported:
4547

4648
* "CtlResCt" : Controller Reset Count
4749
* "CtlResTm" : Controller Reset Elapsed Time

‎arch/powerpc/platforms/pseries/papr_scm.c‎

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,20 @@ static ssize_t flags_show(struct device *dev,
908908
}
909909
DEVICE_ATTR_RO(flags);
910910

911+
static umode_t papr_nd_attribute_visible(struct kobject *kobj,
912+
struct attribute *attr, int n)
913+
{
914+
struct device *dev = kobj_to_dev(kobj);
915+
struct nvdimm *nvdimm = to_nvdimm(dev);
916+
struct papr_scm_priv *p = nvdimm_provider_data(nvdimm);
917+
918+
/* For if perf-stats not available remove perf_stats sysfs */
919+
if (attr == &dev_attr_perf_stats.attr && p->stat_buffer_len == 0)
920+
return 0;
921+
922+
return attr->mode;
923+
}
924+
911925
/* papr_scm specific dimm attributes */
912926
static struct attribute *papr_nd_attributes[] = {
913927
&dev_attr_flags.attr,
@@ -917,6 +931,7 @@ static struct attribute *papr_nd_attributes[] = {
917931

918932
static struct attribute_group papr_nd_attribute_group = {
919933
.name = "papr",
934+
.is_visible = papr_nd_attribute_visible,
920935
.attrs = papr_nd_attributes,
921936
};
922937

@@ -932,7 +947,6 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)
932947
struct nd_region_desc ndr_desc;
933948
unsigned long dimm_flags;
934949
int target_nid, online_nid;
935-
ssize_t stat_size;
936950

937951
p->bus_desc.ndctl = papr_scm_ndctl;
938952
p->bus_desc.module = THIS_MODULE;
@@ -1017,16 +1031,6 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)
10171031
list_add_tail(&p->region_list, &papr_nd_regions);
10181032
mutex_unlock(&papr_ndr_lock);
10191033

1020-
/* Try retriving the stat buffer and see if its supported */
1021-
stat_size = drc_pmem_query_stats(p, NULL, 0);
1022-
if (stat_size > 0) {
1023-
p->stat_buffer_len = stat_size;
1024-
dev_dbg(&p->pdev->dev, "Max perf-stat size %lu-bytes\n",
1025-
p->stat_buffer_len);
1026-
} else {
1027-
dev_info(&p->pdev->dev, "Dimm performance stats unavailable\n");
1028-
}
1029-
10301034
return 0;
10311035

10321036
err: nvdimm_bus_unregister(p->bus);
@@ -1104,6 +1108,7 @@ static int papr_scm_probe(struct platform_device *pdev)
11041108
struct papr_scm_priv *p;
11051109
u8 uuid_raw[UUID_SIZE];
11061110
const char *uuid_str;
1111+
ssize_t stat_size;
11071112
uuid_t uuid;
11081113
int rc;
11091114

@@ -1188,6 +1193,14 @@ static int papr_scm_probe(struct platform_device *pdev)
11881193
p->res.name = pdev->name;
11891194
p->res.flags = IORESOURCE_MEM;
11901195

1196+
/* Try retrieving the stat buffer and see if its supported */
1197+
stat_size = drc_pmem_query_stats(p, NULL, 0);
1198+
if (stat_size > 0) {
1199+
p->stat_buffer_len = stat_size;
1200+
dev_dbg(&p->pdev->dev, "Max perf-stat size %lu-bytes\n",
1201+
p->stat_buffer_len);
1202+
}
1203+
11911204
rc = papr_scm_nvdimm_init(p);
11921205
if (rc)
11931206
goto err2;

0 commit comments

Comments
 (0)