diff options
Diffstat (limited to 'src/vppinfra/linux/sysfs.c')
-rw-r--r-- | src/vppinfra/linux/sysfs.c | 33 |
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); } |