diff mbox

[API-NEXT] linux-generic: packet: tune alloc/free performance for non-reference paths

Message ID 20170112215515.4234-1-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Jan. 12, 2017, 9:55 p.m. UTC
As reported in Bug https://bugs.linaro.org/show_bug.cgi?id=2816 packet
alloc/free performance for non-references appears significantly degraded
after the introduction of packet reference support. Add fastpaths for
non-reference packet frees to optimize this.

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

---
 platform/linux-generic/odp_packet.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

-- 
2.9.3
diff mbox

Patch

diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 170965a..fa2303b 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -603,14 +603,23 @@  static inline void packet_free(odp_packet_hdr_t *pkt_hdr)
 {
 	odp_packet_hdr_t *ref_hdr;
 	uint32_t ref_count;
+	int num_seg;
 
 	do {
 		ref_hdr = pkt_hdr->ref_hdr;
 		ref_count = packet_ref_count(pkt_hdr) - 1;
-		free_bufs(pkt_hdr, 0, pkt_hdr->buf_hdr.segcount);
+		num_seg = pkt_hdr->buf_hdr.segcount;
 
-		if (ref_count == 1)
-			pkt_hdr->unshared_len = pkt_hdr->frame_len;
+		if (odp_likely((CONFIG_PACKET_MAX_SEGS == 1 || num_seg == 1) &&
+			       ref_count == 0)) {
+			buffer_free_multi((odp_buffer_t *)
+					  &pkt_hdr->buf_hdr.handle.handle, 1);
+		} else {
+			free_bufs(pkt_hdr, 0, num_seg);
+
+			if (ref_count == 1)
+				pkt_hdr->unshared_len = pkt_hdr->frame_len;
+		}
 
 		pkt_hdr = ref_hdr;
 	} while (pkt_hdr);