powerpc/papr_scm: add support for reporting NVDIMM 'life_used_percentage' metric
Subsystems (2)
v4 cover powerpc/papr_scm: add support for reporting NVDIMM 'life_used_percentage' metric
Changes since v3[1]:
* Fixed a rebase issue pointed out by Aneesh in first patch in the series.
[1] https://lore.kernel.org/linux-nvdimm/[email protected]
---
This small patchset implements kernel side support for reporting 'life_used_percentage' metric in NDCTL with dimm health output for papr-scm NVDIMMs. With corresponding NDCTL side changes output for should be like:
$ sudo ndctl list -DH
[
{
"dev":"nmem0",
"health":{
"health_state":"ok",
"life_used_percentage":0,
"shutdown_state":"clean"
}
}
]PHYP supports H_SCM_PERFORMANCE_STATS hcall through which an LPAR can fetch various performance stats including 'fuel_gauge' percentage for an NVDIMM. 'fuel_gauge' metric indicates the usable life remaining of an NVDIMM expressed as percentage and 'life_used_percentage' can be calculated as 'life_used_percentage = 100 - fuel_gauge'.
Structure of the patchset
=========================
First patch implements necessary scaffolding needed to issue the H_SCM_PERFORMANCE_STATS hcall and fetch performance stats catalogue. The patch also implements support for 'perf_stats' sysfs attribute to report the full catalogue of supported performance stats by PHYP.
Second and final patch implements support for sending this value to libndctl by extending the PAPR_PDSM_HEALTH pdsm payload to add a new field named 'dimm_fuel_gauge' to it.
Vaibhav Jain (2):
powerpc/papr_scm: Fetch nvdimm performance stats from PHYP powerpc/papr_scm: Add support for fetching nvdimm 'fuel-gauge' metric
Documentation/ABI/testing/sysfs-bus-papr-pmem | 27 +++ arch/powerpc/include/uapi/asm/papr_pdsm.h | 9 + arch/powerpc/platforms/pseries/papr_scm.c | 199 ++++++++++++++++++ 3 files changed, 235 insertions(+)
Signature · 4 lines
2.26.2 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
PATCH v4 1/2 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.
---
Changelog:
v4:
* Fixed a build issue with this patch by moving a hunk from second patch in series to this patch. [ Aneesh ]
v3:
* Updated drc_pmem_query_stats() to not require 'buff_size' and 'out' args to the function. Instead 'buff_size' is calculated from 'num_stats' and instead of populating 'R4' in arg 'out' the value is returned from the function in case 'R4' represents 'max-buffer-size'.
Resend:
None
v2:
* Updated 'struct papr_scm_perf_stats' and 'struct papr_scm_perf_stat' to use big-endian types. [ Aneesh ]
* s/len_stat_buffer/stat_buffer_len/ [ Aneesh ]
* s/statistics_id/stat_id/ , s/statistics_val/stat_val/ [ Aneesh ]
* Conversion from Big endian to cpu endian happens later rather than just after its fetched from PHYP.
* Changed a log statement to unambiguously report dimm performance stats are not available for the given nvdimm [ Ira ]
* Restructed some code to handle error case first [ Ira ]
--- Documentation/ABI/testing/sysfs-bus-papr-pmem | 27 ++++ arch/powerpc/platforms/pseries/papr_scm.c | 150 ++++++++++++++++++ 2 files changed, 177 insertions(+)
Documentation/ABI/testing/sysfs-bus-papr-pmem +27 -0
@@ -25,3 +25,30 @@ Description: NVDIMM have been scrubbed. * "locked" : Indicating that NVDIMM contents cant be modified until next power cycle. + +What: /sys/bus/nd/devices/nmemX/papr/perf_stats +Date: May, 2020 +KernelVersion: v5.9 +Contact: linuxppc-dev <[email protected]>, [email protected], +Description: + (RO) Report various performance stats related to papr-scm NVDIMM + device. Each stat is reported on a new line with each line + composed of a stat-identifier followed by it value. Below are + currently known dimm performance stats which are reported: + + * "CtlResCt" : Controller Reset Count + * "CtlResTm" : Controller Reset Elapsed Time + * "PonSecs " : Power-on Seconds + * "MemLife " : Life Remaining + * "CritRscU" : Critical Resource Utilization + * "HostLCnt" : Host Load Count + * "HostSCnt" : Host Store Count + * "HostSDur" : Host Store Duration + * "HostLDur" : Host Load Duration + * "MedRCnt " : Media Read Count + * "MedWCnt " : Media Write Count + * "MedRDur " : Media Read Duration + * "MedWDur " : Media Write Duration + * "CchRHCnt" : Cache Read Hit Count + * "CchWHCnt" : Cache Write Hit Count + * "FastWCnt" : Fast Write Count
arch/powerpc/platforms/pseries/papr_scm.c +150 -0
192 lines not on this page · raw message
Signature · 4 lines
2.26.2 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [PATCH v4 1/2] powerpc/papr_scm: Fetch nvdimm performance stats from PHYP
Quoted 230 lines · Vaibhav Jain
Update
papr_scm.cto query dimm performance statistics from PHYP viaH_SCM_PERFORMANCE_STATShcall 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 ofH_SCM_PERFORMANCE_STATShcall 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 'structpapr_scm_perf_stat'. These structs are used in newly introduceddrc_pmem_query_stats()that issues theH_SCM_PERFORMANCE_STATShcall.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 todrc_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]>---
Changelog:v4:
* Fixed a build issue with this patch by moving a hunk from second patch in series to this patch. [ Aneesh ]v3:
* Updateddrc_pmem_query_stats()to not require 'buff_size' and 'out' args to the function. Instead 'buff_size' is calculated from 'num_stats' and instead of populating 'R4' in arg 'out' the value is returned from the function in case 'R4' represents 'max-buffer-size'.Resend:
Nonev2:
* Updated 'structpapr_scm_perf_stats' and 'structpapr_scm_perf_stat' to use big-endian types. [ Aneesh ]
* s/len_stat_buffer/stat_buffer_len/ [ Aneesh ]
* s/statistics_id/stat_id/ , s/statistics_val/stat_val/ [ Aneesh ]
* Conversion from Big endian to cpu endian happens later rather than just after its fetched from PHYP.
* Changed a log statement to unambiguously report dimm performance stats are not available for the given nvdimm [ Ira ]
* Restructed some code to handle error case first [ Ira ]--- Documentation/ABI/testing/sysfs-bus-papr-pmem | 27 ++++ arch/powerpc/platforms/pseries/papr_scm.c | 150 ++++++++++++++++++ 2 files changed, 177 insertions(+)Documentation/ABI/testing/sysfs-bus-papr-pmem +27
-0@@ -25,3 +25,30 @@ Description: NVDIMM have been scrubbed. * "locked" : Indicating that NVDIMM contents cant be modified until next power cycle. + +What: /sys/bus/nd/devices/nmemX/papr/perf_stats +Date: May, 2020 +KernelVersion: v5.9 +Contact: linuxppc-dev <[email protected]>, [email protected], +Description: + (RO) Report various performance stats related to papr-scm NVDIMM + device. Each stat is reported on a new line with each line + composed of a stat-identifier followed by it value. Below are + currently known dimm performance stats which are reported: + + * "CtlResCt" : Controller Reset Count + * "CtlResTm" : Controller Reset Elapsed Time + * "PonSecs " : Power-on Seconds + * "MemLife " : Life Remaining + * "CritRscU" : Critical Resource Utilization + * "HostLCnt" : Host Load Count + * "HostSCnt" : Host Store Count + * "HostSDur" : Host Store Duration + * "HostLDur" : Host Load Duration + * "MedRCnt " : Media Read Count + * "MedWCnt " : Media Write Count + * "MedRDur " : Media Read Duration + * "MedWDur " : Media Write Duration + * "CchRHCnt" : Cache Read Hit Count + * "CchWHCnt" : Cache Write Hit Count + * "FastWCnt" : Fast Write Countarch/powerpc/platforms/pseries/papr_scm.c +108
-0@@ -64,6 +64,26 @@ PAPR_PMEM_HEALTH_FATAL | \ PAPR_PMEM_HEALTH_UNHEALTHY) +#define PAPR_SCM_PERF_STATS_EYECATCHER __stringify(SCMSTATS) +#define PAPR_SCM_PERF_STATS_VERSION 0x1 + +/* Struct holding a single performance metric */ +struct papr_scm_perf_stat { +u8 stat_id[8 ]; +__be64 stat_val; +} __packed; + +/* Struct exchanged between kernel and PHYP for fetching drc perf stats */ +struct papr_scm_perf_stats { +u8 eye_catcher[8 ]; +/* Should be PAPR_SCM_PERF_STATS_VERSION */ +__be32 stats_version; +/* Number of stats following */ +__be32 num_statistics; +/* zero or more performance matrics */ +struct papr_scm_perf_stat scm_statistic[]; +} __packed; +/* private struct associated with each region */ struct papr_scm_priv {struct platform_device *pdev;@@ -92,6 +112,9 @@ struct papr_scm_priv {/* Health information for the dimm */ u64 health_bitmap; + +/* length of the stat buffer as expected by phyp */ +size_t stat_buffer_len; };static LIST_HEAD (papr_nd_regions);@@ -200,6 +223,79 @@ static int drc_pmem_query_n_bind(struct papr_scm_priv *p)return drc_pmem_bind (p); } +/* +* Query the Dimm performance stats from PHYP and copy them (if returned) to +* provided struct papr_scm_perf_stats instance 'stats' that can hold atleast +* (num_stats + header) bytes. +* - If buff_stats == NULL the return value is the size in byes of the buffer +* needed to hold all supported performance-statistics. +* - If buff_stats != NULL and num_stats == 0 then we copy all known +* performance-statistics to 'buff_stat' and expect to be large enough to +* hold them. +* - if buff_stats != NULL and num_stats > 0 then copy the requested +* performance-statistics to buff_stats. +*/ +static ssize_t drc_pmem_query_stats (struct papr_scm_priv *p, +struct papr_scm_perf_stats *buff_stats, +unsigned int num_stats) +{ +unsigned long ret[PLPAR_HCALL_BUFSIZE ]; +size_t size; +s64 rc; + +/* Setup the out buffer */ +if (buff_stats) { +memcpy (buff_stats->eye_catcher, +PAPR_SCM_PERF_STATS_EYECATCHER ,8 ); + buff_stats->stats_version = +cpu_to_be32 (PAPR_SCM_PERF_STATS_VERSION ); + buff_stats->num_statistics = +cpu_to_be32 (num_stats); + +/* +* Calculate the buffer size based on num-stats provided +* or use the prefetched max buffer length +*/ +if (num_stats) +/* Calculate size from the num_stats */ + size =sizeof (struct papr_scm_perf_stats ) + + num_stats *sizeof (struct papr_scm_perf_stat ); +else + size = p->stat_buffer_len; + }else { +/* In case of no out buffer ignore the size */ + size =0 ; + } + +/* Do the HCALL asking PHYP for info */ + rc =plpar_hcall (H_SCM_PERFORMANCE_STATS , ret, p->drc_index, + buff_stats ?virt_to_phys (buff_stats) :0 , + size); + +/* Check if the error was due to an unknown stat-id */ +if (rc ==H_PARTIAL ) { +dev_err (&p->pdev->dev, +"Unknown performance stats, Err:0x%016lX\n" , ret[0 ]); +return -ENOENT ; + }else if (rc !=H_SUCCESS ) { +dev_err (&p->pdev->dev, +"Failed to query performance stats, Err:%lld\n" , rc); +return -EIO ; + + }else if (!size) { +/* Handle case where stat buffer size was requested */ +dev_dbg (&p->pdev->dev, +"Performance stats size %ld\n" , ret[0 ]); +return ret[0 ]; + } + +/* Successfully fetched the requested stats from phyp */ +dev_dbg (&p->pdev->dev, +"Performance stats returned %d stats\n" , +be32_to_cpu (buff_stats->num_statistics)); +return 0 ; +} +/* * Issue hcall to retrieve dimm health info and populate papr_scm_priv with the * health information. @@ -637,6 +733,48 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc,return 0 ; } +static ssize_t perf_stats_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +int index, rc; +struct seq_buf s; +struct papr_scm_perf_stat *stat; +struct papr_scm_perf_stats *stats; +struct nvdimm *dimm =to_nvdimm (dev); +struct papr_scm_priv *p =nvdimm_provider_data (dimm); + +if (!p->stat_buffer_len) +return -ENOENT ;
arch/powerpc/platforms/pseries/papr_scm.c static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc, · line 757
Quoted 10 lines
arch/powerpc/platforms/pseries/papr_scm.c +10
-0+ +/* Allocate the buffer for phyp where stats are written */ + stats =kzalloc (p->stat_buffer_len,GFP_KERNEL ); +if (!stats) +return -ENOMEM ; + +/* Ask phyp to return all dimm perf stats */ + rc =drc_pmem_query_stats (p, stats,0 ); +if (rc) + goto free_stats;
So we end up making a HCALL for each read of the sysfs file? You do throttle that for PAPR_HEALTH hcall (flags sysfs file). Do we need to do that here? If not should we make this CAP_SYS_ADMIN? You can possibly add is_visible callback to papr group and then restrict this all to CAP_SYS_ADMIN?
Quoted 58 lines
arch/powerpc/platforms/pseries/papr_scm.c +32
-0+/* +* Go through the returned output buffer and print stats and +* values. Since stat_id is essentially a char string of +* 8 bytes, simply use the string format specifier to print it. +*/ +seq_buf_init (&s, buf,PAGE_SIZE ); +for (index =0 , stat = stats->scm_statistic; + index <be32_to_cpu (stats->num_statistics); + ++index, ++stat) { +seq_buf_printf (&s,"%.8s = 0x%016llX\n" , + stat->stat_id, +be64_to_cpu (stat->stat_val)); + } + +free_stats: +kfree (stats); +return rc ? rc :seq_buf_used (&s); +} +DEVICE_ATTR_RO (perf_stats); +static ssize_t flags_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -682,6 +820,7 @@ DEVICE_ATTR_RO(flags);/* papr_scm specific dimm attributes */ static struct attribute *papr_nd_attributes[] = { &dev_attr_flags.attr, + &dev_attr_perf_stats.attr,NULL , };@@ -702,6 +841,7 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)struct nd_region_desc ndr_desc;unsigned long dimm_flags;int target_nid, online_nid; +ssize_t stat_size; p->bus_desc.ndctl = papr_scm_ndctl; p->bus_desc.module =THIS_MODULE ;@@ -769,6 +909,16 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)list_add_tail (&p->region_list, &papr_nd_regions);mutex_unlock (&papr_ndr_lock); +/* Try retriving the stat buffer and see if its supported */ + stat_size =drc_pmem_query_stats (p,NULL ,0 ); +if (stat_size >0 ) { + p->stat_buffer_len = stat_size; +dev_dbg (&p->pdev->dev,"Max perf-stat size %lu-bytes\n" , + p->stat_buffer_len); + }else { +dev_info (&p->pdev->dev,"Dimm performance stats unavailable\n" ); + } +return 0 ; err:nvdimm_bus_unregister (p->bus);Signature · 1 line
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
PATCH v4 2/2 powerpc/papr_scm: Add support for fetching nvdimm 'fuel-gauge' metric
In reply to Vaibhav JainWe add support for reporting 'fuel-gauge' NVDIMM metric via PAPR_PDSM_HEALTH pdsm payload. 'fuel-gauge' metric indicates the usage life remaining of a papr-scm compatible NVDIMM. PHYP exposes this metric via the H_SCM_PERFORMANCE_STATS.
The metric value is returned from the pdsm by extending the return payload 'struct nd_papr_pdsm_health' without breaking the ABI. A new field 'dimm_fuel_gauge' to hold the metric value is introduced at the end of the payload struct and its presence is indicated by by extension flag PDSM_DIMM_HEALTH_RUN_GAUGE_VALID.
The patch introduces a new function papr_pdsm_fuel_gauge() that is called from papr_pdsm_health(). If fetching NVDIMM performance stats is supported then 'papr_pdsm_fuel_gauge()' allocated an output buffer large enough to hold the performance stat and passes it to drc_pmem_query_stats() that issues the HCALL to PHYP. The return value of the stat is then populated in the 'struct nd_papr_pdsm_health.dimm_fuel_gauge' field with extension flag 'PDSM_DIMM_HEALTH_RUN_GAUGE_VALID' set in 'struct nd_papr_pdsm_health.extension_flags'
---
Changelog:
v4:
* Moved a hunk from this patch to previous patch in the series. [ Aneesh ]
v3:
* Updated papr_pdsm_fuel_guage() to use the updated drc_pmem_query_stats() function.
Resend:
None
v2:
* Restructure code in papr_pdsm_fuel_gauge() to handle error case first [ Ira ]
* Ignore the return value of papr_pdsm_fuel_gauge() in papr_psdm_health() [ Ira ]
--- arch/powerpc/include/uapi/asm/papr_pdsm.h | 9 +++++ arch/powerpc/platforms/pseries/papr_scm.c | 49 +++++++++++++++++++++++ 2 files changed, 58 insertions(+)
arch/powerpc/include/uapi/asm/papr_pdsm.h +9 -0
@@ -72,6 +72,11 @@#define PAPR_PDSM_DIMM_CRITICAL 2#define PAPR_PDSM_DIMM_FATAL 3 +/* struct nd_papr_pdsm_health.extension_flags field flags */ + +/* Indicate that the 'dimm_fuel_gauge' field is valid */ +#define PDSM_DIMM_HEALTH_RUN_GAUGE_VALID 1 +/* * Struct exchanged between kernel & ndctl in for PAPR_PDSM_HEALTH * Various flags indicate the health status of the dimm.
@@ -84,6 +89,7 @@* dimm_locked : Contents of the dimm cant be modified until CEC reboot * dimm_encrypted : Contents of dimm are encrypted. * dimm_health : Dimm health indicator. One of PAPR_PDSM_DIMM_XXXX +* dimm_fuel_gauge : Life remaining of DIMM as a percentage from 0-100 */ struct nd_papr_pdsm_health { union {
@@ -96,6 +102,9 @@ struct nd_papr_pdsm_health {__u8 dimm_locked;__u8 dimm_encrypted;__u16 dimm_health; + +/* Extension flag PDSM_DIMM_HEALTH_RUN_GAUGE_VALID */ +__u16 dimm_fuel_gauge; };__u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE ]; };
arch/powerpc/platforms/pseries/papr_scm.c +49 -0
61 lines not on this page · raw message
Signature · 4 lines
2.26.2 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [PATCH v4 2/2] powerpc/papr_scm: Add support for fetching nvdimm 'fuel-gauge' metric
Quoted 11 lines · Vaibhav Jain
We add support for reporting 'fuel-gauge' NVDIMM metric via
PAPR_PDSM_HEALTHpdsm payload. 'fuel-gauge' metric indicates the usage life remaining of a papr-scm compatible NVDIMM. PHYP exposes this metric via theH_SCM_PERFORMANCE_STATS.The metric value is returned from the pdsm by extending the return payload 'struct
nd_papr_pdsm_health' without breaking the ABI. A new field 'dimm_fuel_gauge' to hold the metric value is introduced at the end of the payload struct and its presence is indicated by by extension flagPDSM_DIMM_HEALTH_RUN_GAUGE_VALID.
Quoted 10 lines
The patch introduces a new function
papr_pdsm_fuel_gauge()that is called frompapr_pdsm_health(). If fetching NVDIMM performance stats is supported then 'papr_pdsm_fuel_gauge()' allocated an output buffer large enough to hold the performance stat and passes it todrc_pmem_query_stats()that issues the HCALL to PHYP. The return value of the stat is then populated in the 'struct nd_papr_pdsm_health.dimm_fuel_gauge' field with extension flag 'PDSM_DIMM_HEALTH_RUN_GAUGE_VALID' set in 'struct nd_papr_pdsm_health.extension_flags'
Quoted 128 lines
Signed-off-by Vaibhav Jain <[email protected]>---
Changelog:v4:
* Moved a hunk from this patch to previous patch in the series. [ Aneesh ]v3:
* Updatedpapr_pdsm_fuel_guage()to use the updateddrc_pmem_query_stats()function.Resend:
Nonev2:
* Restructure code inpapr_pdsm_fuel_gauge()to handle error case first [ Ira ]
* Ignore the return value ofpapr_pdsm_fuel_gauge()inpapr_psdm_health()[ Ira ]--- arch/powerpc/include/uapi/asm/papr_pdsm.h | 9 +++++ arch/powerpc/platforms/pseries/papr_scm.c | 49 +++++++++++++++++++++++ 2 files changed, 58 insertions(+)arch/powerpc/include/uapi/asm/papr_pdsm.h +9
-0@@ -72,6 +72,11 @@#define PAPR_PDSM_DIMM_CRITICAL 2#define PAPR_PDSM_DIMM_FATAL 3 +/* struct nd_papr_pdsm_health.extension_flags field flags */ + +/* Indicate that the 'dimm_fuel_gauge' field is valid */ +#define PDSM_DIMM_HEALTH_RUN_GAUGE_VALID 1 +/* * Struct exchanged between kernel & ndctl in for PAPR_PDSM_HEALTH * Various flags indicate the health status of the dimm. @@ -84,6 +89,7 @@* dimm_locked : Contents of the dimm cant be modified until CEC reboot * dimm_encrypted : Contents of dimm are encrypted. * dimm_health : Dimm health indicator. One of PAPR_PDSM_DIMM_XXXX +* dimm_fuel_gauge : Life remaining of DIMM as a percentage from 0-100 */ struct nd_papr_pdsm_health { union {@@ -96,6 +102,9 @@ struct nd_papr_pdsm_health {__u8 dimm_locked;__u8 dimm_encrypted;__u16 dimm_health; + +/* Extension flag PDSM_DIMM_HEALTH_RUN_GAUGE_VALID */ +__u16 dimm_fuel_gauge; };__u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE ]; };arch/powerpc/platforms/pseries/papr_scm.c +49
-0@@ -518,6 +518,51 @@ static int is_cmd_valid(struct nvdimm *nvdimm, unsigned int cmd, void *buf,return 0 ; } +static int papr_pdsm_fuel_gauge (struct papr_scm_priv *p, +union nd_pdsm_payload *payload) +{ +int rc, size; +u64 statval; +struct papr_scm_perf_stat *stat; +struct papr_scm_perf_stats *stats; + +/* Silently fail if fetching performance metrics isn't supported */ +if (!p->stat_buffer_len) +return 0 ; + +/* Allocate request buffer enough to hold single performance stat */ + size =sizeof (struct papr_scm_perf_stats ) + +sizeof (struct papr_scm_perf_stat ); + + stats =kzalloc (size,GFP_KERNEL ); +if (!stats) +return -ENOMEM ; + + stat = &stats->scm_statistic[0 ]; +memcpy (&stat->stat_id,"MemLife " ,sizeof (stat->stat_id)); + stat->stat_val =0 ; + +/* Fetch the fuel gauge and populate it in payload */ + rc =drc_pmem_query_stats (p, stats,1 ); +if (rc <0 ) { +dev_dbg (&p->pdev->dev,"Err(%d) fetching fuel gauge\n" , rc); + goto free_stats; + } + + statval =be64_to_cpu (stat->stat_val); +dev_dbg (&p->pdev->dev, +"Fetched fuel-gauge %llu" , statval); + payload->health.extension_flags |= +PDSM_DIMM_HEALTH_RUN_GAUGE_VALID ; + payload->health.dimm_fuel_gauge = statval; + + rc =sizeof (struct nd_papr_pdsm_health ); + +free_stats: +kfree (stats); +return rc; +} +/* Fetch the DIMM health info and populate it in provided package. */ static int papr_pdsm_health (struct papr_scm_priv *p,union nd_pdsm_payload *payload)@@ -558,6 +603,10 @@ static int papr_pdsm_health(struct papr_scm_priv *p,/* struct populated hence can release the mutex now */ mutex_unlock (&p->health_mutex); + +/* Populate the fuel gauge meter in the payload */ +papr_pdsm_fuel_gauge (p, payload); + rc =sizeof (struct nd_papr_pdsm_health ); out:Signature · 1 line
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Michael Ellerman
AppliedQuoted 5 lines · Vaibhav Jain
Changes since v3[1]:
* Fixed a rebase issue pointed out by Aneesh in first patch in the series.
Applied to powerpc/next.
[1/2] powerpc/papr_scm: Fetch nvdimm performance stats from PHYP
https://git.kernel.org/powerpc/c/2d02bf835e5731de632c8a13567905fa7c0da01c [2/2] powerpc/papr_scm: Add support for fetching nvdimm 'fuel-gauge' metric https://git.kernel.org/powerpc/c/af0870c4e75655b1931d0a5ffde2f448a2794362
cheers
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]