Skip to content

Commit 643e8e3

Browse files
yhuang-inteldavejiang
authored andcommitted
cxl/region: Support to calculate memory tier abstract distance
An abstract distance value must be assigned by the driver that makes the memory available to the system. It reflects relative performance and is used to place memory nodes backed by CXL regions in the appropriate memory tiers allowing promotion/demotion within the existing memory tiering mechanism. The abstract distance is calculated based on the memory access latency and bandwidth of CXL regions. Signed-off-by: Huang, Ying <ying.huang@intel.com> Acked-by: Dan Williams <dan.j.williams@intel.com> Cc: Alison Schofield <alison.schofield@intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Dave Jiang <dave.jiang@intel.com> Cc: Bharata B Rao <bharata@amd.com> Cc: Alistair Popple <apopple@nvidia.com> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Vishal Verma <vishal.l.verma@intel.com> Cc: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://patch.msgid.link/20240618084639.1419629-3-ying.huang@intel.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent a3483ee commit 643e8e3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

drivers/cxl/core/region.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/uuid.h>
1010
#include <linux/sort.h>
1111
#include <linux/idr.h>
12+
#include <linux/memory-tiers.h>
1213
#include <cxlmem.h>
1314
#include <cxl.h>
1415
#include "core.h"
@@ -2228,6 +2229,7 @@ static void unregister_region(void *_cxlr)
22282229
int i;
22292230

22302231
unregister_memory_notifier(&cxlr->memory_notifier);
2232+
unregister_mt_adistance_algorithm(&cxlr->adist_notifier);
22312233
device_del(&cxlr->dev);
22322234

22332235
/*
@@ -2340,6 +2342,27 @@ static int cxl_region_perf_attrs_callback(struct notifier_block *nb,
23402342
return NOTIFY_OK;
23412343
}
23422344

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+
23432366
/**
23442367
* devm_cxl_add_region - Adds a region to a decoder
23452368
* @cxlrd: root decoder
@@ -2382,6 +2405,10 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,
23822405
cxlr->memory_notifier.priority = CXL_CALLBACK_PRI;
23832406
register_memory_notifier(&cxlr->memory_notifier);
23842407

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+
23852412
rc = devm_add_action_or_reset(port->uport_dev, unregister_region, cxlr);
23862413
if (rc)
23872414
return ERR_PTR(rc);

drivers/cxl/cxl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ struct cxl_region_params {
522522
* @params: active + config params for the region
523523
* @coord: QoS access coordinates for the region
524524
* @memory_notifier: notifier for setting the access coordinates to node
525+
* @adist_notifier: notifier for calculating the abstract distance of node
525526
*/
526527
struct cxl_region {
527528
struct device dev;
@@ -534,6 +535,7 @@ struct cxl_region {
534535
struct cxl_region_params params;
535536
struct access_coordinate coord[ACCESS_COORDINATE_MAX];
536537
struct notifier_block memory_notifier;
538+
struct notifier_block adist_notifier;
537539
};
538540

539541
struct cxl_nvdimm_bridge {

0 commit comments

Comments
 (0)