[ovs-dev] [dpdk patch v2 1/6] netdev: Add function for getting the numa node id of netdev.
Alex Wang
alexw at nicira.com
Mon Sep 8 18:28:04 UTC 2014
This commit adds a new API to the 'struct netdev_class' which
allows user to query the numa node id the 'netdev' is on.
Currently, only netdev-dpdk module implements this function.
Signed-off-by: Alex Wang <alexw at nicira.com>
---
PATCH -> V2
- rebase and refactor the code.
---
lib/netdev-bsd.c | 1 +
lib/netdev-dpdk.c | 9 +++++++++
lib/netdev-dummy.c | 1 +
lib/netdev-linux.c | 1 +
lib/netdev-provider.h | 7 +++++++
lib/netdev-vport.c | 1 +
lib/netdev.c | 12 ++++++++++++
lib/netdev.h | 1 +
8 files changed, 33 insertions(+)
diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index 82f61ff..dd1893c 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -1562,6 +1562,7 @@ netdev_bsd_update_flags(struct netdev *netdev_, enum netdev_flags off,
NULL, /* get_config */ \
NULL, /* set_config */ \
NULL, /* get_tunnel_config */ \
+ NULL, /* get_numa_id */ \
\
netdev_bsd_send, \
netdev_bsd_send_wait, \
diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 62e4cb9..70ee8db 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -581,6 +581,14 @@ netdev_dpdk_get_config(const struct netdev *netdev_, struct smap *args)
return 0;
}
+static int
+netdev_dpdk_get_numa_id(const struct netdev *netdev_)
+{
+ struct netdev_dpdk *netdev = netdev_dpdk_cast(netdev_);
+
+ return netdev->socket_id;
+}
+
static struct netdev_rxq *
netdev_dpdk_rxq_alloc(void)
{
@@ -1345,6 +1353,7 @@ unlock_dpdk:
netdev_dpdk_get_config, \
NULL, /* netdev_dpdk_set_config */ \
NULL, /* get_tunnel_config */ \
+ netdev_dpdk_get_numa_id, /* get_numa_id */ \
\
netdev_dpdk_send, /* send */ \
NULL, /* send_wait */ \
diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index e3cf72d..14239f1 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -1044,6 +1044,7 @@ static const struct netdev_class dummy_class = {
netdev_dummy_get_config,
netdev_dummy_set_config,
NULL, /* get_tunnel_config */
+ NULL, /* get_numa_id */
netdev_dummy_send, /* send */
NULL, /* send_wait */
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index d8a76f9..298ccd6 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -2750,6 +2750,7 @@ netdev_linux_update_flags(struct netdev *netdev_, enum netdev_flags off,
NULL, /* get_config */ \
NULL, /* set_config */ \
NULL, /* get_tunnel_config */ \
+ NULL, /* get_numa_id */ \
\
netdev_linux_send, \
netdev_linux_send_wait, \
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index 56244ad..e8f2ebe 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -22,6 +22,7 @@
#include "connectivity.h"
#include "netdev.h"
#include "list.h"
+#include "ovs-numa.h"
#include "seq.h"
#include "shash.h"
#include "smap.h"
@@ -30,6 +31,8 @@
extern "C" {
#endif
+#define NETDEV_NUMA_UNSPEC OVS_NUMA_UNSPEC
+
/* A network device (e.g. an Ethernet device).
*
* Network device implementations may read these members but should not modify
@@ -250,6 +253,10 @@ struct netdev_class {
const struct netdev_tunnel_config *
(*get_tunnel_config)(const struct netdev *netdev);
+ /* Returns the id of the numa node the 'netdev' is on. If there is no
+ * such info, returns NETDEV_NUMA_UNSPEC. */
+ int (*get_numa_id)(const struct netdev *netdev);
+
/* Sends buffers on 'netdev'.
* Returns 0 if successful (for every buffer), otherwise a positive errno value.
* Returns EAGAIN without blocking if one or more packets cannot be
diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c
index 17adf94..6ab90bf 100644
--- a/lib/netdev-vport.c
+++ b/lib/netdev-vport.c
@@ -775,6 +775,7 @@ get_stats(const struct netdev *netdev, struct netdev_stats *stats)
GET_CONFIG, \
SET_CONFIG, \
GET_TUNNEL_CONFIG, \
+ NULL, /* get_numa_id */ \
\
NULL, /* send */ \
NULL, /* send_wait */ \
diff --git a/lib/netdev.c b/lib/netdev.c
index a71e80d..444ae85 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -475,6 +475,18 @@ netdev_get_tunnel_config(const struct netdev *netdev)
}
}
+/* Returns the id of the numa node the 'netdev' is on. If the function
+ * is not implemented, returns NETDEV_NUMA_UNSPEC. */
+int
+netdev_get_numa_id(const struct netdev *netdev)
+{
+ if (netdev->netdev_class->get_numa_id) {
+ return netdev->netdev_class->get_numa_id(netdev);
+ } else {
+ return NETDEV_NUMA_UNSPEC;
+ }
+}
+
static void
netdev_unref(struct netdev *dev)
OVS_RELEASES(netdev_mutex)
diff --git a/lib/netdev.h b/lib/netdev.h
index 53415b2..f429bc6 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -152,6 +152,7 @@ int netdev_set_config(struct netdev *, const struct smap *args, char **errp);
int netdev_get_config(const struct netdev *, struct smap *);
const struct netdev_tunnel_config *
netdev_get_tunnel_config(const struct netdev *);
+int netdev_get_numa_id(const struct netdev *);
/* Basic properties. */
const char *netdev_get_name(const struct netdev *);
--
1.7.9.5
More information about the dev
mailing list