EM-ODP  3.7.0
Event Machine on ODP
em_queue.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, 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 internal queue functions
34  */
35 
36 #ifndef EM_QUEUE_H_
37 #define EM_QUEUE_H_
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #include <stdlib.h>
44 
45 em_status_t queue_init(queue_tbl_t *const queue_tbl,
46  queue_pool_t *const queue_pool,
47  queue_pool_t *const queue_pool_static);
48 
51 
52 em_queue_t queue_alloc(em_queue_t queue, const char **err_str);
53 em_status_t queue_free(em_queue_t queue);
54 
55 void queue_setup_common(queue_elem_t *q_elem /*out*/,
56  const queue_setup_t *setup);
57 
58 em_queue_t
59 queue_create(const char *name, em_queue_type_t type, em_queue_prio_t prio,
60  em_queue_group_t queue_group, em_queue_t queue_req,
61  em_atomic_group_t atomic_group, const em_queue_conf_t *conf,
62  const char **err_str);
64 queue_delete(queue_elem_t *const queue_elem);
65 
67 queue_enable(queue_elem_t *const q_elem);
68 
70 queue_enable_all(eo_elem_t *const eo_elem);
71 
73 queue_disable(queue_elem_t *const q_elem);
74 
76 queue_disable_all(eo_elem_t *const eo_elem);
77 
80  int is_setup /* vs. is_teardown */);
82 queue_state_change(queue_elem_t *const queue_elem, queue_state_t new_state);
83 
85 queue_state_change_all(eo_elem_t *const eo_elem, queue_state_t new_state);
86 
87 unsigned int queue_count(void);
88 
89 size_t queue_get_name(const queue_elem_t *const q_elem,
90  char name[/*out*/], const size_t maxlen);
91 
92 /** Print information about all EM queues */
93 void print_queue_info(void);
94 /** Print queue capabilities */
95 void print_queue_capa(void);
96 void print_queue_prio_info(void);
97 void print_queue_elem_info(void);
98 
99 /** Get the string of a queue state */
100 const char *queue_get_state_str(queue_state_t state);
101 /** Get the string of a queue type */
102 const char *queue_get_type_str(em_queue_type_t type);
103 
104 /**
105  * Enqueue multiple events into an unscheduled queue.
106  * Internal func, application should use em_send_multi() instead.
107  */
108 static inline unsigned int
109 queue_unsched_enqueue_multi(const em_event_t events[], int num,
110  const queue_elem_t *const q_elem)
111 {
112  odp_event_t odp_events[num];
113  odp_queue_t odp_queue = q_elem->odp_queue;
114  int ret;
115 
116  if (unlikely(EM_CHECK_LEVEL > 1 && odp_queue == ODP_QUEUE_INVALID))
117  return 0;
118 
119  if (unlikely(EM_CHECK_LEVEL > 0 &&
120  q_elem->state != EM_QUEUE_STATE_UNSCHEDULED))
121  return 0;
122 
123  events_em2odp(events, odp_events, num);
124 
125  ret = odp_queue_enq_multi(odp_queue, odp_events, num);
126  if (unlikely(ret < 0))
127  return 0;
128 
129  return ret;
130 }
131 
132 /**
133  * Enqueue en event into an unscheduled queue.
134  * Internal func, application should use em_send() instead.
135  */
136 static inline em_status_t
137 queue_unsched_enqueue(em_event_t event, const queue_elem_t *const q_elem)
138 {
139  odp_event_t odp_event = event_em2odp(event);
140  odp_queue_t odp_queue = q_elem->odp_queue;
141  int ret;
142 
143  if (unlikely(EM_CHECK_LEVEL > 1 &&
144  (odp_event == ODP_EVENT_INVALID ||
145  odp_queue == ODP_QUEUE_INVALID)))
146  return EM_ERR_NOT_FOUND;
147 
148  if (unlikely(EM_CHECK_LEVEL > 0 &&
149  q_elem->state != EM_QUEUE_STATE_UNSCHEDULED))
150  return EM_ERR_BAD_STATE;
151 
152  ret = odp_queue_enq(odp_queue, odp_event);
153  if (unlikely(EM_CHECK_LEVEL > 0 && ret != 0))
154  return EM_ERR_LIB_FAILED;
155 
156  return EM_OK;
157 }
158 
159 static inline int
160 next_local_queue_events(stash_entry_t entry_tbl[/*out*/], int num_events)
161 {
162  em_locm_t *const locm = &em_locm;
163 
164  if (locm->local_queues.empty)
165  return 0;
166 
168 
169  for (int i = 0; i < EM_QUEUE_PRIO_NUM; i++) {
170  /* from hi to lo prio: next prio if local queue is empty */
171  if (locm->local_queues.prio[prio].empty_prio) {
172  prio--;
173  continue;
174  }
175 
176  odp_stash_t stash = locm->local_queues.prio[prio].stash;
177  int num = odp_stash_get_u64(stash, &entry_tbl[0].u64 /*[out]*/,
178  num_events);
179  if (num > 0)
180  return num;
181 
182  locm->local_queues.prio[prio].empty_prio = 1;
183  prio--;
184  }
185 
186  locm->local_queues.empty = 1;
187  return 0;
188 }
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif /* EM_QUEUE_H_ */
queue_get_state_str
const char * queue_get_state_str(queue_state_t state)
Definition: em_queue.c:1673
queue_state_change
em_status_t queue_state_change(queue_elem_t *const queue_elem, queue_state_t new_state)
Definition: em_queue.c:1268
EM_OK
#define EM_OK
Definition: event_machine_types.h:329
em_locm_t::local_queues
local_queues_t local_queues
Definition: em_mem.h:222
EM_QUEUE_PRIO_NUM
#define EM_QUEUE_PRIO_NUM
Definition: event_machine_hw_config.h:103
em_queue_conf_t
Definition: event_machine_types.h:212
queue_pool_t
Definition: em_queue_types.h:298
queue_state_change_all
em_status_t queue_state_change_all(eo_elem_t *const eo_elem, queue_state_t new_state)
Definition: em_queue.c:1282
queue_get_type_str
const char * queue_get_type_str(em_queue_type_t type)
Definition: em_queue.c:1701
print_queue_capa
void print_queue_capa(void)
Definition: em_queue.c:1472
em_locm
ENV_LOCAL em_locm_t em_locm
stash_entry_t
Definition: em_event_types.h:86
EM_ERR_LIB_FAILED
@ EM_ERR_LIB_FAILED
Definition: event_machine_hw_types.h:291
queue_elem_t::state
queue_state_t state
Definition: em_queue_types.h:210
em_queue_type_t
uint32_t em_queue_type_t
Definition: event_machine_types.h:168
queue_enable_all
em_status_t queue_enable_all(eo_elem_t *const eo_elem)
Definition: em_queue.c:1340
eo_elem_t
Definition: em_eo_types.h:47
queue_setup_t
Definition: em_queue_types.h:85
queue_elem_t::odp_queue
odp_queue_t odp_queue
Definition: em_queue_types.h:228
queue_enable
em_status_t queue_enable(queue_elem_t *const q_elem)
Definition: em_queue.c:1319
queue_state_t
uint8_t queue_state_t
Definition: em_queue_types.h:151
queue_tbl_t
Definition: em_queue_types.h:271
queue_setup_common
void queue_setup_common(queue_elem_t *q_elem, const queue_setup_t *setup)
Definition: em_queue.c:779
queue_delete
em_status_t queue_delete(queue_elem_t *const queue_elem)
Definition: em_queue.c:652
queue_create
em_queue_t queue_create(const char *name, em_queue_type_t type, em_queue_prio_t prio, em_queue_group_t queue_group, em_queue_t queue_req, em_atomic_group_t atomic_group, const em_queue_conf_t *conf, const char **err_str)
Definition: em_queue.c:592
queue_disable
em_status_t queue_disable(queue_elem_t *const q_elem)
Definition: em_queue.c:1360
em_status_t
uint32_t em_status_t
Definition: event_machine_types.h:321
EM_CHECK_LEVEL
#define EM_CHECK_LEVEL
Definition: event_machine_config.h:253
queue_state_change__check
em_status_t queue_state_change__check(queue_state_t old_state, queue_state_t new_state, int is_setup)
Definition: em_queue.c:1230
queue_disable_all
em_status_t queue_disable_all(eo_elem_t *const eo_elem)
Definition: em_queue.c:1381
queue_alloc
em_queue_t queue_alloc(em_queue_t queue, const char **err_str)
Definition: em_queue.c:411
queue_init_local
em_status_t queue_init_local(void)
Definition: em_queue.c:303
EM_ERR_NOT_FOUND
@ EM_ERR_NOT_FOUND
Definition: event_machine_hw_types.h:278
print_queue_info
void print_queue_info(void)
Definition: em_queue.c:1749
queue_init
em_status_t queue_init(queue_tbl_t *const queue_tbl, queue_pool_t *const queue_pool, queue_pool_t *const queue_pool_static)
Definition: em_queue.c:217
em_queue_prio_t
uint32_t em_queue_prio_t
Definition: event_machine_types.h:186
queue_term_local
em_status_t queue_term_local(void)
Definition: em_queue.c:367
em_locm_t
Definition: em_mem.h:188
EM_ERR_BAD_STATE
@ EM_ERR_BAD_STATE
Definition: event_machine_hw_types.h:263
queue_elem_t
Definition: em_queue_types.h:180