EM-ODP  3.7.0
Event Machine on ODP
event_machine_hw_specific.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  * Event Machine HW specific functions and other additions.
35  */
36 
37 #ifndef EVENT_MACHINE_HW_SPECIFIC_H
38 #define EVENT_MACHINE_HW_SPECIFIC_H
39 
40 #pragma GCC visibility push(default)
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  * Get the major event type.
48  *
49  * The event type includes a major and a minor part. This function returns the
50  * major part. It can be compared against the enumeration em_event_type_major_e.
51  *
52  * @param type Event type
53  *
54  * @return Major event type
55  */
56 static inline em_event_type_t
57 em_event_type_major(em_event_type_t type)
58 {
59  return type & 0xFF000000;
60 }
61 
62 /* Backwards compatible naming */
63 #define em_get_type_major em_event_type_major
64 
65 /**
66  * Get the minor event type.
67  *
68  * The event type includes a major and a minor part. This function returns the
69  * minor part. It can be compared against a type-specific minor enumeration.
70  *
71  * EM_EVENT_TYPE_SW_DEFAULT is reserved for (SW) events that are
72  * generic and directly accessible buffers of memory.
73  *
74  * @param type Event type
75  *
76  * @return Minor event type
77  */
78 static inline em_event_type_t
79 em_event_type_minor(em_event_type_t type)
80 {
81  return type & 0x00FFFFFF;
82 }
83 
84 /* Backwards compatible naming */
85 #define em_get_type_minor em_event_type_minor
86 
87 /*
88  * Core mask manipulation functions
89  */
90 
91 /**
92  * Zero the whole mask.
93  *
94  * @param[out] mask Core mask to zero (clear)
95  */
97 
98 /**
99  * Set a bit in the mask.
100  *
101  * @param core Core id
102  * @param[out] mask Core mask
103  */
104 void em_core_mask_set(int core, em_core_mask_t *mask);
105 
106 /**
107  * Clear a bit in the mask.
108  *
109  * @param core Core id
110  * @param[out] mask Core mask
111  */
112 void em_core_mask_clr(int core, em_core_mask_t *mask);
113 
114 /**
115  * Test if a bit is set in the mask.
116  *
117  * @param core Core id
118  * @param mask Core mask
119  *
120  * @return Non-zero if core id is set in the mask
121  */
122 int em_core_mask_isset(int core, const em_core_mask_t *mask);
123 
124 /**
125  * Test if the mask is all zero.
126  *
127  * @param mask Core mask
128  *
129  * @return Non-zero if the mask is all zero
130  */
131 int em_core_mask_iszero(const em_core_mask_t *mask);
132 
133 /**
134  * Test if two masks are equal
135  *
136  * @param mask1 First core mask
137  * @param mask2 Second core mask
138  *
139  * @return Non-zero if the two masks are equal
140  */
141 int em_core_mask_equal(const em_core_mask_t *mask1,
142  const em_core_mask_t *mask2);
143 
144 /**
145  * Set a range (0...count-1) of bits in the mask.
146  *
147  * @param count Number of bits to set
148  * @param[out] mask Core mask
149  */
150 void em_core_mask_set_count(int count, em_core_mask_t *mask);
151 
152 /**
153  * Copy core mask
154  *
155  * @param[out] dst Destination core mask
156  * @param src Source core mask
157  */
158 void em_core_mask_copy(em_core_mask_t *dst, const em_core_mask_t *src);
159 
160 /**
161  * Count the number of bits set in the mask.
162  *
163  * @param mask Core mask
164  *
165  * @return Number of bits set
166  */
167 int em_core_mask_count(const em_core_mask_t *mask);
168 
169 /**
170  * Set specified bits from 'bits[]' in core mask.
171  *
172  * core 0: bits[0] = 0x1 (len = 1)
173  * core 1: bits[0] = 0x2 (len = 1)
174  * ...
175  * core 64: bits[0] = 0x0, bits[1] = 0x1 (len = 2)
176  * core 65: bits[0] = 0x0, bits[1] = 0x2 (len = 2)
177  * ...
178  * cores 0-127: bits[0]=0xffffffffffffffff, bits[1]=0xffffffffffffffff (len=2)
179  * ...
180  * @param bits Array of uint64_t:s with the bits to set in the core mask
181  * @param len Number of array elements in bits[].
182  * @param[out] mask Core mask to set.
183  *
184  * @note bits ar 'or'ed into mask, so any previously set bits will remain set.
185  */
186 void em_core_mask_set_bits(const uint64_t bits[], int len,
187  em_core_mask_t *mask);
188 
189 /**
190  * Get core mask, stored in a uint64_t array for the user
191  *
192  * core 0: bits[0] = 0x1 (len = 1)
193  * core 1: bits[0] = 0x2 (len = 1)
194  * ...
195  * core 64: bits[0] = 0x0, bits[1] = 0x1 (len = 2)
196  * core 65: bits[0] = 0x0, bits[1] = 0x2 (len = 2)
197  * ...
198  * cores 0-127: bits[0]=0xffffffffffffffff, bits[1]=0xffffffffffffffff (len=2)
199  * ...
200  * @param[out] bits Array of uint64_t:s that the core mask will be stored in.
201  * @param len Number of array elements in bits[].
202  * @param mask Core mask to get bits from.
203  *
204  * @return The number of uint64_t:s written into bits[].
205  */
206 int em_core_mask_get_bits(uint64_t bits[/*out*/], int len,
207  const em_core_mask_t *mask);
208 
209 /**
210  * Set bits in a mask according to a given string.
211  *
212  * @param mask_str String containing '0xcoremask' to set
213  * @param[out] mask Core mask to set
214  *
215  * @return Zero (0) on success, non-zero on error.
216  *
217  * @note bits ar 'or'ed into mask, so any previously set bits will remain set.
218  */
219 int em_core_mask_set_str(const char *mask_str, em_core_mask_t *mask);
220 
221 /**
222  * Get core mask in string format
223  *
224  * @param[out] mask_str String into which the core mask will be printed
225  * @param len Length of 'mask_str'
226  * @param mask Core mask to convert to string format
227  */
228 void em_core_mask_tostr(char *mask_str /*out*/, int len,
229  const em_core_mask_t *mask);
230 
231 /**
232  * Return the index (position) of the Nth set bit in the core mask
233  *
234  * @param n Nth set bit, note n=1 means first set bit, n=[1...MaxCores]
235  * @param mask Core mask
236  *
237  * @return Index of the Nth set bit, <0 on error or if no such bit.
238  */
239 int em_core_mask_idx(int n, const em_core_mask_t *mask);
240 
241 /**
242  * Bitwise AND operation on two masks, store the result in 'dst'
243  *
244  * dst = src1 & src2
245  *
246  * @param[out] dst Destination core mask, result is stored here
247  * @param src1 Source mask #1
248  * @param src2 Source mask #2
249  */
250 void em_core_mask_and(em_core_mask_t *dst, const em_core_mask_t *src1,
251  const em_core_mask_t *src2);
252 
253 /**
254  * Bitwise OR operation on two masks, store the result in 'dst'
255  *
256  * dst = src1 | src2
257  *
258  * @param[out] dst Destination core mask, result is stored here
259  * @param src1 Source mask #1
260  * @param src2 Source mask #2
261  */
262 void em_core_mask_or(em_core_mask_t *dst, const em_core_mask_t *src1,
263  const em_core_mask_t *src2);
264 
265 /**
266  * Bitwise XOR operation on two masks, store the result in 'dst'
267  *
268  * dst = src1 ^ src2
269  *
270  * @param[out] dst Destination core mask, result is stored here
271  * @param src1 Source mask #1
272  * @param src2 Source mask #2
273  */
274 void em_core_mask_xor(em_core_mask_t *dst, const em_core_mask_t *src1,
275  const em_core_mask_t *src2);
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #pragma GCC visibility pop
282 #endif /* EVENT_MACHINE_HW_SPECIFIC_H */
em_core_mask_set_count
void em_core_mask_set_count(int count, em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:76
em_core_mask_set_str
int em_core_mask_set_str(const char *mask_str, em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:146
em_core_mask_and
void em_core_mask_and(em_core_mask_t *dst, const em_core_mask_t *src1, const em_core_mask_t *src2)
Definition: event_machine_hw_specific.c:181
em_core_mask_zero
void em_core_mask_zero(em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:43
em_core_mask_set
void em_core_mask_set(int core, em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:48
em_core_mask_equal
int em_core_mask_equal(const em_core_mask_t *mask1, const em_core_mask_t *mask2)
Definition: event_machine_hw_specific.c:71
em_core_mask_xor
void em_core_mask_xor(em_core_mask_t *dst, const em_core_mask_t *src1, const em_core_mask_t *src2)
Definition: event_machine_hw_specific.c:195
em_core_mask_isset
int em_core_mask_isset(int core, const em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:58
em_core_mask_iszero
int em_core_mask_iszero(const em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:63
em_core_mask_t
Definition: event_machine_hw_types.h:242
em_core_mask_or
void em_core_mask_or(em_core_mask_t *dst, const em_core_mask_t *src1, const em_core_mask_t *src2)
Definition: event_machine_hw_specific.c:188
em_core_mask_get_bits
int em_core_mask_get_bits(uint64_t bits[], int len, const em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:115
em_event_type_t
uint32_t em_event_type_t
Definition: event_machine_types.h:85
em_core_mask_copy
void em_core_mask_copy(em_core_mask_t *dst, const em_core_mask_t *src)
Definition: event_machine_hw_specific.c:82
em_core_mask_tostr
void em_core_mask_tostr(char *mask_str, int len, const em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:156
em_core_mask_set_bits
void em_core_mask_set_bits(const uint64_t bits[], int len, em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:92
em_core_mask_count
int em_core_mask_count(const em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:87
em_core_mask_idx
int em_core_mask_idx(int n, const em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:164
em_core_mask_clr
void em_core_mask_clr(int core, em_core_mask_t *mask)
Definition: event_machine_hw_specific.c:53