diff options
author | Damjan Marion <damarion@cisco.com> | 2016-09-27 17:51:13 +0200 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2016-09-27 19:39:46 +0000 |
commit | 20f6441c639771467a9699eed177ba5e22368d37 (patch) | |
tree | 9a6e726f8448cf9bef178fc71ec95c90ec4e2811 /vlib | |
parent | c08a1ed69639a7ee0579c6e41f8e21f8fc595530 (diff) |
Fix hugepage detection issue
Per-numa free hugepages number was not read correctly due
to wrong sysfs path.
Change-Id: I889111027d7f93c42e2e4673d8d4e8f75ae065b6
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'vlib')
-rw-r--r-- | vlib/vlib/unix/unix.h | 2 | ||||
-rw-r--r-- | vlib/vlib/unix/util.c | 33 |
2 files changed, 35 insertions, 0 deletions
diff --git a/vlib/vlib/unix/unix.h b/vlib/vlib/unix/unix.h index 510e3f19..69688a62 100644 --- a/vlib/vlib/unix/unix.h +++ b/vlib/vlib/unix/unix.h @@ -213,6 +213,8 @@ clib_error_t *vlib_sysfs_read (char *file_name, char *fmt, ...); u8 *vlib_sysfs_link_to_name (char *link); +int vlib_sysfs_get_free_hugepages (unsigned int numa_node, int page_size); + clib_error_t *foreach_directory_file (char *dir_name, clib_error_t * (*f) (void *arg, u8 * path_name, diff --git a/vlib/vlib/unix/util.c b/vlib/vlib/unix/util.c index fc243e41..edc3e591 100644 --- a/vlib/vlib/unix/util.c +++ b/vlib/vlib/unix/util.c @@ -189,6 +189,39 @@ vlib_sysfs_link_to_name (char *link) return s; } +int +vlib_sysfs_get_free_hugepages (unsigned int numa_node, int page_size) +{ + struct stat sb; + u8 *p = 0; + int r = -1; + + 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) + 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) + goto done; + } + else + goto done; + + _vec_len (p) -= 1; + p = format (p, "/hugepages/hugepages-%ukB/free_hugepages%c", page_size, 0); + vlib_sysfs_read ((char *) p, "%d", &r); + +done: + vec_free (p); + return r; +} + /* * fd.io coding-style-patch-verification: ON * |