Skip to content

Commit c20eaf4

Browse files
davejiangdjbw
authored andcommitted
cxl/region: Add sysfs attribute for locality attributes of CXL regions
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. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/20240308220055.2172956-11-dave.jiang@intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 3d9f4a1 commit c20eaf4

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

Documentation/ABI/testing/sysfs-bus-cxl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,3 +552,37 @@ Description:
552552
attribute is only visible for devices supporting the
553553
capability. The retrieved errors are logged as kernel
554554
events when cxl_poison event tracing is enabled.
555+
556+
557+
What: /sys/bus/cxl/devices/regionZ/accessY/read_bandwidth
558+
/sys/bus/cxl/devices/regionZ/accessY/write_banwidth
559+
Date: Jan, 2024
560+
KernelVersion: v6.9
561+
Contact: linux-cxl@vger.kernel.org
562+
Description:
563+
(RO) The aggregated read or write bandwidth of the region. The
564+
number is the accumulated read or write bandwidth of all CXL memory
565+
devices that contributes to the region in MB/s. It is
566+
identical data that should appear in
567+
/sys/devices/system/node/nodeX/accessY/initiators/read_bandwidth or
568+
/sys/devices/system/node/nodeX/accessY/initiators/write_bandwidth.
569+
See Documentation/ABI/stable/sysfs-devices-node. access0 provides
570+
the number to the closest initiator and access1 provides the
571+
number to the closest CPU.
572+
573+
574+
What: /sys/bus/cxl/devices/regionZ/accessY/read_latency
575+
/sys/bus/cxl/devices/regionZ/accessY/write_latency
576+
Date: Jan, 2024
577+
KernelVersion: v6.9
578+
Contact: linux-cxl@vger.kernel.org
579+
Description:
580+
(RO) The read or write latency of the region. The number is
581+
the worst read or write latency of all CXL memory devices that
582+
contributes to the region in nanoseconds. It is identical data
583+
that should appear in
584+
/sys/devices/system/node/nodeX/accessY/initiators/read_latency or
585+
/sys/devices/system/node/nodeX/accessY/initiators/write_latency.
586+
See Documentation/ABI/stable/sysfs-devices-node. access0 provides
587+
the number to the closest initiator and access1 provides the
588+
number to the closest CPU.

drivers/cxl/core/region.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,98 @@
3030

3131
static struct cxl_region *to_cxl_region(struct device *dev);
3232

33+
#define __ACCESS_ATTR_RO(_level, _name) { \
34+
.attr = { .name = __stringify(_name), .mode = 0444 }, \
35+
.show = _name##_access##_level##_show, \
36+
}
37+
38+
#define ACCESS_DEVICE_ATTR_RO(level, name) \
39+
struct device_attribute dev_attr_access##level##_##name = __ACCESS_ATTR_RO(level, name)
40+
41+
#define ACCESS_ATTR_RO(level, attrib) \
42+
static ssize_t attrib##_access##level##_show(struct device *dev, \
43+
struct device_attribute *attr, \
44+
char *buf) \
45+
{ \
46+
struct cxl_region *cxlr = to_cxl_region(dev); \
47+
\
48+
if (cxlr->coord[level].attrib == 0) \
49+
return -ENOENT; \
50+
\
51+
return sysfs_emit(buf, "%u\n", cxlr->coord[level].attrib); \
52+
} \
53+
static ACCESS_DEVICE_ATTR_RO(level, attrib)
54+
55+
ACCESS_ATTR_RO(0, read_bandwidth);
56+
ACCESS_ATTR_RO(0, read_latency);
57+
ACCESS_ATTR_RO(0, write_bandwidth);
58+
ACCESS_ATTR_RO(0, write_latency);
59+
60+
#define ACCESS_ATTR_DECLARE(level, attrib) \
61+
(&dev_attr_access##level##_##attrib.attr)
62+
63+
static struct attribute *access0_coordinate_attrs[] = {
64+
ACCESS_ATTR_DECLARE(0, read_bandwidth),
65+
ACCESS_ATTR_DECLARE(0, write_bandwidth),
66+
ACCESS_ATTR_DECLARE(0, read_latency),
67+
ACCESS_ATTR_DECLARE(0, write_latency),
68+
NULL
69+
};
70+
71+
ACCESS_ATTR_RO(1, read_bandwidth);
72+
ACCESS_ATTR_RO(1, read_latency);
73+
ACCESS_ATTR_RO(1, write_bandwidth);
74+
ACCESS_ATTR_RO(1, write_latency);
75+
76+
static struct attribute *access1_coordinate_attrs[] = {
77+
ACCESS_ATTR_DECLARE(1, read_bandwidth),
78+
ACCESS_ATTR_DECLARE(1, write_bandwidth),
79+
ACCESS_ATTR_DECLARE(1, read_latency),
80+
ACCESS_ATTR_DECLARE(1, write_latency),
81+
NULL
82+
};
83+
84+
#define ACCESS_VISIBLE(level) \
85+
static umode_t cxl_region_access##level##_coordinate_visible( \
86+
struct kobject *kobj, struct attribute *a, int n) \
87+
{ \
88+
struct device *dev = kobj_to_dev(kobj); \
89+
struct cxl_region *cxlr = to_cxl_region(dev); \
90+
\
91+
if (a == &dev_attr_access##level##_read_latency.attr && \
92+
cxlr->coord[level].read_latency == 0) \
93+
return 0; \
94+
\
95+
if (a == &dev_attr_access##level##_write_latency.attr && \
96+
cxlr->coord[level].write_latency == 0) \
97+
return 0; \
98+
\
99+
if (a == &dev_attr_access##level##_read_bandwidth.attr && \
100+
cxlr->coord[level].read_bandwidth == 0) \
101+
return 0; \
102+
\
103+
if (a == &dev_attr_access##level##_write_bandwidth.attr && \
104+
cxlr->coord[level].write_bandwidth == 0) \
105+
return 0; \
106+
\
107+
return a->mode; \
108+
}
109+
110+
ACCESS_VISIBLE(0);
111+
ACCESS_VISIBLE(1);
112+
113+
static const struct attribute_group cxl_region_access0_coordinate_group = {
114+
.name = "access0",
115+
.attrs = access0_coordinate_attrs,
116+
.is_visible = cxl_region_access0_coordinate_visible,
117+
};
118+
119+
static const struct attribute_group cxl_region_access1_coordinate_group = {
120+
.name = "access1",
121+
.attrs = access1_coordinate_attrs,
122+
.is_visible = cxl_region_access1_coordinate_visible,
123+
};
124+
33125
static ssize_t uuid_show(struct device *dev, struct device_attribute *attr,
34126
char *buf)
35127
{
@@ -2069,6 +2161,8 @@ static const struct attribute_group *region_groups[] = {
20692161
&cxl_base_attribute_group,
20702162
&cxl_region_group,
20712163
&cxl_region_target_group,
2164+
&cxl_region_access0_coordinate_group,
2165+
&cxl_region_access1_coordinate_group,
20722166
NULL,
20732167
};
20742168

0 commit comments

Comments
 (0)