diff mbox series

[v2,11/11] linux-gen: packet: optimize header layout

Message ID 1505221212-27163-12-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [v2,1/11] linux-gen: packet: roll back to copy based references | expand

Commit Message

Github ODP bot Sept. 12, 2017, 1 p.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Pack most often used data into the first and the last cache line
of buffer header, and the first cache line of packet header.
Reduce offsets and head-/tailroom fields to 16 bits, since
those are in maximum as large as a segment, usually much
less. Pack header fields into correct alignments (when possible),
so that holes are avoided.

These changes reduce packet header size by one cache line.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 170 (psavol:master-packet-ref-rework)
 ** https://github.com/Linaro/odp/pull/170
 ** Patch: https://github.com/Linaro/odp/pull/170.patch
 ** Base sha: fb3f36cec108ce9c55241d9f0e66d4832a552b8a
 ** Merge commit sha: bab9e010b5432ba0f2ff0651313a85a6a1b563c2
 **/
 include/odp/arch/default/api/abi/packet.h             |  2 +-
 .../include/odp/api/plat/packet_inlines.h             |  4 ++--
 .../linux-generic/include/odp/api/plat/packet_types.h |  2 +-
 platform/linux-generic/include/odp_buffer_internal.h  | 16 ++++++++--------
 platform/linux-generic/include/odp_packet_internal.h  | 19 ++++++++++++-------
 platform/linux-generic/odp_pool.c                     |  3 +++
 6 files changed, 27 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/include/odp/arch/default/api/abi/packet.h b/include/odp/arch/default/api/abi/packet.h
index 4aac75b9..15cf081b 100644
--- a/include/odp/arch/default/api/abi/packet.h
+++ b/include/odp/arch/default/api/abi/packet.h
@@ -28,7 +28,7 @@  typedef _odp_abi_packet_seg_t *odp_packet_seg_t;
 
 #define ODP_PACKET_INVALID        ((odp_packet_t)0xffffffff)
 #define ODP_PACKET_SEG_INVALID    ((odp_packet_seg_t)0xffffffff)
-#define ODP_PACKET_OFFSET_INVALID (0x0fffffff)
+#define ODP_PACKET_OFFSET_INVALID 0xffff
 
 typedef enum {
 	ODP_PACKET_GREEN = 0,
diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines.h b/platform/linux-generic/include/odp/api/plat/packet_inlines.h
index d0cf1390..6874d149 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h
@@ -56,13 +56,13 @@  static inline uint32_t _odp_packet_len(odp_packet_t pkt)
 /** @internal Inline function @param pkt @return */
 static inline uint32_t _odp_packet_headroom(odp_packet_t pkt)
 {
-	return _odp_pkt_get(pkt, uint32_t, headroom);
+	return _odp_pkt_get(pkt, uint16_t, headroom);
 }
 
 /** @internal Inline function @param pkt @return */
 static inline uint32_t _odp_packet_tailroom(odp_packet_t pkt)
 {
-	return _odp_pkt_get(pkt, uint32_t, tailroom);
+	return _odp_pkt_get(pkt, uint16_t, tailroom);
 }
 
 /** @internal Inline function @param pkt @return */
diff --git a/platform/linux-generic/include/odp/api/plat/packet_types.h b/platform/linux-generic/include/odp/api/plat/packet_types.h
index 96379ebf..68c66312 100644
--- a/platform/linux-generic/include/odp/api/plat/packet_types.h
+++ b/platform/linux-generic/include/odp/api/plat/packet_types.h
@@ -36,7 +36,7 @@  typedef ODP_HANDLE_T(odp_packet_t);
 
 #define ODP_PACKET_INVALID _odp_cast_scalar(odp_packet_t, 0)
 
-#define ODP_PACKET_OFFSET_INVALID (0x0fffffff)
+#define ODP_PACKET_OFFSET_INVALID 0xffff
 
 typedef uint8_t odp_packet_seg_t;
 
diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h
index cd067a08..5d40303b 100644
--- a/platform/linux-generic/include/odp_buffer_internal.h
+++ b/platform/linux-generic/include/odp_buffer_internal.h
@@ -65,13 +65,10 @@  struct odp_buffer_hdr_t {
 	/* Initial buffer data pointer */
 	uint8_t  *base_data;
 
-	/* Reference count */
-	odp_atomic_u32_t ref_cnt;
-
-	/* Event type. Maybe different than pool type (crypto compl event) */
-	int8_t    event_type;
+	/* Pool pointer */
+	void *pool_ptr;
 
-	/* --- 37 bytes --- */
+	/* --- 40 bytes --- */
 
 	/* Segments */
 	seg_entry_t seg[CONFIG_PACKET_MAX_SEGS];
@@ -95,8 +92,11 @@  struct odp_buffer_hdr_t {
 		const void *buf_cctx; /* const alias for ctx */
 	};
 
-	/* Pool pointer */
-	void *pool_ptr;
+	/* Reference count */
+	odp_atomic_u32_t ref_cnt;
+
+	/* Event type. Maybe different than pool type (crypto compl event) */
+	int8_t    event_type;
 
 	/* Initial buffer tail pointer */
 	uint8_t  *buf_end;
diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index d8d4584a..d76d7bf0 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -88,9 +88,14 @@  typedef struct {
 	error_flags_t  error_flags;
 	output_flags_t output_flags;
 
-	uint32_t l2_offset; /**< offset to L2 hdr, e.g. Eth */
-	uint32_t l3_offset; /**< offset to L3 hdr, e.g. IPv4, IPv6 */
-	uint32_t l4_offset; /**< offset to L4 hdr (TCP, UDP, SCTP, also ICMP) */
+	 /* offset to L2 hdr, e.g. Eth */
+	uint16_t l2_offset;
+
+	/* offset to L3 hdr, e.g. IPv4, IPv6 */
+	uint16_t l3_offset;
+
+	/* offset to L4 hdr (TCP, UDP, SCTP, also ICMP) */
+	uint16_t l4_offset;
 } packet_parser_t;
 
 /* Packet extra data length */
@@ -116,14 +121,14 @@  typedef struct {
 
 	packet_parser_t p;
 
-	uint32_t frame_len;
-
 	odp_pktio_t input;
 
-	uint32_t headroom;
-	uint32_t tailroom;
+	uint32_t frame_len;
 	uint32_t shared_len;
 
+	uint16_t headroom;
+	uint16_t tailroom;
+
 	/*
 	 * Members below are not initialized by packet_init()
 	 */
diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c
index 2f65cb20..2a0a35e4 100644
--- a/platform/linux-generic/odp_pool.c
+++ b/platform/linux-generic/odp_pool.c
@@ -41,6 +41,9 @@  ODP_STATIC_ASSERT(CONFIG_POOL_CACHE_SIZE > (2 * CACHE_BURST),
 ODP_STATIC_ASSERT(CONFIG_PACKET_SEG_LEN_MIN >= 256,
 		  "ODP Segment size must be a minimum of 256 bytes");
 
+ODP_STATIC_ASSERT(CONFIG_PACKET_SEG_SIZE < 0xffff,
+		  "Segment size must be less than 64k (16 bit offsets)");
+
 /* Thread local variables */
 typedef struct pool_local_t {
 	pool_cache_t *cache[ODP_CONFIG_POOLS];