Fix build with newer linux headers 66/18366/2
authorDamjan Marion <damarion@cisco.com>
Mon, 18 Mar 2019 16:06:51 +0000 (17:06 +0100)
committerFlorin Coras <florin.coras@gmail.com>
Mon, 18 Mar 2019 17:13:10 +0000 (17:13 +0000)
Change-Id: Ibfdcec60567ec357205fa137257f2d8cba44b01c
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/CMakeLists.txt
src/cmake/syscall.cmake [moved from src/cmake/memfd.cmake with 84% similarity]
src/vppinfra/linux/syscall.h
src/vppinfra/pmalloc.c

index 161e3c5..d467da7 100644 (file)
@@ -84,7 +84,7 @@ set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "vpp")
 set(THREADS_PREFER_PTHREAD_FLAG ON)
 find_package(Threads REQUIRED)
 
-include(cmake/memfd.cmake)
+include(cmake/syscall.cmake)
 include(cmake/api.cmake)
 include(cmake/library.cmake)
 include(cmake/exec.cmake)
similarity index 84%
rename from src/cmake/memfd.cmake
rename to src/cmake/syscall.cmake
index ca499c4..1e0a559 100644 (file)
@@ -24,3 +24,13 @@ if (HAVE_MEMFD_CREATE)
     add_definitions(-DHAVE_MEMFD_CREATE)
 endif()
 
+check_c_source_compiles("
+  #define _GNU_SOURCE
+  #include <sched.h>
+  int main() { return getcpu (0, 0); }
+" HAVE_GETCPU)
+
+if (HAVE_GETCPU)
+    add_definitions(-DHAVE_GETCPU)
+endif()
+
index 1ae029d..c07cad6 100644 (file)
 #include <unistd.h>
 #include <sys/syscall.h>
 
+#ifndef HAVE_GETCPU
 static inline int
-getcpu (unsigned *cpu, unsigned *node, void *tcache)
+getcpu (unsigned *cpu, unsigned *node)
 {
-  return syscall (__NR_getcpu, cpu, node, tcache);
+  return syscall (__NR_getcpu, cpu, node, 0);
 }
+#endif
 
 static inline long
 set_mempolicy (int mode, const unsigned long *nodemask, unsigned long maxnode)
index 9f908f4..d9e50d1 100644 (file)
@@ -21,6 +21,7 @@
 #include <unistd.h>
 #include <linux/mempolicy.h>
 #include <linux/memfd.h>
+#include <sched.h>
 
 #include <vppinfra/format.h>
 #include <vppinfra/linux/syscall.h>
@@ -53,7 +54,7 @@ pmalloc_validate_numa_node (u32 * numa_node)
   if (*numa_node == CLIB_PMALLOC_NUMA_LOCAL)
     {
       u32 cpu;
-      if (getcpu (&cpu, numa_node, 0) != 0)
+      if (getcpu (&cpu, numa_node) != 0)
        return 1;
     }
   return 0;