EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
em_atomic_group.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-2026, 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 atomic group functions
34 *
35 */
36
37#ifndef EM_ATOMIC_GROUP_H_
38#define EM_ATOMIC_GROUP_H_
39
40#include <stdint.h>
41
42#include <odp_api.h>
43
44#include <event_machine.h>
45
47#include "em_mem.h"
48#include "em_queue_types.h"
49#include "misc/list.h"
50#include "misc/objpool.h"
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56#define invalid_atomic_group(atomic_group) \
57 ((unsigned int)agrp_hdl2idx((atomic_group)) >= EM_MAX_ATOMIC_GROUPS)
58
60atomic_group_init(atomic_group_tbl_t *const atomic_group_tbl,
61 atomic_group_pool_t *const atomic_group_pool);
62
63em_atomic_group_t
65
67atomic_group_free(em_atomic_group_t atomic_group);
68
69void atomic_group_remove_queue(queue_elem_t *const q_elem);
70
71void atomic_group_dispatch(odp_event_t odp_evtbl[], const int num_events,
72 queue_elem_t *q_elem);
73
74static inline int
75atomic_group_allocated(const atomic_group_elem_t *agrp_elem)
76{
77 return !objpool_in_pool(&agrp_elem->atomic_group_pool_elem);
78}
79
80static inline int
81agrp_hdl2idx(const em_atomic_group_t atomic_group)
82{
83 return (int)((uintptr_t)atomic_group - 1);
84}
85
86static inline em_atomic_group_t
87agrp_idx2hdl(const int atomic_group_index)
88{
89 return (em_atomic_group_t)(uintptr_t)(atomic_group_index + 1);
90}
91
92static inline atomic_group_elem_t *
93atomic_group_elem_get(const em_atomic_group_t atomic_group)
94{
95 const int ag_idx = agrp_hdl2idx(atomic_group);
96 atomic_group_elem_t *ag_elem;
97
98 if (unlikely((unsigned int)ag_idx > EM_MAX_ATOMIC_GROUPS - 1))
99 return NULL;
100
101 ag_elem = &em_shm->atomic_group_tbl.ag_elem[ag_idx];
102
103 return ag_elem;
104}
105
106static inline void
107atomic_group_add_queue_list(atomic_group_elem_t *const ag_elem,
108 queue_elem_t *const q_elem)
109{
110 odp_ticketlock_lock(&ag_elem->lock);
111 list_add(&ag_elem->qlist_head, &q_elem->agrp.agrp_node);
112 odp_atomic_inc_u32(&ag_elem->num_queues);
113 if (q_elem->priority == EM_QUEUE_PRIO_HIGHEST)
114 odp_atomic_inc_u32(&ag_elem->num_hi_prio_queues);
115 odp_ticketlock_unlock(&ag_elem->lock);
116}
117
118static inline void
119atomic_group_rem_queue_list(atomic_group_elem_t *const ag_elem,
120 queue_elem_t *const q_elem)
121{
122 odp_ticketlock_lock(&ag_elem->lock);
123 if (!list_is_empty(&ag_elem->qlist_head)) {
124 list_rem(&ag_elem->qlist_head, &q_elem->agrp.agrp_node);
125 odp_atomic_dec_u32(&ag_elem->num_queues);
126 if (q_elem->priority == EM_QUEUE_PRIO_HIGHEST)
127 odp_atomic_dec_u32(&ag_elem->num_hi_prio_queues);
128 }
129 odp_ticketlock_unlock(&ag_elem->lock);
130}
131
132void atomic_group_release(void);
133
134unsigned int
135atomic_group_count(void);
136
137/** Print information about all atomic groups */
138void print_atomic_group_info(void);
139
140/** Print information about all queues of the given atomic group */
141void print_atomic_group_queues(em_atomic_group_t ag);
142
143void print_ag_elem_info(void);
144
145#ifdef __cplusplus
146}
147#endif
148
149#endif /* EM_ATOMIC_GROUP_H_ */
em_status_t atomic_group_init(atomic_group_tbl_t *const atomic_group_tbl, atomic_group_pool_t *const atomic_group_pool)
void atomic_group_release(void)
void atomic_group_remove_queue(queue_elem_t *const q_elem)
em_atomic_group_t atomic_group_alloc(void)
void print_atomic_group_queues(em_atomic_group_t ag)
void print_atomic_group_info(void)
void atomic_group_dispatch(odp_event_t odp_evtbl[], const int num_events, queue_elem_t *q_elem)
em_shm_t * em_shm
#define EM_MAX_ATOMIC_GROUPS
uint32_t em_status_t
@ EM_QUEUE_PRIO_HIGHEST
odp_atomic_u32_t num_queues
odp_atomic_u32_t num_hi_prio_queues
objpool_elem_t atomic_group_pool_elem
q_elem_atomic_group_t agrp