Using memset to initialize struct odp_packet_hdr_t contents
to 0 has a significant overhead. Instead, initialize only
the required members of the struct.

Signed-off-by: Matias Elo <[email protected]>
---
 platform/linux-generic/include/odp_packet_internal.h |  8 +++++---
 platform/linux-generic/odp_packet.c                  | 18 ++++++------------
 2 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/platform/linux-generic/include/odp_packet_internal.h 
b/platform/linux-generic/include/odp_packet_internal.h
index 2a12503..cdee1e1 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -143,15 +143,17 @@ typedef struct {
        uint32_t l4_offset; /**< offset to L4 hdr (TCP, UDP, SCTP, also ICMP) */
        uint32_t payload_offset; /**< offset to payload */
 
-       uint32_t l3_len;         /**< Layer 3 length */
-       uint32_t l4_len;         /**< Layer 4 length */
-
        uint32_t frame_len;
        uint32_t headroom;
        uint32_t tailroom;
 
        odp_pktio_t input;
 
+       /* Values below are not initialized by packet_init() */
+
+       uint32_t l3_len;         /**< Layer 3 length */
+       uint32_t l4_len;         /**< Layer 4 length */
+
        uint32_t flow_hash;      /**< Flow hash value */
        odp_time_t timestamp;    /**< Timestamp value */
 
diff --git a/platform/linux-generic/odp_packet.c 
b/platform/linux-generic/odp_packet.c
index 436265e..f5f224d 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -50,23 +50,17 @@ void packet_parse_reset(odp_packet_hdr_t *pkt_hdr)
 static void packet_init(pool_entry_t *pool, odp_packet_hdr_t *pkt_hdr,
                        size_t size, int parse)
 {
-       /*
-       * Reset parser metadata.  Note that we clear via memset to make
-       * this routine indepenent of any additional adds to packet metadata.
-       */
-       const size_t start_offset = ODP_FIELD_SIZEOF(odp_packet_hdr_t, buf_hdr);
-       uint8_t *start;
-       size_t len;
+       pkt_hdr->input_flags.all  = 0;
+       pkt_hdr->output_flags.all = 0;
+       pkt_hdr->error_flags.all  = 0;
 
-       start = (uint8_t *)pkt_hdr + start_offset;
-       len = sizeof(odp_packet_hdr_t) - start_offset;
-       memset(start, 0, len);
-
-       /* Set metadata items that initialize to non-zero values */
+       pkt_hdr->l2_offset = 0;
        pkt_hdr->l3_offset = ODP_PACKET_OFFSET_INVALID;
        pkt_hdr->l4_offset = ODP_PACKET_OFFSET_INVALID;
        pkt_hdr->payload_offset = ODP_PACKET_OFFSET_INVALID;
 
+       pkt_hdr->input = ODP_PKTIO_INVALID;
+
        /* Disable lazy parsing on user allocated packets */
        if (!parse)
                packet_parse_disable(pkt_hdr);
-- 
1.9.1

_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to