Skip to content

Commit 032f7b3

Browse files
davejiangdjbw
authored andcommitted
cxl: Split out combine_coordinates() for common shared usage
Refactor the common code of combining coordinates in order to reduce code. Create a new function cxl_cooordinates_combine() it combine two 'struct access_coordinate'. 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-6-dave.jiang@intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent bd98cbb commit 032f7b3

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

drivers/cxl/core/cdat.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,7 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
185185
xa_for_each(dsmas_xa, index, dent) {
186186
int qos_class;
187187

188-
dent->coord.read_latency = dent->coord.read_latency +
189-
c.read_latency;
190-
dent->coord.write_latency = dent->coord.write_latency +
191-
c.write_latency;
192-
dent->coord.read_bandwidth = min_t(int, c.read_bandwidth,
193-
dent->coord.read_bandwidth);
194-
dent->coord.write_bandwidth = min_t(int, c.write_bandwidth,
195-
dent->coord.write_bandwidth);
196-
188+
cxl_coordinates_combine(&dent->coord, &dent->coord, &c);
197189
dent->entries = 1;
198190
rc = cxl_root->ops->qos_class(cxl_root, &dent->coord, 1,
199191
&qos_class);
@@ -484,4 +476,26 @@ void cxl_switch_parse_cdat(struct cxl_port *port)
484476
}
485477
EXPORT_SYMBOL_NS_GPL(cxl_switch_parse_cdat, CXL);
486478

479+
/**
480+
* cxl_coordinates_combine - Combine the two input coordinates
481+
*
482+
* @out: Output coordinate of c1 and c2 combined
483+
* @c1: input coordinates
484+
* @c2: input coordinates
485+
*/
486+
void cxl_coordinates_combine(struct access_coordinate *out,
487+
struct access_coordinate *c1,
488+
struct access_coordinate *c2)
489+
{
490+
if (c1->write_bandwidth && c2->write_bandwidth)
491+
out->write_bandwidth = min(c1->write_bandwidth,
492+
c2->write_bandwidth);
493+
out->write_latency = c1->write_latency + c2->write_latency;
494+
495+
if (c1->read_bandwidth && c2->read_bandwidth)
496+
out->read_bandwidth = min(c1->read_bandwidth,
497+
c2->read_bandwidth);
498+
out->read_latency = c1->read_latency + c2->read_latency;
499+
}
500+
487501
MODULE_IMPORT_NS(CXL);

drivers/cxl/core/port.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,20 +2096,6 @@ bool schedule_cxl_memdev_detach(struct cxl_memdev *cxlmd)
20962096
}
20972097
EXPORT_SYMBOL_NS_GPL(schedule_cxl_memdev_detach, CXL);
20982098

2099-
static void combine_coordinates(struct access_coordinate *c1,
2100-
struct access_coordinate *c2)
2101-
{
2102-
if (c2->write_bandwidth)
2103-
c1->write_bandwidth = min(c1->write_bandwidth,
2104-
c2->write_bandwidth);
2105-
c1->write_latency += c2->write_latency;
2106-
2107-
if (c2->read_bandwidth)
2108-
c1->read_bandwidth = min(c1->read_bandwidth,
2109-
c2->read_bandwidth);
2110-
c1->read_latency += c2->read_latency;
2111-
}
2112-
21132099
/**
21142100
* cxl_endpoint_get_perf_coordinates - Retrieve performance numbers stored in dports
21152101
* of CXL path
@@ -2143,7 +2129,7 @@ int cxl_endpoint_get_perf_coordinates(struct cxl_port *port,
21432129
* nothing to gather.
21442130
*/
21452131
while (iter && !is_cxl_root(to_cxl_port(iter->dev.parent))) {
2146-
combine_coordinates(&c, &dport->sw_coord);
2132+
cxl_coordinates_combine(&c, &c, &dport->sw_coord);
21472133
c.write_latency += dport->link_latency;
21482134
c.read_latency += dport->link_latency;
21492135

@@ -2152,7 +2138,7 @@ int cxl_endpoint_get_perf_coordinates(struct cxl_port *port,
21522138
}
21532139

21542140
/* Augment with the generic port (host bridge) perf data */
2155-
combine_coordinates(&c, &dport->hb_coord[ACCESS_COORDINATE_LOCAL]);
2141+
cxl_coordinates_combine(&c, &c, &dport->hb_coord[ACCESS_COORDINATE_LOCAL]);
21562142

21572143
/* Get the calculated PCI paths bandwidth */
21582144
pdev = to_pci_dev(port->uport_dev->parent);

drivers/cxl/cxl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,10 @@ int cxl_endpoint_get_perf_coordinates(struct cxl_port *port,
882882

883883
void cxl_memdev_update_perf(struct cxl_memdev *cxlmd);
884884

885+
void cxl_coordinates_combine(struct access_coordinate *out,
886+
struct access_coordinate *c1,
887+
struct access_coordinate *c2);
888+
885889
/*
886890
* Unit test builds overrides this to __weak, find the 'strong' version
887891
* of these symbols in tools/testing/cxl/.

0 commit comments

Comments
 (0)