Blame SOURCES/0113-cxl-list-Add-numa_node-to-memdev-listings.patch

26ccd9
From ca582b2003a2335eafac382e71afdf0a6caaef18 Mon Sep 17 00:00:00 2001
26ccd9
From: Dan Williams <dan.j.williams@intel.com>
26ccd9
Date: Sun, 23 Jan 2022 16:54:11 -0800
26ccd9
Subject: [PATCH 113/217] cxl/list: Add 'numa_node' to memdev listings
26ccd9
26ccd9
If the kernel exports a valid numa_node, >= 0, include it in memdev objects
26ccd9
listings.
26ccd9
26ccd9
Link: https://lore.kernel.org/r/164298565156.3021641.14097226245654611710.stgit@dwillia2-desk3.amr.corp.intel.com
26ccd9
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
26ccd9
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
---
26ccd9
 Documentation/cxl/lib/libcxl.txt |  4 ++++
26ccd9
 cxl/json.c                       |  8 ++++++++
26ccd9
 cxl/lib/libcxl.c                 | 11 +++++++++++
26ccd9
 cxl/lib/libcxl.sym               |  1 +
26ccd9
 cxl/lib/private.h                |  1 +
26ccd9
 cxl/libcxl.h                     |  1 +
26ccd9
 6 files changed, 26 insertions(+)
26ccd9
26ccd9
diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt
26ccd9
index b0253d7..de88d19 100644
26ccd9
--- a/Documentation/cxl/lib/libcxl.txt
26ccd9
+++ b/Documentation/cxl/lib/libcxl.txt
26ccd9
@@ -71,6 +71,7 @@ unsigned long long cxl_memdev_get_ram_size(struct cxl_memdev *memdev);
26ccd9
 const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev);
26ccd9
 size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev);
26ccd9
 int cxl_memdev_nvdimm_bridge_active(struct cxl_memdev *memdev);
26ccd9
+int cxl_memdev_get_numa_node(struct cxl_memdev *memdev);
26ccd9
 ----
26ccd9
 
26ccd9
 A memdev is given a kernel device name of the form "mem%d" where an id
26ccd9
@@ -89,6 +90,9 @@ The 'pmem_size' and 'ram_size' attributes return the current
26ccd9
 provisioning of DPA (Device Physical Address / local capacity) in the
26ccd9
 device.
26ccd9
 
26ccd9
+cxl_memdev_get_numa_node() returns the affinitized CPU node number if
26ccd9
+available or -1 otherwise.
26ccd9
+
26ccd9
 === MEMDEV: Commands
26ccd9
 ----
26ccd9
 struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev, int opcode);
26ccd9
diff --git a/cxl/json.c b/cxl/json.c
26ccd9
index b809332..51918d6 100644
26ccd9
--- a/cxl/json.c
26ccd9
+++ b/cxl/json.c
26ccd9
@@ -190,6 +190,7 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
26ccd9
 	const char *devname = cxl_memdev_get_devname(memdev);
26ccd9
 	struct json_object *jdev, *jobj;
26ccd9
 	unsigned long long serial;
26ccd9
+	int numa_node;
26ccd9
 
26ccd9
 	jdev = json_object_new_object();
26ccd9
 	if (!jdev)
26ccd9
@@ -220,6 +221,13 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
26ccd9
 			json_object_object_add(jdev, "serial", jobj);
26ccd9
 	}
26ccd9
 
26ccd9
+	numa_node = cxl_memdev_get_numa_node(memdev);
26ccd9
+	if (numa_node >= 0) {
26ccd9
+		jobj = json_object_new_int(numa_node);
26ccd9
+		if (jobj)
26ccd9
+			json_object_object_add(jdev, "numa_node", jobj);
26ccd9
+	}
26ccd9
+
26ccd9
 	jobj = json_object_new_string(cxl_memdev_get_host(memdev));
26ccd9
 	if (jobj)
26ccd9
 		json_object_object_add(jdev, "host", jobj);
26ccd9
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
26ccd9
index 0065f6b..14c7db8 100644
26ccd9
--- a/cxl/lib/libcxl.c
26ccd9
+++ b/cxl/lib/libcxl.c
26ccd9
@@ -348,6 +348,12 @@ static void *add_cxl_memdev(void *parent, int id, const char *cxlmem_base)
26ccd9
 	else
26ccd9
 		memdev->serial = strtoull(buf, NULL, 0);
26ccd9
 
26ccd9
+	sprintf(path, "%s/numa_node", cxlmem_base);
26ccd9
+	if (sysfs_read_attr(ctx, path, buf) < 0)
26ccd9
+		memdev->numa_node = -1;
26ccd9
+	else
26ccd9
+		memdev->numa_node = strtol(buf, NULL, 0);
26ccd9
+
26ccd9
 	memdev->dev_path = strdup(cxlmem_base);
26ccd9
 	if (!memdev->dev_path)
26ccd9
 		goto err_read;
26ccd9
@@ -445,6 +451,11 @@ CXL_EXPORT unsigned long long cxl_memdev_get_serial(struct cxl_memdev *memdev)
26ccd9
 	return memdev->serial;
26ccd9
 }
26ccd9
 
26ccd9
+CXL_EXPORT int cxl_memdev_get_numa_node(struct cxl_memdev *memdev)
26ccd9
+{
26ccd9
+	return memdev->numa_node;
26ccd9
+}
26ccd9
+
26ccd9
 CXL_EXPORT const char *cxl_memdev_get_devname(struct cxl_memdev *memdev)
26ccd9
 {
26ccd9
 	return devpath_to_devname(memdev->dev_path);
26ccd9
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
26ccd9
index 29f3498..b13a2d6 100644
26ccd9
--- a/cxl/lib/libcxl.sym
26ccd9
+++ b/cxl/lib/libcxl.sym
26ccd9
@@ -77,6 +77,7 @@ local:
26ccd9
 LIBCXL_2 {
26ccd9
 global:
26ccd9
 	cxl_memdev_get_serial;
26ccd9
+	cxl_memdev_get_numa_node;
26ccd9
 	cxl_memdev_get_host;
26ccd9
 	cxl_bus_get_first;
26ccd9
 	cxl_bus_get_next;
26ccd9
diff --git a/cxl/lib/private.h b/cxl/lib/private.h
26ccd9
index b097bdf..c00bb36 100644
26ccd9
--- a/cxl/lib/private.h
26ccd9
+++ b/cxl/lib/private.h
26ccd9
@@ -20,6 +20,7 @@ struct cxl_pmem {
26ccd9
 struct cxl_endpoint;
26ccd9
 struct cxl_memdev {
26ccd9
 	int id, major, minor;
26ccd9
+	int numa_node;
26ccd9
 	void *dev_buf;
26ccd9
 	size_t buf_len;
26ccd9
 	char *host;
26ccd9
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
26ccd9
index e7b675e..be656ed 100644
26ccd9
--- a/cxl/libcxl.h
26ccd9
+++ b/cxl/libcxl.h
26ccd9
@@ -37,6 +37,7 @@ struct cxl_memdev *cxl_memdev_get_first(struct cxl_ctx *ctx);
26ccd9
 struct cxl_memdev *cxl_memdev_get_next(struct cxl_memdev *memdev);
26ccd9
 int cxl_memdev_get_id(struct cxl_memdev *memdev);
26ccd9
 unsigned long long cxl_memdev_get_serial(struct cxl_memdev *memdev);
26ccd9
+int cxl_memdev_get_numa_node(struct cxl_memdev *memdev);
26ccd9
 const char *cxl_memdev_get_devname(struct cxl_memdev *memdev);
26ccd9
 const char *cxl_memdev_get_host(struct cxl_memdev *memdev);
26ccd9
 struct cxl_bus *cxl_memdev_get_bus(struct cxl_memdev *memdev);
26ccd9
-- 
26ccd9
2.27.0
26ccd9