From 168d7168447b99097f3bbe397ca76b6cb87d34da Mon Sep 17 00:00:00 2001 From: Petri Savolainen Date: Wed, 17 Oct 2018 16:41:52 +0300 Subject: linux-gen: pool: add max num packets in config file This config is used to for maximum capability. The default capability needs to be modest so that system memory limit is not exceeded. User may increase maximum number of packets when system memory size allows (and SHM single VA is not used). Signed-off-by: Petri Savolainen Signed-off-by: Maxim Uvarov --- config/odp-linux-generic.conf | 12 ++++++- platform/linux-generic/include/odp_pool_internal.h | 5 +++ platform/linux-generic/odp_pool.c | 39 ++++++++++++++++++++-- platform/linux-generic/test/process-mode.conf | 2 +- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/config/odp-linux-generic.conf b/config/odp-linux-generic.conf index 4db9ed489..af651d7f6 100644 --- a/config/odp-linux-generic.conf +++ b/config/odp-linux-generic.conf @@ -16,7 +16,7 @@ # Mandatory fields odp_implementation = "linux-generic" -config_file_version = "0.1.0" +config_file_version = "0.1.1" # Shared memory options shm: { @@ -39,6 +39,16 @@ shm: { single_va = 0 } +# Pool options +pool: { + # Packet pool options + pkt: { + # Maximum number of packets per pool. Power of two minus one + # results optimal memory usage (e.g. (256 * 1024) - 1). + max_num = 262143 + } +} + # DPDK pktio options pktio_dpdk: { # Default options diff --git a/platform/linux-generic/include/odp_pool_internal.h b/platform/linux-generic/include/odp_pool_internal.h index 2696e8eec..94f859de0 100644 --- a/platform/linux-generic/include/odp_pool_internal.h +++ b/platform/linux-generic/include/odp_pool_internal.h @@ -89,6 +89,11 @@ typedef struct pool_t { typedef struct pool_table_t { pool_t pool[ODP_CONFIG_POOLS]; odp_shm_t shm; + + struct { + uint32_t pkt_max_num; + } config; + } pool_table_t; extern pool_table_t *pool_tbl; diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c index db7a8da3f..d08be4378 100644 --- a/platform/linux-generic/odp_pool.c +++ b/platform/linux-generic/odp_pool.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -33,8 +34,9 @@ #define UNLOCK(a) odp_ticketlock_unlock(a) #define LOCK_INIT(a) odp_ticketlock_init(a) -#define CACHE_BURST 32 -#define RING_SIZE_MIN (2 * CACHE_BURST) +#define CACHE_BURST 32 +#define RING_SIZE_MIN (2 * CACHE_BURST) +#define POOL_MAX_NUM_MIN RING_SIZE_MIN /* Make sure packet buffers don't cross huge page boundaries starting from this * page size. 2MB is typically the smallest used huge page size. */ @@ -83,6 +85,32 @@ static inline pool_t *pool_from_buf(odp_buffer_t buf) return buf_hdr->pool_ptr; } +static int read_config_file(pool_table_t *pool_tbl) +{ + const char *str; + int val = 0; + + ODP_PRINT("Pool config:\n"); + + str = "pool.pkt.max_num"; + if (!_odp_libconfig_lookup_int(str, &val)) { + ODP_ERR("Config option '%s' not found.\n", str); + return -1; + } + + if (val > CONFIG_POOL_MAX_NUM || val < POOL_MAX_NUM_MIN) { + ODP_ERR("Bad value %s = %u\n", str, val); + return -1; + } + + pool_tbl->config.pkt_max_num = val; + ODP_PRINT(" %s: %i\n", str, val); + + ODP_PRINT("\n"); + + return 0; +} + int odp_pool_init_global(void) { uint32_t i; @@ -101,6 +129,11 @@ int odp_pool_init_global(void) memset(pool_tbl, 0, sizeof(pool_table_t)); pool_tbl->shm = shm; + if (read_config_file(pool_tbl)) { + odp_shm_free(shm); + return -1; + } + for (i = 0; i < ODP_CONFIG_POOLS; i++) { pool_t *pool = pool_entry(i); @@ -950,7 +983,7 @@ int odp_pool_capability(odp_pool_capability_t *capa) /* Packet pools */ capa->pkt.max_pools = ODP_CONFIG_POOLS; capa->pkt.max_len = CONFIG_PACKET_MAX_LEN; - capa->pkt.max_num = CONFIG_POOL_MAX_NUM; + capa->pkt.max_num = pool_tbl->config.pkt_max_num; capa->pkt.min_headroom = CONFIG_PACKET_HEADROOM; capa->pkt.max_headroom = CONFIG_PACKET_HEADROOM; capa->pkt.min_tailroom = CONFIG_PACKET_TAILROOM; diff --git a/platform/linux-generic/test/process-mode.conf b/platform/linux-generic/test/process-mode.conf index 8618f2fdb..d80df25c4 100644 --- a/platform/linux-generic/test/process-mode.conf +++ b/platform/linux-generic/test/process-mode.conf @@ -1,6 +1,6 @@ # Mandatory fields odp_implementation = "linux-generic" -config_file_version = "0.1.0" +config_file_version = "0.1.1" # Shared memory options shm: { -- cgit v1.2.3