49 uword lo_offset, hi_offset;
71 hi_offset = lo_offset + n_bytes - 1;
85 for (i = 0; i <
vec_len (to_free); i++)
90 return lo_offset != ~0 ? pm->
heap + lo_offset : 0;
109 shmctl (pm->
shmid, IPC_RMID, 0);
119 u64 hugepagesize, pagesize;
121 u64 cur, physaddr, ptbits;
125 IPC_CREAT | SHM_HUGETLB | SHM_R | SHM_W);
135 shmctl (pm->
shmid, IPC_RMID, 0);
142 hugepagesize = 2 << 20;
152 fd = open (
"/proc/self/pagemap", O_RDONLY);
156 (void) shmdt (pm->
mem);
169 pfn = (
u64) cur / pagesize;
170 seek_loc = pfn *
sizeof (
u64);
171 if (lseek (fd, seek_loc, SEEK_SET) != seek_loc)
174 shmctl (pm->
shmid, IPC_RMID, 0);
178 if (read (fd, &ptbits,
sizeof (ptbits)) != (
sizeof (ptbits)))
181 shmctl (pm->
shmid, IPC_RMID, 0);
187 physaddr = (ptbits & 0x7fffffffffffffULL) * pagesize;
189 fformat (stderr,
"pm: virtual 0x%llx physical 0x%llx\n",
221 pm->
mem = MAP_FAILED;
232 fformat (stderr,
"%s: use huge pages\n", __FUNCTION__);
237 mmap (0, pm->
mem_size, PROT_READ | PROT_WRITE,
238 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
239 if (pm->
mem == MAP_FAILED)
257 fformat (stderr,
"%s: use fake dma pages\n", __FUNCTION__);
262 if (pm->
mem != MAP_FAILED)
287 .path =
"show physmem",
288 .short_help =
"Show physical memory allocation",
298 cpu_set_t *setp = &
set;
301 int first_set_bit_in_run = -1;
302 int last_set_bit_in_run = -1;
305 rv = sched_getaffinity (0 ,
306 sizeof (*setp), setp);
314 for (i = 0; i < 64; i++)
316 if (CPU_ISSET (i, setp))
318 if (first_set_bit_in_run == -1)
320 first_set_bit_in_run =
i;
321 last_set_bit_in_run =
i;
329 if (i == (last_set_bit_in_run + 1))
330 last_set_bit_in_run =
i;
335 if (first_set_bit_in_run != -1)
337 if (first_set_bit_in_run == (i - 1))
339 _vec_len (s) -= 2 + ((first_set_bit_in_run / 10));
341 s =
format (s,
"%d", last_set_bit_in_run);
342 first_set_bit_in_run = -1;
343 last_set_bit_in_run = -1;
348 if (first_set_bit_in_run != -1)
349 s =
format (s,
"%d", first_set_bit_in_run);
357 .path =
"show affinity",
358 .short_help =
"Show process cpu affinity",
368 cpu_set_t *setp = &
set;
373 memset (setp, 0,
sizeof (*setp));
378 if (
unformat (input,
"%d-%d,", &first, &last))
380 if (first > 64 || last > 64)
387 for (i = first; i <=
last; i++)
391 else if (
unformat (input,
"%d-%d", &first, &last))
393 if (first > 64 || last > 64)
396 for (i = first; i <=
last; i++)
399 else if (
unformat (input,
"%d,", &first))
407 CPU_SET (first, setp);
410 else if (
unformat (input,
"%d", &first))
415 CPU_SET (first, setp);
418 while (another_round);
420 rv = sched_setaffinity (0 ,
421 sizeof (*setp), setp);
434 .path =
"set affinity",
435 .short_help =
"Set process cpu affinity",
451 else if (
unformat (input,
"size-in-mb %d", &size_in_mb) ||
452 unformat (input,
"size %d", &size_in_mb))
sll srl srl sll sra u16x4 i
static clib_error_t * set_affinity(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
vlib_physmem_main_t physmem_main
void * mheap_alloc(void *memory, uword size)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static physmem_main_t physmem_main
static heap_elt_t * last(heap_header_t *h)
u8 * format_mheap(u8 *s, va_list *va)
int vlib_app_physmem_init(vlib_main_t *vm, physmem_main_t *pm, int)
static uword min_log2(uword x)
static int htlb_init(vlib_main_t *vm)
static uword pow2_mask(uword x)
#define MHEAP_FLAG_DISABLE_VM
#define clib_warning(format, args...)
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V...
static uword pointer_to_uword(const void *p)
static heap_elt_t * first(heap_header_t *h)
#define clib_error_return_unix(e, args...)
static clib_error_t * vlib_physmem_configure(vlib_main_t *vm, unformat_input_t *input)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static void * unix_physmem_alloc_aligned(vlib_physmem_main_t *vpm, uword n_bytes, uword alignment)
static void htlb_shutdown(void)
static clib_error_t * show_affinity(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
void *(* os_physmem_alloc_aligned)(vlib_physmem_main_t *pm, uword n_bytes, uword alignment)
void * mheap_get_aligned(void *v, uword n_user_data_bytes, uword align, uword align_offset, uword *offset_return)
#define vec_free(V)
Free vector's memory (no header).
#define clib_unix_warning(format, args...)
void * mheap_alloc_with_flags(void *memory, uword memory_size, uword flags)
void(* os_physmem_free)(void *x)
uword log2_n_bytes_per_page
static void unix_physmem_free(void *x)
static clib_error_t * show_physmem(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
VLIB_CLI_COMMAND(set_interface_ip_source_and_port_range_check_command, static)
void mheap_put(void *v, uword uoffset)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
clib_error_t * unix_physmem_init(vlib_main_t *vm, int physical_memory_required)
vlib_physmem_region_t virtual
#define CLIB_CACHE_LINE_BYTES