EM-ODP  3.7.0
Event Machine on ODP
event_machine_pool.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, 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  * The 'em_pool_cfg_t' type given to em_pool_create() is HW/platform specific
61  * and is defined in event_machine_hw_types.h
62  *
63  * Do not include this from the application, event_machine.h will
64  * do it for you.
65  */
66 
67 #ifdef __cplusplus
68 extern "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  */
98 typedef 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  */
130  uint64_t core_cache_available : 1;
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 
141 typedef 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  * .event_type = EM_EVENT_TYPE_VECTOR:
274  * Max number of events in a vector from the subpool, i.e.
275  * 'number of em_event_t:s in the vector's event-table[]'.
276  * EM does not initialize the vector.
277  */
278  uint32_t size;
279 
280  /** Number of events in the subpool (num > 0) */
281  uint32_t num;
282 
283  /**
284  * Maximum number of locally cached subpool events per EM-core.
285  *
286  * Allocating or freeing events from a core-local event-cache
287  * can be faster than using the global event subpool. Cached
288  * events are only available on the local core and can reduce
289  * the number of globally free events in the subpool, thus
290  * consider setting 'num > EM-core-count * cache_size'.
291  * The actual used cache_size will be smaller than or equal to
292  * the requested value, depending on the implementation.
293  */
294  uint32_t cache_size;
295  } subpool[EM_MAX_SUBPOOLS];
296 
297  /**
298  * Pool statistic options for all subpools
299  */
300  struct {
301  /**
302  * Select: Use pool-specific statistic options from below
303  * or use the global default value 'pool.statistics'
304  * from the config file.
305  * false: Use 'pool.statistics' from config file (default).
306  * true: Use pool-specific statistic options set below.
307  */
308  bool in_use;
309 
311  } stats_opt;
312 
313  /**
314  * Internal check - don't touch!
315  *
316  * EM will verify that em_pool_cfg_init(pool_cfg) has been called before
317  * creating a pool with em_pool_create(..., pool_cfg)
318  */
320 } em_pool_cfg_t;
321 
322 /**
323  * EM pool information and usage statistics
324  */
325 typedef struct {
326  /* Pool name */
327  char name[EM_POOL_NAME_LEN];
328  /** EM pool handle */
329  em_pool_t em_pool;
330  /** Event type of events allocated from the pool */
332  /** Event payload alignment offset for events from the pool */
333  uint32_t align_offset;
334  /** Event user area size for events from the pool */
336  /** Number of subpools within one EM pool, max=EM_MAX_SUBPOOLS */
338  struct {
339  /** Event payload size of the subpool */
340  uint32_t size;
341  /** Number of events in the subpool */
342  uint32_t num;
343  /** Max number of locally cached subpool events per EM-core */
344  uint32_t cache_size;
345  /**
346  * Number of events allocated from the subpool.
347  * Only if the 'available' or 'cache_available' is set to true
348  * in 'pool.statistics' of EM config file or in
349  * 'em_pool_cfg_t::stats_opt::opt' given to function
350  * em_pool_create(..., pool_cfg), otherwise .used=0.
351  */
352  uint32_t used;
353  /**
354  * Number of events free in the subpool.
355  * Only if the 'available' or 'cache_available' is set to true
356  * in 'pool.statistics' of EM config file or in
357  * 'em_pool_cfg_t::stats_opt::opt' given to function
358  * em_pool_create(..., pool_cfg), otherwise .free=0.
359  */
360  uint32_t free;
361  } subpool[EM_MAX_SUBPOOLS];
363 
364 typedef struct {
365  /** The number of available events in the pool */
366  uint64_t available;
367 
368  /** The number of alloc operations from the pool. Includes both
369  * successful and failed operations (pool empty).
370  */
371  uint64_t alloc_ops;
372 
373  /** The number of failed alloc operations (pool empty) */
374  uint64_t alloc_fails;
375 
376  /** The number of free operations to the pool */
377  uint64_t free_ops;
378 
379  /** The total number of alloc and free operations. Includes both
380  * successful and failed operations (pool empty).
381  */
382  uint64_t total_ops;
383 
384  /** The number of available events in the local caches of all cores */
385  uint64_t cache_available;
386 
387  /** The number of successful alloc operations from pool caches (returned
388  * at least one event).
389  */
390  uint64_t cache_alloc_ops;
391 
392  /** The number of free operations, which stored events to pool caches. */
393  uint64_t cache_free_ops;
394 
395  /** Internal use - don't touch! */
396  uint64_t __internal_use[EM_POOL_SUBPOOL_STAT_INTERNAL];
398 
399 typedef struct {
400  uint32_t num_subpools;
403 
404 /**
405  * Pool subpool statistics counters
406  *
407  * Same as em_pool_subpool_stats_t excluding the __internal_use.
408  */
409 typedef struct {
410  /** The number of available events in the pool */
411  uint64_t available;
412 
413  /** The number of alloc operations from the pool. Includes both
414  * successful and failed operations (pool empty).
415  */
416  uint64_t alloc_ops;
417 
418  /** The number of failed alloc operations (pool empty) */
419  uint64_t alloc_fails;
420 
421  /** The number of free operations to the pool */
422  uint64_t free_ops;
423 
424  /** The total number of alloc and free operations. Includes both
425  * successful and failed operations (pool empty).
426  */
427  uint64_t total_ops;
428 
429  /** The number of available events in the local caches of all cores */
430  uint64_t cache_available;
431 
432  /** The number of successful alloc operations from pool caches (returned
433  * at least one event).
434  */
435  uint64_t cache_alloc_ops;
436 
437  /** The number of free operations, which stored events to pool caches. */
438  uint64_t cache_free_ops;
440 
441 typedef struct {
442  uint32_t num_subpools;
445 
446 /**
447  * Initialize EM-pool configuration parameters for em_pool_create()
448  *
449  * Initialize em_pool_cfg_t to default values for all fields.
450  * After initialization, the user further needs to update the fields of
451  * 'em_pool_cfg_t' with appropriate sizing information before calling
452  * em_pool_create().
453  *
454  * Always initialize 'pool_cfg' first with em_pool_cfg_init(pool_cfg) to
455  * ensure backwards compatibility with potentially added new options.
456  *
457  * @param pool_cfg Address of the em_pool_cfg_t to be initialized
458  *
459  * @see em_pool_cfg_t and em_pool_create()
460  */
461 void em_pool_cfg_init(em_pool_cfg_t *const pool_cfg);
462 
463 /**
464  * Create a new EM event pool
465  *
466  * Create an EM event pool that can be used for event allocation. The event pool
467  * is created and configured according to the platform/HW specific em_pool_cfg_t
468  * given as argument.
469  *
470  * @param name Pool name (optional, NULL ok)
471  * @param pool A specific pool handle to be used or EM_POOL_UNDEF to let
472  * EM decide (i.e. use a free handle).
473  * @param pool_cfg Pointer to the pool config
474  *
475  * @return EM pool handle or EM_POOL_UNDEF on error
476  *
477  * @see em_pool_cfg_t and em_pool_cfg_init()
478  */
479 em_pool_t
480 em_pool_create(const char *name, em_pool_t pool, const em_pool_cfg_t *pool_cfg);
481 
482 /**
483  * Delete an existing EM event pool
484  *
485  * @param pool EM event pool handle of the pool to be deleted.
486  *
487  * @return EM_OK if successful
488  */
490 em_pool_delete(em_pool_t pool);
491 
492 /**
493  * Find an EM event pool by name.
494  *
495  * Finds a pool by the given name (exact match). An empty string will not match
496  * anything. The search is case sensitive. The function will return the first
497  * match only if there are duplicate names.
498  *
499  * @param name the name to look for
500  *
501  * @return pool handle or EM_POOL_UNDEF if not found
502  *
503  * @see em_pool_create()
504  */
505 em_pool_t
506 em_pool_find(const char *name);
507 
508 /**
509  * Get the name of an EM event pool.
510  *
511  * A copy of the name string (up to 'maxlen' characters) is written to the user
512  * given buffer.
513  * The string is always null terminated, even if the given buffer length is less
514  * than the name length.
515  *
516  * If the event pool has no name, the function returns 0 and writes an
517  * empty string.
518  *
519  * @param pool EM event pool
520  * @param[out] name Destination buffer
521  * @param maxlen Maximum length (including the terminating '0')
522  *
523  * @return Number of characters written (excludes the terminating '0').
524  */
525 size_t
526 em_pool_get_name(em_pool_t pool, char *name /*out*/, size_t maxlen);
527 
528 /**
529  * Initialize event pool iteration and return the first event pool handle.
530  *
531  * Can be used to initialize the iteration to retrieve all created event pools
532  * for debugging or management purposes. Use em_pool_get_next() after this call
533  * until it returns EM_POOL_UNDEF.
534  * A new call to em_pool_get_first() resets the iteration, which is maintained
535  * per core (thread). The operation should be completed in one go before
536  * returning from the EO's event receive function (or start/stop).
537  *
538  * The number of event pools (output arg 'num') may not match the amount of
539  * event pools actually returned by iterating using em_pool_get_next()
540  * if event pools are added or removed in parallel by another core. The order
541  * of the returned event pool handles is undefined.
542  *
543  * @code
544  * unsigned int num;
545  * em_pool_t pool = em_pool_get_first(&num);
546  * while (pool != EM_POOL_UNDEF) {
547  * pool = em_pool_get_next();
548  * }
549  * @endcode
550  *
551  * @param[out] num Pointer to an unsigned int to store the amount of
552  * event pools into
553  * @return The first event pool handle or EM_POOL_UNDEF if none exist
554  *
555  * @see em_pool_get_next()
556  */
557 em_pool_t
558 em_pool_get_first(unsigned int *num /*out*/);
559 
560 /**
561  * Return the next event pool handle.
562  *
563  * Continues the event pool iteration started by em_pool_get_first()
564  * and returns the next event pool handle.
565  *
566  * @return The next event pool handle or EM_POOL_UNDEF if the atomic
567  * group iteration is completed (i.e. no more event pools available).
568  *
569  * @see em_pool_get_first()
570  */
571 em_pool_t
572 em_pool_get_next(void);
573 
574 /**
575  * Retrieve information about an EM pool.
576  *
577  * @param pool EM pool handle
578  * @param[out] pool_info Pointer to pool info that will be written
579  *
580  * @return EM_OK if successful
581  *
582  * @note Set the 'available' or 'cache_available' in 'pool.statistics' of EM
583  * config file or in 'em_pool_cfg_t::stats_opt::opt' given to function
584  * em_pool_create(..., pool_cfg) to true for usage statistics, otherwise,
585  * only basic info is output omitting pool usage information (= all zeros).
586  */
588 em_pool_info(em_pool_t pool, em_pool_info_t *pool_info /*out*/);
589 
590 /**
591  * Helper function to print EM Pool information for a given pool.
592  *
593  * Uses em_pool_info() when printing the pool information.
594  *
595  * @param pool EM pool handle
596  *
597  * @note Set the 'available' or 'cache_available' in 'pool.statistics' of EM
598  * config file or in 'em_pool_cfg_t::stats_opt::opt' given to function
599  * em_pool_create(..., pool_cfg) to true for usage statistics, otherwise,
600  * only basic info is printed, omitting pool usage information (= all zeros).
601  */
602 void
603 em_pool_info_print(em_pool_t pool);
604 
605 /**
606  * @brief Return the number of subpools in an EM pool.
607  *
608  * @param pool EM pool handle
609  *
610  * @return Number of subpools in the given pool(max=EM_MAX_SUBPOOLS)
611  * or -1 on error
612  */
613 int em_pool_get_num_subpools(em_pool_t pool);
614 
615 /**
616  * Helper function to print EM Pool information for all pools in the system.
617  *
618  * Uses em_pool_info() when printing the pool information.
619  *
620  * @note Set the 'available' or 'cache_available' in 'pool.statistics' of EM
621  * config file or in 'em_pool_cfg_t::stats_opt::opt' given to function
622  * em_pool_create(..., pool_cfg) to true for usage statistics, otherwise,
623  * only basic info is printed, omitting pool usage information (= all zeros).
624  */
625 void
627 
628 /**
629  * @brief Retrieve statistics about an EM pool.
630  *
631  * Read the statistic counters enabled in 'em_pool_cfg_t::stats_opt' passed to
632  * em_pool_create() or in the 'pool.statistics' of EM config file. Note that
633  * there may be some delay until performed pool operations are visible in the
634  * statistics.
635  *
636  * @param pool EM pool handle
637  * @param[out] pool_stats Pointer to pool statistics. A successful call
638  * writes to this pointer the requested pool statistics.
639  *
640  * @return EM_OK if the statistics of all subpools of 'pool' are read successfully
641  *
642  * @note Runtime argument checking is not done unless EM_CHECK_LEVEL > 0.
643  *
644  * @see em_pool_cfg_t::stats_opt and em_pool_stats_t.
645  */
646 em_status_t em_pool_stats(em_pool_t pool, em_pool_stats_t *pool_stats /*out*/);
647 
648 /**
649  * Reset statistics for an EM pool.
650  *
651  * Reset all statistic counters in 'em_pool_stats_t::subpool_stats' to zero
652  * except:
653  * 'em_pool_subpool_stats_t::available'
654  * 'em_pool_subpool_stats_t::cache_available',
655  *
656  * @param pool EM Pool handle
657  *
658  * @return EM_OK if successful
659  */
660 em_status_t em_pool_stats_reset(em_pool_t pool);
661 
662 /**
663  * @brief Helper function to print statistics for an EM pool.
664  *
665  * Note that there may be some delay until performed pool operations are visible
666  * in the statistics.
667  *
668  * @param pool EM pool handle
669  *
670  * Uses em_pool_stats() when printing the pool statistics.
671  */
672 void em_pool_stats_print(em_pool_t pool);
673 
674 /**
675  * @brief Retrieve statistics about subpool(s) of an EM pool.
676  *
677  * Read the subpool statistic counters set in 'em_pool_cfg_t::stats_opt' passed
678  * to em_pool_create() or in the 'pool.statistics' of EM config file. Note that
679  * there may be some delay until performed pool operations are visible in the
680  * statistics.
681  *
682  * The function returns the number of subpool statistics actually retrieved. A
683  * return value equal to 'num_subpools' means that the subpool statistics for
684  * given indices in 'subpools' are all retrieved successfully. A value less than
685  * 'num_subpools' means that the statistics for subpools whose indices are given
686  * at the end of 'subpools' can not be fetched. The function will not modify
687  * corresponding 'subpool_stats'.
688  *
689  * @param pool EM pool handle
690  * @param subpools Array of subpool indices, must contain
691  * 'num_subpools' valid subpool-indices.
692  * 0 <= indices < number of subpools 'pool' has.
693  * @param num_subpools Number of subpools to retrieve statistics for.
694  * 0 < num_subpools <= number of subpools 'pool' has.
695  * @param[out] subpool_stats Array of subpool statistics, must have room for
696  * 'num_subpools' entries of subpool statistics.
697  * A successful call writes to this array the requested
698  * subpool statistics [out].
699  *
700  * @return number of stats successfully fetched (equal to 'num_subpools' if all
701  * successful) or 0 on error.
702  *
703  * @code
704  * em_pool_t pool = 1;
705  * int num = 3;
706  * int subpools[3] = [0, 3, 2];
707  * em_pool_subpool_stats_t stats[3];
708  * int ret = em_pool_subpool_stats(pool, subpools, num, stats);
709  * @endcode
710  *
711  * The mapping between stats and subpools is as follows:
712  * stats[0] <-> subpools[0]
713  * stats[1] <-> subpools[1]
714  * ...
715  * stats[num_subpools - 1] <-> subpools[num_subpools - 1]
716  * So in above code, stats[1] stores statistics for the subpool whose index is 3.
717  *
718  * @note Runtime argument checking is not done unless EM_CHECK_LEVEL > 0.
719  *
720  * @see em_pool_cfg_t::stats_opt and em_pool_subpool_stats_t.
721  */
722 int
723 em_pool_subpool_stats(em_pool_t pool, const int subpools[], int num_subpools,
724  em_pool_subpool_stats_t subpool_stats[/*out*/]);
725 
726 /**
727  * Reset statistics for subpool(s) of an EM pool.
728  *
729  * Reset all statistics counters in given subpools of an EM pool to zero except:
730  * 'em_pool_subpool_stats_t::available'
731  * 'em_pool_subpool_stats_t::cache_available'
732  *
733  * @param pool EM pool handle
734  * @param subpools Array of subpool indices
735  * 0 <= indices < number of subpools pool has
736  * @param num_subpools Number of subpools to reset statistics for
737  * 0 < num_subpools <= number of subpools pool has
738  *
739  * @return EM_OK if successful
740  */
742 em_pool_subpool_stats_reset(em_pool_t pool, const int subpools[], int num_subpools);
743 
744 /**
745  * @brief Helper function to print statistics for subpool(s) of an EM pool.
746  *
747  * Note that there may be some delay until performed pool operations are visible
748  * in the statistics.
749  *
750  * @param pool EM pool handle
751  * @param subpools Array of subpool indices
752  * 0 <= indices < number of subpools pool has
753  * @param num_subpools Number of subpools to print statistics for
754  * 0 < num_subpools <= number of subpools pool has
755  *
756  * Uses em_pool_subpool_stats() when printing the subpool statistics.
757  */
758 void em_pool_subpool_stats_print(em_pool_t pool, const int subpools[], int num_subpools);
759 
760 /**
761  * @brief Retrieve selected statistics about an EM pool.
762  *
763  * Read the selected statistic counters specified in 'em_pool_stats_opt_t'. The
764  * selected counters must have been enabled in 'em_pool_cfg_t::stats_opt' passed
765  * to em_pool_create() or in the 'pool.statistics' of EM config file. Values of
766  * the unselected counters are undefined. Note that there may be some delay until
767  * performed pool operations are visible in the statistics.
768  *
769  * @param pool EM pool handle
770  * @param[out] pool_stats Pointer to pool statistics. A successful call
771  * writes to this pointer the requested pool statistics.
772  * @param opt Used to select the statistic counters to read
773  *
774  * @return EM_OK if the selected statistics of all subpools of 'pool' are read
775  * successfully
776  *
777  * @note Runtime argument checking is not done unless EM_CHECK_LEVEL > 0.
778  *
779  * @see em_pool_cfg_t::stats_opt, em_pool_stats_selected_t and em_pool_stats_opt_t.
780  */
782 em_pool_stats_selected(em_pool_t pool, em_pool_stats_selected_t *pool_stats/*out*/,
783  const em_pool_stats_opt_t *opt);
784 
785 /**
786  * @brief Helper function to print selected statistics for an EM pool.
787  *
788  * Note that there may be some delay until performed pool operations are visible
789  * in the statistics.
790  *
791  * @param pool EM pool handle
792  * @param opt Used to select the statistic counters to print
793  *
794  * Uses em_pool_stats_selected() when printing the selected pool statistics.
795  */
796 void em_pool_stats_selected_print(em_pool_t pool, const em_pool_stats_opt_t *opt);
797 
798 /**
799  * @brief Retrieve selected statistics about subpool(s) of an EM pool.
800  *
801  * Read the selected subpool statistic counters given in 'em_pool_stats_opt_t'.
802  * The selected counters must have been enabled in 'em_pool_cfg_t::stats_opt'
803  * passed to em_pool_create() or in the 'pool.statistics' of EM config file.
804  * Values of the unselected counters are undefined. Note that there may be some
805  * delay until performed pool operations are visible in the statistics.
806  *
807  * The function returns the number of selected subpool statistics actually read.
808  * A return value of 'num_subpools' means that the selected subpool statistics
809  * for the given indices in 'subpools' are all retrieved successfully. A value
810  * less than 'num_subpools' means that the selected statistics for subpools whose
811  * indices are given at the end of 'subpools' can not be fetched. The function
812  * will not modify corresponding 'subpool_stats'.
813  *
814  * @param pool EM pool handle
815  * @param subpools Array of subpool indices, must contain
816  * 'num_subpools' valid subpool-indices.
817  * 0 <= indices < number of subpools 'pool' has.
818  * @param num_subpools Number of subpools to retrieve statistics for.
819  * 0 < num_subpools <= number of subpools 'pool' has.
820  * @param[out] subpool_stats Array of subpool statistics, must have room for
821  * 'num_subpools' entries of subpool statistics.
822  * A successful call writes to this array the
823  * requested subpool statistics [out].
824  * @param opt Used to select the statistic counters to read
825  *
826  * @return number of subpool_stats successfully fetched (equal to 'num_subpools'
827  * if all successful) or 0 on error.
828  *
829  * @code
830  * em_pool_t pool = 1;
831  * int num = 3;
832  * int subpools[3] = [0, 3, 2];
833  * em_pool_subpool_stats_selected_t stats[3];
834  * em_pool_stats_opt_t opt = {.bit.available = 1};
835  * int ret = em_pool_subpool_stats_selected(pool, subpools, num, stats, &opt);
836  * @endcode
837  *
838  * The mapping between stats and subpools is as follows:
839  * stats[0] <-> subpools[0]
840  * stats[1] <-> subpools[1]
841  * ...
842  * stats[num_subpools - 1] <-> subpools[num_subpools - 1]
843  * So in above code, stats[1] stores selected statistics for the subpool whose
844  * index is 3.
845  *
846  * @note Runtime argument checking is not done unless EM_CHECK_LEVEL > 0.
847  *
848  * @see em_pool_cfg_t::stats_opt, em_pool_subpool_stats_selected_t and em_pool_stats_opt_t.
849  */
850 int em_pool_subpool_stats_selected(em_pool_t pool, const int subpools[], int num_subpools,
851  em_pool_subpool_stats_selected_t subpool_stats[/*out*/],
852  const em_pool_stats_opt_t *opt);
853 
854 /**
855  * @brief Helper function to print selected statistics for subpool(s) of an EM pool.
856  *
857  * Note that there may be some delay until performed pool operations are visible
858  * in the statistics.
859  *
860  * @param pool EM pool handle
861  * @param subpools Array of subpool indices
862  * 0 <= indices < number of subpools pool has
863  * @param num_subpools Number of subpools to print statistics for
864  * 0 < num_subpools <= number of subpools pool has
865  * @param opt Used to select the statistic counters to print
866  *
867  * Uses em_pool_subpool_stats_selected() when printing the selected subpool statistics.
868  */
869 void em_pool_subpool_stats_selected_print(em_pool_t pool, const int subpools[],
870  int num_subpools, const em_pool_stats_opt_t *opt);
871 /**
872  * Convert an EM pool handle to an unsigned integer
873  *
874  * @param pool EM pool handle to be converted
875  * @return uint64_t value that can be used to print/display the handle
876  *
877  * @note This routine is intended to be used for diagnostic purposes
878  * to enable applications to e.g. generate a printable value that represents
879  * an em_pool_t handle.
880  */
881 uint64_t em_pool_to_u64(em_pool_t pool);
882 
883 /**
884  * @}
885  */
886 #ifdef __cplusplus
887 }
888 #endif
889 
890 #pragma GCC visibility pop
891 #endif /* EVENT_MACHINE_POOL_H_ */
em_pool_get_num_subpools
int em_pool_get_num_subpools(em_pool_t pool)
Return the number of subpools in an EM pool.
Definition: event_machine_pool.c:293
em_pool_stats_opt_t::available
uint64_t available
Definition: event_machine_pool.h:102
em_pool_subpool_stats
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.
Definition: event_machine_pool.c:399
em_pool_stats_opt_t::all
uint64_t all
Definition: event_machine_pool.h:138
em_pool_info_t::align_offset
uint32_t align_offset
Definition: event_machine_pool.h:333
em_pool_info_t::size
uint32_t size
Definition: event_machine_pool.h:340
em_pool_get_next
em_pool_t em_pool_get_next(void)
Definition: event_machine_pool.c:194
em_pool_stats_opt_t::alloc_ops
uint64_t alloc_ops
Definition: event_machine_pool.h:105
em_pool_subpool_stats_reset
em_status_t em_pool_subpool_stats_reset(em_pool_t pool, const int subpools[], int num_subpools)
Definition: event_machine_pool.c:450
em_pool_subpool_stats_print
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.
Definition: event_machine_pool.c:481
em_pool_find
em_pool_t em_pool_find(const char *name)
Definition: event_machine_pool.c:127
em_pool_stats_opt_t::cache_alloc_ops
uint64_t cache_alloc_ops
Definition: event_machine_pool.h:120
em_pool_stats_opt_t::core_cache_available
uint64_t core_cache_available
Definition: event_machine_pool.h:130
em_pool_info_t::em_pool
em_pool_t em_pool
Definition: event_machine_pool.h:329
em_pool_stats_print
void em_pool_stats_print(em_pool_t pool)
Helper function to print statistics for an EM pool.
Definition: event_machine_pool.c:390
em_pool_info_print_all
void em_pool_info_print_all(void)
Definition: event_machine_pool.c:313
em_pool_info_t::num
uint32_t num
Definition: event_machine_pool.h:342
em_pool_subpool_stats_t::cache_free_ops
uint64_t cache_free_ops
Definition: event_machine_pool.h:393
em_pool_info_t::used
uint32_t used
Definition: event_machine_pool.h:352
em_pool_cfg_t::value
uint32_t value
Definition: event_machine_pool.h:194
em_pool_info_t::num_subpools
int num_subpools
Definition: event_machine_pool.h:337
em_pool_stats_opt_t::free_ops
uint64_t free_ops
Definition: event_machine_pool.h:111
em_pool_subpool_stats_selected_t::free_ops
uint64_t free_ops
Definition: event_machine_pool.h:422
em_pool_cfg_t::in_use
bool in_use
Definition: event_machine_pool.h:185
em_pool_subpool_stats_selected_t::available
uint64_t available
Definition: event_machine_pool.h:411
em_pool_info_t::user_area_size
size_t user_area_size
Definition: event_machine_pool.h:335
em_pool_create
em_pool_t em_pool_create(const char *name, em_pool_t pool, const em_pool_cfg_t *pool_cfg)
Definition: event_machine_pool.c:76
em_pool_subpool_stats_t::alloc_fails
uint64_t alloc_fails
Definition: event_machine_pool.h:374
em_pool_stats_opt_t::cache_free_ops
uint64_t cache_free_ops
Definition: event_machine_pool.h:123
em_pool_stats_selected_t
Definition: event_machine_pool.h:441
em_pool_subpool_stats_selected_print
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.
Definition: event_machine_pool.c:612
em_pool_delete
em_status_t em_pool_delete(em_pool_t pool)
Definition: event_machine_pool.c:115
em_pool_subpool_stats_selected_t::cache_available
uint64_t cache_available
Definition: event_machine_pool.h:430
em_pool_get_name
size_t em_pool_get_name(em_pool_t pool, char *name, size_t maxlen)
Definition: event_machine_pool.c:136
em_pool_cfg_t::size
uint32_t size
Definition: event_machine_pool.h:278
em_pool_cfg_t
Definition: event_machine_pool.h:141
em_pool_info_t::cache_size
uint32_t cache_size
Definition: event_machine_pool.h:344
em_pool_subpool_stats_t
Definition: event_machine_pool.h:364
em_pool_subpool_stats_selected_t::total_ops
uint64_t total_ops
Definition: event_machine_pool.h:427
em_pool_subpool_stats_t::free_ops
uint64_t free_ops
Definition: event_machine_pool.h:377
em_pool_subpool_stats_selected_t::alloc_fails
uint64_t alloc_fails
Definition: event_machine_pool.h:419
em_pool_stats_opt_t::total_ops
uint64_t total_ops
Definition: event_machine_pool.h:114
em_pool_cfg_init
void em_pool_cfg_init(em_pool_cfg_t *const pool_cfg)
Definition: event_machine_pool.c:43
em_pool_cfg_t::num
uint32_t num
Definition: event_machine_pool.h:281
em_pool_stats_opt_t::cache_available
uint64_t cache_available
Definition: event_machine_pool.h:117
em_pool_cfg_t::__internal_check
uint32_t __internal_check
Definition: event_machine_pool.h:319
em_pool_cfg_t::cache_size
uint32_t cache_size
Definition: event_machine_pool.h:294
em_pool_cfg_t::num_subpools
int num_subpools
Definition: event_machine_pool.h:264
em_pool_info_t::event_type
em_event_type_t event_type
Definition: event_machine_pool.h:331
em_pool_info
em_status_t em_pool_info(em_pool_t pool, em_pool_info_t *pool_info)
Definition: event_machine_pool.c:216
em_pool_stats_opt_t::alloc_fails
uint64_t alloc_fails
Definition: event_machine_pool.h:108
em_status_t
uint32_t em_status_t
Definition: event_machine_types.h:321
em_pool_subpool_stats_t::alloc_ops
uint64_t alloc_ops
Definition: event_machine_pool.h:371
em_pool_subpool_stats_t::available
uint64_t available
Definition: event_machine_pool.h:366
em_pool_stats_t
Definition: event_machine_pool.h:399
em_event_type_t
uint32_t em_event_type_t
Definition: event_machine_types.h:85
em_pool_info_print
void em_pool_info_print(em_pool_t pool)
Definition: event_machine_pool.c:287
em_pool_stats_opt_t
Definition: event_machine_pool.h:98
em_pool_subpool_stats_selected_t::cache_alloc_ops
uint64_t cache_alloc_ops
Definition: event_machine_pool.h:435
em_pool_subpool_stats_t::cache_available
uint64_t cache_available
Definition: event_machine_pool.h:385
em_pool_subpool_stats_selected
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.
Definition: event_machine_pool.c:554
EM_POOL_NAME_LEN
#define EM_POOL_NAME_LEN
Definition: event_machine_hw_config.h:196
em_pool_get_first
em_pool_t em_pool_get_first(unsigned int *num)
Definition: event_machine_pool.c:166
em_pool_subpool_stats_selected_t::cache_free_ops
uint64_t cache_free_ops
Definition: event_machine_pool.h:438
em_pool_to_u64
uint64_t em_pool_to_u64(em_pool_t pool)
Definition: event_machine_pool.c:619
em_pool_cfg_t::size
size_t size
Definition: event_machine_pool.h:224
em_pool_stats_selected
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.
Definition: event_machine_pool.c:501
em_pool_cfg_t::event_type
em_event_type_t event_type
Definition: event_machine_pool.h:156
EM_MAX_SUBPOOLS
#define EM_MAX_SUBPOOLS
The number of subpools in each EM pool. The subpool is a pool with buffers of only one size.
Definition: event_machine_hw_types.h:254
em_pool_subpool_stats_t::cache_alloc_ops
uint64_t cache_alloc_ops
Definition: event_machine_pool.h:390
em_pool_info_t::free
uint32_t free
Definition: event_machine_pool.h:360
em_pool_info_t
Definition: event_machine_pool.h:325
em_pool_subpool_stats_selected_t
Definition: event_machine_pool.h:409
EM_POOL_SUBPOOL_STAT_INTERNAL
#define EM_POOL_SUBPOOL_STAT_INTERNAL
Definition: event_machine_hw_config.h:208
em_pool_stats
em_status_t em_pool_stats(em_pool_t pool, em_pool_stats_t *pool_stats)
Retrieve statistics about an EM pool.
Definition: event_machine_pool.c:327
em_pool_subpool_stats_selected_t::alloc_ops
uint64_t alloc_ops
Definition: event_machine_pool.h:416
em_pool_stats_selected_print
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.
Definition: event_machine_pool.c:546
em_pool_subpool_stats_t::total_ops
uint64_t total_ops
Definition: event_machine_pool.h:382
em_pool_stats_reset
em_status_t em_pool_stats_reset(em_pool_t pool)
Definition: event_machine_pool.c:365