From: Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>
To: "Morten Brørup" <mb@smartsharesystems.com>,
"Olivier Matz" <olivier.matz@6wind.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] rte_mbuf library likely()/unlikely()
Date: Mon, 23 Jul 2018 17:51:38 +0000 [thread overview]
Message-ID: <HE1PR0801MB1930747F372E5B543B4F273098560@HE1PR0801MB1930.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35B421EE@smartserver.smartshare.dk>
Do you see any performance improvements with these changes?
-----Original Message-----
From: dev <dev-bounces@dpdk.org> On Behalf Of Morten Brørup
Sent: Monday, July 23, 2018 8:54 AM
To: Olivier Matz <olivier.matz@6wind.com>
Cc: dev@dpdk.org
Subject: [dpdk-dev] rte_mbuf library likely()/unlikely()
Hi Olivier,
I noticed that __rte_pktmbuf_read() could do with an unlikely(), so I went through the entire library. Here are my suggested modifications.
diff -bu rte_mbuf.c.orig rte_mbuf.c
--- rte_mbuf.c.orig 2018-07-23 15:13:22.000000000 +0200
+++ rte_mbuf.c 2018-07-23 15:32:53.000000000 +0200
@@ -173,19 +173,19 @@
{
unsigned int nb_segs, pkt_len;
- if (m == NULL)
+ if (unlikely(m == NULL))
rte_panic("mbuf is NULL\n");
/* generic checks */
- if (m->pool == NULL)
+ if (unlikely(m->pool == NULL))
rte_panic("bad mbuf pool\n");
- if (m->buf_iova == 0)
+ if (unlikely(m->buf_iova == 0))
rte_panic("bad IO addr\n");
- if (m->buf_addr == NULL)
+ if (unlikely(m->buf_addr == NULL))
rte_panic("bad virt addr\n");
uint16_t cnt = rte_mbuf_refcnt_read(m);
- if ((cnt == 0) || (cnt == UINT16_MAX))
+ if (unlikely((cnt == 0) || (cnt == UINT16_MAX)))
rte_panic("bad ref cnt\n");
/* nothing to check for sub-segments */
@@ -193,7 +193,7 @@
return;
/* data_len is supposed to be not more than pkt_len */
- if (m->data_len > m->pkt_len)
+ if (unlikely(m->data_len > m->pkt_len))
rte_panic("bad data_len\n");
nb_segs = m->nb_segs;
@@ -204,9 +204,9 @@
pkt_len -= m->data_len;
} while ((m = m->next) != NULL);
- if (nb_segs)
+ if (unlikely(nb_segs))
rte_panic("bad nb_segs\n");
- if (pkt_len)
+ if (unlikely(pkt_len))
rte_panic("bad pkt_len\n");
}
@@ -249,7 +249,7 @@
const struct rte_mbuf *seg = m;
uint32_t buf_off = 0, copy_len;
- if (off + len > rte_pktmbuf_pkt_len(m))
+ if (unlikely(off + len > rte_pktmbuf_pkt_len(m)))
return NULL;
while (off >= rte_pktmbuf_data_len(seg)) {
@@ -257,7 +257,7 @@
seg = seg->next;
}
- if (off + len <= rte_pktmbuf_data_len(seg))
+ if (likely(off + len <= rte_pktmbuf_data_len(seg)))
return rte_pktmbuf_mtod_offset(seg, char *, off);
/* rare case: header is split among several segments */
@@ -344,7 +344,7 @@
unsigned int i;
int ret;
- if (buflen == 0)
+ if (unlikely(buflen == 0))
return -1;
buf[0] = '\0';
@@ -355,9 +355,9 @@
if (name == NULL)
name = rx_flags[i].default_name;
ret = snprintf(buf, buflen, "%s ", name);
- if (ret < 0)
+ if (unlikely(ret < 0))
return -1;
- if ((size_t)ret >= buflen)
+ if (unlikely((size_t)ret >= buflen))
return -1;
buf += ret;
buflen -= ret;
@@ -440,7 +440,7 @@
unsigned int i;
int ret;
- if (buflen == 0)
+ if (unlikely(buflen == 0))
return -1;
buf[0] = '\0';
@@ -451,9 +451,9 @@
if (name == NULL)
name = tx_flags[i].default_name;
ret = snprintf(buf, buflen, "%s ", name);
- if (ret < 0)
+ if (unlikely(ret < 0))
return -1;
- if ((size_t)ret >= buflen)
+ if (unlikely((size_t)ret >= buflen))
return -1;
buf += ret;
buflen -= ret;
diff -bu rte_mbuf.h.orig rte_mbuf.h
--- rte_mbuf.h.orig 2018-07-23 15:13:26.000000000 +0200
+++ rte_mbuf.h 2018-07-23 15:24:25.000000000 +0200
@@ -1007,7 +1007,7 @@
{
struct rte_mbuf *m;
- if (rte_mempool_get(mp, (void **)&m) < 0)
+ if (unlikely(rte_mempool_get(mp, (void **)&m) < 0))
return NULL;
MBUF_RAW_ALLOC_CHECK(m);
return m;
@@ -1268,7 +1268,7 @@
static inline struct rte_mbuf *rte_pktmbuf_alloc(struct rte_mempool *mp)
{
struct rte_mbuf *m;
- if ((m = rte_mbuf_raw_alloc(mp)) != NULL)
+ if (likely((m = rte_mbuf_raw_alloc(mp)) != NULL))
rte_pktmbuf_reset(m);
return m;
}
@@ -1696,7 +1696,7 @@
{
struct rte_mbuf *m_next;
- if (m != NULL)
+ if (likely(m != NULL))
__rte_mbuf_sanity_check(m, 1);
while (m != NULL) {
@@ -2099,7 +2099,7 @@
struct rte_mbuf *cur_tail;
/* Check for number-of-segments-overflow */
- if (head->nb_segs + tail->nb_segs > RTE_MBUF_MAX_NB_SEGS)
+ if (unlikely(head->nb_segs + tail->nb_segs > RTE_MBUF_MAX_NB_SEGS))
return -EOVERFLOW;
/* Chain 'tail' onto the old tail */
@@ -2147,28 +2147,28 @@
m->outer_l3_len;
/* Headers are fragmented */
- if (rte_pktmbuf_data_len(m) < inner_l3_offset + m->l3_len + m->l4_len)
+ if (unlikely(rte_pktmbuf_data_len(m) < inner_l3_offset + m->l3_len + m->l4_len))
return -ENOTSUP;
/* IP checksum can be counted only for IPv4 packet */
- if ((ol_flags & PKT_TX_IP_CKSUM) && (ol_flags & PKT_TX_IPV6))
+ if (unlikely((ol_flags & PKT_TX_IP_CKSUM) && (ol_flags & PKT_TX_IPV6)))
return -EINVAL;
/* IP type not set when required */
if (ol_flags & (PKT_TX_L4_MASK | PKT_TX_TCP_SEG))
- if (!(ol_flags & (PKT_TX_IPV4 | PKT_TX_IPV6)))
+ if (unlikely(!(ol_flags & (PKT_TX_IPV4 | PKT_TX_IPV6))))
return -EINVAL;
/* Check requirements for TSO packet */
if (ol_flags & PKT_TX_TCP_SEG)
- if ((m->tso_segsz == 0) ||
+ if (unlikely((m->tso_segsz == 0) ||
((ol_flags & PKT_TX_IPV4) &&
- !(ol_flags & PKT_TX_IP_CKSUM)))
+ !(ol_flags & PKT_TX_IP_CKSUM))))
return -EINVAL;
/* PKT_TX_OUTER_IP_CKSUM set for non outer IPv4 packet. */
- if ((ol_flags & PKT_TX_OUTER_IP_CKSUM) &&
- !(ol_flags & PKT_TX_OUTER_IPV4))
+ if (unlikely((ol_flags & PKT_TX_OUTER_IP_CKSUM) &&
+ !(ol_flags & PKT_TX_OUTER_IPV4)))
return -EINVAL;
return 0;
diff -bu rte_mbuf_ptype.c.orig rte_mbuf_ptype.c
--- rte_mbuf_ptype.c.orig 2018-07-23 15:45:49.000000000 +0200
+++ rte_mbuf_ptype.c 2018-07-23 15:44:59.000000000 +0200
@@ -118,15 +118,15 @@
{
int ret;
- if (buflen == 0)
+ if (unlikely(buflen == 0))
return -1;
buf[0] = '\0';
if ((ptype & RTE_PTYPE_ALL_MASK) == RTE_PTYPE_UNKNOWN) {
ret = snprintf(buf, buflen, "UNKNOWN");
- if (ret < 0)
+ if (unlikely(ret < 0))
return -1;
- if ((size_t)ret >= buflen)
+ if (unlikely((size_t)ret >= buflen))
return -1;
return 0;
}
@@ -134,9 +134,9 @@
if ((ptype & RTE_PTYPE_L2_MASK) != 0) {
ret = snprintf(buf, buflen, "%s ",
rte_get_ptype_l2_name(ptype));
- if (ret < 0)
+ if (unlikely(ret < 0))
return -1;
- if ((size_t)ret >= buflen)
+ if (unlikely((size_t)ret >= buflen))
return -1;
buf += ret;
buflen -= ret;
@@ -144,9 +144,9 @@
if ((ptype & RTE_PTYPE_L3_MASK) != 0) {
ret = snprintf(buf, buflen, "%s ",
rte_get_ptype_l3_name(ptype));
- if (ret < 0)
+ if (unlikely(ret < 0))
return -1;
- if ((size_t)ret >= buflen)
+ if (unlikely((size_t)ret >= buflen))
return -1;
buf += ret;
buflen -= ret;
@@ -154,9 +154,9 @@
if ((ptype & RTE_PTYPE_L4_MASK) != 0) {
ret = snprintf(buf, buflen, "%s ",
rte_get_ptype_l4_name(ptype));
- if (ret < 0)
+ if (unlikely(ret < 0))
return -1;
- if ((size_t)ret >= buflen)
+ if (unlikely((size_t)ret >= buflen))
return -1;
buf += ret;
buflen -= ret;
@@ -164,9 +164,9 @@
if ((ptype & RTE_PTYPE_TUNNEL_MASK) != 0) {
ret = snprintf(buf, buflen, "%s ",
rte_get_ptype_tunnel_name(ptype));
- if (ret < 0)
+ if (unlikely(ret < 0))
return -1;
- if ((size_t)ret >= buflen)
+ if (unlikely((size_t)ret >= buflen))
return -1;
buf += ret;
buflen -= ret;
@@ -174,9 +174,9 @@
if ((ptype & RTE_PTYPE_INNER_L2_MASK) != 0) {
ret = snprintf(buf, buflen, "%s ",
rte_get_ptype_inner_l2_name(ptype));
- if (ret < 0)
+ if (unlikely(ret < 0))
return -1;
- if ((size_t)ret >= buflen)
+ if (unlikely((size_t)ret >= buflen))
return -1;
buf += ret;
buflen -= ret;
@@ -184,9 +184,9 @@
if ((ptype & RTE_PTYPE_INNER_L3_MASK) != 0) {
ret = snprintf(buf, buflen, "%s ",
rte_get_ptype_inner_l3_name(ptype));
- if (ret < 0)
+ if (unlikely(ret < 0))
return -1;
- if ((size_t)ret >= buflen)
+ if (unlikely((size_t)ret >= buflen))
return -1;
buf += ret;
buflen -= ret;
@@ -194,9 +194,9 @@
if ((ptype & RTE_PTYPE_INNER_L4_MASK) != 0) {
ret = snprintf(buf, buflen, "%s ",
rte_get_ptype_inner_l4_name(ptype));
- if (ret < 0)
+ if (unlikely(ret < 0))
return -1;
- if ((size_t)ret >= buflen)
+ if (unlikely((size_t)ret >= buflen))
return -1;
buf += ret;
buflen -= ret;
Med venlig hilsen / kind regards
Morten Brørup
CTO
SmartShare Systems A/S
Tonsbakken 16-18
DK-2740 Skovlunde
Denmark
Office +45 70 20 00 93
Direct +45 89 93 50 22
Mobile +45 25 40 82 12
mb@smartsharesystems.com <mailto:mb@smartsharesystems.com>
www.smartsharesystems.com <https://www.smartsharesystems.com/>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
next prev parent reply other threads:[~2018-07-23 17:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-23 13:53 Morten Brørup
2018-07-23 17:37 ` Stephen Hemminger
2018-07-23 18:59 ` Morten Brørup
2018-07-23 19:45 ` Stephen Hemminger
2018-07-23 17:51 ` Honnappa Nagarahalli [this message]
2018-07-23 19:09 ` Morten Brørup
2018-07-23 22:40 ` Wiles, Keith
2018-07-24 7:29 ` Olivier Matz
2018-07-24 8:13 ` Morten Brørup
2018-07-24 11:31 ` Van Haaren, Harry
2018-07-24 13:02 ` Wiles, Keith
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=HE1PR0801MB1930747F372E5B543B4F273098560@HE1PR0801MB1930.eurprd08.prod.outlook.com \
--to=honnappa.nagarahalli@arm.com \
--cc=dev@dpdk.org \
--cc=mb@smartsharesystems.com \
--cc=olivier.matz@6wind.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).