Skip to content

Commit 7a4f148

Browse files
davejiangdjbw
authored andcommitted
cxl: Compute the entire CXL path latency and bandwidth data
CXL Memory Device SW Guide [1] rev1.0 2.11.2 provides instruction on how to calculate latency and bandwidth for CXL memory device. Calculate minimum bandwidth and total latency for the path from the CXL device to the root port. The QTG id is retrieved by providing the performance data as input and calling the root port callback ->get_qos_class(). The retrieved id is stored with the cxl_port of the CXL device. For example for a device that is directly attached to a host bus: Total Latency = Device Latency (from CDAT) + Dev to Host Bus (HB) Link Latency + Generic Port Latency Min Bandwidth = Min bandwidth for link bandwidth between HB and CXL device, device CDAT bandwidth, and Generic Port Bandwidth For a device that has a switch in between host bus and CXL device: Total Latency = Device (CDAT) Latency + Dev to Switch Link Latency + Switch (CDAT) Latency + Switch to HB Link Latency + Generic Port Latency Min Bandwidth = Min bandwidth for link bandwidth between CXL device to CXL switch, CXL device CDAT bandwidth, CXL switch CDAT bandwidth, CXL switch to HB bandwidth, and Generic Port Bandwidth. [1]: https://cdrdv2-public.intel.com/643805/643805_CXL%20Memory%20Device%20SW%20Guide_Rev1p0.pdf Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/170319624458.2212653.13252496567443656371.stgit@djiang5-mobl3 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 14a6960 commit 7a4f148

1 file changed

Lines changed: 58 additions & 1 deletion

File tree

drivers/cxl/core/cdat.c

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ struct dsmas_entry {
1212
struct range dpa_range;
1313
u8 handle;
1414
struct access_coordinate coord;
15+
16+
int entries;
17+
int qos_class;
1518
};
1619

1720
static int cdat_dsmas_handler(union acpi_subtable_headers *header, void *arg,
@@ -154,6 +157,55 @@ static int cxl_cdat_endpoint_process(struct cxl_port *port,
154157
return cdat_table_parse_output(rc);
155158
}
156159

160+
static int cxl_port_perf_data_calculate(struct cxl_port *port,
161+
struct xarray *dsmas_xa)
162+
{
163+
struct access_coordinate c;
164+
struct cxl_port *root_port;
165+
struct cxl_root *cxl_root;
166+
struct dsmas_entry *dent;
167+
int valid_entries = 0;
168+
unsigned long index;
169+
int rc;
170+
171+
rc = cxl_endpoint_get_perf_coordinates(port, &c);
172+
if (rc) {
173+
dev_dbg(&port->dev, "Failed to retrieve perf coordinates.\n");
174+
return rc;
175+
}
176+
177+
root_port = find_cxl_root(port);
178+
cxl_root = to_cxl_root(root_port);
179+
if (!cxl_root->ops || !cxl_root->ops->qos_class)
180+
return -EOPNOTSUPP;
181+
182+
xa_for_each(dsmas_xa, index, dent) {
183+
int qos_class;
184+
185+
dent->coord.read_latency = dent->coord.read_latency +
186+
c.read_latency;
187+
dent->coord.write_latency = dent->coord.write_latency +
188+
c.write_latency;
189+
dent->coord.read_bandwidth = min_t(int, c.read_bandwidth,
190+
dent->coord.read_bandwidth);
191+
dent->coord.write_bandwidth = min_t(int, c.write_bandwidth,
192+
dent->coord.write_bandwidth);
193+
194+
dent->entries = 1;
195+
rc = cxl_root->ops->qos_class(root_port, &dent->coord, 1, &qos_class);
196+
if (rc != 1)
197+
continue;
198+
199+
valid_entries++;
200+
dent->qos_class = qos_class;
201+
}
202+
203+
if (!valid_entries)
204+
return -ENOENT;
205+
206+
return 0;
207+
}
208+
157209
static void discard_dsmas(struct xarray *xa)
158210
{
159211
unsigned long index;
@@ -183,7 +235,12 @@ void cxl_endpoint_parse_cdat(struct cxl_port *port)
183235
return;
184236
}
185237

186-
/* Performance data processing */
238+
rc = cxl_port_perf_data_calculate(port, dsmas_xa);
239+
if (rc) {
240+
dev_dbg(&port->dev, "Failed to do perf coord calculations.\n");
241+
return;
242+
}
243+
187244
}
188245
EXPORT_SYMBOL_NS_GPL(cxl_endpoint_parse_cdat, CXL);
189246

0 commit comments

Comments
 (0)