FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
svm_common.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2009 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #ifndef __included_svm_common_h__
19 #define __included_svm_common_h__
20 
21 #include <stdarg.h>
22 #include <pthread.h>
23 #include <vppinfra/types.h>
24 
25 #define SVM_VERSION ((1<<16) | 1) /* set to declare region ready. */
26 
27 #define SVM_FLAGS_MHEAP (1<<0) /* region contains an mheap */
28 #define SVM_FLAGS_FILE (1<<1) /* region backed by one or more files */
29 #define SVM_FLAGS_NODATA (1<<2) /* region will be further subdivided */
30 #define SVM_FLAGS_NEED_DATA_INIT (1<<3)
31 
32 #define SVM_PVT_MHEAP_SIZE (128<<10) /* region's private mheap (128k) */
33 
34 typedef struct svm_region_
35 {
36  volatile uword version;
37  pthread_mutex_t mutex;
38  pthread_cond_t condvar;
39  int mutex_owner_pid; /* in case of trouble */
42  uword virtual_base; /* base of the region object */
44  void *region_heap;
45  void *data_base; /* data portion base address */
46  void *data_heap; /* data heap, if any */
47  volatile void *user_ctx; /* user context pointer */
48  /* stuff allocated in the region's heap */
49  uword bitmap_size; /* nbits in virtual alloc bitmap */
50  uword *bitmap; /* the bitmap */
51  char *region_name;
52  char *backing_file;
53  char **filenames;
55  /* pad */
56 
57  /* next page:
58  * (64K) clib heap for the region itself
59  *
60  * data_base -> whatever is in this region
61  */
62 
63 } svm_region_t;
64 
65 typedef struct svm_map_region_args_
66 {
67  const char *root_path; /* NULL means use the truly global arena */
68  const char *name;
73  char *backing_file;
75  /* uid, gid to own the svm region(s) */
76  int uid;
77  int gid;
79 
80 
81 /*
82  * Memory shared across all router instances. Packet buffers, etc
83  * Base should be "out of the way," and size should be big enough to
84  * cover everything we plan to put here.
85  */
86 #define SVM_GLOBAL_REGION_SIZE (64<<20)
87 #define SVM_GLOBAL_REGION_NAME "/global_vm"
88 #if defined (__aarch64__)
89 #define VA_BITS 48
90 #define BASEVA ((1ul << VA_BITS) / 4)
91 #define SVM_GLOBAL_REGION_BASEVA (BASEVA - (2 * SVM_GLOBAL_REGION_SIZE))
92 #else
93 #define SVM_GLOBAL_REGION_BASEVA 0x30000000
94 #endif
95 
96 /*
97  * Memory shared across individual router instances.
98  */
99 #define SVM_OVERLAY_REGION_BASEVA \
100  (SVM_GLOBAL_REGION_BASEVA + SVM_GLOBAL_REGION_SIZE)
101 #define SVM_OVERLAY_REGION_SIZE (1<<20)
102 #define SVM_OVERLAY_REGION_BASENAME "/overlay_vm"
103 
104 typedef struct
105 {
108 
109 typedef struct
110 {
111  svm_subregion_t *subregions; /* subregion pool */
114  int uid;
115  int gid;
117 
118 
120 void svm_region_init (void);
122  svm_region_t * rp);
123 int svm_region_init_chroot (const char *root_path);
124 void svm_region_init_chroot_uid_gid (const char *root_path, int uid, int gid);
126 void svm_region_exit (void);
127 void svm_region_unmap (void *rp_arg);
128 void svm_client_scan (const char *root_path);
131 u8 *format_svm_region (u8 * s, va_list * args);
132 
134 
135 #endif /* __included_svm_common_h__ */
136 
137 /*
138  * fd.io coding-style-patch-verification: ON
139  *
140  * Local Variables:
141  * eval: (c-set-style "gnu")
142  * End:
143  */
const char * root_path
Definition: svm_common.h:67
a
Definition: bitmap.h:516
u8 * format_svm_region(u8 *s, va_list *args)
Definition: svm.c:143
uword virtual_base
Definition: svm_common.h:42
void svm_region_unmap(void *rp_arg)
Definition: svm.c:1000
struct svm_map_region_args_ svm_map_region_args_t
uword * client_pids
Definition: svm_common.h:54
volatile void * user_ctx
Definition: svm_common.h:47
unsigned long u64
Definition: types.h:89
svm_region_t * svm_get_root_rp(void)
Definition: svm.c:54
pthread_cond_t condvar
Definition: svm_common.h:38
int svm_region_init_chroot(const char *root_path)
Definition: svm.c:817
void * data_base
Definition: svm_common.h:45
void svm_region_init_args(svm_map_region_args_t *a)
Definition: svm.c:851
struct svm_region_ svm_region_t
svm_subregion_t * subregions
Definition: svm_common.h:111
char * backing_file
Definition: svm_common.h:52
uword virtual_size
Definition: svm_common.h:43
char * region_name
Definition: svm_common.h:51
void svm_client_scan_this_region_nolock(svm_region_t *rp)
Definition: svm.c:1168
void svm_region_init_mapped_region(svm_map_region_args_t *a, svm_region_t *rp)
Definition: svm.c:438
void svm_region_init(void)
Definition: svm.c:800
uword bitmap_size
Definition: svm_common.h:49
u8 * shm_name_from_svm_map_region_args(svm_map_region_args_t *a)
Definition: svm.c:388
void svm_client_scan(const char *root_path)
Definition: svm.c:1196
volatile uword version
Definition: svm_common.h:36
int mutex_owner_tag
Definition: svm_common.h:40
void svm_region_init_chroot_uid_gid(const char *root_path, int uid, int gid)
Definition: svm.c:834
u64 uword
Definition: types.h:112
void svm_region_exit(void)
Definition: svm.c:1117
void * svm_region_find_or_create(svm_map_region_args_t *a)
Definition: svm.c:857
unsigned char u8
Definition: types.h:56
const char * name
Definition: svm_common.h:68
void * region_heap
Definition: svm_common.h:44
uword * bitmap
Definition: svm_common.h:50
char ** filenames
Definition: svm_common.h:53
void * data_heap
Definition: svm_common.h:46
int mutex_owner_pid
Definition: svm_common.h:39
uword flags
Definition: svm_common.h:41
pthread_mutex_t mutex
Definition: svm_common.h:37