2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 #ifndef __included_ssvm_h__
16 #define __included_ssvm_h__
20 #include <sys/types.h>
23 #include <netinet/in.h>
30 #include <vppinfra/clib.h>
31 #include <vppinfra/vec.h>
32 #include <vppinfra/hash.h>
33 #include <vppinfra/bitmap.h>
34 #include <vppinfra/fifo.h>
35 #include <vppinfra/time.h>
36 #include <vppinfra/mheap.h>
37 #include <vppinfra/heap.h>
38 #include <vppinfra/pool.h>
39 #include <vppinfra/format.h>
42 #define MMAP_PAGESIZE (clib_mem_get_page_size())
45 #define SSVM_N_OPAQUE 7
51 volatile u32 owner_pid;
53 u32 tag; /* for debugging */
55 /* The allocation arena */
58 /* Segment must be mapped at this address, or no supper */
60 /* The actual mmap size */
65 void *opaque[SSVM_N_OPAQUE];
67 /* Set when the master application thinks it's time to make the donuts */
70 /* Needed to make unique MAC addresses, etc. */
72 } ssvm_shared_header_t;
76 ssvm_shared_header_t *sh;
83 u32 per_interface_next_index;
88 ssvm_lock (ssvm_shared_header_t * h, u32 my_pid, u32 tag)
90 if (h->owner_pid == my_pid)
96 while (__sync_lock_test_and_set (&h->lock, 1))
99 h->owner_pid = my_pid;
100 h->recursion_count = 1;
105 ssvm_lock_non_recursive (ssvm_shared_header_t * h, u32 tag)
107 while (__sync_lock_test_and_set (&h->lock, 1))
114 ssvm_unlock (ssvm_shared_header_t * h)
116 if (--h->recursion_count == 0)
120 CLIB_MEMORY_BARRIER ();
126 ssvm_unlock_non_recursive (ssvm_shared_header_t * h)
129 CLIB_MEMORY_BARRIER ();
134 ssvm_push_heap (ssvm_shared_header_t * sh)
137 oldheap = clib_mem_set_heap (sh->heap);
138 return ((void *) oldheap);
142 ssvm_pop_heap (void *oldheap)
144 clib_mem_set_heap (oldheap);
147 #define foreach_ssvm_api_error \
148 _(NO_NAME, "No shared segment name", -100) \
149 _(NO_SIZE, "Size not set (master)", -101) \
150 _(CREATE_FAILURE, "Create failed", -102) \
151 _(SET_SIZE, "Set size failed", -103) \
152 _(MMAP, "mmap failed", -104) \
153 _(SLAVE_TIMEOUT, "Slave map timeout", -105)
157 #define _(n,s,c) SSVM_API_ERROR_##n = c,
158 foreach_ssvm_api_error
160 } ssvm_api_error_enum_t;
162 #define SSVM_API_ERROR_NO_NAME (-10)
164 int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index);
165 int ssvm_slave_init (ssvm_private_t * ssvm, int timeout_in_seconds);
166 void ssvm_delete (ssvm_private_t * ssvm);
168 #endif /* __included_ssvm_h__ */
171 * fd.io coding-style-patch-verification: ON
174 * eval: (c-set-style "gnu")