Skip to content

Commit 117132e

Browse files
davejiangdjbw
authored andcommitted
cxl/test: Add support for qos_class checking
Set a fake qos_class to a unique value in order to do simple testing of qos_class for root decoders and mem devs via user cxl_test. A mock function is added to set the fake qos_class values for memory device and overrides cxl_endpoint_parse_cdat() in cxl driver code. Signed-off-by: Dave Jiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent cc21441 commit 117132e

File tree

4 files changed

+70
-9
lines changed

4 files changed

+70
-9
lines changed

tools/testing/cxl/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ldflags-y += --wrap=cxl_hdm_decode_init
1313
ldflags-y += --wrap=cxl_dvsec_rr_decode
1414
ldflags-y += --wrap=devm_cxl_add_rch_dport
1515
ldflags-y += --wrap=cxl_rcd_component_reg_phys
16+
ldflags-y += --wrap=cxl_endpoint_parse_cdat
1617

1718
DRIVERS := ../../../drivers
1819
CXL_SRC := $(DRIVERS)/cxl

tools/testing/cxl/test/cxl.c

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
static int interleave_arithmetic;
1717

18+
#define FAKE_QTG_ID 42
19+
1820
#define NR_CXL_HOST_BRIDGES 2
1921
#define NR_CXL_SINGLE_HOST 1
2022
#define NR_CXL_RCH 1
@@ -209,7 +211,7 @@ static struct {
209211
.granularity = 4,
210212
.restrictions = ACPI_CEDT_CFMWS_RESTRICT_TYPE3 |
211213
ACPI_CEDT_CFMWS_RESTRICT_VOLATILE,
212-
.qtg_id = 0,
214+
.qtg_id = FAKE_QTG_ID,
213215
.window_size = SZ_256M * 4UL,
214216
},
215217
.target = { 0 },
@@ -224,7 +226,7 @@ static struct {
224226
.granularity = 4,
225227
.restrictions = ACPI_CEDT_CFMWS_RESTRICT_TYPE3 |
226228
ACPI_CEDT_CFMWS_RESTRICT_VOLATILE,
227-
.qtg_id = 1,
229+
.qtg_id = FAKE_QTG_ID,
228230
.window_size = SZ_256M * 8UL,
229231
},
230232
.target = { 0, 1, },
@@ -239,7 +241,7 @@ static struct {
239241
.granularity = 4,
240242
.restrictions = ACPI_CEDT_CFMWS_RESTRICT_TYPE3 |
241243
ACPI_CEDT_CFMWS_RESTRICT_PMEM,
242-
.qtg_id = 2,
244+
.qtg_id = FAKE_QTG_ID,
243245
.window_size = SZ_256M * 4UL,
244246
},
245247
.target = { 0 },
@@ -254,7 +256,7 @@ static struct {
254256
.granularity = 4,
255257
.restrictions = ACPI_CEDT_CFMWS_RESTRICT_TYPE3 |
256258
ACPI_CEDT_CFMWS_RESTRICT_PMEM,
257-
.qtg_id = 3,
259+
.qtg_id = FAKE_QTG_ID,
258260
.window_size = SZ_256M * 8UL,
259261
},
260262
.target = { 0, 1, },
@@ -269,7 +271,7 @@ static struct {
269271
.granularity = 4,
270272
.restrictions = ACPI_CEDT_CFMWS_RESTRICT_TYPE3 |
271273
ACPI_CEDT_CFMWS_RESTRICT_PMEM,
272-
.qtg_id = 4,
274+
.qtg_id = FAKE_QTG_ID,
273275
.window_size = SZ_256M * 4UL,
274276
},
275277
.target = { 2 },
@@ -284,7 +286,7 @@ static struct {
284286
.granularity = 4,
285287
.restrictions = ACPI_CEDT_CFMWS_RESTRICT_TYPE3 |
286288
ACPI_CEDT_CFMWS_RESTRICT_VOLATILE,
287-
.qtg_id = 5,
289+
.qtg_id = FAKE_QTG_ID,
288290
.window_size = SZ_256M,
289291
},
290292
.target = { 3 },
@@ -301,7 +303,7 @@ static struct {
301303
.granularity = 4,
302304
.restrictions = ACPI_CEDT_CFMWS_RESTRICT_TYPE3 |
303305
ACPI_CEDT_CFMWS_RESTRICT_PMEM,
304-
.qtg_id = 0,
306+
.qtg_id = FAKE_QTG_ID,
305307
.window_size = SZ_256M * 8UL,
306308
},
307309
.target = { 0, },
@@ -317,7 +319,7 @@ static struct {
317319
.granularity = 0,
318320
.restrictions = ACPI_CEDT_CFMWS_RESTRICT_TYPE3 |
319321
ACPI_CEDT_CFMWS_RESTRICT_PMEM,
320-
.qtg_id = 1,
322+
.qtg_id = FAKE_QTG_ID,
321323
.window_size = SZ_256M * 8UL,
322324
},
323325
.target = { 0, 1, },
@@ -333,7 +335,7 @@ static struct {
333335
.granularity = 0,
334336
.restrictions = ACPI_CEDT_CFMWS_RESTRICT_TYPE3 |
335337
ACPI_CEDT_CFMWS_RESTRICT_PMEM,
336-
.qtg_id = 0,
338+
.qtg_id = FAKE_QTG_ID,
337339
.window_size = SZ_256M * 16UL,
338340
},
339341
.target = { 0, 1, 0, 1, },
@@ -976,6 +978,48 @@ static int mock_cxl_port_enumerate_dports(struct cxl_port *port)
976978
return 0;
977979
}
978980

981+
/*
982+
* Faking the cxl_dpa_perf for the memdev when appropriate.
983+
*/
984+
static void dpa_perf_setup(struct cxl_port *endpoint, struct range *range,
985+
struct cxl_dpa_perf *dpa_perf)
986+
{
987+
dpa_perf->qos_class = FAKE_QTG_ID;
988+
dpa_perf->dpa_range = *range;
989+
dpa_perf->coord.read_latency = 500;
990+
dpa_perf->coord.write_latency = 500;
991+
dpa_perf->coord.read_bandwidth = 1000;
992+
dpa_perf->coord.write_bandwidth = 1000;
993+
}
994+
995+
static void mock_cxl_endpoint_parse_cdat(struct cxl_port *port)
996+
{
997+
struct cxl_root *cxl_root __free(put_cxl_root) =
998+
find_cxl_root(port);
999+
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport_dev);
1000+
struct cxl_dev_state *cxlds = cxlmd->cxlds;
1001+
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
1002+
struct range pmem_range = {
1003+
.start = cxlds->pmem_res.start,
1004+
.end = cxlds->pmem_res.end,
1005+
};
1006+
struct range ram_range = {
1007+
.start = cxlds->ram_res.start,
1008+
.end = cxlds->ram_res.end,
1009+
};
1010+
1011+
if (!cxl_root)
1012+
return;
1013+
1014+
if (range_len(&ram_range))
1015+
dpa_perf_setup(port, &ram_range, &mds->ram_perf);
1016+
1017+
if (range_len(&pmem_range))
1018+
dpa_perf_setup(port, &pmem_range, &mds->pmem_perf);
1019+
1020+
cxl_memdev_update_perf(cxlmd);
1021+
}
1022+
9791023
static struct cxl_mock_ops cxl_mock_ops = {
9801024
.is_mock_adev = is_mock_adev,
9811025
.is_mock_bridge = is_mock_bridge,
@@ -989,6 +1033,7 @@ static struct cxl_mock_ops cxl_mock_ops = {
9891033
.devm_cxl_setup_hdm = mock_cxl_setup_hdm,
9901034
.devm_cxl_add_passthrough_decoder = mock_cxl_add_passthrough_decoder,
9911035
.devm_cxl_enumerate_decoders = mock_cxl_enumerate_decoders,
1036+
.cxl_endpoint_parse_cdat = mock_cxl_endpoint_parse_cdat,
9921037
.list = LIST_HEAD_INIT(cxl_mock_ops.list),
9931038
};
9941039

tools/testing/cxl/test/mock.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,20 @@ resource_size_t __wrap_cxl_rcd_component_reg_phys(struct device *dev,
285285
}
286286
EXPORT_SYMBOL_NS_GPL(__wrap_cxl_rcd_component_reg_phys, CXL);
287287

288+
void __wrap_cxl_endpoint_parse_cdat(struct cxl_port *port)
289+
{
290+
int index;
291+
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
292+
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport_dev);
293+
294+
if (ops && ops->is_mock_dev(cxlmd->dev.parent))
295+
ops->cxl_endpoint_parse_cdat(port);
296+
else
297+
cxl_endpoint_parse_cdat(port);
298+
put_cxl_mock_ops(index);
299+
}
300+
EXPORT_SYMBOL_NS_GPL(__wrap_cxl_endpoint_parse_cdat, CXL);
301+
288302
MODULE_LICENSE("GPL v2");
289303
MODULE_IMPORT_NS(ACPI);
290304
MODULE_IMPORT_NS(CXL);

tools/testing/cxl/test/mock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct cxl_mock_ops {
2525
int (*devm_cxl_add_passthrough_decoder)(struct cxl_port *port);
2626
int (*devm_cxl_enumerate_decoders)(
2727
struct cxl_hdm *hdm, struct cxl_endpoint_dvsec_info *info);
28+
void (*cxl_endpoint_parse_cdat)(struct cxl_port *port);
2829
};
2930

3031
void register_cxl_mock_ops(struct cxl_mock_ops *ops);

0 commit comments

Comments
 (0)