diff options
Diffstat (limited to 'src/vppinfra')
-rw-r--r-- | src/vppinfra/format.h | 6 | ||||
-rw-r--r-- | src/vppinfra/linux/mem.c | 5 | ||||
-rw-r--r-- | src/vppinfra/mem.h | 23 | ||||
-rw-r--r-- | src/vppinfra/pmalloc.c | 18 | ||||
-rw-r--r-- | src/vppinfra/std-formats.c | 68 |
5 files changed, 98 insertions, 22 deletions
diff --git a/src/vppinfra/format.h b/src/vppinfra/format.h index 678029e2a16..e71c7b347e8 100644 --- a/src/vppinfra/format.h +++ b/src/vppinfra/format.h @@ -298,6 +298,12 @@ unformat_function_t unformat_memory_size; /* Unparse memory size e.g. 100, 100k, 100m, 100g. */ u8 *format_memory_size (u8 * s, va_list * va); +/* Parse memory page size e.g. 4K, 2M */ +unformat_function_t unformat_log2_page_size; + +/* Unparse memory page size e.g. 4K, 2M */ +u8 *format_log2_page_size (u8 * s, va_list * va); + /* Format c identifier: e.g. a_name -> "a name". */ u8 *format_c_identifier (u8 * s, va_list * va); diff --git a/src/vppinfra/linux/mem.c b/src/vppinfra/linux/mem.c index 5826a6a7e49..c5811816c1f 100644 --- a/src/vppinfra/linux/mem.c +++ b/src/vppinfra/linux/mem.c @@ -103,7 +103,8 @@ clib_mem_get_fd_log2_page_size (int fd) } void -clib_mem_vm_randomize_va (uword * requested_va, u32 log2_page_size) +clib_mem_vm_randomize_va (uword * requested_va, + clib_mem_page_sz_t log2_page_size) { u8 bit_mask = 15; @@ -345,7 +346,7 @@ clib_mem_vm_ext_free (clib_mem_vm_alloc_t * a) } uword -clib_mem_vm_reserve (uword start, uword size, u32 log2_page_sz) +clib_mem_vm_reserve (uword start, uword size, clib_mem_page_sz_t log2_page_sz) { uword off, pagesize = 1ULL << log2_page_sz; int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS; diff --git a/src/vppinfra/mem.h b/src/vppinfra/mem.h index c97ee8af157..31c5fd841ad 100644 --- a/src/vppinfra/mem.h +++ b/src/vppinfra/mem.h @@ -54,6 +54,23 @@ #define CLIB_MAX_MHEAPS 256 #define CLIB_MAX_NUMAS 8 +typedef enum +{ + CLIB_MEM_PAGE_SZ_UNKNOWN = 0, + CLIB_MEM_PAGE_SZ_DEFAULT = 1, + CLIB_MEM_PAGE_SZ_DEFAULT_HUGE = 2, + CLIB_MEM_PAGE_SZ_4K = 12, + CLIB_MEM_PAGE_SZ_16K = 14, + CLIB_MEM_PAGE_SZ_64K = 16, + CLIB_MEM_PAGE_SZ_1M = 20, + CLIB_MEM_PAGE_SZ_2M = 21, + CLIB_MEM_PAGE_SZ_16M = 24, + CLIB_MEM_PAGE_SZ_32M = 25, + CLIB_MEM_PAGE_SZ_512M = 29, + CLIB_MEM_PAGE_SZ_1G = 30, + CLIB_MEM_PAGE_SZ_16G = 34, +} clib_mem_page_sz_t; + /* Unspecified NUMA socket */ #define VEC_NUMA_UNSPECIFIED (0xFF) @@ -410,7 +427,8 @@ void clib_mem_vm_ext_free (clib_mem_vm_alloc_t * a); u64 clib_mem_get_fd_page_size (int fd); uword clib_mem_get_default_hugepage_size (void); int clib_mem_get_fd_log2_page_size (int fd); -uword clib_mem_vm_reserve (uword start, uword size, u32 log2_page_sz); +uword clib_mem_vm_reserve (uword start, uword size, + clib_mem_page_sz_t log2_page_sz); u64 *clib_mem_vm_get_paddr (void *mem, int log2_page_size, int n_pages); void clib_mem_destroy_mspace (void *mspace); void clib_mem_destroy (void); @@ -425,7 +443,8 @@ typedef struct } clib_mem_vm_map_t; clib_error_t *clib_mem_vm_ext_map (clib_mem_vm_map_t * a); -void clib_mem_vm_randomize_va (uword * requested_va, u32 log2_page_size); +void clib_mem_vm_randomize_va (uword * requested_va, + clib_mem_page_sz_t log2_page_size); void mheap_trace (void *v, int enable); uword clib_mem_trace_enable_disable (uword enable); void clib_mem_trace (int enable); diff --git a/src/vppinfra/pmalloc.c b/src/vppinfra/pmalloc.c index e0f3f3a6585..870f3647229 100644 --- a/src/vppinfra/pmalloc.c +++ b/src/vppinfra/pmalloc.c @@ -584,24 +584,6 @@ clib_pmalloc_free (clib_pmalloc_main_t * pm, void *va) } static u8 * -format_log2_page_size (u8 * s, va_list * va) -{ - u32 log2_page_sz = va_arg (*va, u32); - - if (log2_page_sz >= 30) - return format (s, "%uGB", 1 << (log2_page_sz - 30)); - - if (log2_page_sz >= 20) - return format (s, "%uMB", 1 << (log2_page_sz - 20)); - - if (log2_page_sz >= 10) - return format (s, "%uKB", 1 << (log2_page_sz - 10)); - - return format (s, "%uB", 1 << log2_page_sz); -} - - -static u8 * format_pmalloc_page (u8 * s, va_list * va) { clib_pmalloc_page_t *pp = va_arg (*va, clib_pmalloc_page_t *); diff --git a/src/vppinfra/std-formats.c b/src/vppinfra/std-formats.c index 62d309e2fb0..f4892d6d6f4 100644 --- a/src/vppinfra/std-formats.c +++ b/src/vppinfra/std-formats.c @@ -268,6 +268,74 @@ unformat_memory_size (unformat_input_t * input, va_list * va) return 1; } +/* Unparse memory page size e.g. 4K, 2M */ +u8 * +format_log2_page_size (u8 * s, va_list * va) +{ + clib_mem_page_sz_t log2_page_sz = va_arg (*va, clib_mem_page_sz_t); + + if (log2_page_sz == CLIB_MEM_PAGE_SZ_UNKNOWN) + return format (s, "unknown"); + + if (log2_page_sz == CLIB_MEM_PAGE_SZ_DEFAULT) + return format (s, "default"); + + if (log2_page_sz == CLIB_MEM_PAGE_SZ_DEFAULT_HUGE) + return format (s, "default-hugepage"); + + if (log2_page_sz >= 30) + return format (s, "%uG", 1 << (log2_page_sz - 30)); + + if (log2_page_sz >= 20) + return format (s, "%uM", 1 << (log2_page_sz - 20)); + + if (log2_page_sz >= 10) + return format (s, "%uK", 1 << (log2_page_sz - 10)); + + return format (s, "%u", 1 << log2_page_sz); +} + +/* Parse memory page size e.g. 4K, 2M */ +uword +unformat_log2_page_size (unformat_input_t * input, va_list * va) +{ + uword amount, shift, c; + clib_mem_page_sz_t *result = va_arg (*va, clib_mem_page_sz_t *); + + if (unformat (input, "default")) + return CLIB_MEM_PAGE_SZ_DEFAULT; + + if (unformat (input, "default-hugepage")) + return CLIB_MEM_PAGE_SZ_DEFAULT_HUGE; + + if (!unformat (input, "%wd%_", &amount)) + return CLIB_MEM_PAGE_SZ_UNKNOWN; + + c = unformat_get_input (input); + switch (c) + { + case 'k': + case 'K': + shift = 10; + break; + case 'm': + case 'M': + shift = 20; + break; + case 'g': + case 'G': + shift = 30; + break; + default: + shift = 0; + unformat_put_input (input); + break; + } + + *result = min_log2 (amount) + shift; + return 1; +} + /* Format c identifier: e.g. a_name -> "a name". Works for both vector names and null terminated c strings. */ u8 * |