Fix build with newer linux headers
Change-Id: Ibfdcec60567ec357205fa137257f2d8cba44b01c
Signed-off-by: Damjan Marion <damarion@cisco.com>
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 161e3c5..d467da7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -84,7 +84,7 @@
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)
diff --git a/src/cmake/memfd.cmake b/src/cmake/syscall.cmake
similarity index 84%
rename from src/cmake/memfd.cmake
rename to src/cmake/syscall.cmake
index ca499c4..1e0a559 100644
--- a/src/cmake/memfd.cmake
+++ b/src/cmake/syscall.cmake
@@ -24,3 +24,13 @@
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()
+
diff --git a/src/vppinfra/linux/syscall.h b/src/vppinfra/linux/syscall.h
index 1ae029d..c07cad6 100644
--- a/src/vppinfra/linux/syscall.h
+++ b/src/vppinfra/linux/syscall.h
@@ -19,11 +19,13 @@
#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)
diff --git a/src/vppinfra/pmalloc.c b/src/vppinfra/pmalloc.c
index 9f908f4..d9e50d1 100644
--- a/src/vppinfra/pmalloc.c
+++ b/src/vppinfra/pmalloc.c
@@ -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 @@
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;