aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/linux/sysfs.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-10-22 13:01:46 +0200
committerDamjan Marion <dmarion@me.com>2018-10-22 13:01:19 +0000
commit6f3f1cbf7760efb17c5754c3dbccdefd433675cb (patch)
tree72d67fe93dbed7ef98676eb1e9250eb9d7c366b2 /src/vppinfra/linux/sysfs.c
parent68b7cb8febb2ad7123f165f9db10d3ffc3b409fe (diff)
vppinfra: use log2 page size in hugepage functions
Change-Id: Ibec32c6df32f4cd9889d378e244f170c93ad295b Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/linux/sysfs.c')
-rw-r--r--src/vppinfra/linux/sysfs.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/vppinfra/linux/sysfs.c b/src/vppinfra/linux/sysfs.c
index 5f611e6a341..199e6bbfd69 100644
--- a/src/vppinfra/linux/sysfs.c
+++ b/src/vppinfra/linux/sysfs.c
@@ -22,6 +22,8 @@
#include <fcntl.h>
#include <dirent.h>
+#define DEFAULT_HUGETLB_SIZE 2048
+
clib_error_t *
clib_sysfs_write (char *file_name, char *fmt, ...)
{
@@ -114,11 +116,13 @@ clib_sysfs_link_to_name (char *link)
}
clib_error_t *
-clib_sysfs_set_nr_hugepages (int numa_node, int page_size, int nr)
+clib_sysfs_set_nr_hugepages (int numa_node, int log2_page_size, int nr)
{
clib_error_t *error = 0;
struct stat sb;
u8 *p = 0;
+ int page_size = log2_page_size ? 1ULL << (log2_page_size - 10) :
+ DEFAULT_HUGETLB_SIZE;
p = format (p, "/sys/devices/system/node/node%u%c", numa_node, 0);
@@ -159,11 +163,13 @@ done:
static clib_error_t *
clib_sysfs_get_xxx_hugepages (char *type, int numa_node,
- int page_size, int *val)
+ int log2_page_size, int *val)
{
clib_error_t *error = 0;
struct stat sb;
u8 *p = 0;
+ int page_size = log2_page_size ? 1ULL << (log2_page_size - 10) :
+ DEFAULT_HUGETLB_SIZE;
p = format (p, "/sys/devices/system/node/node%u%c", numa_node, 0);
@@ -203,41 +209,44 @@ done:
}
clib_error_t *
-clib_sysfs_get_free_hugepages (int numa_node, int page_size, int *v)
+clib_sysfs_get_free_hugepages (int numa_node, int log2_page_size, int *v)
{
- return clib_sysfs_get_xxx_hugepages ("free", numa_node, page_size, v);
+ return clib_sysfs_get_xxx_hugepages ("free", numa_node, log2_page_size, v);
}
clib_error_t *
-clib_sysfs_get_nr_hugepages (int numa_node, int page_size, int *v)
+clib_sysfs_get_nr_hugepages (int numa_node, int log2_page_size, int *v)
{
- return clib_sysfs_get_xxx_hugepages ("nr", numa_node, page_size, v);
+ return clib_sysfs_get_xxx_hugepages ("nr", numa_node, log2_page_size, v);
}
clib_error_t *
-clib_sysfs_get_surplus_hugepages (int numa_node, int page_size, int *v)
+clib_sysfs_get_surplus_hugepages (int numa_node, int log2_page_size, int *v)
{
- return clib_sysfs_get_xxx_hugepages ("surplus", numa_node, page_size, v);
+ return clib_sysfs_get_xxx_hugepages ("surplus", numa_node, log2_page_size,
+ v);
}
clib_error_t *
-clib_sysfs_prealloc_hugepages (int numa_node, int page_size, int nr)
+clib_sysfs_prealloc_hugepages (int numa_node, int log2_page_size, int nr)
{
clib_error_t *error = 0;
int n, needed;
- error = clib_sysfs_get_free_hugepages (numa_node, page_size, &n);
+ int page_size = log2_page_size ? 1ULL << (log2_page_size - 10) :
+ DEFAULT_HUGETLB_SIZE;
+ error = clib_sysfs_get_free_hugepages (numa_node, log2_page_size, &n);
if (error)
return error;
needed = nr - n;
if (needed <= 0)
return 0;
- error = clib_sysfs_get_nr_hugepages (numa_node, page_size, &n);
+ error = clib_sysfs_get_nr_hugepages (numa_node, log2_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 clib_sysfs_set_nr_hugepages (numa_node, page_size, n + needed);
+ return clib_sysfs_set_nr_hugepages (numa_node, log2_page_size, n + needed);
}