vlib: move linux-specific code to vlib/linux 60/8360/3
authorDamjan Marion <damarion@cisco.com>
Fri, 8 Sep 2017 10:26:12 +0000 (12:26 +0200)
committerDave Barach <openvpp@barachs.net>
Fri, 8 Sep 2017 15:24:50 +0000 (15:24 +0000)
Change-Id: Id79d2c2be7a98e15416a537c890a8f2dd6d4464d
Signed-off-by: Damjan Marion <damarion@cisco.com>
13 files changed:
src/plugins/dpdk/device/init.c
src/plugins/memif/memif.c
src/plugins/memif/private.h
src/vlib.am
src/vlib/linux/pci.c [moved from src/vlib/pci/linux_pci.c with 99% similarity]
src/vlib/linux/physmem.c [moved from src/vlib/unix/physmem.c with 92% similarity]
src/vlib/linux/syscall.h [new file with mode: 0644]
src/vlib/linux/sysfs.c [new file with mode: 0644]
src/vlib/linux/sysfs.h [new file with mode: 0644]
src/vlib/threads_cli.c
src/vlib/unix/unix.h
src/vlib/unix/util.c
src/vnet/devices/af_packet/af_packet.c

index e23542f..4ef3b67 100755 (executable)
@@ -17,6 +17,7 @@
 #include <vppinfra/error.h>
 #include <vppinfra/format.h>
 #include <vppinfra/bitmap.h>
+#include <vlib/linux/sysfs.h>
 #include <vlib/unix/unix.h>
 
 #include <vnet/ethernet/ethernet.h>
index 7e2d947..4c387b9 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <vlib/vlib.h>
 #include <vlib/unix/unix.h>
+#include <vlib/linux/syscall.h>
 #include <vnet/plugin/plugin.h>
 #include <vnet/ethernet/ethernet.h>
 #include <vpp/app/version.h>
index 985ac5e..b5f2f8f 100644 (file)
@@ -228,24 +228,6 @@ int memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args);
 int memif_delete_if (vlib_main_t * vm, memif_if_t * mif);
 clib_error_t *memif_plugin_api_hookup (vlib_main_t * vm);
 
-#ifndef __NR_memfd_create
-#if defined __x86_64__
-#define __NR_memfd_create 319
-#elif defined __arm__
-#define __NR_memfd_create 385
-#elif defined __aarch64__
-#define __NR_memfd_create 279
-#else
-#error "__NR_memfd_create unknown for this architecture"
-#endif
-#endif
-
-static inline int
-memfd_create (const char *name, unsigned int flags)
-{
-  return syscall (__NR_memfd_create, name, flags);
-}
-
 static_always_inline void *
 memif_get_buffer (memif_if_t * mif, memif_ring_t * ring, u16 slot)
 {
@@ -253,18 +235,6 @@ memif_get_buffer (memif_if_t * mif, memif_ring_t * ring, u16 slot)
   return mif->regions[region].shm + ring->desc[slot].offset;
 }
 
-#ifndef F_LINUX_SPECIFIC_BASE
-#define F_LINUX_SPECIFIC_BASE 1024
-#endif
-#define MFD_ALLOW_SEALING       0x0002U
-#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
-#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
-
-#define F_SEAL_SEAL     0x0001 /* prevent further seals from being set */
-#define F_SEAL_SHRINK   0x0002 /* prevent file from shrinking */
-#define F_SEAL_GROW     0x0004 /* prevent file from growing */
-#define F_SEAL_WRITE    0x0008 /* prevent writes */
-
 /* memif.c */
 clib_error_t *memif_init_regions_and_queues (memif_if_t * mif);
 clib_error_t *memif_connect (memif_if_t * mif);
index cab90e2..41d6869 100644 (file)
@@ -32,13 +32,15 @@ libvlib_la_SOURCES =                                \
   vlib/format.c                                        \
   vlib/i2c.c                                   \
   vlib/init.c                                  \
+  vlib/linux/pci.c                             \
+  vlib/linux/physmem.c                         \
+  vlib/linux/sysfs.c                           \
   vlib/main.c                                  \
   vlib/mc.c                                    \
   vlib/node.c                                  \
   vlib/node_cli.c                              \
   vlib/node_format.c                           \
   vlib/pci/pci.c                               \
-  vlib/pci/linux_pci.c                         \
   vlib/threads.c                               \
   vlib/threads_cli.c                           \
   vlib/trace.c
@@ -58,6 +60,8 @@ nobase_include_HEADERS +=                     \
   vlib/global_funcs.h                          \
   vlib/i2c.h                                   \
   vlib/init.h                                  \
+  vlib/linux/sysfs.h                           \
+  vlib/linux/syscall.h                         \
   vlib/main.h                                  \
   vlib/mc.h                                    \
   vlib/node_funcs.h                            \
@@ -79,7 +83,6 @@ libvlib_la_SOURCES +=                         \
   vlib/unix/mc_socket.c                                \
   vlib/unix/plugin.c                           \
   vlib/unix/plugin.h                           \
-  vlib/unix/physmem.c                          \
   vlib/unix/util.c
 
 nobase_include_HEADERS +=                      \
similarity index 99%
rename from src/vlib/pci/linux_pci.c
rename to src/vlib/linux/pci.c
index 2d3c0a8..cd2affd 100644 (file)
@@ -40,6 +40,7 @@
 #include <vlib/vlib.h>
 #include <vlib/pci/pci.h>
 #include <vlib/unix/unix.h>
+#include <vlib/linux/sysfs.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
similarity index 92%
rename from src/vlib/unix/physmem.c
rename to src/vlib/linux/physmem.c
index d5d5d6c..6731295 100644 (file)
 #include <vlib/vlib.h>
 #include <vlib/physmem.h>
 #include <vlib/unix/unix.h>
-
-#ifndef __NR_memfd_create
-#if defined __x86_64__
-#define __NR_memfd_create 319
-#elif defined __arm__
-#define __NR_memfd_create 385
-#elif defined __aarch64__
-#define __NR_memfd_create 279
-#else
-#error "__NR_memfd_create unknown for this architecture"
-#endif
-#endif
-
-static inline int
-memfd_create (const char *name, unsigned int flags)
-{
-  return syscall (__NR_memfd_create, name, flags);
-}
-
-#ifndef F_LINUX_SPECIFIC_BASE
-#define F_LINUX_SPECIFIC_BASE 1024
-#endif
-#define MFD_ALLOW_SEALING       0x0002U
-#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
-#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
-
-#define F_SEAL_SEAL     0x0001 /* prevent further seals from being set */
-#define F_SEAL_SHRINK   0x0002 /* prevent file from shrinking */
-#define F_SEAL_GROW     0x0004 /* prevent file from growing */
-#define F_SEAL_WRITE    0x0008 /* prevent writes */
+#include <vlib/linux/syscall.h>
+#include <vlib/linux/sysfs.h>
 
 static void *
 unix_physmem_alloc_aligned (vlib_main_t * vm, vlib_physmem_region_index_t idx,
diff --git a/src/vlib/linux/syscall.h b/src/vlib/linux/syscall.h
new file mode 100644 (file)
index 0000000..9e37997
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef included_linux_syscall_h
+#define included_linux_syscall_h
+
+#ifndef __NR_memfd_create
+#if defined __x86_64__
+#define __NR_memfd_create 319
+#elif defined __arm__
+#define __NR_memfd_create 385
+#elif defined __aarch64__
+#define __NR_memfd_create 279
+#else
+#error "__NR_memfd_create unknown for this architecture"
+#endif
+#endif
+
+static inline int
+memfd_create (const char *name, unsigned int flags)
+{
+  return syscall (__NR_memfd_create, name, flags);
+}
+
+#ifndef F_LINUX_SPECIFIC_BASE
+#define F_LINUX_SPECIFIC_BASE 1024
+#endif
+#define MFD_ALLOW_SEALING       0x0002U
+#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
+#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
+
+#define F_SEAL_SEAL     0x0001 /* prevent further seals from being set */
+#define F_SEAL_SHRINK   0x0002 /* prevent file from shrinking */
+#define F_SEAL_GROW     0x0004 /* prevent file from growing */
+#define F_SEAL_WRITE    0x0008 /* prevent writes */
+
+
+#endif /* included_linux_syscall_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vlib/linux/sysfs.c b/src/vlib/linux/sysfs.c
new file mode 100644 (file)
index 0000000..f92f9ef
--- /dev/null
@@ -0,0 +1,250 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vlib/vlib.h>
+#include <vlib/unix/unix.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+
+clib_error_t *
+vlib_sysfs_write (char *file_name, char *fmt, ...)
+{
+  u8 *s;
+  int fd;
+  clib_error_t *error = 0;
+
+  fd = open (file_name, O_WRONLY);
+  if (fd < 0)
+    return clib_error_return_unix (0, "open `%s'", file_name);
+
+  va_list va;
+  va_start (va, fmt);
+  s = va_format (0, fmt, &va);
+  va_end (va);
+
+  if (write (fd, s, vec_len (s)) < 0)
+    error = clib_error_return_unix (0, "write `%s'", file_name);
+
+  vec_free (s);
+  close (fd);
+  return error;
+}
+
+clib_error_t *
+vlib_sysfs_read (char *file_name, char *fmt, ...)
+{
+  unformat_input_t input;
+  u8 *s = 0;
+  int fd;
+  ssize_t sz;
+  uword result;
+
+  fd = open (file_name, O_RDONLY);
+  if (fd < 0)
+    return clib_error_return_unix (0, "open `%s'", file_name);
+
+  vec_validate (s, 4095);
+
+  sz = read (fd, s, vec_len (s));
+  if (sz < 0)
+    {
+      close (fd);
+      vec_free (s);
+      return clib_error_return_unix (0, "read `%s'", file_name);
+    }
+
+  _vec_len (s) = sz;
+  unformat_init_vector (&input, s);
+
+  va_list va;
+  va_start (va, fmt);
+  result = va_unformat (&input, fmt, &va);
+  va_end (va);
+
+  vec_free (s);
+  close (fd);
+
+  if (result == 0)
+    return clib_error_return (0, "unformat error");
+
+  return 0;
+}
+
+u8 *
+vlib_sysfs_link_to_name (char *link)
+{
+  char *p, buffer[64];
+  unformat_input_t in;
+  u8 *s = 0;
+  int r;
+
+  r = readlink (link, buffer, sizeof (buffer) - 1);
+
+  if (r < 0)
+    return 0;
+
+  buffer[r] = 0;
+  p = strrchr (buffer, '/');
+
+  if (!p)
+    return 0;
+
+  unformat_init_string (&in, p + 1, strlen (p + 1));
+  if (unformat (&in, "%s", &s) != 1)
+    clib_unix_warning ("no string?");
+  unformat_free (&in);
+
+  return s;
+}
+
+clib_error_t *
+vlib_sysfs_set_nr_hugepages (unsigned int numa_node, int page_size, int nr)
+{
+  clib_error_t *error = 0;
+  struct stat sb;
+  u8 *p = 0;
+
+  p = format (p, "/sys/devices/system/node/node%u%c", numa_node, 0);
+
+  if (stat ((char *) p, &sb) == 0)
+    {
+      if (S_ISDIR (sb.st_mode) == 0)
+       {
+         error = clib_error_return (0, "'%s' is not directory", p);
+         goto done;
+       }
+    }
+  else if (numa_node == 0)
+    {
+      vec_reset_length (p);
+      p = format (p, "/sys/kernel/mm%c", 0);
+      if (stat ((char *) p, &sb) < 0 || S_ISDIR (sb.st_mode) == 0)
+       {
+         error = clib_error_return (0, "'%s' does not exist or it is not "
+                                    "directory", p);
+         goto done;
+       }
+    }
+  else
+    {
+      error = clib_error_return (0, "'%s' does not exist", p);
+      goto done;
+    }
+
+  _vec_len (p) -= 1;
+  p = format (p, "/hugepages/hugepages-%ukB/nr_hugepages%c", page_size, 0);
+  vlib_sysfs_write ((char *) p, "%d", nr);
+
+done:
+  vec_free (p);
+  return error;
+}
+
+
+static clib_error_t *
+vlib_sysfs_get_xxx_hugepages (char *type, unsigned int numa_node,
+                             int page_size, int *val)
+{
+  clib_error_t *error = 0;
+  struct stat sb;
+  u8 *p = 0;
+
+  p = format (p, "/sys/devices/system/node/node%u%c", numa_node, 0);
+
+  if (stat ((char *) p, &sb) == 0)
+    {
+      if (S_ISDIR (sb.st_mode) == 0)
+       {
+         error = clib_error_return (0, "'%s' is not directory", p);
+         goto done;
+       }
+    }
+  else if (numa_node == 0)
+    {
+      vec_reset_length (p);
+      p = format (p, "/sys/kernel/mm%c", 0);
+      if (stat ((char *) p, &sb) < 0 || S_ISDIR (sb.st_mode) == 0)
+       {
+         error = clib_error_return (0, "'%s' does not exist or it is not "
+                                    "directory", p);
+         goto done;
+       }
+    }
+  else
+    {
+      error = clib_error_return (0, "'%s' does not exist", p);
+      goto done;
+    }
+
+  _vec_len (p) -= 1;
+  p = format (p, "/hugepages/hugepages-%ukB/%s_hugepages%c", page_size,
+             type, 0);
+  error = vlib_sysfs_read ((char *) p, "%d", val);
+
+done:
+  vec_free (p);
+  return error;
+}
+
+clib_error_t *
+vlib_sysfs_get_free_hugepages (unsigned int numa_node, int page_size, int *v)
+{
+  return vlib_sysfs_get_xxx_hugepages ("free", numa_node, page_size, v);
+}
+
+clib_error_t *
+vlib_sysfs_get_nr_hugepages (unsigned int numa_node, int page_size, int *v)
+{
+  return vlib_sysfs_get_xxx_hugepages ("nr", numa_node, page_size, v);
+}
+
+clib_error_t *
+vlib_sysfs_get_surplus_hugepages (unsigned int numa_node, int page_size,
+                                 int *v)
+{
+  return vlib_sysfs_get_xxx_hugepages ("surplus", numa_node, page_size, v);
+}
+
+clib_error_t *
+vlib_sysfs_prealloc_hugepages (unsigned int numa_node, int page_size, int nr)
+{
+  clib_error_t *error = 0;
+  int n, needed;
+  error = vlib_sysfs_get_free_hugepages (numa_node, page_size, &n);
+  if (error)
+    return error;
+  needed = nr - n;
+  if (needed <= 0)
+    return 0;
+
+  error = vlib_sysfs_get_nr_hugepages (numa_node, page_size, &n);
+  if (error)
+    return error;
+  clib_warning ("pre-allocating %u additional %uK hugepages on numa node %u",
+               needed, page_size, numa_node);
+  return vlib_sysfs_set_nr_hugepages (numa_node, page_size, n + needed);
+}
+
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vlib/linux/sysfs.h b/src/vlib/linux/sysfs.h
new file mode 100644 (file)
index 0000000..14b7131
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef included_linux_sysfs_h
+#define included_linux_sysfs_h
+
+clib_error_t *vlib_sysfs_write (char *file_name, char *fmt, ...);
+
+clib_error_t *vlib_sysfs_read (char *file_name, char *fmt, ...);
+
+u8 *vlib_sysfs_link_to_name (char *link);
+
+clib_error_t *vlib_sysfs_set_nr_hugepages (unsigned int numa_node,
+                                          int page_size, int nr);
+clib_error_t *vlib_sysfs_get_nr_hugepages (unsigned int numa_node,
+                                          int page_size, int *v);
+clib_error_t *vlib_sysfs_get_free_hugepages (unsigned int numa_node,
+                                            int page_size, int *v);
+clib_error_t *vlib_sysfs_get_surplus_hugepages (unsigned int numa_node,
+                                               int page_size, int *v);
+clib_error_t *vlib_sysfs_prealloc_hugepages (unsigned int numa_node,
+                                            int page_size, int nr);
+
+#endif /* included_linux_sysfs_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
index 36f8109..f8d5d8f 100644 (file)
@@ -18,6 +18,7 @@
 #include <vlib/vlib.h>
 
 #include <vlib/threads.h>
+#include <vlib/linux/sysfs.h>
 #include <vlib/unix/unix.h>
 
 static u8 *
index b5a3342..1b0d8b9 100644 (file)
@@ -217,23 +217,6 @@ extern u8 **vlib_thread_stacks;
 
 /* utils */
 
-clib_error_t *vlib_sysfs_write (char *file_name, char *fmt, ...);
-
-clib_error_t *vlib_sysfs_read (char *file_name, char *fmt, ...);
-
-u8 *vlib_sysfs_link_to_name (char *link);
-
-clib_error_t *vlib_sysfs_set_nr_hugepages (unsigned int numa_node,
-                                          int page_size, int nr);
-clib_error_t *vlib_sysfs_get_nr_hugepages (unsigned int numa_node,
-                                          int page_size, int *v);
-clib_error_t *vlib_sysfs_get_free_hugepages (unsigned int numa_node,
-                                            int page_size, int *v);
-clib_error_t *vlib_sysfs_get_surplus_hugepages (unsigned int numa_node,
-                                               int page_size, int *v);
-clib_error_t *vlib_sysfs_prealloc_hugepages (unsigned int numa_node,
-                                            int page_size, int nr);
-
 clib_error_t *foreach_directory_file (char *dir_name,
                                      clib_error_t * (*f) (void *arg,
                                                           u8 * path_name,
index 0e252ac..5472751 100644 (file)
@@ -98,225 +98,6 @@ foreach_directory_file (char *dir_name,
   return error;
 }
 
-clib_error_t *
-vlib_sysfs_write (char *file_name, char *fmt, ...)
-{
-  u8 *s;
-  int fd;
-  clib_error_t *error = 0;
-
-  fd = open (file_name, O_WRONLY);
-  if (fd < 0)
-    return clib_error_return_unix (0, "open `%s'", file_name);
-
-  va_list va;
-  va_start (va, fmt);
-  s = va_format (0, fmt, &va);
-  va_end (va);
-
-  if (write (fd, s, vec_len (s)) < 0)
-    error = clib_error_return_unix (0, "write `%s'", file_name);
-
-  vec_free (s);
-  close (fd);
-  return error;
-}
-
-clib_error_t *
-vlib_sysfs_read (char *file_name, char *fmt, ...)
-{
-  unformat_input_t input;
-  u8 *s = 0;
-  int fd;
-  ssize_t sz;
-  uword result;
-
-  fd = open (file_name, O_RDONLY);
-  if (fd < 0)
-    return clib_error_return_unix (0, "open `%s'", file_name);
-
-  vec_validate (s, 4095);
-
-  sz = read (fd, s, vec_len (s));
-  if (sz < 0)
-    {
-      close (fd);
-      vec_free (s);
-      return clib_error_return_unix (0, "read `%s'", file_name);
-    }
-
-  _vec_len (s) = sz;
-  unformat_init_vector (&input, s);
-
-  va_list va;
-  va_start (va, fmt);
-  result = va_unformat (&input, fmt, &va);
-  va_end (va);
-
-  vec_free (s);
-  close (fd);
-
-  if (result == 0)
-    return clib_error_return (0, "unformat error");
-
-  return 0;
-}
-
-u8 *
-vlib_sysfs_link_to_name (char *link)
-{
-  char *p, buffer[64];
-  unformat_input_t in;
-  u8 *s = 0;
-  int r;
-
-  r = readlink (link, buffer, sizeof (buffer) - 1);
-
-  if (r < 0)
-    return 0;
-
-  buffer[r] = 0;
-  p = strrchr (buffer, '/');
-
-  if (!p)
-    return 0;
-
-  unformat_init_string (&in, p + 1, strlen (p + 1));
-  if (unformat (&in, "%s", &s) != 1)
-    clib_unix_warning ("no string?");
-  unformat_free (&in);
-
-  return s;
-}
-
-clib_error_t *
-vlib_sysfs_set_nr_hugepages (unsigned int numa_node, int page_size, int nr)
-{
-  clib_error_t *error = 0;
-  struct stat sb;
-  u8 *p = 0;
-
-  p = format (p, "/sys/devices/system/node/node%u%c", numa_node, 0);
-
-  if (stat ((char *) p, &sb) == 0)
-    {
-      if (S_ISDIR (sb.st_mode) == 0)
-       {
-         error = clib_error_return (0, "'%s' is not directory", p);
-         goto done;
-       }
-    }
-  else if (numa_node == 0)
-    {
-      vec_reset_length (p);
-      p = format (p, "/sys/kernel/mm%c", 0);
-      if (stat ((char *) p, &sb) < 0 || S_ISDIR (sb.st_mode) == 0)
-       {
-         error = clib_error_return (0, "'%s' does not exist or it is not "
-                                    "directory", p);
-         goto done;
-       }
-    }
-  else
-    {
-      error = clib_error_return (0, "'%s' does not exist", p);
-      goto done;
-    }
-
-  _vec_len (p) -= 1;
-  p = format (p, "/hugepages/hugepages-%ukB/nr_hugepages%c", page_size, 0);
-  vlib_sysfs_write ((char *) p, "%d", nr);
-
-done:
-  vec_free (p);
-  return error;
-}
-
-
-static clib_error_t *
-vlib_sysfs_get_xxx_hugepages (char *type, unsigned int numa_node,
-                             int page_size, int *val)
-{
-  clib_error_t *error = 0;
-  struct stat sb;
-  u8 *p = 0;
-
-  p = format (p, "/sys/devices/system/node/node%u%c", numa_node, 0);
-
-  if (stat ((char *) p, &sb) == 0)
-    {
-      if (S_ISDIR (sb.st_mode) == 0)
-       {
-         error = clib_error_return (0, "'%s' is not directory", p);
-         goto done;
-       }
-    }
-  else if (numa_node == 0)
-    {
-      vec_reset_length (p);
-      p = format (p, "/sys/kernel/mm%c", 0);
-      if (stat ((char *) p, &sb) < 0 || S_ISDIR (sb.st_mode) == 0)
-       {
-         error = clib_error_return (0, "'%s' does not exist or it is not "
-                                    "directory", p);
-         goto done;
-       }
-    }
-  else
-    {
-      error = clib_error_return (0, "'%s' does not exist", p);
-      goto done;
-    }
-
-  _vec_len (p) -= 1;
-  p = format (p, "/hugepages/hugepages-%ukB/%s_hugepages%c", page_size,
-             type, 0);
-  error = vlib_sysfs_read ((char *) p, "%d", val);
-
-done:
-  vec_free (p);
-  return error;
-}
-
-clib_error_t *
-vlib_sysfs_get_free_hugepages (unsigned int numa_node, int page_size, int *v)
-{
-  return vlib_sysfs_get_xxx_hugepages ("free", numa_node, page_size, v);
-}
-
-clib_error_t *
-vlib_sysfs_get_nr_hugepages (unsigned int numa_node, int page_size, int *v)
-{
-  return vlib_sysfs_get_xxx_hugepages ("nr", numa_node, page_size, v);
-}
-
-clib_error_t *
-vlib_sysfs_get_surplus_hugepages (unsigned int numa_node, int page_size,
-                                 int *v)
-{
-  return vlib_sysfs_get_xxx_hugepages ("surplus", numa_node, page_size, v);
-}
-
-clib_error_t *
-vlib_sysfs_prealloc_hugepages (unsigned int numa_node, int page_size, int nr)
-{
-  clib_error_t *error = 0;
-  int n, needed;
-  error = vlib_sysfs_get_free_hugepages (numa_node, page_size, &n);
-  if (error)
-    return error;
-  needed = nr - n;
-  if (needed <= 0)
-    return 0;
-
-  error = vlib_sysfs_get_nr_hugepages (numa_node, page_size, &n);
-  if (error)
-    return error;
-  clib_warning ("pre-allocating %u additional %uK hugepages on numa node %u",
-               needed, page_size, numa_node);
-  return vlib_sysfs_set_nr_hugepages (numa_node, page_size, n + needed);
-}
-
 clib_error_t *
 vlib_unix_recursive_mkdir (char *path)
 {
index ea52878..e7e6921 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <vlib/vlib.h>
 #include <vlib/unix/unix.h>
+#include <vlib/linux/sysfs.h>
 #include <vnet/ip/ip.h>
 #include <vnet/ethernet/ethernet.h>