diff mbox series

[v2,2/3] cxl/region: Add sysfs attribute for locality attributes of CXL regions

Message ID 170268216573.1381493.1848451783927736490.stgit@djiang5-mobl3
State Superseded
Headers show
Series cxl: Add support to report region access coordinates to numa nodes | expand

Commit Message

Dave Jiang Dec. 15, 2023, 11:16 p.m. UTC
Add read/write latencies and bandwidth sysfs attributes for the enabled CXL
region. The bandwidth is the aggregated bandwidth of all devices that
contribute to the CXL region. The latency is the worst latency of the
device amongst all the devices that contribute to the CXL region.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
v2:
- Add units for documentation (Brice, Dan)
- Add explanation initiator/target relation. (Brice)
- Fix issue in commit log (Fan)
---
 Documentation/ABI/testing/sysfs-bus-cxl |   56 +++++++++++++++++++++++++++++++
 drivers/cxl/core/region.c               |   24 +++++++++++++
 2 files changed, 80 insertions(+)

Comments

Jonathan Cameron Dec. 19, 2023, 2:58 p.m. UTC | #1
On Fri, 15 Dec 2023 16:16:05 -0700
Dave Jiang <dave.jiang@intel.com> wrote:

> Add read/write latencies and bandwidth sysfs attributes for the enabled CXL
> region. The bandwidth is the aggregated bandwidth of all devices that
> contribute to the CXL region. The latency is the worst latency of the
> device amongst all the devices that contribute to the CXL region.
> 
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
A few comments inline.

Jonathan

> ---
> v2:
> - Add units for documentation (Brice, Dan)
> - Add explanation initiator/target relation. (Brice)
> - Fix issue in commit log (Fan)
> ---
>  Documentation/ABI/testing/sysfs-bus-cxl |   56 +++++++++++++++++++++++++++++++
>  drivers/cxl/core/region.c               |   24 +++++++++++++
>  2 files changed, 80 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl
> index fff2581b8033..e859f466a6b5 100644
> --- a/Documentation/ABI/testing/sysfs-bus-cxl
> +++ b/Documentation/ABI/testing/sysfs-bus-cxl
> @@ -552,3 +552,59 @@ Description:
>  		attribute is only visible for devices supporting the
>  		capability. The retrieved errors are logged as kernel
>  		events when cxl_poison event tracing is enabled.
> +
> +
> +What:		/sys/bus/cxl/devices/regionZ/read_bandwidth
> +Date:		Apr, 2023
> +KernelVersion:	v6.8
> +Contact:	linux-cxl@vger.kernel.org
> +Description:
> +		(RO) The aggregated read bandwidth of the region. The number is
> +		the accumulated read bandwidth of all CXL memory devices that
> +		contributes to the region in MB/s. Should be equivalent to
> +		attributes in /sys/devices/system/node/nodeX/accessY/. See
> +		Documentation/ABI/stable/sysfs-devices-node.
> +		The host bus latency in the calculation is from proximity
> +		domain 0 to the host bus proximity domain.

If it's equivalent to /sys/devices/system/node/nodeX/accessY then it isn't
the domain 0 value it's the domain Y one. (IIRC how that works!)

> +
> +
> +What:		/sys/bus/cxl/devices/regionZ/write_bandwidth
> +Date:		Apr, 2023
> +KernelVersion:	v6.8
> +Contact:	linux-cxl@vger.kernel.org
> +Description:
> +		(RO) The aggregated write bandwidth of the region. The number is
> +		the accumulated write bandwidth of all CXL memory devices that
> +		contributes to the region in MB/s. Should be equivalent to
> +		attributes in /sys/devices/system/node/nodeX/accessY/. See
> +		Documentation/ABI/stable/sysfs-devices-node.
> +		The host bus latency in the calculation is from proximity
> +		domain 0 to the host bus proximity domain.
> +
> +
> +What:		/sys/bus/cxl/devices/regionZ/read_latency
> +Date:		Apr, 2023
> +KernelVersion:	v6.8
> +Contact:	linux-cxl@vger.kernel.org
> +Description:
> +		(RO) The read latency of the region. The number is
> +		the worst read latency of all CXL memory devices that
> +		contributes to the region in nanoseconds. Should be
> +		equivalent to attributes in /sys/devices/system/node/nodeX/accessY/.
> +		See Documentation/ABI/stable/sysfs-devices-node.
> +		The host bus latency in the calculation is from proximity
> +		domain 0 to the host bus proximity domain.
> +
> +
> +What:		/sys/bus/cxl/devices/regionZ/write_latency
> +Date:		Apr, 2023
> +KernelVersion:	v6.8
> +Contact:	linux-cxl@vger.kernel.org
> +Description:
> +		(RO) The write latency of the region. The number is
> +		the worst write latency of all CXL memory devices that
> +		contributes to the region in nanoseconds. Should be
> +		equivalent to attributes in /sys/devices/system/node/nodeX/accessY/.
> +		See Documentation/ABI/stable/sysfs-devices-node.
> +		The host bus latency in the calculation is from proximity
> +		domain 0 to the host bus proximity domain.
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index be7383e74ef5..d97fa5f32e86 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -645,6 +645,26 @@ static ssize_t size_show(struct device *dev, struct device_attribute *attr,
>  }
>  static DEVICE_ATTR_RW(size);
>  
> +#define ACCESS_ATTR(attrib)					\
> +static ssize_t attrib##_show(struct device *dev,		\
> +			   struct device_attribute *attr,	\
> +			   char *buf)				\
> +{								\
> +	struct cxl_region *cxlr = to_cxl_region(dev);		\
> +								\
> +	if (cxlr->coord.write_bandwidth == 0)			\

Fun questions for long run.  Does a RO DC region ever supply a write bandwidth?
Also, I'd prefer returning an error to say it's not provided than
returning that it is, but the length of the string is 0.
coord.attrib seems better in general.

I'd prefer to hide these attributes entirely if the value isn't available.
Is that tricky to do for some reason?  There is already a cxl_region_visible()
callback.

> +		return 0;					\
> +								\
> +	return sysfs_emit(buf, "%u\n",				\
> +			  cxlr->coord.attrib);			\

Oddly short line wrap.

> +}								\
> +static DEVICE_ATTR_RO(attrib)
> +
> +ACCESS_ATTR(read_bandwidth);
> +ACCESS_ATTR(read_latency);
> +ACCESS_ATTR(write_bandwidth);
> +ACCESS_ATTR(write_latency);
> +
>  static struct attribute *cxl_region_attrs[] = {
>  	&dev_attr_uuid.attr,
>  	&dev_attr_commit.attr,
> @@ -653,6 +673,10 @@ static struct attribute *cxl_region_attrs[] = {
>  	&dev_attr_resource.attr,
>  	&dev_attr_size.attr,
>  	&dev_attr_mode.attr,
> +	&dev_attr_read_bandwidth.attr,
> +	&dev_attr_write_bandwidth.attr,
> +	&dev_attr_read_latency.attr,
> +	&dev_attr_write_latency.attr,
>  	NULL,
>  };
>  
> 
>
diff mbox series

Patch

diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl
index fff2581b8033..e859f466a6b5 100644
--- a/Documentation/ABI/testing/sysfs-bus-cxl
+++ b/Documentation/ABI/testing/sysfs-bus-cxl
@@ -552,3 +552,59 @@  Description:
 		attribute is only visible for devices supporting the
 		capability. The retrieved errors are logged as kernel
 		events when cxl_poison event tracing is enabled.
+
+
+What:		/sys/bus/cxl/devices/regionZ/read_bandwidth
+Date:		Apr, 2023
+KernelVersion:	v6.8
+Contact:	linux-cxl@vger.kernel.org
+Description:
+		(RO) The aggregated read bandwidth of the region. The number is
+		the accumulated read bandwidth of all CXL memory devices that
+		contributes to the region in MB/s. Should be equivalent to
+		attributes in /sys/devices/system/node/nodeX/accessY/. See
+		Documentation/ABI/stable/sysfs-devices-node.
+		The host bus latency in the calculation is from proximity
+		domain 0 to the host bus proximity domain.
+
+
+What:		/sys/bus/cxl/devices/regionZ/write_bandwidth
+Date:		Apr, 2023
+KernelVersion:	v6.8
+Contact:	linux-cxl@vger.kernel.org
+Description:
+		(RO) The aggregated write bandwidth of the region. The number is
+		the accumulated write bandwidth of all CXL memory devices that
+		contributes to the region in MB/s. Should be equivalent to
+		attributes in /sys/devices/system/node/nodeX/accessY/. See
+		Documentation/ABI/stable/sysfs-devices-node.
+		The host bus latency in the calculation is from proximity
+		domain 0 to the host bus proximity domain.
+
+
+What:		/sys/bus/cxl/devices/regionZ/read_latency
+Date:		Apr, 2023
+KernelVersion:	v6.8
+Contact:	linux-cxl@vger.kernel.org
+Description:
+		(RO) The read latency of the region. The number is
+		the worst read latency of all CXL memory devices that
+		contributes to the region in nanoseconds. Should be
+		equivalent to attributes in /sys/devices/system/node/nodeX/accessY/.
+		See Documentation/ABI/stable/sysfs-devices-node.
+		The host bus latency in the calculation is from proximity
+		domain 0 to the host bus proximity domain.
+
+
+What:		/sys/bus/cxl/devices/regionZ/write_latency
+Date:		Apr, 2023
+KernelVersion:	v6.8
+Contact:	linux-cxl@vger.kernel.org
+Description:
+		(RO) The write latency of the region. The number is
+		the worst write latency of all CXL memory devices that
+		contributes to the region in nanoseconds. Should be
+		equivalent to attributes in /sys/devices/system/node/nodeX/accessY/.
+		See Documentation/ABI/stable/sysfs-devices-node.
+		The host bus latency in the calculation is from proximity
+		domain 0 to the host bus proximity domain.
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index be7383e74ef5..d97fa5f32e86 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -645,6 +645,26 @@  static ssize_t size_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RW(size);
 
+#define ACCESS_ATTR(attrib)					\
+static ssize_t attrib##_show(struct device *dev,		\
+			   struct device_attribute *attr,	\
+			   char *buf)				\
+{								\
+	struct cxl_region *cxlr = to_cxl_region(dev);		\
+								\
+	if (cxlr->coord.write_bandwidth == 0)			\
+		return 0;					\
+								\
+	return sysfs_emit(buf, "%u\n",				\
+			  cxlr->coord.attrib);			\
+}								\
+static DEVICE_ATTR_RO(attrib)
+
+ACCESS_ATTR(read_bandwidth);
+ACCESS_ATTR(read_latency);
+ACCESS_ATTR(write_bandwidth);
+ACCESS_ATTR(write_latency);
+
 static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_uuid.attr,
 	&dev_attr_commit.attr,
@@ -653,6 +673,10 @@  static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_resource.attr,
 	&dev_attr_size.attr,
 	&dev_attr_mode.attr,
+	&dev_attr_read_bandwidth.attr,
+	&dev_attr_write_bandwidth.attr,
+	&dev_attr_read_latency.attr,
+	&dev_attr_write_latency.attr,
 	NULL,
 };