From: Stephen Hemminger <stephen@networkplumber.org>
To: "Morten Brørup" <mb@smartsharesystems.com>
Cc: "Olivier Matz" <olivier.matz@6wind.com>, <dev@dpdk.org>
Subject: Re: rte_mbuf library likely()/unlikely()
Date: Mon, 23 Jul 2018 12:45:56 -0700 [thread overview]
Message-ID: <20180723124556.73564e05@xeon-e3> (raw)
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35B421F0@smartserver.smartshare.dk>
On Mon, 23 Jul 2018 20:59:29 +0200
Morten Brørup <mb@smartsharesystems.com> wrote:
> > -----Original Message-----
> > From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> > Sent: Monday, July 23, 2018 7:38 PM
> > To: Morten Brørup
> > Cc: Olivier Matz; dev@dpdk.org
> > Subject: Re: [dpdk-dev] rte_mbuf library likely()/unlikely()
> >
> > On Mon, 23 Jul 2018 15:53:42 +0200
> > Morten Brørup <mb@smartsharesystems.com> wrote:
> >
> > > 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");
> > >
> > >
> >
> > Adding is unlikely is not necessary since rte_panic is marked with cold
> > attribute
> > which has the same effect.
>
> I was not aware of this. Although it is not visible from the source code files using rte_panic(), it probably means we shouldn't as so much as I thought. Here's an updated patch for rte_mbuf.c, where it is relevant. The other two suggested patches are unaffected.
>
> 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 20:52:35.000000000 +0200
> @@ -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;
>
>
> Med venlig hilsen / kind regards
> - Morten Brørup
Yes, this makes sense.
Please format patch with signed-off-by and submit according to
the contributing guidelines Creating Patches section.
https://doc.dpdk.org/guides/contributing/patches.html
next prev parent reply other threads:[~2018-07-23 19:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-23 13:53 rte_mbuf library likely()/unlikely() 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 [this message]
2018-07-23 17:51 ` Honnappa Nagarahalli
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=20180723124556.73564e05@xeon-e3 \
--to=stephen@networkplumber.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.