|
9 | 9 | #include <linux/uuid.h>
|
10 | 10 | #include <linux/sort.h>
|
11 | 11 | #include <linux/idr.h>
|
| 12 | +#include <linux/memory-tiers.h> |
12 | 13 | #include <cxlmem.h>
|
13 | 14 | #include <cxl.h>
|
14 | 15 | #include "core.h"
|
@@ -2228,6 +2229,7 @@ static void unregister_region(void *_cxlr)
|
2228 | 2229 | int i;
|
2229 | 2230 |
|
2230 | 2231 | unregister_memory_notifier(&cxlr->memory_notifier);
|
| 2232 | + unregister_mt_adistance_algorithm(&cxlr->adist_notifier); |
2231 | 2233 | device_del(&cxlr->dev);
|
2232 | 2234 |
|
2233 | 2235 | /*
|
@@ -2340,6 +2342,27 @@ static int cxl_region_perf_attrs_callback(struct notifier_block *nb,
|
2340 | 2342 | return NOTIFY_OK;
|
2341 | 2343 | }
|
2342 | 2344 |
|
| 2345 | +static int cxl_region_calculate_adistance(struct notifier_block *nb, |
| 2346 | + unsigned long nid, void *data) |
| 2347 | +{ |
| 2348 | + struct cxl_region *cxlr = container_of(nb, struct cxl_region, |
| 2349 | + adist_notifier); |
| 2350 | + struct access_coordinate *perf; |
| 2351 | + int *adist = data; |
| 2352 | + int region_nid; |
| 2353 | + |
| 2354 | + region_nid = cxl_region_nid(cxlr); |
| 2355 | + if (nid != region_nid) |
| 2356 | + return NOTIFY_OK; |
| 2357 | + |
| 2358 | + perf = &cxlr->coord[ACCESS_COORDINATE_CPU]; |
| 2359 | + |
| 2360 | + if (mt_perf_to_adistance(perf, adist)) |
| 2361 | + return NOTIFY_OK; |
| 2362 | + |
| 2363 | + return NOTIFY_STOP; |
| 2364 | +} |
| 2365 | + |
2343 | 2366 | /**
|
2344 | 2367 | * devm_cxl_add_region - Adds a region to a decoder
|
2345 | 2368 | * @cxlrd: root decoder
|
@@ -2382,6 +2405,10 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,
|
2382 | 2405 | cxlr->memory_notifier.priority = CXL_CALLBACK_PRI;
|
2383 | 2406 | register_memory_notifier(&cxlr->memory_notifier);
|
2384 | 2407 |
|
| 2408 | + cxlr->adist_notifier.notifier_call = cxl_region_calculate_adistance; |
| 2409 | + cxlr->adist_notifier.priority = 100; |
| 2410 | + register_mt_adistance_algorithm(&cxlr->adist_notifier); |
| 2411 | + |
2385 | 2412 | rc = devm_add_action_or_reset(port->uport_dev, unregister_region, cxlr);
|
2386 | 2413 | if (rc)
|
2387 | 2414 | return ERR_PTR(rc);
|
|
0 commit comments