EM-ODP  3.7.0
Event Machine on ODP
em_queue_group.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  *
34  * EM internal queue group functions
35  *
36  */
37 
38 #ifndef EM_QUEUE_GROUP_H_
39 #define EM_QUEUE_GROUP_H_
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 #define invalid_qgrp(queue_group) \
46  ((unsigned int)qgrp_hdl2idx((queue_group)) >= EM_MAX_QUEUE_GROUPS)
47 
48 em_status_t queue_group_init(queue_group_tbl_t *const queue_group_tbl,
49  queue_group_pool_t *const queue_group_pool);
50 em_status_t queue_group_init_local(void);
51 void queue_group_join_all(void);
52 
53 em_queue_group_t
54 queue_group_create(const char *name, const em_core_mask_t *mask,
55  int num_notif, const em_notif_t notif_tbl[],
56  em_queue_group_t queue_group);
57 em_queue_group_t
58 queue_group_create_sync(const char *name, const em_core_mask_t *mask,
59  em_queue_group_t requested_queue_group);
60 
62 queue_group_modify(queue_group_elem_t *const qgrp_elem,
63  const em_core_mask_t *new_mask,
64  int num_notif, const em_notif_t notif_tbl[],
65  bool is_delete);
68  const em_core_mask_t *new_mask, bool is_delete);
69 
70 void queue_group_add_queue_list(queue_group_elem_t *const queue_group_elem,
71  queue_elem_t *const queue_elem);
72 void queue_group_rem_queue_list(queue_group_elem_t *const queue_group_elem,
73  queue_elem_t *const queue_elem);
74 unsigned int queue_group_count(void);
75 
76 /**
77  * @brief Check that only running EM cores are set in mask
78  *
79  * @param mask Queue group core mask
80  * @return EM_OK if mask is valid
81  */
83 
84 /**
85  * @brief Print EM queue group info
86  */
88 
89 /**
90  * @brief Print info about all queues belonging to the given queue group
91  */
92 void queue_group_queues_print(em_queue_group_t qgrp);
93 
94 /**
95  * @brief EM internal event handler, add core to an EM queue group.
96  * (see em_internal_event.c&h)
97  *
98  * Handle the internal event requesting to add the core to an
99  * ODP schedule group that is related to an EM queue group.
100  */
102 
103 /**
104  * @brief EM internal event handler, remove core from an EM queue group.
105  * (see em_internal_event.c&h)
106  *
107  * Handle the internal event requesting to remove the core from an
108  * ODP schedule group that is related to an EM queue group.
109  */
111 
112 /**
113  * Convert queue group handle <-> index
114  */
115 static inline int
116 qgrp_hdl2idx(const em_queue_group_t queue_group)
117 {
118  return (int)((uintptr_t)queue_group - 1);
119 }
120 
121 /**
122  * Convert queue group index <-> handle
123  */
124 static inline em_queue_group_t
125 qgrp_idx2hdl(const int queue_group_idx)
126 {
127  return (em_queue_group_t)(uintptr_t)(queue_group_idx + 1);
128 }
129 
130 /**
131  * Return the queue group element ptr or NULL if no such element
132  */
133 static inline queue_group_elem_t *
134 queue_group_elem_get(em_queue_group_t queue_group)
135 {
136  const int qgrp_idx = qgrp_hdl2idx(queue_group);
137  queue_group_elem_t *qgrp_elem;
138 
139  if (unlikely((unsigned int)qgrp_idx > EM_MAX_QUEUE_GROUPS - 1))
140  return NULL;
141 
142  qgrp_elem = &em_shm->queue_group_tbl.queue_group_elem[qgrp_idx];
143 
144  return qgrp_elem;
145 }
146 
147 static inline int
148 queue_group_allocated(const queue_group_elem_t *queue_group_elem)
149 {
150  return !objpool_in_pool(&queue_group_elem->queue_group_pool_elem);
151 }
152 
153 /**
154  * Write the EM single-core queue group name for a given core.
155  */
156 static inline void
157 core_queue_grp_name(int core, char qgrp_name[/*out:len*/], size_t len)
158 {
159  const size_t maxlen = len < EM_QUEUE_GROUP_NAME_LEN ?
161 
162  if (unlikely(maxlen == 0))
163  return;
164 
165  /* write "core#" into qgrp_name[] */
166  snprintf(qgrp_name, maxlen, "%s%d",
168  qgrp_name[maxlen - 1] = '\0';
169 }
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 #endif /* EM_QUEUE_GROUP_H_ */
queue_group_join_all
void queue_group_join_all(void)
The calling core joins all available queue groups.
Definition: em_queue_group.c:370
queue_group_queues_print
void queue_group_queues_print(em_queue_group_t qgrp)
Print info about all queues belonging to the given queue group.
Definition: em_queue_group.c:1553
queue_group_elem_t
Definition: em_queue_group_types.h:59
i_event__qgrp_rem_core_req
void i_event__qgrp_rem_core_req(const internal_event_t *i_ev)
EM internal event handler, remove core from an EM queue group. (see em_internal_event....
Definition: em_queue_group.c:1220
EM_QUEUE_GROUP_NAME_LEN
#define EM_QUEUE_GROUP_NAME_LEN
Definition: event_machine_hw_config.h:152
i_event__qgrp_add_core_req
void i_event__qgrp_add_core_req(const internal_event_t *i_ev)
EM internal event handler, add core to an EM queue group. (see em_internal_event.c&h)
Definition: em_queue_group.c:1207
queue_group_tbl_t
Definition: em_queue_group_types.h:86
queue_group_create_sync
em_queue_group_t queue_group_create_sync(const char *name, const em_core_mask_t *mask, em_queue_group_t requested_queue_group)
Definition: em_queue_group.c:598
EM_QUEUE_GROUP_CORE_BASE_NAME
#define EM_QUEUE_GROUP_CORE_BASE_NAME
Definition: event_machine_hw_config.h:185
queue_group_init
em_status_t queue_group_init(queue_group_tbl_t *const queue_group_tbl, queue_group_pool_t *const queue_group_pool)
Definition: em_queue_group.c:122
em_core_mask_t
Definition: event_machine_hw_types.h:242
queue_group_elem_t::queue_group_pool_elem
objpool_elem_t queue_group_pool_elem
Definition: em_queue_group_types.h:69
queue_group_info_print_all
void queue_group_info_print_all(void)
Print EM queue group info.
Definition: em_queue_group.c:1491
internal_event_t
Definition: em_internal_event_types.h:93
em_status_t
uint32_t em_status_t
Definition: event_machine_types.h:321
em_shm
em_shm_t * em_shm
Definition: event_machine_init.c:41
EM_MAX_QUEUE_GROUPS
#define EM_MAX_QUEUE_GROUPS
Definition: event_machine_hw_config.h:142
queue_group_modify
em_status_t queue_group_modify(queue_group_elem_t *const qgrp_elem, const em_core_mask_t *new_mask, int num_notif, const em_notif_t notif_tbl[], bool is_delete)
Definition: em_queue_group.c:942
em_notif_t
Definition: event_machine_types.h:268
queue_group_create
em_queue_group_t queue_group_create(const char *name, const em_core_mask_t *mask, int num_notif, const em_notif_t notif_tbl[], em_queue_group_t queue_group)
Definition: em_queue_group.c:583
queue_group_modify_sync
em_status_t queue_group_modify_sync(queue_group_elem_t *const qgrp_elem, const em_core_mask_t *new_mask, bool is_delete)
Definition: em_queue_group.c:1034
queue_group_pool_t
Definition: em_queue_group_types.h:94
queue_elem_t
Definition: em_queue_types.h:180
queue_group_check_mask
em_status_t queue_group_check_mask(const em_core_mask_t *mask)
Check that only running EM cores are set in mask.
Definition: em_queue_group.c:610