[3/3] linux-gen: pool: select packet pool segment size at runtime

Message ID 1496216614-1147-3-git-send-email-matias.elo@nokia.com
State New
Headers show
Series
  • [1/3] linux-gen: pool: combine duplicate struct pool_t members
Related show

Commit Message

Matias Elo May 31, 2017, 7:43 a.m.
Previously packet pool segment size was always selected based on the
internal configuration defines. After this patch packet pool segment size
is selected during pool_create() which enables creating multiple packet
pools with different segment sizes.

Signed-off-by: Matias Elo <matias.elo@nokia.com>

---
 .../linux-generic/include/odp_config_internal.h    |  2 +-
 platform/linux-generic/odp_pool.c                  | 23 +++++++++++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

-- 
2.7.4

Patch

diff --git a/platform/linux-generic/include/odp_config_internal.h b/platform/linux-generic/include/odp_config_internal.h
index e7d84c9..45afba3 100644
--- a/platform/linux-generic/include/odp_config_internal.h
+++ b/platform/linux-generic/include/odp_config_internal.h
@@ -98,7 +98,7 @@  extern "C" {
  * defined segment length (seg_len in odp_pool_param_t) will be rounded up into
  * this value.
  */
-#define CONFIG_PACKET_SEG_LEN_MIN CONFIG_PACKET_MAX_SEG_LEN
+#define CONFIG_PACKET_SEG_LEN_MIN 256
 
 /* Maximum number of shared memory blocks.
  *
diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c
index 317f113..7a6bad5 100644
--- a/platform/linux-generic/odp_pool.c
+++ b/platform/linux-generic/odp_pool.c
@@ -329,12 +329,29 @@  static odp_pool_t pool_create(const char *name, odp_pool_param_t *params,
 		break;
 
 	case ODP_POOL_PACKET:
+		seg_len = CONFIG_PACKET_MAX_SEG_LEN;
+		max_len = CONFIG_PACKET_MAX_SEGS * seg_len;
+
+		if (params->pkt.len)
+			seg_len = params->pkt.len;
+		if (params->pkt.seg_len &&
+		    params->pkt.seg_len > seg_len)
+			seg_len = params->pkt.seg_len;
+		if (seg_len < CONFIG_PACKET_SEG_LEN_MIN)
+			seg_len = CONFIG_PACKET_SEG_LEN_MIN;
+
+		/* Make sure max length packet fits */
+		if (params->pkt.max_len != 0)
+			max_len = params->pkt.max_len;
+		if ((max_len + seg_len - 1) / seg_len >
+				CONFIG_PACKET_MAX_SEGS)
+			seg_len = (max_len + CONFIG_PACKET_MAX_SEGS - 1) /
+				CONFIG_PACKET_MAX_SEGS;
+
 		headroom    = CONFIG_PACKET_HEADROOM;
 		tailroom    = CONFIG_PACKET_TAILROOM;
 		num         = params->pkt.num;
 		uarea_size  = params->pkt.uarea_size;
-		seg_len     = CONFIG_PACKET_MAX_SEG_LEN;
-		max_len     = CONFIG_PACKET_MAX_SEGS * seg_len;
 		break;
 
 	case ODP_POOL_TIMEOUT:
@@ -819,7 +836,7 @@  int odp_pool_capability(odp_pool_capability_t *capa)
 	capa->pkt.min_headroom     = CONFIG_PACKET_HEADROOM;
 	capa->pkt.min_tailroom     = CONFIG_PACKET_TAILROOM;
 	capa->pkt.max_segs_per_pkt = CONFIG_PACKET_MAX_SEGS;
-	capa->pkt.min_seg_len      = max_seg_len;
+	capa->pkt.min_seg_len      = CONFIG_PACKET_SEG_LEN_MIN;
 	capa->pkt.max_seg_len      = max_seg_len;
 	capa->pkt.max_uarea_size   = MAX_SIZE;