36 EM_ODP_EM_DEFAULT_POOL_ERROR);
38 EM_ODP_EM_POOL_UNDEF_ERROR);
41 EM_ODP_EM_EVENT_USER_AREA_MAX_SIZE_ERROR);
48 #define ALIGN_OFFSET_MAX ((int)(16))
51 COMPILE_TIME_ASSERT(ALIGN_OFFSET_MAX <=
52 ((1 << (sizeof_field(
event_hdr_t, align_offset) * 8)) - 1),
53 ALIGN_OFFSET_MAX__TOO_LARGE);
70 pool_alloc(em_pool_t pool)
78 if (unlikely(objpool_elem == NULL))
81 mpool_elem = mpool_poolelem2pool(objpool_elem);
85 mpool_elem = pool_elem_get(pool);
86 if (unlikely(mpool_elem == NULL))
89 ret = objpool_rem_elem(&
em_shm->mpool_pool.objpool,
91 if (unlikely(ret != 0))
100 pool_free(em_pool_t pool)
104 if (unlikely(mpool_elem == NULL))
107 objpool_add(&
em_shm->mpool_pool.objpool,
115 static int event_type_from_string(
const char *str,
em_event_type_t *event_type )
117 if (strstr(str,
"EM_EVENT_TYPE_SW")) {
119 }
else if (strstr(str,
"EM_EVENT_TYPE_PACKET")) {
121 }
else if (strstr(str,
"EM_EVENT_TYPE_VECTOR")) {
124 EM_LOG(EM_LOG_ERR,
"Event type %s not supported.\n", str);
132 static inline int read_config_subpool(
const libconfig_list_t *subpool,
int index,
137 ret = em_libconfig_list_lookup_int(subpool, index,
"size",
139 if (unlikely(ret != 1)) {
141 "Option '%s.subpools[%d].size' not found or wrong type.\n",
142 pool_cfg_str, index);
147 EM_LOG(EM_LOG_ERR,
"Invalid '%s.subpools[%d].size'.\n",
148 pool_cfg_str, index);
153 ret = em_libconfig_list_lookup_int(subpool, index,
"num",
155 if (unlikely(ret != 1)) {
157 "Option '%s.subpools[%d].num' not found or wrong type.\n",
158 pool_cfg_str, index);
163 EM_LOG(EM_LOG_ERR,
"Invalid '%s.subpools[%d].num'.\n",
164 pool_cfg_str, index);
172 ret = em_libconfig_list_lookup_int(subpool, index,
"cache_size",
177 uint32_t min_cache_size;
178 const odp_pool_capability_t *capa;
180 capa = &
em_shm->mpool_tbl.odp_pool_capability;
183 capa->buf.min_cache_size : capa->pkt.min_cache_size;
187 "'%s.subpools[%d].cache_size' too small.\n",
188 pool_cfg_str, index);
191 }
else if (ret == 0) {
193 "'%s.subpools[%d].cache_size' wrong data type.\n",
194 pool_cfg_str, index);
203 const char **err_str)
205 const odp_pool_capability_t *capa = &
em_shm->mpool_tbl.odp_pool_capability;
208 if (capa->buf.max_pools == 0) {
209 *err_str =
"SW (buf) pool type unsupported";
213 if (capa->pkt.max_pools == 0) {
214 *err_str =
"PACKET pool type unsupported";
218 if (capa->vector.max_pools == 0) {
219 *err_str =
"VECTOR pool type unsupported";
223 *err_str =
"Pool type unsupported, use _SW, _PACKET or _VECTOR";
230 static inline bool is_align_offset_valid(
const em_pool_cfg_t *pool_cfg)
241 static inline int is_user_area_valid(
const em_pool_cfg_t *pool_cfg,
242 const odp_pool_capability_t *capa,
243 const char **err_str)
250 *err_str =
"Event user area too large";
257 if (req_odp_uarea_sz > capa->pkt.max_uarea_size) {
258 *err_str =
"ODP pkt max uarea not large enough";
265 if (req_odp_uarea_sz > capa->vector.max_uarea_size) {
266 *err_str =
"ODP pkt-vector max uarea not large enough";
275 static inline int read_config_align_offset(
const libconfig_group_t *align_offset,
276 const char *pool_cfg_str,
282 ret = em_libconfig_group_lookup_bool(align_offset,
"in_use",
284 if (unlikely(!ret)) {
286 "'%s.align_offset.in_use' not found or wrong type\n",
292 ret = em_libconfig_group_lookup_int(align_offset,
"value",
294 if (unlikely(!ret)) {
296 "'%s.align_offset.value' not found or wrong type\n",
302 if (!is_align_offset_valid(cfg)) {
303 EM_LOG(EM_LOG_ERR,
"Invalid '%s.align_offset.value': %d\n"
304 "Max align_offset is %d and it must be power of 2\n",
313 static inline int read_config_user_area(
const libconfig_group_t *user_area,
314 const char *pool_cfg_str,
318 const odp_pool_capability_t *capa;
319 const char *err_str =
"";
322 ret = em_libconfig_group_lookup_bool(user_area,
"in_use",
324 if (unlikely(!ret)) {
326 "'%s.user_area.in_use' not found or wrong type\n",
332 ret = em_libconfig_group_lookup_int(user_area,
"size",
334 if (unlikely(!ret)) {
336 "'%s.user_area.size' not found or wrong type\n",
341 capa = &
em_shm->mpool_tbl.odp_pool_capability;
343 if (is_user_area_valid(cfg, capa, &err_str) < 0) {
344 EM_LOG(EM_LOG_ERR,
"%s: %ld\n", err_str, cfg->
user_area.
size);
352 static inline int read_config_pkt_headroom(
const libconfig_group_t *pkt_headroom,
353 const char *pool_cfg_str,
357 const odp_pool_capability_t *capa;
360 ret = em_libconfig_group_lookup_bool(pkt_headroom,
"in_use",
362 if (unlikely(!ret)) {
364 "'%s.pkt.headroom.in_use' not found or wrong type\n",
370 ret = em_libconfig_group_lookup_int(pkt_headroom,
"value",
372 if (unlikely(!ret)) {
374 "'%s.pkt.headroom.value' not found or wrong type\n",
380 capa = &
em_shm->mpool_tbl.odp_pool_capability;
382 cfg->
pkt.
headroom.value > capa->pkt.max_headroom) {
384 "'%s.pkt.headroom.value' %d too large (max=%d)\n",
386 capa->pkt.max_headroom);
394 static int read_config_startup_pools_conf(
const libconfig_list_t *list,
int index)
400 const char *pool_name;
401 const char *event_type;
402 char pool_cfg_str[40];
403 libconfig_group_t *pool_cfg;
404 const libconfig_list_t *subpool;
405 const libconfig_group_t *headroom;
406 const libconfig_group_t *user_area;
407 const libconfig_group_t *align_offset;
410 const char *err_str =
"";
412 snprintf(pool_cfg_str,
sizeof(pool_cfg_str),
413 "startup_pools.conf[%d].pool_cfg", index);
415 pool_cfg = em_libconfig_list_lookup_group(list, index,
"pool_cfg");
417 EM_LOG(EM_LOG_ERR,
"Conf option '%s' not found\n", pool_cfg_str);
429 ret = em_libconfig_group_lookup_string(pool_cfg,
"event_type", &event_type);
430 if (unlikely(!ret)) {
431 EM_LOG(EM_LOG_ERR,
"'%s.event_type' not found.\n", pool_cfg_str);
435 ret = event_type_from_string(event_type, &cfg->
event_type);
436 if (unlikely(ret < 0))
439 ret = is_pool_type_supported(cfg->
event_type, &err_str);
441 EM_LOG(EM_LOG_ERR,
"%s", err_str);
446 ret = em_libconfig_group_lookup_int(pool_cfg,
"num_subpools",
448 if (unlikely(!ret)) {
449 EM_LOG(EM_LOG_ERR,
"'%s.num_subpools' not found.\n", pool_cfg_str);
454 EM_LOG(EM_LOG_ERR,
"Invalid '%s.num_subpools'\n"
455 "Valid value range is [1, %d]\n", pool_cfg_str,
461 subpool = em_libconfig_group_lookup_list(pool_cfg,
"subpools");
462 if (unlikely(!subpool)) {
463 EM_LOG(EM_LOG_ERR,
"'%s.subpools' not found.\n", pool_cfg_str);
467 num_subpools = em_libconfig_list_length(subpool);
469 EM_LOG(EM_LOG_ERR,
"The number of subpool configuration given\n"
470 "in '%s.subpools' does not match '%s.num_subpools'.\n",
471 pool_cfg_str, pool_cfg_str);
475 for (
int j = 0; j < num_subpools; j++) {
476 ret = read_config_subpool(subpool, j, pool_cfg_str, cfg);
478 if (unlikely(ret < 0))
485 ret_pool = em_libconfig_list_lookup_int(list, index,
"pool", &pool);
486 if (unlikely(ret_pool == 0)) {
488 "'startup_pools.conf[%d].pool' has wrong data type(expect int)\n",
496 EM_LOG(EM_LOG_ERR,
"Invalid pool ID %d, valid IDs are within [0, %d]\n",
501 conf->pool = (em_pool_t)(uintptr_t)pool;
505 ret = em_libconfig_list_lookup_string(list, index,
"name", &pool_name);
506 if (unlikely(ret == 0)) {
508 "'startup_pools.conf[%d].name' has wrong data type(expect string)\n",
513 if (ret_pool == 1 && ret == 1) {
517 if (is_default_name && !is_default_id) {
519 "Default name \"%s\" with non-default ID %d\n",
524 if (is_default_id && !is_default_name) {
526 "Default pool ID 1 with non-default name \"%s\"\n",
537 align_offset = em_libconfig_group_lookup_group(pool_cfg,
"align_offset");
539 if (align_offset && read_config_align_offset(align_offset, pool_cfg_str, cfg))
542 user_area = em_libconfig_group_lookup_group(pool_cfg,
"user_area");
543 if (user_area && read_config_user_area(user_area, pool_cfg_str, cfg))
546 headroom = em_libconfig_group_lookup_group(pool_cfg,
"pkt.headroom");
548 if (read_config_pkt_headroom(headroom, pool_cfg_str, cfg))
553 EM_PRINT(
"pkt.headroom will be ignored for non packet type!\n");
560 static void print_config_startup_pools(
void)
564 const char *str =
"";
566 EM_PRINT(
" startup_pools.num: %u\n",
em_shm->opt.startup_pools.num);
568 for (uint32_t i = 0; i <
em_shm->opt.startup_pools.num; i++) {
569 conf = &
em_shm->opt.startup_pools.conf[i];
571 snprintf(str_conf,
sizeof(str_conf),
" startup_pools.conf[%d]", i);
574 EM_PRINT(
"%s.name: %s\n", str_conf, conf->name);
577 EM_PRINT(
"%s.pool: %d\n", str_conf, (
int)(uintptr_t)conf->pool);
581 str =
"EM_EVENT_TYPE_SW";
583 str =
"EM_EVENT_TYPE_PACKET";
585 str =
"EM_EVENT_TYPE_VECTOR";
586 EM_PRINT(
"%s.pool_cfg.event_type: %s\n", str_conf, str);
590 EM_PRINT(
"%s.pool_cfg.align_offset.in_use: %s\n", str_conf, str);
591 EM_PRINT(
"%s.pool_cfg.align_offset.value: %d\n", str_conf,
596 EM_PRINT(
"%s.pool_cfg.user_area.in_use: %s\n", str_conf, str);
597 EM_PRINT(
"%s.pool_cfg.user_area.size: %ld\n", str_conf,
601 str = conf->cfg.
pkt.
headroom.in_use ?
"true" :
"false";
602 EM_PRINT(
"%s.pool_cfg.pkt.headroom.in_use: %s\n", str_conf, str);
603 EM_PRINT(
"%s.pool_cfg.pkt.headroom.value: %d\n", str_conf,
607 EM_PRINT(
"%s.pool_cfg.num_subpools: %u\n", str_conf,
612 EM_PRINT(
"%s.pool_cfg.subpools[%d].size: %u\n", str_conf,
615 EM_PRINT(
"%s.pool_cfg.subpools[%d].num: %u\n", str_conf,
618 EM_PRINT(
"%s.pool_cfg.subpools[%d].cache_size: %u\n",
625 static int read_config_startup_pools(
void)
629 int num_startup_pools;
630 const libconfig_list_t *conf_list;
631 libconfig_setting_t *default_setting;
632 libconfig_setting_t *runtime_setting;
633 libconfig_setting_t *startup_pools_setting;
636 &default_setting, &runtime_setting);
650 startup_pools_setting = runtime_setting;
655 startup_pools_setting = default_setting;
660 EM_PRINT(
"EM-startup_pools config:\n");
665 ret = em_libconfig_setting_lookup_int(startup_pools_setting,
"num",
667 if (unlikely(!ret)) {
668 EM_LOG(EM_LOG_ERR,
"Option 'startup_pools.num' not found\n");
672 if (num_startup_pools <= 0 || num_startup_pools >
EM_CONFIG_POOLS - 1) {
674 "Number of startup_pools %d is too large or too small\n"
675 "Valid value range is [1, %d]\n",
680 conf_list = em_libconfig_setting_get_list(startup_pools_setting,
"conf");
682 EM_LOG(EM_LOG_ERR,
"Conf option 'startup_pools.conf' not found\n");
686 list_len = em_libconfig_list_length(conf_list);
687 if (list_len != num_startup_pools) {
689 "The number of pool configuration(s) given in\n"
690 "'startup_pools.conf':%d does not match number of\n"
691 "startup_pools specified in 'startup_pools.num': %d\n",
692 list_len, num_startup_pools);
696 for (
int i = 0; i < list_len; i++) {
697 if (read_config_startup_pools_conf(conf_list, i) < 0)
701 em_shm->opt.startup_pools.num = num_startup_pools;
703 print_config_startup_pools();
708 static int read_config_pool(
void)
710 const char *conf_str;
711 bool val_bool =
false;
715 const odp_pool_capability_t *capa =
716 &
em_shm->mpool_tbl.odp_pool_capability;
718 EM_PRINT(
"EM-pool config:\n");
723 conf_str =
"pool.statistics.available";
724 ret = em_libconfig_lookup_bool(&
em_shm->
libconfig, conf_str, &val_bool);
725 if (unlikely(!ret)) {
726 EM_LOG(EM_LOG_ERR,
"Config option '%s' not found\n", conf_str);
729 em_shm->opt.pool.statistics.available = (int)val_bool;
730 EM_PRINT(
" %s: %s(%d)\n", conf_str, val_bool ?
"true" :
"false", val_bool);
735 conf_str =
"pool.statistics.alloc_ops";
736 ret = em_libconfig_lookup_bool(&
em_shm->
libconfig, conf_str, &val_bool);
737 if (unlikely(!ret)) {
738 EM_LOG(EM_LOG_ERR,
"Config option '%s' not found\n", conf_str);
741 em_shm->opt.pool.statistics.alloc_ops = (int)val_bool;
742 EM_PRINT(
" %s: %s(%d)\n", conf_str, val_bool ?
"true" :
"false", val_bool);
747 conf_str =
"pool.statistics.alloc_fails";
748 ret = em_libconfig_lookup_bool(&
em_shm->
libconfig, conf_str, &val_bool);
749 if (unlikely(!ret)) {
750 EM_LOG(EM_LOG_ERR,
"Config option '%s' not found\n", conf_str);
753 em_shm->opt.pool.statistics.alloc_fails = (int)val_bool;
754 EM_PRINT(
" %s: %s(%d)\n", conf_str, val_bool ?
"true" :
"false", val_bool);
759 conf_str =
"pool.statistics.free_ops";
760 ret = em_libconfig_lookup_bool(&
em_shm->
libconfig, conf_str, &val_bool);
761 if (unlikely(!ret)) {
762 EM_LOG(EM_LOG_ERR,
"Config option '%s' not found\n", conf_str);
765 em_shm->opt.pool.statistics.free_ops = (int)val_bool;
766 EM_PRINT(
" %s: %s(%d)\n", conf_str, val_bool ?
"true" :
"false", val_bool);
771 conf_str =
"pool.statistics.total_ops";
772 ret = em_libconfig_lookup_bool(&
em_shm->
libconfig, conf_str, &val_bool);
773 if (unlikely(!ret)) {
774 EM_LOG(EM_LOG_ERR,
"Config option '%s' not found\n", conf_str);
777 em_shm->opt.pool.statistics.total_ops = (int)val_bool;
778 EM_PRINT(
" %s: %s(%d)\n", conf_str, val_bool ?
"true" :
"false", val_bool);
783 conf_str =
"pool.statistics.cache_available";
784 ret = em_libconfig_lookup_bool(&
em_shm->
libconfig, conf_str, &val_bool);
785 if (unlikely(!ret)) {
786 EM_LOG(EM_LOG_ERR,
"Config option '%s' not found\n", conf_str);
789 em_shm->opt.pool.statistics.cache_available = (int)val_bool;
790 EM_PRINT(
" %s: %s(%d)\n", conf_str, val_bool ?
"true" :
"false", val_bool);
795 conf_str =
"pool.statistics.cache_alloc_ops";
796 ret = em_libconfig_lookup_bool(&
em_shm->
libconfig, conf_str, &val_bool);
797 if (unlikely(!ret)) {
798 EM_LOG(EM_LOG_ERR,
"Config option '%s' not found\n", conf_str);
801 em_shm->opt.pool.statistics.cache_alloc_ops = (int)val_bool;
802 EM_PRINT(
" %s: %s(%d)\n", conf_str, val_bool ?
"true" :
"false", val_bool);
807 conf_str =
"pool.statistics.cache_free_ops";
808 ret = em_libconfig_lookup_bool(&
em_shm->
libconfig, conf_str, &val_bool);
809 if (unlikely(!ret)) {
810 EM_LOG(EM_LOG_ERR,
"Config option '%s' not found\n", conf_str);
813 em_shm->opt.pool.statistics.cache_free_ops = (int)val_bool;
814 EM_PRINT(
" %s: %s(%d)\n", conf_str, val_bool ?
"true" :
"false", val_bool);
819 conf_str =
"pool.statistics.core_cache_available";
820 ret = em_libconfig_lookup_bool(&
em_shm->
libconfig, conf_str, &val_bool);
821 if (unlikely(!ret)) {
822 EM_LOG(EM_LOG_ERR,
"Config option '%s' not found\n", conf_str);
825 em_shm->opt.pool.statistics.core_cache_available = (int)val_bool;
826 EM_PRINT(
" %s: %s(%d)\n", conf_str, val_bool ?
"true" :
"false", val_bool);
831 conf_str =
"pool.align_offset";
833 if (unlikely(!ret)) {
834 EM_LOG(EM_LOG_ERR,
"Config option '%s' not found.\n", conf_str);
837 if (val < 0 || val > ALIGN_OFFSET_MAX || !POWEROF2(val)) {
839 "Bad config value '%s = %d' (max: %d and value must be power of 2)\n",
840 conf_str, val, ALIGN_OFFSET_MAX);
844 em_shm->opt.pool.align_offset = val;
845 EM_PRINT(
" %s (default): %d (max: %d)\n",
846 conf_str, val, ALIGN_OFFSET_MAX);
851 conf_str =
"pool.user_area_size";
853 if (unlikely(!ret)) {
854 EM_LOG(EM_LOG_ERR,
"Config option '%s' not found.\n", conf_str);
857 if (val < 0 || (
unsigned int)val > capa->pkt.max_uarea_size ||
859 EM_LOG(EM_LOG_ERR,
"Bad config value '%s = %d'\n",
864 em_shm->opt.pool.user_area_size = val;
865 EM_PRINT(
" %s (default): %d (max: %d)\n",
872 conf_str =
"pool.pkt_headroom";
874 if (unlikely(!ret)) {
875 EM_LOG(EM_LOG_ERR,
"Config option '%s' not found.\n", conf_str);
879 if (val < 0 || (
unsigned int)val > capa->pkt.max_headroom) {
880 EM_LOG(EM_LOG_ERR,
"Bad config value '%s = %d'\n",
885 em_shm->opt.pool.pkt_headroom = val;
886 EM_PRINT(
" %s (default): %d (max: %u)\n",
887 conf_str, val, capa->pkt.max_headroom);
893 read_config_file(
void)
896 if (read_config_pool() < 0)
900 if (read_config_startup_pools() < 0)
917 "Size of odp_pool_stats_t must be smaller than that of em_pool_subpool_stats_t");
919 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_t, available) ==
921 sizeof_field(odp_pool_stats_t, available) ==
923 "em_pool_subpool_stats_t.available differs from odp_pool_stats_t.available!");
925 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_t, alloc_ops) ==
927 sizeof_field(odp_pool_stats_t, alloc_ops) ==
929 "em_pool_subpool_stats_t.alloc_ops differs from odp_pool_stats_t.alloc_ops!");
931 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_t, alloc_fails) ==
933 sizeof_field(odp_pool_stats_t, alloc_fails) ==
935 "em_pool_subpool_stats_t.alloc_fails differs from odp_pool_stats_t.alloc_fails!");
937 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_t, free_ops) ==
939 sizeof_field(odp_pool_stats_t, free_ops) ==
941 "em_pool_subpool_stats_t.free_ops differs from odp_pool_stats_t.free_ops!");
943 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_t, total_ops) ==
945 sizeof_field(odp_pool_stats_t, total_ops) ==
947 "em_pool_subpool_stats_t.total_ops differs from odp_pool_stats_t.total_ops!");
949 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_t, cache_available) ==
951 sizeof_field(odp_pool_stats_t, cache_available) ==
953 "em_pool_subpool_stats_t.cache_available differs from that of odp_pool_stats_t!");
955 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_t, cache_alloc_ops) ==
957 sizeof_field(odp_pool_stats_t, cache_alloc_ops) ==
959 "em_pool_subpool_stats_t.cache_alloc_ops differs from that of odp_pool_stats_t!");
961 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_t, cache_free_ops) ==
963 sizeof_field(odp_pool_stats_t, cache_free_ops) ==
965 "em_pool_subpool_stats_t.cache_free_ops differs from that of odp_pool_stats_t!");
967 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_t, thread) ==
969 sizeof_field(odp_pool_stats_t, thread) <=
971 "em_pool_subpool_stats_t.__internal_use differs from odp_pool_stats_t.thread");
973 #define STRUCT_ERR_STR \
974 "em_pool_subpool_stats_t.%s differs from odp_pool_stats_t.%s either in size or in offset!\n"
976 static int check_em_pool_subpool_stats(
void)
980 "Size of odp_pool_stats_t bigger than that of em_pool_subpool_stats_t\n");
984 if (offsetof(odp_pool_stats_t, available) !=
986 sizeof_field(odp_pool_stats_t, available) !=
988 EM_LOG(EM_LOG_ERR, STRUCT_ERR_STR,
"available",
"available");
992 if (offsetof(odp_pool_stats_t, alloc_ops) !=
994 sizeof_field(odp_pool_stats_t, alloc_ops) !=
996 EM_LOG(EM_LOG_ERR, STRUCT_ERR_STR,
"alloc_ops",
"alloc_ops");
1000 if (offsetof(odp_pool_stats_t, alloc_fails) !=
1002 sizeof_field(odp_pool_stats_t, alloc_fails) !=
1004 EM_LOG(EM_LOG_ERR, STRUCT_ERR_STR,
"alloc_fails",
"alloc_fails");
1008 if (offsetof(odp_pool_stats_t, free_ops) !=
1010 sizeof_field(odp_pool_stats_t, free_ops) !=
1012 EM_LOG(EM_LOG_ERR, STRUCT_ERR_STR,
"free_ops",
"free_ops");
1016 if (offsetof(odp_pool_stats_t, total_ops) !=
1018 sizeof_field(odp_pool_stats_t, total_ops) !=
1020 EM_LOG(EM_LOG_ERR, STRUCT_ERR_STR,
"total_ops",
"total_ops");
1024 if (offsetof(odp_pool_stats_t, cache_available) !=
1026 sizeof_field(odp_pool_stats_t, cache_available) !=
1028 EM_LOG(EM_LOG_ERR, STRUCT_ERR_STR,
"cache_available",
"cache_available");
1032 if (offsetof(odp_pool_stats_t, cache_alloc_ops) !=
1034 sizeof_field(odp_pool_stats_t, cache_alloc_ops) !=
1036 EM_LOG(EM_LOG_ERR, STRUCT_ERR_STR,
"cache_alloc_ops",
"cache_alloc_ops");
1040 if (offsetof(odp_pool_stats_t, cache_free_ops) !=
1042 sizeof_field(odp_pool_stats_t, cache_free_ops) !=
1044 EM_LOG(EM_LOG_ERR, STRUCT_ERR_STR,
"cache_free_ops",
"cache_free_ops");
1048 if (offsetof(odp_pool_stats_t, thread) !=
1050 sizeof_field(odp_pool_stats_t, thread) >
1052 EM_LOG(EM_LOG_ERR, STRUCT_ERR_STR,
"__internal_use",
"thread");
1067 #define SIZE_NOT_EQUAL_ERR_STR \
1068 "Size of odp_pool_stats_selected_t must equal to that of em_pool_subpool_stats_selected_t\n"
1071 SIZE_NOT_EQUAL_ERR_STR);
1073 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_selected_t, available) ==
1075 sizeof_field(odp_pool_stats_selected_t, available) ==
1077 "available in em_pool_subpool_stats_selected_t and odp_pool_stats_selected_t differs!");
1079 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_selected_t, alloc_ops) ==
1081 sizeof_field(odp_pool_stats_selected_t, alloc_ops) ==
1083 "em_pool_subpool_stats_selected_t.alloc_ops differs from odp_pool_stats_selected_t.alloc_ops!");
1085 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_selected_t, alloc_fails) ==
1087 sizeof_field(odp_pool_stats_selected_t, alloc_fails) ==
1089 "em_pool_subpool_stats_selected_t.alloc_fails differs from odp_pool_stats_selected_t.alloc_fails!");
1091 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_selected_t, free_ops) ==
1093 sizeof_field(odp_pool_stats_selected_t, free_ops) ==
1095 "em_pool_subpool_stats_selected_t.free_ops differs from odp_pool_stats_selected_t.free_ops!");
1097 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_selected_t, total_ops) ==
1099 sizeof_field(odp_pool_stats_selected_t, total_ops) ==
1101 "em_pool_subpool_stats_selected_t.total_ops differs from odp_pool_stats_selected_t.total_ops!");
1103 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_selected_t, cache_available) ==
1105 sizeof_field(odp_pool_stats_selected_t, cache_available) ==
1107 "em_pool_subpool_stats_selected_t.cache_available differs from that of odp_pool_stats_selected_t!");
1109 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_selected_t, cache_alloc_ops) ==
1111 sizeof_field(odp_pool_stats_selected_t, cache_alloc_ops) ==
1113 "em_pool_subpool_stats_selected_t.cache_alloc_ops differs from that of odp_pool_stats_selected_t!");
1115 ODP_STATIC_ASSERT(offsetof(odp_pool_stats_selected_t, cache_free_ops) ==
1117 sizeof_field(odp_pool_stats_selected_t, cache_free_ops) ==
1119 "em_pool_subpool_stats_selected_t.cache_free_ops differs from that of odp_pool_stats_selected_t!");
1121 #define SELECTED_TYPE_ERR_FMT \
1122 "em_pool_subpool_stats_selected_t.%s differs from odp_pool_stats_selected_t.%s\n"
1124 static int check_em_pool_subpool_stats_selected(
void)
1128 "odp_pool_stats_selected_t vs em_pool_subpool_stats_selected_t size diff\n");
1132 if (offsetof(odp_pool_stats_selected_t, available) !=
1134 sizeof_field(odp_pool_stats_selected_t, available) !=
1136 EM_LOG(EM_LOG_ERR, SELECTED_TYPE_ERR_FMT,
"available",
"available");
1140 if (offsetof(odp_pool_stats_selected_t, alloc_ops) !=
1142 sizeof_field(odp_pool_stats_selected_t, alloc_ops) !=
1144 EM_LOG(EM_LOG_ERR, SELECTED_TYPE_ERR_FMT,
"alloc_ops",
"alloc_ops");
1148 if (offsetof(odp_pool_stats_selected_t, alloc_fails) !=
1150 sizeof_field(odp_pool_stats_selected_t, alloc_fails) !=
1152 EM_LOG(EM_LOG_ERR, SELECTED_TYPE_ERR_FMT,
"alloc_fails",
"alloc_fails");
1156 if (offsetof(odp_pool_stats_selected_t, free_ops) !=
1158 sizeof_field(odp_pool_stats_selected_t, free_ops) !=
1160 EM_LOG(EM_LOG_ERR, SELECTED_TYPE_ERR_FMT,
"free_ops",
"free_ops");
1164 if (offsetof(odp_pool_stats_selected_t, total_ops) !=
1166 sizeof_field(odp_pool_stats_selected_t, total_ops) !=
1168 EM_LOG(EM_LOG_ERR, SELECTED_TYPE_ERR_FMT,
"total_ops",
"total_ops");
1172 if (offsetof(odp_pool_stats_selected_t, cache_available) !=
1174 sizeof_field(odp_pool_stats_selected_t, cache_available) !=
1176 EM_LOG(EM_LOG_ERR, SELECTED_TYPE_ERR_FMT,
"cache_available",
"cache_available");
1180 if (offsetof(odp_pool_stats_selected_t, cache_alloc_ops) !=
1182 sizeof_field(odp_pool_stats_selected_t, cache_alloc_ops) !=
1184 EM_LOG(EM_LOG_ERR, SELECTED_TYPE_ERR_FMT,
"cache_alloc_ops",
"cache_alloc_ops");
1188 if (offsetof(odp_pool_stats_selected_t, cache_free_ops) !=
1190 sizeof_field(odp_pool_stats_selected_t, cache_free_ops) !=
1192 EM_LOG(EM_LOG_ERR, SELECTED_TYPE_ERR_FMT,
"cache_free_ops",
"cache_free_ops");
1200 "Size of odp_pool_stats_opt_t differs from that of em_pool_stats_opt_t\n");
1208 em_pool_t pool_default;
1210 bool default_pool_set =
false;
1211 const uint32_t objpool_subpools = MIN(4, OBJSUBPOOLS_MAX);
1214 if (check_em_pool_subpool_stats())
1218 if (check_em_pool_subpool_stats_selected())
1225 ret = objpool_init(&mpool_pool->objpool, objpool_subpools);
1230 pool = pool_idx2hdl(i);
1233 if (unlikely(!mpool_elem))
1239 mpool_elem->
odp_pool[j] = ODP_POOL_INVALID;
1240 mpool_elem->
size[j] = 0;
1243 objpool_add(&mpool_pool->objpool, i % objpool_subpools,
1254 if (odp_pool_capability(&mpool_tbl->odp_pool_capability) != 0)
1258 if (read_config_file())
1278 for (uint32_t i = 0; i <
em_shm->opt.startup_pools.num; i++) {
1279 startup_pool_conf = &
em_shm->opt.startup_pools.conf[i];
1284 default_pool_set =
true;
1288 &startup_pool_conf->cfg);
1291 startup_pool_conf->pool,
1292 &startup_pool_conf->cfg);
1300 if (!default_pool_set) {
1319 "Status before delete:\n");
1323 em_pool_t pool = pool_idx2hdl(i);
1327 if (mpool_elem && pool_allocated(mpool_elem)) {
1328 ret = pool_delete(pool);
1338 static int invalid_pool_cache_cfg(
const em_pool_cfg_t *pool_cfg,
1339 const char **err_str)
1341 const odp_pool_capability_t *capa =
1342 &
em_shm->mpool_tbl.odp_pool_capability;
1343 uint32_t min_cache_size;
1344 uint32_t cache_size;
1347 min_cache_size = capa->buf.min_cache_size;
1349 min_cache_size = capa->pkt.min_cache_size;
1351 min_cache_size = capa->vector.min_cache_size;
1358 *err_str =
"Invalid subpool size/num";
1359 return -(1 * 10 + i);
1363 if (unlikely(cache_size < min_cache_size)) {
1364 *err_str =
"Requested cache size too small";
1365 return -(2 * 10 + i);
1379 int invalid_pool_cfg(
const em_pool_cfg_t *pool_cfg,
const char **err_str)
1382 const odp_pool_capability_t *capa = &
em_shm->mpool_tbl.odp_pool_capability;
1385 *err_str =
"Pool config NULL";
1389 *err_str =
"Pool config not initialized";
1395 *err_str =
"Invalid number of subpools";
1399 ret = is_pool_type_supported(pool_cfg->
event_type, err_str);
1403 if (!is_align_offset_valid(pool_cfg)) {
1404 *err_str =
"Invalid align offset";
1408 ret = is_user_area_valid(pool_cfg, capa, err_str);
1414 pool_cfg->
pkt.
headroom.value > capa->pkt.max_headroom) {
1415 *err_str =
"Requested pkt headroom size too large";
1419 ret = invalid_pool_cache_cfg(pool_cfg, err_str);
1424 int check_pool_uarea_persistence(
const em_pool_cfg_t *pool_cfg,
const char **err_str)
1426 #if ODP_VERSION_API_NUM(1, 42, 0) <= ODP_VERSION_API
1427 bool has_uarea_persistence;
1428 const odp_pool_capability_t *capa = &
em_shm->mpool_tbl.odp_pool_capability;
1432 has_uarea_persistence = capa->buf.uarea_persistence ? true :
false;
1433 *err_str =
"buf-pool (EM_EVENT_TYPE_SW)";
1436 has_uarea_persistence = capa->pkt.uarea_persistence ? true :
false;
1437 *err_str =
"pkt-pool (EM_EVENT_TYPE_PACKET)";
1440 has_uarea_persistence = capa->vector.uarea_persistence ? true :
false;
1441 *err_str =
"vector-pool (EM_EVENT_TYPE_VECTOR)";
1444 has_uarea_persistence =
false;
1445 *err_str =
"unknown pool-type";
1449 return has_uarea_persistence ? 0 : -1;
1463 uint64_t num_tot = 0;
1465 uint64_t num_free = 0;
1476 prealloc_hdr = event_prealloc(pool_elem, size);
1477 if (likely(prealloc_hdr)) {
1478 list_add(&evlist, &prealloc_hdr->
list_node);
1481 }
while (prealloc_hdr);
1483 if (unlikely(num < num_tot))
1486 "alloc: events expected:%" PRIu64
" actual:%" PRIu64
"",
1489 while (!list_is_empty(&evlist)) {
1490 node = list_rem_first(&evlist);
1491 prealloc_hdr = list_node_to_prealloc_hdr(node);
1496 if (unlikely(num_free > num))
1499 "free: events expected:%" PRIu64
" actual:%" PRIu64
"",
1511 *sorted_cfg = *pool_cfg;
1513 for (
int i = 0; i < num_subpools - 1; i++) {
1516 for (
int j = i + 1; j < num_subpools; j++) {
1549 const odp_pool_capability_t *capa =
1550 &
em_shm->mpool_tbl.odp_pool_capability;
1552 uint32_t max_cache_size;
1555 max_cache_size = capa->buf.max_cache_size;
1557 max_cache_size = capa->pkt.max_cache_size;
1559 max_cache_size = capa->vector.max_cache_size;
1561 for (
int i = 0; i < num_subpools; i++) {
1562 if (max_cache_size < pool_cfg->subpool[i].cache_size)
1572 uint32_t *align_offset , uint32_t *odp_align )
1574 const odp_pool_capability_t *capa =
1575 &
em_shm->mpool_tbl.odp_pool_capability;
1576 uint32_t offset = 0;
1577 uint32_t align = ODP_CACHE_LINE_SIZE;
1583 offset =
em_shm->opt.pool.align_offset;
1587 if (align > capa->pkt.max_align)
1588 align = capa->pkt.max_align;
1590 if (align > capa->buf.max_align)
1591 align = capa->buf.max_align;
1594 *align_offset = offset;
1598 if (!POWEROF2(align) || align <= offset)
1608 set_uarea_size(
const em_pool_cfg_t *pool_cfg,
size_t *uarea_size)
1611 size_t max_size = 0;
1612 const odp_pool_capability_t *capa =
1613 &
em_shm->mpool_tbl.odp_pool_capability;
1618 size =
em_shm->opt.pool.user_area_size;
1627 if (size > max_size)
1640 uint32_t *pkt_headroom ,
1641 uint32_t *max_headroom )
1643 const odp_pool_capability_t *capa =
1644 &
em_shm->mpool_tbl.odp_pool_capability;
1646 uint32_t headroom =
em_shm->opt.pool.pkt_headroom;
1652 *pkt_headroom = headroom;
1653 *max_headroom = capa->pkt.max_headroom;
1655 if (unlikely(headroom > capa->pkt.max_headroom))
1662 static void set_pool_params_stats(odp_pool_stats_opt_t *param_stats ,
1663 const odp_pool_stats_opt_t *capa_stats,
1666 param_stats->all = 0;
1668 if (capa_stats->bit.available)
1669 param_stats->bit.available = stats_opt->
available;
1671 if (capa_stats->bit.alloc_ops)
1672 param_stats->bit.alloc_ops = stats_opt->
alloc_ops;
1674 if (capa_stats->bit.alloc_fails)
1675 param_stats->bit.alloc_fails = stats_opt->
alloc_fails;
1677 if (capa_stats->bit.free_ops)
1678 param_stats->bit.free_ops = stats_opt->
free_ops;
1680 if (capa_stats->bit.total_ops)
1681 param_stats->bit.total_ops = stats_opt->
total_ops;
1683 if (capa_stats->bit.cache_alloc_ops)
1686 if (capa_stats->bit.cache_available)
1689 if (capa_stats->bit.cache_free_ops)
1692 if (capa_stats->bit.thread_cache_available)
1697 static void set_pool_params_pkt(odp_pool_param_t *pool_params ,
1699 uint32_t size, uint32_t num, uint32_t cache_size,
1700 uint32_t align_offset, uint32_t odp_align,
1701 uint32_t uarea_size, uint32_t pkt_headroom)
1703 const odp_pool_capability_t *capa = &
em_shm->mpool_tbl.odp_pool_capability;
1705 odp_pool_param_init(pool_params);
1707 pool_params->type = ODP_POOL_PACKET;
1709 pool_params->pkt.num = num;
1710 pool_params->pkt.max_num = num;
1712 if (size > align_offset)
1713 size = size - align_offset;
1717 pool_params->pkt.len = size;
1718 pool_params->pkt.max_len = size;
1719 pool_params->pkt.seg_len = size;
1720 pool_params->pkt.align = odp_align;
1725 pool_params->pkt.uarea_size =
sizeof(
event_hdr_t) + uarea_size;
1730 pool_params->pkt.headroom = pkt_headroom;
1731 if (pkt_headroom < align_offset)
1732 pool_params->pkt.headroom = align_offset;
1734 pool_params->pkt.cache_size = cache_size;
1738 set_pool_params_stats(&pool_params->stats, &capa->pkt.stats,
1741 set_pool_params_stats(&pool_params->stats, &capa->pkt.stats,
1742 &
em_shm->opt.pool.statistics);
1746 static void set_pool_params_vector(odp_pool_param_t *pool_params ,
1748 uint32_t size, uint32_t num,
1749 uint32_t cache_size, uint32_t uarea_size)
1751 const odp_pool_capability_t *capa = &
em_shm->mpool_tbl.odp_pool_capability;
1753 odp_pool_param_init(pool_params);
1755 pool_params->type = ODP_POOL_VECTOR;
1756 pool_params->vector.num = num;
1757 pool_params->vector.max_size = size;
1759 pool_params->vector.uarea_size =
sizeof(
event_hdr_t) + uarea_size;
1760 pool_params->vector.cache_size = cache_size;
1764 set_pool_params_stats(&pool_params->stats, &capa->vector.stats,
1767 set_pool_params_stats(&pool_params->stats, &capa->vector.stats,
1768 &
em_shm->opt.pool.statistics);
1772 static void set_pool_params_buf(odp_pool_param_t *pool_params ,
1774 uint32_t size, uint32_t num, uint32_t cache_size,
1775 uint32_t align_offset, uint32_t odp_align,
1776 uint32_t uarea_size)
1778 const odp_pool_capability_t *capa = &
em_shm->mpool_tbl.odp_pool_capability;
1780 odp_pool_param_init(pool_params);
1782 pool_params->type = ODP_POOL_BUFFER;
1783 pool_params->buf.num = num;
1784 pool_params->buf.size = size;
1786 pool_params->buf.size += 32 - align_offset;
1787 pool_params->buf.align = odp_align;
1788 pool_params->buf.uarea_size =
sizeof(
event_hdr_t) + uarea_size;
1789 pool_params->buf.cache_size = cache_size;
1793 set_pool_params_stats(&pool_params->stats, &capa->buf.stats,
1796 set_pool_params_stats(&pool_params->stats, &capa->buf.stats,
1797 &
em_shm->opt.pool.statistics);
1802 uint32_t align_offset, uint32_t odp_align,
1803 uint32_t uarea_size, uint32_t pkt_headroom,
1809 for (
int i = 0; i < num_subpools; i++) {
1810 char pool_name[ODP_POOL_NAME_LEN];
1811 odp_pool_param_t pool_params;
1817 set_pool_params_pkt(&pool_params , pool_cfg,
1818 size, num, cache_size,
1819 align_offset, odp_align,
1820 uarea_size, pkt_headroom);
1822 set_pool_params_vector(&pool_params , pool_cfg,
1823 size, num, cache_size,
1826 set_pool_params_buf(&pool_params , pool_cfg,
1827 size, num, cache_size,
1828 align_offset, odp_align, uarea_size);
1832 mpool_elem->
stats_opt = pool_params.stats;
1834 snprintf(pool_name,
sizeof(pool_name),
"%" PRI_POOL ":%d-%s",
1835 mpool_elem->
em_pool, i, mpool_elem->name);
1836 pool_name[
sizeof(pool_name) - 1] =
'\0';
1838 odp_pool_t odp_pool = odp_pool_create(pool_name, &pool_params);
1840 if (unlikely(odp_pool == ODP_POOL_INVALID))
1843 mpool_elem->
odp_pool[i] = odp_pool;
1846 int odp_pool_idx = odp_pool_index(odp_pool);
1848 if (unlikely(odp_pool_idx < 0))
1853 (uint32_t)(uintptr_t)mpool_elem->
em_pool;
1863 pool_create(
const char *name, em_pool_t req_pool,
const em_pool_cfg_t *pool_cfg)
1869 const em_pool_t pool = pool_alloc(req_pool);
1877 if (!mpool_elem || mpool_elem->
em_pool != pool)
1884 if (name && *name) {
1885 strncpy(mpool_elem->name, name,
sizeof(mpool_elem->name));
1886 mpool_elem->name[
sizeof(mpool_elem->name) - 1] =
'\0';
1888 mpool_elem->name[0] =
'\0';
1896 sort_pool_cfg(pool_cfg, &sorted_cfg);
1902 set_poolcache_size(&sorted_cfg);
1910 uint32_t align_offset = 0;
1911 uint32_t odp_align = 0;
1916 err = set_align(&sorted_cfg, &align_offset,
1918 if (unlikely(err)) {
1920 "EM-pool:\"%s\" align mismatch:\n"
1921 "align:%u cfg:align_offset:%u",
1922 name, odp_align, align_offset);
1933 size_t uarea_size = 0;
1935 err = set_uarea_size(&sorted_cfg, &uarea_size);
1936 if (unlikely(err)) {
1938 "EM-pool:\"%s\" invalid uarea config: req.size:%zu",
1949 uint32_t pkt_headroom = 0;
1950 uint32_t max_headroom = 0;
1953 err = set_pkt_headroom(&sorted_cfg, &pkt_headroom,
1955 if (unlikely(err)) {
1957 "EM-pool:\"%s\" invalid pkt headroom:\n"
1958 "headroom:%u vs. max:headroom:%u",
1959 name, pkt_headroom, max_headroom);
1968 err = create_subpools(&sorted_cfg, align_offset, odp_align,
1969 (uint32_t)uarea_size, pkt_headroom, mpool_elem );
1970 if (unlikely(err)) {
1973 "EM-pool:\"%s\" create fails:%d\n"
1974 "subpools req:%d vs. subpools created:%d",
1983 if (esv_enabled() &&
em_shm->opt.esv.prealloc_pools)
1984 pool_prealloc(mpool_elem);
1990 (void)pool_delete(pool);
1995 pool_delete(em_pool_t pool)
2000 if (unlikely(mpool_elem == NULL || !pool_allocated(mpool_elem)))
2004 odp_pool_t odp_pool = mpool_elem->
odp_pool[i];
2008 if (odp_pool == ODP_POOL_INVALID)
2011 odp_pool_idx = odp_pool_index(odp_pool);
2013 ret = odp_pool_destroy(odp_pool);
2017 mpool_elem->
odp_pool[i] = ODP_POOL_INVALID;
2018 mpool_elem->
size[i] = 0;
2021 if (unlikely(odp_pool_idx < 0))
2026 mpool_elem->name[0] =
'\0';
2030 return pool_free(pool);
2034 pool_find(
const char *name)
2036 if (name && *name) {
2039 &
em_shm->mpool_tbl.pool[i];
2041 if (pool_allocated(mpool_elem) &&
2056 #define POOL_INFO_HDR_STR \
2057 " id name type offset uarea sizes [size count(used/free) cache]\n"
2059 #define POOL_INFO_SUBSTR_FMT \
2060 "%d:[sz=%" PRIu32 " n=%" PRIu32 "(%" PRIu32 "/%" PRIu32 ") $=%" PRIu32 "]"
2062 #define POOL_INFO_SUBSTR_NO_STATS_FMT \
2063 "%d:[sz=%" PRIu32 " n=%" PRIu32 "(-/-) cache=%" PRIu32 "]"
2065 void pool_info_print_hdr(
unsigned int num_pools)
2067 if (num_pools == 1) {
2068 EM_PRINT(
"EM Event Pool\n"
2072 EM_PRINT(
"EM Event Pools:%2u\n"
2073 "-----------------\n"
2074 POOL_INFO_HDR_STR, num_pools);
2078 void pool_info_print(em_pool_t pool)
2082 const char *pool_type;
2085 if (unlikely(stat !=
EM_OK)) {
2086 EM_PRINT(
" %-6" PRI_POOL " %-16s n/a n/a n/a n/a [n/a]\n",
2098 EM_PRINT(
" %-6" PRI_POOL " %-16s %4s %02u %02zu %02u ",
2099 pool, pool_info.name, pool_type,
2104 char subpool_str[42];
2106 if (pool_info.subpool[i].
used || pool_info.subpool[i].
free) {
2107 snprintf(subpool_str,
sizeof(subpool_str),
2108 POOL_INFO_SUBSTR_FMT, i,
2109 pool_info.subpool[i].
size,
2110 pool_info.subpool[i].
num,
2111 pool_info.subpool[i].
used,
2112 pool_info.subpool[i].
free,
2115 snprintf(subpool_str,
sizeof(subpool_str),
2116 POOL_INFO_SUBSTR_NO_STATS_FMT, i,
2117 pool_info.subpool[i].
size,
2118 pool_info.subpool[i].
num,
2121 subpool_str[
sizeof(subpool_str) - 1] =
'\0';
2122 EM_PRINT(
" %-42s", subpool_str);
2128 #define POOL_STATS_HDR_STR \
2129 "EM pool statistics for pool %" PRI_POOL ":\n\n"\
2130 "Subpool Available Alloc_ops Alloc_fails Free_ops Total_ops Cache_available" \
2131 " Cache_alloc_ops Cache_free_ops\n"\
2132 "--------------------------------------------------------------------------" \
2133 "-------------------------------\n%s"
2135 #define POOL_STATS_LEN 107
2136 #define POOL_STATS_FMT "%-8u%-10lu%-10lu%-12lu%-9lu%-10lu%-16lu%-16lu%-15lu\n"
2138 void pool_stats_print(em_pool_t pool)
2147 char stats_str[stats_str_len];
2149 if (pool_elem == NULL || !pool_allocated(pool_elem)) {
2150 EM_LOG(EM_LOG_ERR,
"EM-pool:%" PRI_POOL " invalid\n", pool);
2155 if (unlikely(stat !=
EM_OK)) {
2156 EM_PRINT(
"Failed to fetch EM pool statistics\n");
2160 for (uint32_t i = 0; i < pool_stats.num_subpools; i++) {
2161 subpool_stats = &pool_stats.subpool_stats[i];
2162 n_print = snprintf(stats_str + len, stats_str_len - len,
2174 if (n_print >= stats_str_len - len)
2180 stats_str[len] =
'\0';
2181 EM_PRINT(POOL_STATS_HDR_STR, pool, stats_str);
2184 #define POOL_STATS_SELECTED_HDR_STR \
2185 "Selected EM pool statistics for pool %" PRI_POOL ":\n\n"\
2186 "Selected statistic counters: %s\n\n"\
2187 "Subpool Available Alloc_ops Alloc_fails Free_ops Total_ops Cache_available" \
2188 " Cache_alloc_ops Cache_free_ops\n"\
2189 "--------------------------------------------------------------------------" \
2190 "-------------------------------\n%s"
2192 #define OPT_STR_LEN 150
2200 n_print = snprintf(opt_str + len, 12,
"%s",
"available");
2205 n_print = snprintf(opt_str + len, 12,
"%s", len ?
", alloc_ops" :
"alloc_ops");
2210 n_print = snprintf(opt_str + len, 14,
"%s", len ?
", alloc_fails" :
"alloc_fails");
2215 n_print = snprintf(opt_str + len, 11,
"%s", len ?
", free_ops" :
"free_ops");
2220 n_print = snprintf(opt_str + len, 12,
"%s", len ?
", total_ops" :
"total_ops");
2225 n_print = snprintf(opt_str + len, 18,
"%s",
2226 len ?
", cache_available" :
"cache_available");
2231 n_print = snprintf(opt_str + len, 18,
"%s",
2232 len ?
", cache_alloc_ops" :
"cache_alloc_ops");
2237 snprintf(opt_str + len, 17,
"%s", len ?
", cache_free_ops" :
"cache_free_ops");
2248 char opt_str[OPT_STR_LEN];
2250 char stats_str[stats_str_len];
2252 if (pool_elem == NULL || !pool_allocated(pool_elem)) {
2253 EM_LOG(EM_LOG_ERR,
"EM-pool:%" PRI_POOL " invalid\n", pool);
2258 if (unlikely(stat !=
EM_OK)) {
2259 EM_PRINT(
"Failed to fetch EM selected pool statistics\n");
2263 for (uint32_t i = 0; i < pool_stats.num_subpools; i++) {
2264 subpool_stats = &pool_stats.subpool_stats[i];
2266 n_print = snprintf(stats_str + len, stats_str_len - len,
2279 if (n_print >= stats_str_len - len)
2284 stats_str[len] =
'\0';
2287 fill_opt_str(opt_str, opt);
2289 EM_PRINT(POOL_STATS_SELECTED_HDR_STR, pool, opt_str, stats_str);
2292 #define SUBPOOL_STATS_HDR_STR \
2293 "EM subpool statistics for pool %" PRI_POOL ":\n\n"\
2294 "Subpool Available Alloc_ops Alloc_fails Free_ops Total_ops Cache_available" \
2295 " Cache_alloc_ops Cache_free_ops\n"\
2296 "--------------------------------------------------------------------------" \
2297 "-------------------------------\n%s"
2299 void subpools_stats_print(em_pool_t pool,
const int subpools[],
int num_subpools)
2306 const int stats_str_len = num_subpools * POOL_STATS_LEN + 1;
2307 char stats_str[stats_str_len];
2309 if (pool_elem == NULL || !pool_allocated(pool_elem)) {
2310 EM_LOG(EM_LOG_ERR,
"EM-pool:%" PRI_POOL " invalid\n", pool);
2315 if (unlikely(!num_stats || num_stats > num_subpools)) {
2316 EM_LOG(EM_LOG_ERR,
"Failed to fetch subpool statistics\n");
2321 for (
int i = 0; i < num_stats; i++) {
2322 n_print = snprintf(stats_str + len, stats_str_len - len,
2324 subpools[i], stats[i].available, stats[i].alloc_ops,
2325 stats[i].alloc_fails, stats[i].free_ops,
2326 stats[i].total_ops, stats[i].cache_available,
2327 stats[i].cache_alloc_ops, stats[i].cache_free_ops);
2330 if (n_print >= stats_str_len - len)
2336 stats_str[len] =
'\0';
2337 EM_PRINT(SUBPOOL_STATS_HDR_STR, pool, stats_str);
2340 #define SUBPOOL_STATS_SELECTED_HDR_STR \
2341 "Selected EM subpool statistics for pool %" PRI_POOL ":\n\n"\
2342 "Selected statistic counters: %s\n\n"\
2343 "Subpool Available Alloc_ops Alloc_fails Free_ops Total_ops Cache_available" \
2344 " Cache_alloc_ops Cache_free_ops\n"\
2345 "--------------------------------------------------------------------------" \
2346 "-------------------------------\n%s"
2348 void subpools_stats_selected_print(em_pool_t pool,
const int subpools[],
2352 char opt_str[OPT_STR_LEN];
2357 const int stats_str_len = num_subpools * POOL_STATS_LEN + 1;
2358 char stats_str[stats_str_len];
2360 if (pool_elem == NULL || !pool_allocated(pool_elem)) {
2361 EM_LOG(EM_LOG_ERR,
"EM-pool:%" PRI_POOL " invalid\n", pool);
2365 memset(stats, 0,
sizeof(stats));
2367 if (unlikely(!num_stats || num_stats > num_subpools)) {
2368 EM_LOG(EM_LOG_ERR,
"Failed to fetch selected subpool statistics\n");
2373 for (
int i = 0; i < num_stats; i++) {
2374 n_print = snprintf(stats_str + len, stats_str_len - len,
2376 subpools[i], stats[i].available, stats[i].alloc_ops,
2377 stats[i].alloc_fails, stats[i].free_ops,
2378 stats[i].total_ops, stats[i].cache_available,
2379 stats[i].cache_alloc_ops, stats[i].cache_free_ops);
2382 if (n_print >= stats_str_len - len)
2387 stats_str[len] =
'\0';
2390 fill_opt_str(opt_str, opt);
2391 EM_PRINT(SUBPOOL_STATS_SELECTED_HDR_STR, pool, opt_str, stats_str);
2394 void print_pool_elem_info(
void)
2397 "pool-elem size: %zu B\n",
2400 EM_DBG(
"\t\toffset\tsize\n"
2401 "\t\t------\t-----\n"
2402 "event_type:\t%3zu B\t%3zu B\n"
2403 "align_offset:\t%3zu B\t%3zu B\n"
2404 "user_area info:\t%3zu B\t%3zu B\n"
2405 "num_subpools:\t%3zu B\t%3zu B\n"
2406 "size[]:\t\t%3zu B\t%3zu B\n"
2407 "odp_pool[]:\t%3zu B\t%3zu B\n"
2408 "em_pool:\t%3zu B\t%3zu B\n"
2409 "objpool_elem:\t%3zu B\t%3zu B\n"
2410 "stats_opt:\t%3zu B\t%3zu B\n"
2411 "pool_cfg:\t%3zu B\t%3zu B\n"
2412 "name[]:\t\t%3zu B\t%3zu B\n",