FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
svm.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * svm.h - shared VM allocation, mmap(...MAP_FIXED...)
4  * brain police
5  *
6  * Copyright (c) 2009 Cisco and/or its affiliates.
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at:
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *------------------------------------------------------------------
19  */
20 
21 #ifndef __included_svm_h__
22 #define __included_svm_h__
23 
24 #include <pthread.h>
25 #include <vppinfra/clib.h>
26 #include <vppinfra/mem.h>
27 #include <svm/svm_common.h>
28 
29 #define MMAP_PAGESIZE (clib_mem_get_page_size())
30 
31 static inline void *
33 {
34  clib_mem_heap_t *oldheap;
36  u8 *rv;
37 
38  pthread_mutex_lock (&rp->mutex);
39  oldheap = clib_mem_set_heap (rp->data_heap);
41  clib_mem_set_heap (oldheap);
42  pthread_mutex_unlock (&rp->mutex);
43  return (rv);
44 }
45 
46 static inline void *
48  uword size, uword align, uword offset)
49 {
50  clib_mem_heap_t *oldheap;
52  u8 *rv;
53 
54  pthread_mutex_lock (&rp->mutex);
55  oldheap = clib_mem_set_heap (rp->data_heap);
57  1 /* yes, call os_out_of_memory */ );
58  clib_mem_set_heap (oldheap);
59  pthread_mutex_unlock (&rp->mutex);
60  return (rv);
61 }
62 
63 static inline void
64 svm_mem_free (svm_region_t * rp, void *ptr)
65 {
66  clib_mem_heap_t *oldheap;
68 
69  pthread_mutex_lock (&rp->mutex);
70  oldheap = clib_mem_set_heap (rp->data_heap);
71  clib_mem_free (ptr);
72  clib_mem_set_heap (oldheap);
73  pthread_mutex_unlock (&rp->mutex);
74 
75 }
76 
77 static inline void *
79 {
80  clib_mem_heap_t *oldheap;
81  oldheap = clib_mem_set_heap (rp->region_heap);
82  return ((void *) oldheap);
83 }
84 
85 static inline void *
87 {
88  clib_mem_heap_t *oldheap;
89  oldheap = clib_mem_set_heap (rp->data_heap);
90  return ((void *) oldheap);
91 }
92 
93 static inline void
94 svm_pop_heap (void *oldheap)
95 {
96  clib_mem_set_heap (oldheap);
97 }
98 
99 #endif /* __included_svm_h__ */
100 
101 /*
102  * fd.io coding-style-patch-verification: ON
103  *
104  * Local Variables:
105  * eval: (c-set-style "gnu")
106  * End:
107  */
svm_region_::data_heap
void * data_heap
Definition: svm_common.h:47
clib.h
clib_mem_free
static void clib_mem_free(void *p)
Definition: mem.h:314
svm_common.h
svm_mem_alloc_aligned_at_offset
static void * svm_mem_alloc_aligned_at_offset(svm_region_t *rp, uword size, uword align, uword offset)
Definition: svm.h:47
svm_region_::mutex
pthread_mutex_t mutex
Definition: svm_common.h:38
svm_mem_alloc
static void * svm_mem_alloc(svm_region_t *rp, uword size)
Definition: svm.h:32
uword
u64 uword
Definition: types.h:112
svm_pop_heap
static void svm_pop_heap(void *oldheap)
Definition: svm.h:94
size
u32 size
Definition: vhost_user.h:125
clib_bihash_value
template key/value backing page structure
Definition: bihash_doc.h:44
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
svm_mem_free
static void svm_mem_free(svm_region_t *rp, void *ptr)
Definition: svm.h:64
svm_region_::flags
uword flags
Definition: svm_common.h:42
svm_region_::region_heap
void * region_heap
Definition: svm_common.h:45
svm_push_pvt_heap
static void * svm_push_pvt_heap(svm_region_t *rp)
Definition: svm.h:78
svm_region_
Definition: svm_common.h:35
u8
unsigned char u8
Definition: types.h:56
clib_mem_alloc_aligned_at_offset
static void * clib_mem_alloc_aligned_at_offset(uword size, uword align, uword align_offset, int os_out_of_memory_on_failure)
Definition: mem.h:225
rv
int __clib_unused rv
Definition: application.c:491
mem.h
SVM_FLAGS_MHEAP
#define SVM_FLAGS_MHEAP
Definition: svm_common.h:28
svm_push_data_heap
static void * svm_push_data_heap(svm_region_t *rp)
Definition: svm.h:86
clib_mem_set_heap
static clib_mem_heap_t * clib_mem_set_heap(clib_mem_heap_t *heap)
Definition: mem.h:368
clib_mem_heap_t
Definition: mem.h:107
clib_mem_alloc
static void * clib_mem_alloc(uword size)
Definition: mem.h:256