On 27 Sep 2019, at 19:26, William Tu wrote:
The patch detects the numa node id from the name of the netdev,
by reading the '/sys/class/net/<devname>/device/numa_node'.
If not available, ex: virtual device, or any error happens,
return numa id 0.
Signed-off-by: William Tu <[email protected]>
Will you update the “Limitations/Known Issues” section as part of
the libnuma and numa_alloc_onnode() patch?
---
v2:
Address feedback from Eelco
fix memory leak of xaspintf
log using INFO instead of WARN
---
lib/netdev-afxdp.c | 41 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 36 insertions(+), 5 deletions(-)
diff --git a/lib/netdev-afxdp.c b/lib/netdev-afxdp.c
index 6e01803272aa..6ff1473461a6 100644
--- a/lib/netdev-afxdp.c
+++ b/lib/netdev-afxdp.c
@@ -552,11 +552,42 @@ out:
int
netdev_afxdp_get_numa_id(const struct netdev *netdev)
{
- /* FIXME: Get netdev's PCIe device ID, then find
- * its NUMA node id.
- */
- VLOG_INFO("FIXME: Device %s always use numa id 0.",
- netdev_get_name(netdev));
+ const char *numa_node_path;
+ long int node_id;
+ char buffer[4];
+ FILE *stream;
+ int n;
+
+ numa_node_path = xasprintf("/sys/class/net/%s/device/numa_node",
+ netdev_get_name(netdev));
+ stream = fopen(numa_node_path, "r");
+ if (!stream) {
+ /* Virtual device does not have this info. */
+ VLOG_INFO_RL(&rl, "Open %s failed: %s, use numa_id 0",
+ numa_node_path, ovs_strerror(errno));
+ free(numa_node_path);
+ return 0;
+ }
+
+ n = fread(buffer, 1, sizeof buffer, stream);
+ if (!n) {
+ goto error;
+ }
+
+ node_id = strtol(buffer, NULL, 10);
+ if (node_id < 0 || node_id > 2) {
+ goto error;
+ }
Any reason why you limit this to 2? Guess it depends on the kernel’s
CONFIG_NODES_SHIFT value. You might be able to use the libnuma API
numa_max_possible_node().
+
+ fclose(stream);
+ free(numa_node_path);
+ return (int)node_id;
Guess you need a space after (int) node_id.
+
+error:
+ VLOG_WARN_RL(&rl, "Error detecting numa node of %s, use numa_id
0",
+ numa_node_path);
+ free(numa_node_path);
+ fclose(stream);
return 0;
}
--
2.7.4
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev