|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
23 #include <sys/types.h>
26 #include <netinet/in.h>
72 if ((fd = open (
"/proc/self/maps", 0)) < 0)
87 if (bits >= 36 && bits <= 48)
93 #ifdef CLIB_SANITIZE_ADDR
94 return 0x200000000000;
97 return 0x130000000ULL;
103 pthread_mutex_lock (&rp->
mutex);
140 pthread_mutex_unlock (&rp->
mutex);
154 s =
format (s,
"NODATA ");
166 if (
size >= (1 << 20))
170 else if (
size >= (1 << 10))
185 int verbose = va_arg (*args,
int);
189 s =
format (s,
"%s: base va 0x%x size 0x%x %U\n",
192 s =
format (s,
" user_ctx 0x%x, bitmap_size %d\n",
200 " region_heap 0x%x data_base 0x%x data_heap 0x%x\n",
215 s =
format (s,
" VM in use: ");
235 s =
format (s,
" 0x%x - 0x%x (%dk)\n",
lo,
hi,
270 (
a->pvt_heap_size ?
a->pvt_heap_size :
277 fd = open (
a->backing_file, O_RDWR | O_CREAT, 0777);
285 if (fstat (fd, &statb) < 0)
292 if (statb.st_mode & S_IFREG)
294 if (statb.st_size == 0)
296 if (lseek (fd, map_size, SEEK_SET) == (off_t) - 1)
302 if (write (fd, &junk, 1) != 1)
316 map_size =
a->backing_mmap_size;
319 ASSERT (map_size <= rp->virtual_size -
322 if (mmap (rp->
data_base, map_size, PROT_READ | PROT_WRITE,
323 MAP_SHARED | MAP_FIXED, fd, 0) == MAP_FAILED)
360 fd = open (
a->backing_file, O_RDWR, 0777);
368 if (fstat (fd, &statb) < 0)
375 if (statb.st_mode & S_IFREG)
377 if (statb.st_size == 0)
379 if (lseek (fd, map_size, SEEK_SET) == (off_t) - 1)
385 if (write (fd, &junk, 1) != 1)
399 map_size =
a->backing_mmap_size;
402 ASSERT (map_size <= rp->virtual_size
407 if (mmap (rp->
data_base, map_size, PROT_READ | PROT_WRITE,
408 MAP_SHARED | MAP_FIXED, fd, 0) == MAP_FAILED)
424 int root_path_offset = 0;
430 if (
a->root_path[0] ==
'/')
433 if (
a->name[0] ==
'/')
436 shm_name =
format (0,
"/%s-%s%c", &
a->root_path[root_path_offset],
437 &
a->name[name_offset], 0);
440 shm_name =
format (0,
"%s%c",
a->name, 0);
447 pthread_mutexattr_t attr;
448 pthread_condattr_t cattr;
449 int nbits, words, bit;
458 if (pthread_mutexattr_init (&attr))
461 if (pthread_mutexattr_setpshared (&attr, PTHREAD_PROCESS_SHARED))
464 if (pthread_mutex_init (&rp->
mutex, &attr))
467 if (pthread_mutexattr_destroy (&attr))
470 if (pthread_condattr_init (&cattr))
473 if (pthread_condattr_setpshared (&cattr, PTHREAD_PROCESS_SHARED))
476 if (pthread_cond_init (&rp->
condvar, &cattr))
479 if (pthread_condattr_destroy (&cattr))
521 while (overhead_space > 0);
557 int pid_holding_region_lock;
559 int dead_region_recovery = 0;
562 struct timespec ts, tsrem;
571 getpid (),
a->name, shm_name);
573 svm_fd = shm_open ((
char *) shm_name, O_RDWR | O_CREAT | O_EXCL, 0777);
577 if (fchmod (svm_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
580 if (fchown (svm_fd,
a->uid,
a->gid) < 0)
585 if (lseek (svm_fd,
a->size, SEEK_SET) == (off_t) - 1)
591 if (write (svm_fd, &junk, 1) != 1)
599 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, svm_fd, 0);
612 return ((
void *) rp);
616 svm_fd = shm_open ((
char *) shm_name, O_RDWR, 0777);
622 perror (
"svm_region_map(mmap open)");
627 if (fchown (svm_fd,
a->uid,
a->gid) < 0)
633 if (0 != fstat (svm_fd, &stat))
639 if (stat.st_size > 0)
645 clib_warning (
"waiting for resize of shm file timed out");
650 ts.tv_nsec = 100000000;
651 while (nanosleep (&ts, &tsrem) < 0)
657 PROT_READ | PROT_WRITE, MAP_SHARED, svm_fd, 0);
672 while (rp->
version == 0 && deadman++ < 5)
684 munmap (rp,
a->size);
693 PROT_READ | PROT_WRITE,
694 MAP_SHARED | MAP_FIXED, svm_fd, 0);
716 if (pid_holding_region_lock && kill (pid_holding_region_lock, 0) < 0)
718 pthread_mutexattr_t attr;
720 (
"region %s mutex held by dead pid %d, tag %d, force unlock",
723 if (pthread_mutexattr_init (&attr))
725 if (pthread_mutexattr_setpshared (&attr, PTHREAD_PROCESS_SHARED))
727 if (pthread_mutex_init (&rp->
mutex, &attr))
729 dead_region_recovery = 1;
732 if (dead_region_recovery)
739 if (dead_region_recovery)
748 if (dead_region_recovery)
755 return ((
void *) rp);
776 uword randomize_baseva;
792 a->baseva += randomize_baseva;
846 a->root_path = root_path;
863 a->root_path = root_path;
905 if (
a->root_path == NULL)
937 for (
i = 0;
i < (need_nbits - 1);
i++)
950 while (index < root_rp->bitmap_size);
955 clib_warning (
"region %s: not enough VM to allocate 0x%llx (%lld)",
969 for (
i = 0;
i < need_nbits;
i++)
1010 clib_warning (
"[%d] shm_unlink (%s)", getpid (), shm_name);
1011 shm_unlink ((
const char *) shm_name);
1026 int i, mypid = getpid ();
1029 uword virtual_base, virtual_size;
1073 if (nclients_left == 0)
1097 for (
i = 0;
i < nbits;
i++)
1131 munmap ((
void *) virtual_base, virtual_size);
1140 munmap ((
void *) virtual_base, virtual_size);
1162 int i, mypid = getpid ();
1163 uword virtual_base, virtual_size;
1207 munmap ((
void *) virtual_base, virtual_size);
1226 int mypid = getpid ();
1262 int mypid = getpid ();
1306 a->root_path = root_path;
1307 a->name = (
char *) svm_names[
i];
1311 pthread_mutex_lock (&rp->
mutex);
1315 pthread_mutex_unlock (&rp->
mutex);
#define SVM_GLOBAL_REGION_SIZE
#define SVM_FLAGS_NEED_DATA_INIT
void svm_region_exit(void)
static void region_unlock(svm_region_t *rp)
static int svm_region_init_internal(svm_map_region_args_t *a)
svm_region_t * svm_get_root_rp(void)
void svm_region_unlink(svm_region_t *rp)
void svm_region_unmap_client(void *rp_arg)
#define vec_c_string_is_terminated(V)
Test whether a vector is a NULL terminated c-string.
void svm_region_exit_client(void)
void svm_region_init(void)
int svm_region_init_chroot(const char *root_path)
#define count_leading_zeros(x)
void svm_region_unmap(void *rp_arg)
#define hash_create_string(elts, value_bytes)
#define hash_set_mem(h, key, value)
#define pool_put(P, E)
Free an object E in pool P.
#define vec_delete(V, N, M)
Delete N elements starting at element M.
void * svm_map_region(svm_map_region_args_t *a)
void svm_region_init_chroot_uid_gid(const char *root_path, int uid, int gid)
static u64 rnd_pagesize(u64 size)
static u8 * format_svm_size(u8 *s, va_list *args)
#define clib_unix_warning(format, args...)
void svm_region_init_args(svm_map_region_args_t *a)
void svm_region_init_mapped_region(svm_map_region_args_t *a, svm_region_t *rp)
#define pool_foreach(VAR, POOL)
Iterate through pool.
clib_mem_heap_t * clib_mem_create_heap(void *base, uword size, int is_locked, char *fmt,...)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void * svm_region_find_or_create(svm_map_region_args_t *a)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define hash_unset_mem(h, key)
#define vec_dup(V)
Return copy of vector (no header, no alignment)
#define clib_unix_error(format, args...)
f64 end
end of the time range
if(node->flags &VLIB_NODE_FLAG_TRACE) vnet_interface_output_trace(vm
static void svm_pop_heap(void *oldheap)
svm_subregion_t * subregions
Fixed length block allocator. Pools are built from clib vectors and bitmaps. Use pools when repeatedl...
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
#define CLIB_MEMORY_BARRIER()
static int root_rp_refcount
static uword clib_bitmap_get_no_check(uword *ai, uword i)
Gets the ith bit value from a bitmap Does not sanity-check the bit position.
#define hash_get_mem(h, key)
#define vec_free(V)
Free vector's memory (no header).
static svm_region_t * root_rp
static void svm_region_exit_internal(u8 is_client)
u64 svm_get_global_region_base_va()
static int svm_data_region_create(svm_map_region_args_t *a, svm_region_t *rp)
static u8 * format_svm_flags(u8 *s, va_list *args)
description fragment has unexpected format
void svm_client_scan_this_region_nolock(svm_region_t *rp)
#define CLIB_MEM_UNPOISON(a, s)
u8 * format_svm_region(u8 *s, va_list *args)
static void region_lock(svm_region_t *rp, int tag)
static void * svm_push_pvt_heap(svm_region_t *rp)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void svm_mutex_cleanup(void)
#define SVM_GLOBAL_REGION_NAME
#define uword_to_pointer(u, type)
void svm_client_scan(const char *root_path)
#define SVM_PVT_MHEAP_SIZE
#define clib_warning(format, args...)
static pthread_mutex_t * mutexes_held[MAXLOCK]
void svm_region_unmap_internal(void *rp_arg, u8 is_client)
static uword clib_bitmap_set_no_check(uword *a, uword i, uword new_value)
Sets the ith bit of a bitmap to new_value.
static u64 clib_cpu_time_now(void)
u8 * shm_name_from_svm_map_region_args(svm_map_region_args_t *a)
#define vec_bytes(v)
Number of data bytes in vector.
static int svm_data_region_map(svm_map_region_args_t *a, svm_region_t *rp)