EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
event_machine_pool.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-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#ifndef EVENT_MACHINE_POOL_H_
32#define EVENT_MACHINE_POOL_H_
33
34#pragma GCC visibility push(default)
35
36/**
37 * @file
38 * @defgroup em_pool Event Pool
39 * Event Machine event pool related services
40 * @{
41 *
42 * EM events are allocated from event pools with em_alloc() and freed back into
43 * them with em_free(). The event pools to be allocated from must first be
44 * created with em_pool_create().
45 *
46 * Note that EM should always provide at least one pool, i.e. 'EM_POOL_DEFAULT'
47 * that can be used for event allocation. The default pool creation is platform
48 * specific: it can e.g. be done in 'em_init(conf)' with an appropriate default
49 * pool configuration, which is either given in the runtime config file through
50 * 'startup_pools' option or passed via the 'conf' (em_conf_t) parameter of
51 * em_init().
52 *
53 * In addition to the default pool, startup pools configured in the runtime
54 * config file through option 'startup_pools' are also created during em_init().
55 *
56 * Further event pools should be created explicitly with em_pool_create().
57 *
58 * Event pool APIs for pool deletion, lookup, iteration etc. are listed below.
59 *
60 * Do not include this file directly, event_machine.h will do it for you.
61 */
62
66
67#ifdef __cplusplus
68extern "C" {
69#endif
70
71/**
72 * EM pool configuration
73 *
74 * Configuration of an EM event pool consisting of up to 'EM_MAX_SUBPOOLS'
75 * subpools, each supporting a specific event payload size. Event allocation,
76 * i.e. em_alloc(), will use the subpool that provides the best fit for the
77 * requested size.
78 *
79 * Example usage:
80 * @code
81 * em_pool_cfg_t pool_cfg;
82 *
83 * em_pool_cfg_init(&pool_cfg); // init with default values (mandatory)
84 * pool_cfg.event_type = EM_EVENT_TYPE_PACKET;
85 * ...
86 * pool_cfg.num_subpools = 4;
87 * pool_cfg.subpool[0].size = X;
88 * pool_cfg.subpool[0].num = Y;
89 * pool_cfg.subpool[0].cache_size = Z;
90 * ...
91 * pool = em_pool_create(..., &pool_cfg);
92 * @endcode
93 */
94
95/**
96 * EM pool statistic counter options
97 */
98typedef union {
99 /** Option flags */
100 struct {
101 /** See em_pool_subpool_stats_t::available */
102 uint64_t available : 1;
103
104 /** See em_pool_subpool_stats_t::alloc_ops */
105 uint64_t alloc_ops : 1;
106
107 /** See em_pool_subpool_stats_t::alloc_fails */
108 uint64_t alloc_fails : 1;
109
110 /** See em_pool_subpool_stats_t::free_ops */
111 uint64_t free_ops : 1;
112
113 /** See em_pool_subpool_stats_t::total_ops */
114 uint64_t total_ops : 1;
115
116 /** See em_pool_subpool_stats_t::cache_available */
117 uint64_t cache_available : 1;
118
119 /** See em_pool_subpool_stats_t::cache_alloc_ops */
120 uint64_t cache_alloc_ops : 1;
121
122 /** See em_pool_subpool_stats_t::cache_free_ops */
123 uint64_t cache_free_ops : 1;
124
125 /** Enables applications to read core/thread cache
126 * available of the underlying ODP pool with ODP
127 * API (e.g. odp_pool_stats()). EM pool statistic APIs
128 * do not support fetching core_cache_available.
129 */
131 };
132
133 /** All bits of the bit field structure
134 *
135 * This field can be used to set/clear all flags, or for bitwise
136 * operations over the entire structure.
137 */
138 uint64_t all;
140
141typedef struct {
142 /**
143 * The event type determines the pool type used:
144 * - EM_EVENT_TYPE_SW creates subpools of type 'ODP_POOL_BUFFER'
145 * This kind of EM pool can be used to allocate events of major
146 * type EM_EVENT_TYPE_SW.
147 * - EM_EVENT_TYPE_PACKET creates subpools of type 'ODP_POOL_PACKET'
148 * This kind of EM pool can be used to allocate events of major
149 * type EM_EVENT_TYPE_PACKET or EM_EVENT_TYPE_SW.
150 * - EM_EVENT_TYPE_VECTOR creates subpools of type 'ODP_POOL_VECTOR'
151 * This kind of EM pool can ONLY be used to allocate event
152 * vectors of major event type EM_EVENT_TYPE_VECTOR.
153 * @note Only major event types are considered here, setting the minor
154 * type is an error.
155 */
157 /**
158 * Alignment offset in bytes for the event payload start address
159 * (for all events allocated from this EM pool).
160 *
161 * Only valid for pools with event_type EM_EVENT_TYPE_SW or
162 * EM_EVENT_TYPE_PACKET (i.e. ignored for EM_EVENT_TYPE_VECTOR pools).
163 *
164 * The default EM event payload start address alignment is a
165 * power-of-two that is at minimum 32 bytes (i.e. 32 B, 64 B, 128 B etc.
166 * depending on e.g. target cache-line size).
167 * The 'align_offset.value' option can be used to fine-tune the
168 * start-address by a small offset to e.g. make room for a small
169 * SW header before the rest of the payload that might need a specific
170 * alignment for direct HW-access.
171 * Example: setting 'align_offset.value = 8' makes sure that the payload
172 * _after_ 8 bytes will be aligned at minimum (2^x) 32 bytes.
173 *
174 * This option conserns all events allocated from the pool and overrides
175 * the global config file option 'pool.align_offset' for this pool.
176 */
177 struct {
178 /**
179 * Select: Use pool-specific align-offset 'value' from below or
180 * use the global default value 'pool.align_offset'
181 * from the config file.
182 * false: Use 'pool.align_offset' from the config file (default)
183 * true: Use pool-specific value set below.
184 */
185 bool in_use;
186 /**
187 * Pool-specific event payload alignment offset value in bytes
188 * (only evaluated if 'in_use=true').
189 * Overrides the config file value 'pool.align_offset' for this
190 * pool.
191 * The given 'value' must be a small power-of-two: 2, 4, or 8
192 * 0: Explicitly set 'No align offset' for the pool.
193 */
194 uint32_t value;
195 } align_offset;
196
197 /**
198 * Event user area size in bytes.
199 * (for all events allocated from this EM pool).
200 *
201 * The user area is located within the event metadata (hdr) and is not
202 * part of the event payload. The event user area can e.g. be used to
203 * store additional state data related to the payload contents. EM does
204 * not initialize the contents of the user area.
205 *
206 * This option concerns all events allocated from the pool and overrides
207 * the global config file option 'pool.user_area_size' for this pool.
208 */
209 struct {
210 /**
211 * Select: Use pool-specific event user area 'size' from below
212 * or use the global default value 'pool.user_area_size'
213 * from the config file.
214 * false: Use 'pool.user_area_size' from config file (default).
215 * true: Use pool-specific size set below.
216 */
217 bool in_use;
218 /**
219 * Pool-specific event user area size in bytes (only evaluated
220 * if 'in_use=true').
221 * Overrides the config file 'pool.user_area_size' for this pool
222 * 0: Explicitly set 'No user area' for the pool.
223 */
224 size_t size;
225 } user_area;
226
227 /**
228 * Parameters for an EM-pool with '.event_type = EM_EVENT_TYPE_PACKET'
229 * Ignored for other pool types.
230 */
231 struct {
232 /**
233 * Pool-specific packet minimum headroom
234 *
235 * This option conserns all events allocated from the pool and
236 * overrides the global config file option 'pool.pkt_headroom'
237 * for this pool.
238 */
239 struct {
240 /**
241 * Select: Use pool-specific packet headroom value from
242 * below or use the global default value
243 * 'pool.pkt_headroom' from the config file.
244 * false: Use 'pool.pkt_headroom' from the config file
245 * (default).
246 * true: Use pool-specific value set below.
247 */
248 bool in_use;
249 /**
250 * Pool-specific packet minimum headroom in bytes,
251 * each packet must have at least this much headroom.
252 * (only evaluated if 'in_use=true').
253 * Overrides the config file value 'pool.pkt_headroom'
254 * for this pool.
255 * 0: Explicitly set 'No headroom' for the pool.
256 */
257 uint32_t value;
258 } headroom;
259 } pkt;
260
261 /**
262 * Number of subpools within one EM pool, min=1, max=EM_MAX_SUBPOOLS
263 */
265 /**
266 * Subpool params array: .subpool[num_subpools]
267 */
268 struct {
269 /**
270 * .event_type = EM_EVENT_TYPE_SW or EM_EVENT_TYPE_PACKET:
271 * Event payload size of the subpool (size > 0), bytes(B).
272 * EM does not initialize the payload data.
273 *
274 * .event_type = EM_EVENT_TYPE_VECTOR:
275 * Max number of events in a vector from the subpool, i.e.
276 * 'number of em_event_t:s in the vector's event-table[]'.
277 * EM does not initialize the vector.
278 *
279 * @note When used as an aggregator-queue vector pool
280 * (em_queue_aggr_conf_t::pool), EM pins the aggregator
281 * to the first subpool whose 'size' >=
282 * em_queue_aggr_conf_t::max_size at queue creation time.
283 * All vector events for that aggregator come from that
284 * one subpool. Different aggregators can target different
285 * subpools by using different 'max_size' values.
286 */
287 uint32_t size;
288
289 /** Number of events in the subpool (num > 0) */
290 uint32_t num;
291
292 /**
293 * Maximum number of locally cached subpool events per EM-core.
294 *
295 * Allocating or freeing events from a core-local event-cache
296 * can be faster than using the global event subpool. Cached
297 * events are only available on the local core and can reduce
298 * the number of globally free events in the subpool, thus
299 * consider setting 'num > EM-core-count * cache_size'.
300 * The actual used cache_size will be smaller than or equal to
301 * the requested value, depending on the implementation.
302 */
303 uint32_t cache_size;
304 } subpool[EM_MAX_SUBPOOLS];
305
306 /**
307 * Pool statistic options for all subpools
308 *
309 * The options set either from the global config file or from the pool
310 * specific 'stats_opt.opt' below are ineffective without ODP support.
311 */
312 struct {
313 /**
314 * Select: Use pool-specific statistic options from below
315 * or use the global default value 'pool.statistics'
316 * from the config file.
317 * false: Use 'pool.statistics' from config file (default).
318 * true: Use pool-specific statistic options set below.
319 */
320 bool in_use;
321
323 } stats_opt;
324
325 /**
326 * Internal check - don't touch!
327 *
328 * EM will verify that em_pool_cfg_init(pool_cfg) has been called before
329 * creating a pool with em_pool_create(..., pool_cfg)
330 */
333
334/**
335 * EM pool information and usage statistics
336 */
337typedef struct {
338 /* Pool name */
339 char name[EM_POOL_NAME_LEN];
340 /** EM pool handle */
341 em_pool_t em_pool;
342 /** Event type of events allocated from the pool */
344 /** Event payload alignment offset for events from the pool */
345 uint32_t align_offset;
346 /** Event user area size for events from the pool */
348 /** The statistic options used during pool creation */
350 /** Number of subpools within one EM pool, max=EM_MAX_SUBPOOLS */
352 struct {
353 /** Event payload size of the subpool */
354 uint32_t size;
355 /** Number of events in the subpool */
356 uint32_t num;
357 /** Max number of locally cached subpool events per EM-core */
358 uint32_t cache_size;
359 /**
360 * Number of events allocated from the subpool.
361 * Only if the 'available' or 'cache_available' is set to true
362 * in 'pool.statistics' of EM config file or in
363 * 'em_pool_cfg_t::stats_opt::opt' given to function
364 * em_pool_create(..., pool_cfg), otherwise .used=0.
365 */
366 uint32_t used;
367 /**
368 * Number of events free in the subpool.
369 * Only if the 'available' or 'cache_available' is set to true
370 * in 'pool.statistics' of EM config file or in
371 * 'em_pool_cfg_t::stats_opt::opt' given to function
372 * em_pool_create(..., pool_cfg), otherwise .free=0.
373 */
374 uint32_t free;
375 } subpool[EM_MAX_SUBPOOLS];
377
378typedef struct {
379 /** The number of available events in the pool */
380 uint64_t available;
381
382 /** The number of alloc operations from the pool. Includes both
383 * successful and failed operations (pool empty).
384 */
385 uint64_t alloc_ops;
386
387 /** The number of failed alloc operations (pool empty) */
388 uint64_t alloc_fails;
389
390 /** The number of free operations to the pool */
391 uint64_t free_ops;
392
393 /** The total number of alloc and free operations. Includes both
394 * successful and failed operations (pool empty).
395 */
396 uint64_t total_ops;
397
398 /** The number of available events in the local caches of all cores */
400
401 /** The number of successful alloc operations from pool caches (returned
402 * at least one event).
403 */
405
406 /** The number of free operations, which stored events to pool caches. */
408
409 /** Internal use - don't touch! */
410 uint64_t __internal_use[EM_POOL_SUBPOOL_STAT_INTERNAL];
412
413typedef struct {
414 uint32_t num_subpools;
417
418/**
419 * Pool subpool statistics counters
420 *
421 * Same as em_pool_subpool_stats_t excluding the __internal_use.
422 */
423typedef struct {
424 /** The number of available events in the pool */
425 uint64_t available;
426
427 /** The number of alloc operations from the pool. Includes both
428 * successful and failed operations (pool empty).
429 */
430 uint64_t alloc_ops;
431
432 /** The number of failed alloc operations (pool empty) */
433 uint64_t alloc_fails;
434
435 /** The number of free operations to the pool */
436 uint64_t free_ops;
437
438 /** The total number of alloc and free operations. Includes both
439 * successful and failed operations (pool empty).
440 */
441 uint64_t total_ops;
442
443 /** The number of available events in the local caches of all cores */
445
446 /** The number of successful alloc operations from pool caches (returned
447 * at least one event).
448 */
450
451 /** The number of free operations, which stored events to pool caches. */
454
455typedef struct {
456 uint32_t num_subpools;
459
460/**
461 * Initialize EM-pool configuration parameters for em_pool_create()
462 *
463 * Initialize em_pool_cfg_t to default values for all fields.
464 * After initialization, the user further needs to update the fields of
465 * 'em_pool_cfg_t' with appropriate sizing information before calling
466 * em_pool_create().
467 *
468 * Always initialize 'pool_cfg' first with em_pool_cfg_init(pool_cfg) to
469 * ensure backwards compatibility with potentially added new options.
470 *
471 * @param pool_cfg Address of the em_pool_cfg_t to be initialized
472 *
473 * @see em_pool_cfg_t and em_pool_create()
474 */
475void em_pool_cfg_init(em_pool_cfg_t *const pool_cfg);
476
477/**
478 * Create a new EM event pool
479 *
480 * Create an EM event pool that can be used for event allocation. The event pool
481 * is created and configured according to the platform/HW specific em_pool_cfg_t
482 * given as argument.
483 *
484 * @param name Pool name (optional, NULL ok)
485 * @param pool A specific pool handle to be used or EM_POOL_UNDEF to let
486 * EM decide (i.e. use a free handle).
487 * @param pool_cfg Pointer to the pool config
488 *
489 * @return EM pool handle or EM_POOL_UNDEF on error
490 *
491 * @see em_pool_cfg_t and em_pool_cfg_init()
492 */
493em_pool_t
494em_pool_create(const char *name, em_pool_t pool, const em_pool_cfg_t *pool_cfg);
495
496/**
497 * Delete an existing EM event pool
498 *
499 * @param pool EM event pool handle of the pool to be deleted.
500 *
501 * @return EM_OK if successful
502 */
503em_status_t em_pool_delete(em_pool_t pool);
504
505/**
506 * Find an EM event pool by name.
507 *
508 * Finds a pool by the given name (exact match). An empty string will not match
509 * anything. The search is case sensitive. The function will return the first
510 * match only if there are duplicate names.
511 *
512 * @param name the name to look for
513 *
514 * @return pool handle or EM_POOL_UNDEF if not found
515 *
516 * @see em_pool_create()
517 */
518em_pool_t em_pool_find(const char *name);
519
520/**
521 * Get the name of an EM event pool.
522 *
523 * A copy of the name string (up to 'maxlen' characters) is written to the user
524 * given buffer.
525 * The string is always null terminated, even if the given buffer length is less
526 * than the name length.
527 *
528 * If the event pool has no name, the function returns 0 and writes an
529 * empty string.
530 *
531 * @param pool EM event pool
532 * @param[out] name Destination buffer
533 * @param maxlen Maximum length (including the terminating '0')
534 *
535 * @return Number of characters written (excludes the terminating '0').
536 */
537size_t em_pool_name(em_pool_t pool, char *name /*out*/, size_t maxlen);
538
539/* Backwards compatible naming ("get") */
540#define em_pool_get_name em_pool_name
541
542/**
543 * Initialize event pool iteration and return the first event pool handle.
544 *
545 * Can be used to initialize the iteration to retrieve all created event pools
546 * for debugging or management purposes. Use em_pool_next() after this call
547 * until it returns EM_POOL_UNDEF.
548 * A new call to em_pool_first() resets the iteration, which is maintained
549 * per core (thread). The operation should be completed in one go before
550 * returning from the EO's event receive function (or start/stop).
551 *
552 * The number of event pools (output arg 'num') may not match the amount of
553 * event pools actually returned by iterating using em_pool_next()
554 * if event pools are added or removed in parallel by another core. The order
555 * of the returned event pool handles is undefined.
556 *
557 * @code
558 * unsigned int num;
559 * em_pool_t pool = em_pool_first(&num);
560 * while (pool != EM_POOL_UNDEF) {
561 * pool = em_pool_next();
562 * }
563 * @endcode
564 *
565 * @param[out] num Pointer to an unsigned int to store the amount of
566 * event pools into
567 * @return The first event pool handle or EM_POOL_UNDEF if none exist
568 *
569 * @see em_pool_next()
570 */
571em_pool_t em_pool_first(unsigned int *num /*out*/);
572
573/* Backwards compatible naming ("get") */
574#define em_pool_get_first em_pool_first
575
576/**
577 * Return the next event pool handle.
578 *
579 * Continues the event pool iteration started by em_pool_first()
580 * and returns the next event pool handle.
581 *
582 * @return The next event pool handle or EM_POOL_UNDEF if the atomic
583 * group iteration is completed (i.e. no more event pools available).
584 *
585 * @see em_pool_first()
586 */
587em_pool_t em_pool_next(void);
588
589/* Backwards compatible naming ("get") */
590#define em_pool_get_next em_pool_next
591
592/**
593 * Retrieve information about an EM pool.
594 *
595 * @param pool EM pool handle
596 * @param[out] pool_info Pointer to pool info that will be written
597 *
598 * @return EM_OK if successful
599 *
600 * @note Set at least 'available' in 'pool.statistics' of EM config file or in
601 * 'em_pool_cfg_t::stats_opt::opt' given to function em_pool_create(..., pool_cfg)
602 * to true for usage statistics, otherwise, only basic info is output, omitting
603 * pool usage information (= all zeros).
604 * If 'cache_available' is not enabled or enabled but ineffective without ODP
605 * support, the 'pool_info->subpool[i].used' and 'pool_info->subpool[i].free'
606 * fields may not be accurate.
607 */
608em_status_t em_pool_info(em_pool_t pool, em_pool_info_t *pool_info /*out*/);
609
610/**
611 * Helper function to print EM Pool information for a given pool.
612 *
613 * Uses em_pool_info() when printing the pool information.
614 *
615 * @param pool EM pool handle
616 *
617 * @note Set at least 'available' in 'pool.statistics' of EM config file or in
618 * 'em_pool_cfg_t::stats_opt::opt' given to function em_pool_create(..., pool_cfg)
619 * to true for usage statistics, otherwise, only basic info is printed, omitting
620 * pool usage information (= all zeros).
621 * If 'cache_available' is not enabled or enabled but ineffective without ODP
622 * support, the 'pool_info->subpool[i].used' and 'pool_info->subpool[i].free'
623 * fields may not be accurate.
624 *
625 * @note This function does not print 'pool_info_t::stats_opt'. To print the statistic
626 * options used during pool creation, use 'em_pool_stats_opt_print()' instead.
627 */
628void em_pool_info_print(em_pool_t pool);
629
630/**
631 * @brief Return the number of subpools in an EM pool.
632 *
633 * @param pool EM pool handle
634 *
635 * @return Number of subpools in the given pool(max=EM_MAX_SUBPOOLS)
636 * or -1 on error
637 */
638int em_pool_num_subpools(em_pool_t pool);
639
640/* Backwards compatible naming ("get") */
641#define em_pool_get_num_subpools em_pool_num_subpools
642
643/**
644 * Helper function to print EM Pool information for all pools in the system.
645 *
646 * Uses em_pool_info() when printing the pool information.
647 *
648 * @note Set at least 'available' in 'pool.statistics' of EM config file or in
649 * 'em_pool_cfg_t::stats_opt::opt' given to function em_pool_create(..., pool_cfg)
650 * to true for usage statistics, otherwise, only basic info is printed, omitting
651 * pool usage information (= all zeros).
652 * If 'cache_available' is not enabled or enabled but ineffective without ODP
653 * support, the 'pool_info->subpool[i].used' and 'pool_info->subpool[i].free'
654 * fields may not be accurate.
655 *
656 * @note This function does not print 'pool_info_t::stats_opt'. To print the statistic
657 * options used during pool creation, use 'em_pool_stats_opt_print_all()' instead.
658 */
659void em_pool_info_print_all(void);
660
661/**
662 * A convenience function to retrieve the pool statistics options actually
663 * in use for a given EM pool.
664 *
665 * @param pool EM pool handle
666 * @param[out] pool_stats_opt Pointer to pool stats opt that will be written
667 *
668 * @note Pool statistics options used during pool creation are determined by the
669 * 'em_pool_cfg_t::stats_opt::in_use' given to function
670 * em_pool_create(..., pool_cfg):
671 * - If 'em_pool_cfg_t::stats_opt::in_use' is true, the statistics
672 * options from 'em_pool_cfg_t::stats_opt::opt' given to function
673 * em_pool_create(..., pool_cfg) is used.
674 * - If 'em_pool_cfg_t::stats_opt::in_use' is false, the global setting
675 * 'pool.statistics' from the EM config file is used instead.
676 *
677 * @note The EM Pool statistics options set either from the global config file
678 * or from the pool specific configuration are only effective with ODP
679 * support. For example, if 'cache_available' is set to true, but the
680 * underlying ODP implementation does not support 'cache_available'
681 * statistic, this function will return 'pool_stats_opt.cache_available'
682 * as false.
683 *
684 * @return EM_OK if successful
685 */
686em_status_t em_pool_stats_opt(em_pool_t pool, em_pool_stats_opt_t *pool_stats_opt /*out*/);
687
688/**
689 * Helper function to print EM Pool statistics options for a given pool.
690 *
691 * Uses em_pool_stats_opt() when printing the pool statistics options.
692 *
693 * @param pool EM pool handle
694 */
695void em_pool_stats_opt_print(em_pool_t pool);
696
697/**
698 * Helper function to print EM Pool statistics options for all EM pools.
699 *
700 * Uses em_pool_stats_opt() when printing the pool statistics options.
701 */
703
704/**
705 * @brief Retrieve statistics about an EM pool.
706 *
707 * Read the statistic counters enabled in 'em_pool_cfg_t::stats_opt' passed to
708 * em_pool_create() or in the 'pool.statistics' of EM config file, and supported
709 * by the underlying ODP implementation. Any counters that are ineffective (not
710 * enabled or enabled but not supported) will be set to zero. Note that there
711 * may be some delay until performed pool operations are visible in the
712 * statistics.
713 *
714 * @param pool EM pool handle
715 * @param[out] pool_stats Pointer to pool statistics. A successful call
716 * writes to this pointer the requested pool statistics.
717 *
718 * @return EM_OK if the statistics of all subpools of 'pool' are read successfully
719 *
720 * @note Runtime argument checking is not done unless EM_CHECK_LEVEL > 0.
721 *
722 * @see em_pool_cfg_t::stats_opt and em_pool_stats_t.
723 */
724em_status_t em_pool_stats(em_pool_t pool, em_pool_stats_t *pool_stats /*out*/);
725
726/**
727 * Reset statistics for an EM pool.
728 *
729 * Reset all statistic counters in 'em_pool_stats_t::subpool_stats' to zero
730 * except:
731 * 'em_pool_subpool_stats_t::available'
732 * 'em_pool_subpool_stats_t::cache_available',
733 *
734 * @param pool EM Pool handle
735 *
736 * @return EM_OK if successful
737 */
738em_status_t em_pool_stats_reset(em_pool_t pool);
739
740/**
741 * @brief Helper function to print statistics for an EM pool.
742 *
743 * Note that there may be some delay until performed pool operations are visible
744 * in the statistics.
745 *
746 * @param pool EM pool handle
747 *
748 * Uses em_pool_stats() when printing the pool statistics.
749 */
750void em_pool_stats_print(em_pool_t pool);
751
752/**
753 * @brief Retrieve statistics about subpool(s) of an EM pool.
754 *
755 * Read the subpool statistic counters set in 'em_pool_cfg_t::stats_opt' passed
756 * to em_pool_create() or in the 'pool.statistics' of EM config file, and
757 * supported by the underlying ODP implementation. Any counters that are
758 * ineffective (not enabled or enabled but not supported) will be set to zero.
759 * Note that there may be some delay until performed pool operations are visible
760 * in the statistics.
761 *
762 * The function returns the number of subpool statistics actually retrieved. A
763 * return value equal to 'num_subpools' means that the subpool statistics for
764 * given indices in 'subpools' are all retrieved successfully. A value less than
765 * 'num_subpools' means that the statistics for subpools whose indices are given
766 * at the end of 'subpools' can not be fetched. The function will not modify
767 * corresponding 'subpool_stats'.
768 *
769 * @param pool EM pool handle
770 * @param subpools Array of subpool indices, must contain
771 * 'num_subpools' valid subpool-indices.
772 * 0 <= indices < number of subpools 'pool' has.
773 * @param num_subpools Number of subpools to retrieve statistics for.
774 * 0 < num_subpools <= number of subpools 'pool' has.
775 * @param[out] subpool_stats Array of subpool statistics, must have room for
776 * 'num_subpools' entries of subpool statistics.
777 * A successful call writes to this array the requested
778 * subpool statistics [out].
779 *
780 * @return number of stats successfully fetched (equal to 'num_subpools' if all
781 * successful) or 0 on error.
782 *
783 * @code
784 * em_pool_t pool = 1;
785 * int num = 3;
786 * int subpools[3] = [0, 3, 2];
787 * em_pool_subpool_stats_t stats[3];
788 * int ret = em_pool_subpool_stats(pool, subpools, num, stats);
789 * @endcode
790 *
791 * The mapping between stats and subpools is as follows:
792 * stats[0] <-> subpools[0]
793 * stats[1] <-> subpools[1]
794 * ...
795 * stats[num_subpools - 1] <-> subpools[num_subpools - 1]
796 * So in above code, stats[1] stores statistics for the subpool whose index is 3.
797 *
798 * @note Runtime argument checking is not done unless EM_CHECK_LEVEL > 0.
799 *
800 * @see em_pool_cfg_t::stats_opt and em_pool_subpool_stats_t.
801 */
802int em_pool_subpool_stats(em_pool_t pool, const int subpools[], int num_subpools,
803 em_pool_subpool_stats_t subpool_stats[/*out*/]);
804
805/**
806 * Reset statistics for subpool(s) of an EM pool.
807 *
808 * Reset all statistics counters in given subpools of an EM pool to zero except:
809 * 'em_pool_subpool_stats_t::available'
810 * 'em_pool_subpool_stats_t::cache_available'
811 *
812 * @param pool EM pool handle
813 * @param subpools Array of subpool indices
814 * 0 <= indices < number of subpools pool has
815 * @param num_subpools Number of subpools to reset statistics for
816 * 0 < num_subpools <= number of subpools pool has
817 *
818 * @return EM_OK if successful
819 */
821 const int subpools[], int num_subpools);
822
823/**
824 * @brief Helper function to print statistics for subpool(s) of an EM pool.
825 *
826 * Note that there may be some delay until performed pool operations are visible
827 * in the statistics.
828 *
829 * @param pool EM pool handle
830 * @param subpools Array of subpool indices
831 * 0 <= indices < number of subpools pool has
832 * @param num_subpools Number of subpools to print statistics for
833 * 0 < num_subpools <= number of subpools pool has
834 *
835 * Uses em_pool_subpool_stats() when printing the subpool statistics.
836 */
837void em_pool_subpool_stats_print(em_pool_t pool, const int subpools[], int num_subpools);
838
839/**
840 * @brief Retrieve selected statistics about an EM pool.
841 *
842 * Read the selected statistic counters specified in 'em_pool_stats_opt_t'. Only
843 * counters that have been enabled in the 'pool.statistics' of EM config file or
844 * in 'em_pool_cfg_t::stats_opt' (via em_pool_create()) will be returned. Values
845 * of the unselected counters are undefined. If a selected counter is not
846 * supported by the underlying ODP implementation, the function will return an
847 * error. To prevent errors, use 'em_pool_stats_opt()' to verify which statistic
848 * counters are in use for the given pool before selecting them. Note that there
849 * may be some delay until performed pool operations are visible in the
850 * statistics.
851 *
852 * @param pool EM pool handle
853 * @param[out] pool_stats Pointer to pool statistics. A successful call
854 * writes to this pointer the requested pool statistics.
855 * @param opt Used to select the statistic counters to read
856 *
857 * @return EM_OK if the selected statistics of all subpools of 'pool' are read
858 * successfully
859 *
860 * @note Runtime argument checking is not done unless EM_CHECK_LEVEL > 0.
861 *
862 * @see em_pool_cfg_t::stats_opt, em_pool_stats_selected_t and em_pool_stats_opt_t.
863 */
865em_pool_stats_selected(em_pool_t pool, em_pool_stats_selected_t *pool_stats/*out*/,
866 const em_pool_stats_opt_t *opt);
867
868/**
869 * @brief Helper function to print selected statistics for an EM pool.
870 *
871 * Note that there may be some delay until performed pool operations are visible
872 * in the statistics.
873 *
874 * @param pool EM pool handle
875 * @param opt Used to select the statistic counters to print
876 *
877 * Uses em_pool_stats_selected() when printing the selected pool statistics.
878 */
879void em_pool_stats_selected_print(em_pool_t pool, const em_pool_stats_opt_t *opt);
880
881/**
882 * @brief Retrieve selected statistics about subpool(s) of an EM pool.
883 *
884 * Read the selected subpool statistic counters given in 'em_pool_stats_opt_t'.
885 * The selected counters must have been enabled in 'em_pool_cfg_t::stats_opt'
886 * passed to em_pool_create() or in the 'pool.statistics' of EM config file.
887 * Values of the unselected counters are undefined. If a selected counter is not
888 * supported by the underlying ODP implementation, the function will return an
889 * error. To prevent errors, use 'em_pool_stats_opt()' to verify which statistic
890 * counters are in use for the given pool before selecting them. Note that there
891 * may be some delay until performed pool operations are visible in the
892 * statistics.
893 *
894 * The function returns the number of selected subpool statistics actually read.
895 * A return value of 'num_subpools' means that the selected subpool statistics
896 * for the given indices in 'subpools' are all retrieved successfully. A value
897 * less than 'num_subpools' means that the selected statistics for subpools whose
898 * indices are given at the end of 'subpools' can not be fetched. The function
899 * will not modify corresponding 'subpool_stats'.
900 *
901 * @param pool EM pool handle
902 * @param subpools Array of subpool indices, must contain
903 * 'num_subpools' valid subpool-indices.
904 * 0 <= indices < number of subpools 'pool' has.
905 * @param num_subpools Number of subpools to retrieve statistics for.
906 * 0 < num_subpools <= number of subpools 'pool' has.
907 * @param[out] subpool_stats Array of subpool statistics, must have room for
908 * 'num_subpools' entries of subpool statistics.
909 * A successful call writes to this array the
910 * requested subpool statistics [out].
911 * @param opt Used to select the statistic counters to read
912 *
913 * @return number of subpool_stats successfully fetched (equal to 'num_subpools'
914 * if all successful) or 0 on error.
915 *
916 * @code
917 * em_pool_t pool = 1;
918 * int num = 3;
919 * int subpools[3] = [0, 3, 2];
920 * em_pool_subpool_stats_selected_t stats[3];
921 * em_pool_stats_opt_t opt = {.bit.available = 1};
922 * int ret = em_pool_subpool_stats_selected(pool, subpools, num, stats, &opt);
923 * @endcode
924 *
925 * The mapping between stats and subpools is as follows:
926 * stats[0] <-> subpools[0]
927 * stats[1] <-> subpools[1]
928 * ...
929 * stats[num_subpools - 1] <-> subpools[num_subpools - 1]
930 * So in above code, stats[1] stores selected statistics for the subpool whose
931 * index is 3.
932 *
933 * @note Runtime argument checking is not done unless EM_CHECK_LEVEL > 0.
934 *
935 * @see em_pool_cfg_t::stats_opt, em_pool_subpool_stats_selected_t and em_pool_stats_opt_t.
936 */
937int em_pool_subpool_stats_selected(em_pool_t pool, const int subpools[], int num_subpools,
938 em_pool_subpool_stats_selected_t subpool_stats[/*out*/],
939 const em_pool_stats_opt_t *opt);
940
941/**
942 * @brief Helper function to print selected statistics for subpool(s) of an EM pool.
943 *
944 * Note that there may be some delay until performed pool operations are visible
945 * in the statistics.
946 *
947 * @param pool EM pool handle
948 * @param subpools Array of subpool indices
949 * 0 <= indices < number of subpools pool has
950 * @param num_subpools Number of subpools to print statistics for
951 * 0 < num_subpools <= number of subpools pool has
952 * @param opt Used to select the statistic counters to print
953 *
954 * Uses em_pool_subpool_stats_selected() when printing the selected subpool statistics.
955 */
956void em_pool_subpool_stats_selected_print(em_pool_t pool, const int subpools[],
957 int num_subpools, const em_pool_stats_opt_t *opt);
958/**
959 * Convert an EM pool handle to an unsigned integer
960 *
961 * @param pool EM pool handle to be converted
962 * @return uint64_t value that can be used to print/display the handle
963 *
964 * @note This routine is intended to be used for diagnostic purposes
965 * to enable applications to e.g. generate a printable value that represents
966 * an em_pool_t handle.
967 */
968uint64_t em_pool_to_u64(em_pool_t pool);
969
970/**
971 * @}
972 */
973#ifdef __cplusplus
974}
975#endif
976
977#pragma GCC visibility pop
978#endif /* EVENT_MACHINE_POOL_H_ */
#define EM_POOL_SUBPOOL_STAT_INTERNAL
#define EM_MAX_SUBPOOLS
The maximum number of subpools in each EM pool. The subpool is a pool with buffers of only one size.
#define EM_POOL_NAME_LEN
uint32_t em_event_type_t
uint32_t em_status_t
void em_pool_stats_opt_print(em_pool_t pool)
em_pool_t em_pool_find(const char *name)
em_pool_t em_pool_create(const char *name, em_pool_t pool, const em_pool_cfg_t *pool_cfg)
void em_pool_cfg_init(em_pool_cfg_t *const pool_cfg)
void em_pool_subpool_stats_selected_print(em_pool_t pool, const int subpools[], int num_subpools, const em_pool_stats_opt_t *opt)
Helper function to print selected statistics for subpool(s) of an EM pool.
em_pool_t em_pool_next(void)
uint64_t em_pool_to_u64(em_pool_t pool)
em_status_t em_pool_subpool_stats_reset(em_pool_t pool, const int subpools[], int num_subpools)
void em_pool_stats_opt_print_all(void)
int em_pool_subpool_stats_selected(em_pool_t pool, const int subpools[], int num_subpools, em_pool_subpool_stats_selected_t subpool_stats[], const em_pool_stats_opt_t *opt)
Retrieve selected statistics about subpool(s) of an EM pool.
size_t em_pool_name(em_pool_t pool, char *name, size_t maxlen)
void em_pool_subpool_stats_print(em_pool_t pool, const int subpools[], int num_subpools)
Helper function to print statistics for subpool(s) of an EM pool.
void em_pool_stats_selected_print(em_pool_t pool, const em_pool_stats_opt_t *opt)
Helper function to print selected statistics for an EM pool.
em_status_t em_pool_stats_reset(em_pool_t pool)
void em_pool_stats_print(em_pool_t pool)
Helper function to print statistics for an EM pool.
em_status_t em_pool_stats_selected(em_pool_t pool, em_pool_stats_selected_t *pool_stats, const em_pool_stats_opt_t *opt)
Retrieve selected statistics about an EM pool.
em_status_t em_pool_info(em_pool_t pool, em_pool_info_t *pool_info)
void em_pool_info_print(em_pool_t pool)
em_status_t em_pool_delete(em_pool_t pool)
em_status_t em_pool_stats_opt(em_pool_t pool, em_pool_stats_opt_t *pool_stats_opt)
int em_pool_subpool_stats(em_pool_t pool, const int subpools[], int num_subpools, em_pool_subpool_stats_t subpool_stats[])
Retrieve statistics about subpool(s) of an EM pool.
em_pool_t em_pool_first(unsigned int *num)
em_status_t em_pool_stats(em_pool_t pool, em_pool_stats_t *pool_stats)
Retrieve statistics about an EM pool.
int em_pool_num_subpools(em_pool_t pool)
Return the number of subpools in an EM pool.
void em_pool_info_print_all(void)
em_event_type_t event_type
em_event_type_t event_type
em_pool_stats_opt_t stats_opt