diff mbox series

[v2,2/3] linux-generic: packet: add branch hints for reference optimization

Message ID 1502748005-17591-3-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v2,1/3] linux-generic: packet: improve packet_init() performance | expand

Commit Message

Github ODP bot Aug. 14, 2017, 10 p.m. UTC
From: Bill Fischofer <bill.fischofer@linaro.org>


Add odp_likely() and odp_unlikely() hints on critical paths in packet
allocation / free processing to optimize reference support.

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

---
/** Email created from pull request 125 (Bill-Fischofer-Linaro:pktrefs-opt)
 ** https://github.com/Linaro/odp/pull/125
 ** Patch: https://github.com/Linaro/odp/pull/125.patch
 ** Base sha: 90d4ce1b3b25ca18446131906007571cc0ed0191
 ** Merge commit sha: 6d464aeb30e24833ae787e3997a411103c16c70c
 **/
 platform/linux-generic/odp_packet.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index f18bd4dd..a71a5926 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -444,13 +444,14 @@  static inline void free_bufs(odp_packet_hdr_t *pkt_hdr, int first, int num)
 	for (i = 0, nfree = 0; i < num; i++) {
 		odp_packet_hdr_t *hdr = pkt_hdr->buf_hdr.seg[first + i].hdr;
 
-		if (packet_ref_count(hdr) == 1 || packet_ref_dec(hdr) == 1) {
+		if (odp_likely(packet_ref_count(hdr) == 1 ||
+			       packet_ref_dec(hdr) == 1)) {
 			ODP_ASSERT((packet_ref_count_set(hdr, 0), 1));
 			buf_hdr[nfree++] = &hdr->buf_hdr;
 		}
 	}
 
-	if (nfree > 0)
+	if (odp_likely(nfree > 0))
 		buffer_free_multi(buf_hdr, nfree);
 }
 
@@ -468,8 +469,8 @@  static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr,
 		for (i = 0, nfree = 0; i < num; i++) {
 			new_hdr = pkt_hdr->buf_hdr.seg[i].hdr;
 
-			if (packet_ref_count(new_hdr) == 1 ||
-			    packet_ref_dec(new_hdr) == 1) {
+			if (odp_likely(packet_ref_count(new_hdr) == 1 ||
+				       packet_ref_dec(new_hdr) == 1)) {
 				ODP_ASSERT((packet_ref_count_set(new_hdr, 0),
 					    1));
 				buf_hdr[nfree++] = &new_hdr->buf_hdr;
@@ -492,7 +493,7 @@  static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr,
 
 		pkt_hdr = new_hdr;
 
-		if (nfree > 0)
+		if (odp_likely(nfree > 0))
 			buffer_free_multi(buf_hdr, nfree);
 	} else {
 		/* Free last 'num' bufs */
@@ -658,7 +659,7 @@  void odp_packet_free_multi(const odp_packet_t pkt[], int num)
 			ref_hdr = pkt_hdr->ref_hdr;
 
 			/* Make sure we have enough space for this pkt's segs */
-			if (nfree + num_seg > nbufs) {
+			if (odp_unlikely(nfree + num_seg > nbufs)) {
 				buffer_free_multi(buf_hdr, nfree);
 				nfree = 0;
 			}
@@ -681,7 +682,7 @@  void odp_packet_free_multi(const odp_packet_t pkt[], int num)
 		} while (pkt_hdr);
 	}
 
-	if (nfree > 0)
+	if (odp_likely(nfree > 0))
 		buffer_free_multi(buf_hdr, nfree);
 }