Skip to content

Commit 53fa3ba

Browse files
vaibhav92gregkh
authored andcommitted
powerpc/papr_scm: Make 'perf_stats' invisible if perf-stats unavailable
[ Upstream commit ed78f56 ] 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 Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 04db493 commit 53fa3ba

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>, linux-nvdimm@lists.01.org,
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
@@ -868,6 +868,20 @@ static ssize_t flags_show(struct device *dev,
868868
}
869869
DEVICE_ATTR_RO(flags);
870870

871+
static umode_t papr_nd_attribute_visible(struct kobject *kobj,
872+
struct attribute *attr, int n)
873+
{
874+
struct device *dev = kobj_to_dev(kobj);
875+
struct nvdimm *nvdimm = to_nvdimm(dev);
876+
struct papr_scm_priv *p = nvdimm_provider_data(nvdimm);
877+
878+
/* For if perf-stats not available remove perf_stats sysfs */
879+
if (attr == &dev_attr_perf_stats.attr && p->stat_buffer_len == 0)
880+
return 0;
881+
882+
return attr->mode;
883+
}
884+
871885
/* papr_scm specific dimm attributes */
872886
static struct attribute *papr_nd_attributes[] = {
873887
&dev_attr_flags.attr,
@@ -877,6 +891,7 @@ static struct attribute *papr_nd_attributes[] = {
877891

878892
static struct attribute_group papr_nd_attribute_group = {
879893
.name = "papr",
894+
.is_visible = papr_nd_attribute_visible,
880895
.attrs = papr_nd_attributes,
881896
};
882897

@@ -892,7 +907,6 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)
892907
struct nd_region_desc ndr_desc;
893908
unsigned long dimm_flags;
894909
int target_nid, online_nid;
895-
ssize_t stat_size;
896910

897911
p->bus_desc.ndctl = papr_scm_ndctl;
898912
p->bus_desc.module = THIS_MODULE;
@@ -963,16 +977,6 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)
963977
list_add_tail(&p->region_list, &papr_nd_regions);
964978
mutex_unlock(&papr_ndr_lock);
965979

966-
/* Try retriving the stat buffer and see if its supported */
967-
stat_size = drc_pmem_query_stats(p, NULL, 0);
968-
if (stat_size > 0) {
969-
p->stat_buffer_len = stat_size;
970-
dev_dbg(&p->pdev->dev, "Max perf-stat size %lu-bytes\n",
971-
p->stat_buffer_len);
972-
} else {
973-
dev_info(&p->pdev->dev, "Dimm performance stats unavailable\n");
974-
}
975-
976980
return 0;
977981

978982
err: nvdimm_bus_unregister(p->bus);
@@ -1050,6 +1054,7 @@ static int papr_scm_probe(struct platform_device *pdev)
10501054
struct papr_scm_priv *p;
10511055
u8 uuid_raw[UUID_SIZE];
10521056
const char *uuid_str;
1057+
ssize_t stat_size;
10531058
uuid_t uuid;
10541059
int rc;
10551060

@@ -1133,6 +1138,14 @@ static int papr_scm_probe(struct platform_device *pdev)
11331138
p->res.name = pdev->name;
11341139
p->res.flags = IORESOURCE_MEM;
11351140

1141+
/* Try retrieving the stat buffer and see if its supported */
1142+
stat_size = drc_pmem_query_stats(p, NULL, 0);
1143+
if (stat_size > 0) {
1144+
p->stat_buffer_len = stat_size;
1145+
dev_dbg(&p->pdev->dev, "Max perf-stat size %lu-bytes\n",
1146+
p->stat_buffer_len);
1147+
}
1148+
11361149
rc = papr_scm_nvdimm_init(p);
11371150
if (rc)
11381151
goto err2;

0 commit comments

Comments
 (0)