48 uword lo_offset, hi_offset;
70 hi_offset = lo_offset + n_bytes - 1;
84 for (i = 0; i <
vec_len (to_free); i++)
89 return lo_offset != ~0 ? pm->
heap + lo_offset : 0;
106 shmctl (pm->
shmid, IPC_RMID, 0);
115 u64 hugepagesize, pagesize;
117 u64 cur, physaddr, ptbits;
121 IPC_CREAT | SHM_HUGETLB | SHM_R | SHM_W);
131 shmctl (pm->
shmid, IPC_RMID, 0);
138 hugepagesize = 2<<20;
148 fd = open(
"/proc/self/pagemap", O_RDONLY);
166 pfn = (
u64) cur / pagesize;
167 seek_loc = pfn *
sizeof (
u64);
168 if (lseek (fd, seek_loc, SEEK_SET) != seek_loc)
171 shmctl (pm->
shmid, IPC_RMID, 0);
175 if (read (fd, &ptbits,
sizeof (ptbits)) != (
sizeof(ptbits)))
178 shmctl (pm->
shmid, IPC_RMID, 0);
184 physaddr = (ptbits & 0x7fffffffffffffULL) * pagesize;
186 fformat(stderr,
"pm: virtual 0x%llx physical 0x%llx\n",
209 char * dev_uio_dma_file =
"/dev/uio-dma";
210 int using_fake_memory = 0;
218 pm->
mem = MAP_FAILED;
227 if (physical_memory_required)
231 fformat(stderr,
"%s: use huge pages\n", __FUNCTION__);
234 pm->
uio_dma_fd = open (dev_uio_dma_file, O_RDWR);
241 if (physical_memory_required)
247 using_fake_memory = 1;
248 pm->
mem = mmap (0, pm->
mem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
249 if (pm->
mem == MAP_FAILED)
269 if (using_fake_memory)
270 fformat(stderr,
"%s: use fake dma pages\n", __FUNCTION__);
272 fformat(stderr,
"%s: use uio dma pages\n", __FUNCTION__);
277 if (pm->
mem != MAP_FAILED)
307 .path =
"show physmem",
308 .short_help =
"Show physical memory allocation",
318 cpu_set_t *setp = &
set;
321 int first_set_bit_in_run = -1;
322 int last_set_bit_in_run = -1;
325 rv = sched_getaffinity (0 ,
326 sizeof (*setp), setp);
334 for (i = 0; i < 64; i++)
336 if (CPU_ISSET(i, setp))
338 if (first_set_bit_in_run == -1)
340 first_set_bit_in_run =
i;
341 last_set_bit_in_run =
i;
349 if (i == (last_set_bit_in_run+1))
350 last_set_bit_in_run =
i;
355 if (first_set_bit_in_run != -1)
357 if (first_set_bit_in_run == (i-1))
359 _vec_len (s) -= 2 + ((first_set_bit_in_run/10));
361 s =
format (s,
"%d", last_set_bit_in_run);
362 first_set_bit_in_run = -1;
363 last_set_bit_in_run = -1;
368 if (first_set_bit_in_run != -1)
369 s =
format (s,
"%d", first_set_bit_in_run);
376 .path =
"show affinity",
377 .short_help =
"Show process cpu affinity",
387 cpu_set_t *setp = &
set;
392 memset (setp, 0,
sizeof (*setp));
396 if (
unformat (input,
"%d-%d,", &first, &last))
398 if (first > 64 || last > 64)
405 for (i = first; i <=
last; i++)
409 else if (
unformat (input,
"%d-%d", &first, &last))
411 if (first > 64 || last > 64)
414 for (i = first; i <=
last; i++)
417 else if (
unformat (input,
"%d,", &first))
425 CPU_SET(first, setp);
428 else if (
unformat (input,
"%d", &first))
433 CPU_SET(first, setp);
435 }
while (another_round);
437 rv = sched_setaffinity (0 ,
438 sizeof (*setp), setp);
450 .path =
"set affinity",
451 .short_help =
"Set process cpu affinity",
466 else if (
unformat(input,
"size-in-mb %d", &size_in_mb) ||
467 unformat(input,
"size %d", &size_in_mb))
sll srl srl sll sra u16x4 i
static void(BVT(clib_bihash)*h, BVT(clib_bihash_value)*v)
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)
void *(* os_physmem_alloc_aligned)(vlib_physmem_main_t *pm, uword n_bytes, uword alignment)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static physmem_main_t physmem_main
u8 * format_mheap(u8 *s, va_list *va)
int vlib_app_physmem_init(vlib_main_t *vm, physmem_main_t *pm, int)
always_inline heap_elt_t * last(heap_header_t *h)
static int htlb_init(vlib_main_t *vm)
#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)
always_inline 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 * 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...)
#define VLIB_CLI_COMMAND(x,...)
void * mheap_alloc_with_flags(void *memory, uword memory_size, uword flags)
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)
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
always_inline uword min_log2(uword x)
#define clib_error_return(e, args...)
always_inline uword pow2_mask(uword x)
#define CLIB_CACHE_LINE_BYTES
void(* os_physmem_free)(void *x)