EM-ODP  3.7.0
Event Machine on ODP
em_event_state.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Nokia Solutions and Networks
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31  /**
32  * @file
33  * EM event state verification support
34  */
35 
36 #ifndef EM_EVENT_CHECKS_H_
37 #define EM_EVENT_CHECKS_H_
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /**
44  * @brief ESV API operation IDs
45  */
46 typedef enum {
47  EVSTATE__UNDEF = 0, /* Must be first! */
48  EVSTATE__PREALLOC,
49  EVSTATE__ALLOC,
50  EVSTATE__ALLOC_MULTI,
51  EVSTATE__EVENT_CLONE,
52  EVSTATE__EVENT_REF,
53  EVSTATE__FREE,
54  EVSTATE__FREE_MULTI,
55  EVSTATE__EVENT_VECTOR_FREE,
56  EVSTATE__INIT,
57  EVSTATE__INIT_MULTI,
58  EVSTATE__INIT_EXTEV,
59  EVSTATE__INIT_EXTEV_MULTI,
60  EVSTATE__UPDATE_EXTEV,
61  EVSTATE__SEND,
62  EVSTATE__SEND__FAIL,
63  EVSTATE__SEND_EGRP,
64  EVSTATE__SEND_EGRP__FAIL,
65  EVSTATE__SEND_MULTI,
66  EVSTATE__SEND_MULTI__FAIL,
67  EVSTATE__SEND_EGRP_MULTI,
68  EVSTATE__SEND_EGRP_MULTI__FAIL,
69  EVSTATE__EO_START_SEND_BUFFERED,
70  EVSTATE__MARK_SEND,
71  EVSTATE__UNMARK_SEND,
72  EVSTATE__MARK_FREE,
73  EVSTATE__UNMARK_FREE,
74  EVSTATE__MARK_FREE_MULTI,
75  EVSTATE__UNMARK_FREE_MULTI,
76  EVSTATE__DISPATCH,
77  EVSTATE__DISPATCH_MULTI,
78  EVSTATE__DISPATCH_SCHED__FAIL,
79  EVSTATE__DISPATCH_LOCAL__FAIL,
80  EVSTATE__DEQUEUE,
81  EVSTATE__DEQUEUE_MULTI,
82  EVSTATE__TMO_SET_ABS,
83  EVSTATE__TMO_SET_ABS__FAIL,
84  EVSTATE__TMO_SET_REL,
85  EVSTATE__TMO_SET_REL__FAIL,
86  EVSTATE__TMO_SET_PERIODIC,
87  EVSTATE__TMO_SET_PERIODIC__FAIL,
88  EVSTATE__TMO_CANCEL,
89  EVSTATE__TMO_ACK,
90  EVSTATE__TMO_ACK__NOSKIP,
91  EVSTATE__TMO_ACK__FAIL,
92  EVSTATE__TMO_CREATE,
93  EVSTATE__TMO_DELETE,
94  EVSTATE__AG_DELETE,
95  EVSTATE__TERM_CORE__QUEUE_LOCAL,
96  EVSTATE__TERM,
97  EVSTATE__LAST /* Must be last! */
98 } esv_apiop_t;
99 
100 /* esv_apiop_t::EVSTATE__LAST must fit into ev_hdr_state_t::uint8_t api_op */
101 COMPILE_TIME_ASSERT(EVSTATE__LAST <= UINT8_MAX, EVSTATE__LAST__TOO_BIG);
102 
103 /**
104  * Init values for the event-state counters.
105  *
106  * The counters are 16-bit but are updated as one combined 64-bit atomic var,
107  * thus the init values are in the middle of the u16-range to avoid wraparounds
108  * when decrementing below '0'.
109  */
110 /** Initial event generation value */
111 #define EVGEN_INIT ((uint16_t)0x1000)
112 /** Max evgen value before resetting to 'EVGEN_INIT' to avoid wrap */
113 #define EVGEN_MAX ((uint16_t)UINT16_MAX - 0x1000)
114 /** Initial send count value */
115 #define SEND_CNT_INIT ((uint16_t)0x8000) /* = 0 + 'offset' */
116 /** Initial reference count value */
117 #define REF_CNT_INIT ((uint16_t)0x8000) /* = 0 + 'offset' */
118 /** Max reference count before resetting to 'REF_CNT_INIT' to avoid wrap */
119 #define REF_CNT_MAX ((uint16_t)UINT16_MAX - 0x1000)
120 
121 /**
122  * Return 'true' if ESV is enabled
123  *
124  * - EM_ESV_ENABLE is set via the 'configure' script: --enable/disable-esv
125  * - esv.enable' is set via the EM config file (default: conf/em-odp.conf)
126  */
127 static inline bool esv_enabled(void)
128 {
129  return EM_ESV_ENABLE && em_shm->opt.esv.enable;
130 }
131 
132 /**
133  * Init ESV (if enabled at compile time), read config options
134  */
135 em_status_t esv_init(void);
136 /**
137  * In the case that ESV has been disabled during compile time, verify that the compile-time
138  * option and runtime config file options do not clash - warn the user otherwise!
139  *
140  * The user might not notice that the run time config file option has no effect if ESV has
141  * been disabled during compile time. The warning printed at startup is meant to notify the
142  * user that ESV will be disabled no matter the content in the run time config file.
143  */
144 void esv_disabled_warn_config(void);
145 /**
146  * Set the initial event state during em_pool_create() when preallocating events
147  */
148 em_event_t evstate_prealloc(const em_event_t event, event_hdr_t *const ev_hdr);
149 /**
150  * Set the initial event state during timeout allocation.
151  */
152 em_event_t evstate_alloc_tmo(const em_event_t event, event_hdr_t *const ev_hdr);
153 /**
154  * Set the initial event state during em_alloc() / em_event_clone()
155  */
156 em_event_t evstate_alloc(const em_event_t event, event_hdr_t *const ev_hdr,
157  const uint16_t api_op);
158 /**
159  * Set the initial state of multiple events during em_alloc_multi()
160  */
161 void evstate_alloc_multi(em_event_t ev_tbl[/*in/out*/],
162  event_hdr_t *const ev_hdr_tbl[], const int num);
163 /**
164  * Update event state during em_event_ref()
165  */
166 em_event_t evstate_ref(const em_event_t event, event_hdr_t *const ev_hdr);
167 
168 /**
169  * Set the initial state for an event
170  * (e.g. an new odp-event converted into an EM-event)
171  */
172 em_event_t evstate_init(const em_event_t event, event_hdr_t *const ev_hdr,
173  bool is_extev);
174 /**
175  * Set the initial state for events
176  * (e.g. new odp-events converted into EM-events)
177  */
178 void evstate_init_multi(em_event_t ev_tbl[/*in/out*/],
179  event_hdr_t *const ev_hdr_tbl[], const int num,
180  bool is_extev);
181 
182 /**
183  * Update the state for external events input into EM.
184  * Used when esv.prealloc_pools = true and the input event was allocated
185  * externally to EM (e.g. by ODP) but from an EM event-pool.
186  */
187 em_event_t evstate_update(const em_event_t event,
188  event_hdr_t *const ev_hdr, bool is_extev);
189 
190 /**
191  * Check & update event state during em_free() or em_event_mark_free()
192  */
193 void evstate_free(em_event_t event, event_hdr_t *const ev_hdr,
194  const uint16_t api_op);
195 /**
196  * Check & update event state during em_event_unmark_free()
197  */
198 void evstate_free_revert(em_event_t event, event_hdr_t *const ev_hdr,
199  const uint16_t api_op);
200 
201 /**
202  * Check & update the state of multiple events during em_free_multi() or
203  * em_event_mark_free_multi()
204  */
205 void evstate_free_multi(const em_event_t ev_tbl[],
206  event_hdr_t *const ev_hdr_tbl[], const int num,
207  const uint16_t api_op);
208 /**
209  * Check & update event state during em_event_unmark_free_multi()
210  */
211 void evstate_free_revert_multi(const em_event_t ev_tbl[],
212  event_hdr_t *const ev_hdr_tbl[], const int num,
213  const uint16_t api_op);
214 /**
215  * Check & update event state - event passed from EM to user.
216  *
217  * em_dispatch(), em_queue_dequeue(), em_tmo_cancel(), em_tmo_delete()
218  */
219 em_event_t evstate_em2usr(em_event_t event, event_hdr_t *const ev_hdr,
220  const uint16_t api_op);
221 /**
222  * Revert EM-to-user event-state update on failed operation.
223  */
224 em_event_t evstate_em2usr_revert(em_event_t event, event_hdr_t *const ev_hdr,
225  const uint16_t api_op);
226 /**
227  * Check & update the state of multiple events - events passed from EM to user
228  *
229  * em_dispatch(), em_queue_dequeue_multi(), em_term()
230  */
231 void evstate_em2usr_multi(em_event_t ev_tbl[/*in/out*/],
232  event_hdr_t *const ev_hdr_tbl[], const int num,
233  const uint16_t api_op);
234 /**
235  * Revert EM-to-user event-state updates on failed operation.
236  */
237 void evstate_em2usr_revert_multi(em_event_t ev_tbl[/*in/out*/],
238  event_hdr_t *const ev_hdr_tbl[], const int num,
239  const uint16_t api_op);
240 /**
241  * Check & update event state - event passed from the user to EM.
242  *
243  * em_send(), em_send_group(), em_tmo_set_abs/rel/periodic(), em_tmo_ack()
244  */
245 void evstate_usr2em(em_event_t event, event_hdr_t *const ev_hdr,
246  const uint16_t api_op);
247 /**
248  * Revert user-to-EM event-state update on failed operation.
249  */
250 void evstate_usr2em_revert(em_event_t event, event_hdr_t *const ev_hdr,
251  const uint16_t api_op);
252 /**
253  * Check & update the state of multiple events - events passed from user to EM
254  *
255  * em_send_multi(), em_send_group_multi()
256  */
257 void evstate_usr2em_multi(const em_event_t ev_tbl[],
258  event_hdr_t *const ev_hdr_tbl[], const int num,
259  const uint16_t api_op);
260 /**
261  * Revert user-to-EM event-state updates on failed operation.
262  */
263 void evstate_usr2em_revert_multi(const em_event_t ev_tbl[],
264  event_hdr_t *const ev_hdr_tbl[], const int num,
265  const uint16_t api_op);
266 /**
267  * Check & update event state during em_event_unmark_send()
268  *
269  * Wrapper function for evstate_usr2em_revert(..., EVSTATE__UNMARK_SEND) with
270  * extra error checks.
271  */
272 void evstate_unmark_send(const em_event_t event, event_hdr_t *const ev_hdr);
273 
274 /**
275  * Check & update event state during em_event_unmark_free()
276  *
277  * Wrapper function for evstate_free_revert(..., EVSTATE__UNMARK_FREE) with
278  * extra error checks.
279  */
280 void evstate_unmark_free(const em_event_t event, event_hdr_t *const ev_hdr,
281  const uint16_t api_op);
282 
283 /**
284  * Check & update event state for multiple events during
285  * em_event_unmark_free_multi()
286  *
287  * Wrapper function for
288  * evstate_free_revert_multi(..., EVSTATE__UNMARK_FREE_MULTI)
289  * with extra error checks.
290  */
291 void evstate_unmark_free_multi(const em_event_t ev_tbl[],
292  event_hdr_t *const ev_hdr_tbl[], const int num,
293  const uint16_t api_op);
294 
295 #ifdef __cplusplus
296 }
297 #endif
298 
299 #endif /* EM_EVENT_CHECKS_H_ */
evstate_unmark_free
void evstate_unmark_free(const em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
Definition: em_event_state.c:1094
evstate_em2usr_revert_multi
void evstate_em2usr_revert_multi(em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
Definition: em_event_state.c:980
evstate_free_multi
void evstate_free_multi(const em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
Definition: em_event_state.c:932
evstate_usr2em_revert_multi
void evstate_usr2em_revert_multi(const em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
Definition: em_event_state.c:1018
esv_disabled_warn_config
void esv_disabled_warn_config(void)
Definition: em_event_state.c:1210
evstate_usr2em_revert
void evstate_usr2em_revert(em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
Definition: em_event_state.c:999
evstate_init_multi
void evstate_init_multi(em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, bool is_extev)
Definition: em_event_state.c:797
evstate_free
void evstate_free(em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
Definition: em_event_state.c:914
evstate_init
em_event_t evstate_init(const em_event_t event, event_hdr_t *const ev_hdr, bool is_extev)
Definition: em_event_state.c:788
evstate_free_revert
void evstate_free_revert(em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
Definition: em_event_state.c:923
event_hdr
Definition: em_event_types.h:184
evstate_update
em_event_t evstate_update(const em_event_t event, event_hdr_t *const ev_hdr, bool is_extev)
Definition: em_event_state.c:895
evstate_em2usr_revert
em_event_t evstate_em2usr_revert(em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
Definition: em_event_state.c:961
evstate_alloc
em_event_t evstate_alloc(const em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
Definition: em_event_state.c:738
evstate_alloc_tmo
em_event_t evstate_alloc_tmo(const em_event_t event, event_hdr_t *const ev_hdr)
Definition: em_event_state.c:750
em_status_t
uint32_t em_status_t
Definition: event_machine_types.h:321
evstate_free_revert_multi
void evstate_free_revert_multi(const em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
Definition: em_event_state.c:942
evstate_em2usr
em_event_t evstate_em2usr(em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
Definition: em_event_state.c:952
evstate_prealloc
em_event_t evstate_prealloc(const em_event_t event, event_hdr_t *const ev_hdr)
Definition: em_event_state.c:733
em_shm
em_shm_t * em_shm
Definition: event_machine_init.c:41
evstate_usr2em_multi
void evstate_usr2em_multi(const em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
Definition: em_event_state.c:1008
EM_ESV_ENABLE
#define EM_ESV_ENABLE
Definition: event_machine_config.h:275
evstate_alloc_multi
void evstate_alloc_multi(em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num)
Definition: em_event_state.c:755
evstate_unmark_free_multi
void evstate_unmark_free_multi(const em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
Definition: em_event_state.c:1110
evstate_em2usr_multi
void evstate_em2usr_multi(em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
Definition: em_event_state.c:970
evstate_ref
em_event_t evstate_ref(const em_event_t event, event_hdr_t *const ev_hdr)
Definition: em_event_state.c:780
esv_init
em_status_t esv_init(void)
Definition: em_event_state.c:1202
esv_apiop_t
esv_apiop_t
ESV API operation IDs.
Definition: em_event_state.h:46
evstate_usr2em
void evstate_usr2em(em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
Definition: em_event_state.c:990
evstate_unmark_send
void evstate_unmark_send(const em_event_t event, event_hdr_t *const ev_hdr)
Definition: em_event_state.c:1079