[ovs-dev] [PATCH 1/5] ovs-numa: Remove non-linux stubs.

Daniele Di Proietto diproiettod at vmware.com
Tue Jun 7 01:51:30 UTC 2016


Instead of having static inline stubs for non linux platform we can use
the implementations in ovs-numa.c.  With one small change to
ovs_numa_dump_cores_on_numa(), they will behave exactly like the
stubs for the non-linux case, because 'found_numa_and_core' will be
false and the socket and cpu hmaps will be empty.

There are a few places where conditional compilation is required: the
code that parses the linux specific sysfs entries and its dependencies.
It requires opendir() and readdir() and doesn't make sense outside of
linux anyway.

This change is required to have a cross-platform ovs-numa dummy
implementation for testing.

Signed-off-by: Daniele Di Proietto <diproiettod at vmware.com>
---
 lib/automake.mk |   4 +--
 lib/ovs-numa.c  |  21 ++++++-----
 lib/ovs-numa.h  | 107 +-------------------------------------------------------
 3 files changed, 16 insertions(+), 116 deletions(-)

diff --git a/lib/automake.mk b/lib/automake.mk
index e196ada..eabc0e7 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -164,6 +164,8 @@ lib_libopenvswitch_la_SOURCES = \
 	lib/ovs-atomic.h \
 	lib/ovs-lldp.c \
 	lib/ovs-lldp.h \
+	lib/ovs-numa.c \
+	lib/ovs-numa.h \
 	lib/ovs-rcu.c \
 	lib/ovs-rcu.h \
 	lib/ovs-router.h \
@@ -349,8 +351,6 @@ lib_libopenvswitch_la_SOURCES += \
 	lib/netlink-protocol.h \
 	lib/netlink-socket.c \
 	lib/netlink-socket.h \
-	lib/ovs-numa.c \
-	lib/ovs-numa.h \
 	lib/rtnetlink.c \
 	lib/rtnetlink.h \
 	lib/route-table.c \
diff --git a/lib/ovs-numa.c b/lib/ovs-numa.c
index 747648a..461d734 100644
--- a/lib/ovs-numa.c
+++ b/lib/ovs-numa.c
@@ -14,19 +14,18 @@
  * limitations under the License.
  */
 
-/* On non-Linux, these functions are defined inline in ovs-numa.h. */
-#ifdef __linux__
-
 #include <config.h>
 #include "ovs-numa.h"
 
 #include <ctype.h>
+#ifdef __linux__
 #include <dirent.h>
 #include <errno.h>
 #include <stddef.h>
 #include <string.h>
 #include <sys/types.h>
 #include <unistd.h>
+#endif /* __linux__ */
 
 #include "hash.h"
 #include "hmap.h"
@@ -82,18 +81,21 @@ static struct hmap all_cpu_cores = HMAP_INITIALIZER(&all_cpu_cores);
 /* True if numa node and core info are correctly extracted. */
 static bool found_numa_and_core;
 
+#ifdef __linux__
 /* Returns true if 'str' contains all digits.  Returns false otherwise. */
 static bool
 contain_all_digits(const char *str)
 {
     return str[strspn(str, "0123456789")] == '\0';
 }
+#endif /* __linux__ */
 
 /* Discovers all numa nodes and the corresponding cpu cores.
  * Constructs the 'struct numa_node' and 'struct cpu_core'. */
 static void
 discover_numa_and_core(void)
 {
+#ifdef __linux__
     int n_cpus = 0;
     int i;
     DIR *dir;
@@ -165,6 +167,7 @@ discover_numa_and_core(void)
     if (hmap_count(&all_numa_nodes) && hmap_count(&all_cpu_cores)) {
         found_numa_and_core = true;
     }
+#endif /* __linux__ */
 }
 
 /* Gets 'struct cpu_core' by 'core_id'. */
@@ -373,14 +376,14 @@ ovs_numa_unpin_core(unsigned core_id)
 struct ovs_numa_dump *
 ovs_numa_dump_cores_on_numa(int numa_id)
 {
-    struct ovs_numa_dump *dump = NULL;
+    struct ovs_numa_dump *dump = xmalloc(sizeof *dump);
     struct numa_node *numa = get_numa_by_numa_id(numa_id);
 
+    ovs_list_init(&dump->dump);
+
     if (numa) {
         struct cpu_core *core;
 
-        dump = xmalloc(sizeof *dump);
-        ovs_list_init(&dump->dump);
         LIST_FOR_EACH(core, list_node, &numa->cores) {
             struct ovs_numa_info *info = xmalloc(sizeof *info);
 
@@ -398,6 +401,10 @@ ovs_numa_dump_destroy(struct ovs_numa_dump *dump)
 {
     struct ovs_numa_info *iter;
 
+    if (!dump) {
+        return;
+    }
+
     LIST_FOR_EACH_POP (iter, list_node, &dump->dump) {
         free(iter);
     }
@@ -466,5 +473,3 @@ ovs_numa_set_cpu_mask(const char *cmask)
         core->available = false;
     }
 }
-
-#endif /* __linux__ */
diff --git a/lib/ovs-numa.h b/lib/ovs-numa.h
index e7ff465..c2619d1 100644
--- a/lib/ovs-numa.h
+++ b/lib/ovs-numa.h
@@ -38,8 +38,6 @@ struct ovs_numa_info {
     unsigned core_id;
 };
 
-#ifdef __linux__
-
 void ovs_numa_init(void);
 bool ovs_numa_numa_id_is_valid(int numa_id);
 bool ovs_numa_core_id_is_valid(unsigned core_id);
@@ -60,107 +58,4 @@ void ovs_numa_dump_destroy(struct ovs_numa_dump *);
 #define FOR_EACH_CORE_ON_NUMA(ITER, DUMP)                    \
     LIST_FOR_EACH((ITER), list_node, &(DUMP)->dump)
 
-#else
-
-static inline void
-ovs_numa_init(void)
-{
-    /* Nothing */
-}
-
-static inline bool
-ovs_numa_numa_id_is_valid(int numa_id OVS_UNUSED)
-{
-    return false;
-}
-
-static inline bool
-ovs_numa_core_id_is_valid(unsigned core_id OVS_UNUSED)
-{
-    return false;
-}
-
-static inline bool
-ovs_numa_core_is_pinned(unsigned core_id OVS_UNUSED)
-{
-    return false;
-}
-
-static inline void
-ovs_numa_set_cpu_mask(const char *cmask OVS_UNUSED)
-{
-    /* Nothing */
-}
-
-static inline int
-ovs_numa_get_n_numas(void)
-{
-    return OVS_NUMA_UNSPEC;
-}
-
-static inline int
-ovs_numa_get_n_cores(void)
-{
-    return OVS_CORE_UNSPEC;
-}
-
-static inline int
-ovs_numa_get_numa_id(unsigned core_id OVS_UNUSED)
-{
-    return OVS_NUMA_UNSPEC;
-}
-
-static inline int
-ovs_numa_get_n_cores_on_numa(int numa_id OVS_UNUSED)
-{
-    return OVS_CORE_UNSPEC;
-}
-
-static inline int
-ovs_numa_get_n_unpinned_cores_on_numa(int numa_id OVS_UNUSED)
-{
-    return OVS_CORE_UNSPEC;
-}
-
-static inline bool
-ovs_numa_try_pin_core_specific(unsigned core_id OVS_UNUSED)
-{
-    return false;
-}
-
-static inline unsigned
-ovs_numa_get_unpinned_core_any(void)
-{
-    return OVS_CORE_UNSPEC;
-}
-
-static inline unsigned
-ovs_numa_get_unpinned_core_on_numa(int numa_id OVS_UNUSED)
-{
-    return OVS_CORE_UNSPEC;
-}
-
-static inline void
-ovs_numa_unpin_core(unsigned core_id OVS_UNUSED)
-{
-    /* Nothing */
-}
-
-static inline struct ovs_numa_dump *
-ovs_numa_dump_cores_on_numa(int numa_id OVS_UNUSED)
-{
-    return NULL;
-}
-
-static inline void
-ovs_numa_dump_destroy(struct ovs_numa_dump *dump OVS_UNUSED)
-{
-    /* Nothing */
-}
-
-/* No loop. */
-#define FOR_EACH_CORE_ON_NUMA(ITER, DUMP)                    \
-    for ((ITER) = NULL; (ITER);)
-
-#endif /* __linux__ */
-#endif /* ovs-thead.h */
+#endif /* ovs-numa.h */
-- 
2.8.1




More information about the dev mailing list