From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id 2E83D160 for ; Mon, 23 Jul 2018 21:46:00 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id e6-v6so1106510pgv.2 for ; Mon, 23 Jul 2018 12:46:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r4wV4bDGve/Q4bNoTXjh6LGsGvRf9yJrq1gxcaqTqRE=; b=xTiANOBbpBLB+8ttYnhlScVABdyxJS2xC/OENrVj8SpII1UhLC3rD2h0b7YwSPFw5V SRai6MohqeWCMHaz6i0kiBWQeQRodQQqSLk4ySk9bm053+VeKO3/sq/zFqcWTekCsSfi 9HC4jjYBTEP5eJ31r4T/XQSOoEwHorlL73mLCLwoa5IRpNY6DkgiwlkIyeNS8DXQmtGl POapUEZqzBQn1r7UJLyGZbINse4pQ9mXaMHCjC0TFQauFteUh1RGRfg1FsO8L6MyiAqH lO6A8zpaKBoeAz95DfrYs/mdvNrWrGfjiGpJQ8YuHktFS2gZNfC+Zo9vBBTiSiD8iKj4 ij5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r4wV4bDGve/Q4bNoTXjh6LGsGvRf9yJrq1gxcaqTqRE=; b=BxfO1RIDw/SZtB/6d4SCiBwp2w6njutKUaW7N2sgrV8ypvsVg/W+s6hU0PL5PQa7W/ wQAP9KbRCl7Jdz6sDUyVOcvo2GFUJFKlPIkgEJ01Bn021qczfy6bi/4xDtCELWD5IjwN 41gsQeqrpMlLYvrksRX9hpbKUYNWwRhHkLA6Nwa7CLuF/9/oYB2juWZpWWLDKmnl0Hl/ MRdZ2TBRqGy/q4qd0yIKYn9zFQBGBfQGwtLUHmNyfv80vqrt28RRR3r+R1G6zTHX9uNY 4aiHUZcH+//2G/HLGODfxBTMS6jKt+P2Ykup4HDu1+ffxUXJDSGbctLQ5BO0r/0uMdBI 8n0A== X-Gm-Message-State: AOUpUlG/fbTvnZMQiXStc1rtLo3ewu8SbUjg3113cuUigk9EY5vLqh5K xJ0h8F7CLAyQapwwnqqPUYQv5v0wbsc= X-Google-Smtp-Source: AAOMgpeGGilUwqu84IRLx25oCx62lSQrlB3kSOBR5MO9kHiB2vB33CJKdAI8mau+J4f1qaCJoQ9fSg== X-Received: by 2002:aa7:800f:: with SMTP id j15-v6mr14453711pfi.174.1532375159306; Mon, 23 Jul 2018 12:45:59 -0700 (PDT) Received: from xeon-e3 (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id i6-v6sm14634281pgc.7.2018.07.23.12.45.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jul 2018 12:45:59 -0700 (PDT) Date: Mon, 23 Jul 2018 12:45:56 -0700 From: Stephen Hemminger To: Morten =?UTF-8?B?QnLDuHJ1cA==?= Cc: "Olivier Matz" , Message-ID: <20180723124556.73564e05@xeon-e3> In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35B421F0@smartserver.smartshare.dk> References: <98CBD80474FA8B44BF855DF32C47DC35B421EE@smartserver.smartshare.dk> <20180723103757.47e4c26b@xeon-e3> <98CBD80474FA8B44BF855DF32C47DC35B421F0@smartserver.smartshare.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [dpdk-dev] rte_mbuf library likely()/unlikely() X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jul 2018 19:46:00 -0000 On Mon, 23 Jul 2018 20:59:29 +0200 Morten Br=C3=B8rup wrote: > > -----Original Message----- > > From: Stephen Hemminger [mailto:stephen@networkplumber.org] > > Sent: Monday, July 23, 2018 7:38 PM > > To: Morten Br=C3=B8rup > > Cc: Olivier Matz; dev@dpdk.org > > Subject: Re: [dpdk-dev] rte_mbuf library likely()/unlikely() > >=20 > > On Mon, 23 Jul 2018 15:53:42 +0200 > > Morten Br=C3=B8rup wrote: > > =20 > > > Hi Olivier, > > > > > > > > > > > > I noticed that __rte_pktmbuf_read() could do with an unlikely(), so I= =20 > > went through the entire library. Here are my suggested modifications. = =20 > > > > > > > > > > > > > > > > > > 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 =3D=3D NULL) > > > > > > + if (unlikely(m =3D=3D NULL)) > > > > > > rte_panic("mbuf is NULL\n"); > > > > > > =20 > >=20 > > Adding is unlikely is not necessary since rte_panic is marked with cold > > attribute > > which has the same effect. =20 >=20 > 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 tho= ught. Here's an updated patch for rte_mbuf.c, where it is relevant. The oth= er two suggested patches are unaffected. >=20 > 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 =3D m; > uint32_t buf_off =3D 0, copy_len; >=20 > - if (off + len > rte_pktmbuf_pkt_len(m)) > + if (unlikely(off + len > rte_pktmbuf_pkt_len(m))) > return NULL; >=20 > while (off >=3D rte_pktmbuf_data_len(seg)) { > @@ -257,7 +257,7 @@ > seg =3D seg->next; > } >=20 > - if (off + len <=3D rte_pktmbuf_data_len(seg)) > + if (likely(off + len <=3D rte_pktmbuf_data_len(seg))) > return rte_pktmbuf_mtod_offset(seg, char *, off); >=20 > /* rare case: header is split among several segments */ > @@ -344,7 +344,7 @@ > unsigned int i; > int ret; >=20 > - if (buflen =3D=3D 0) > + if (unlikely(buflen =3D=3D 0)) > return -1; >=20 > buf[0] =3D '\0'; > @@ -355,9 +355,9 @@ > if (name =3D=3D NULL) > name =3D rx_flags[i].default_name; > ret =3D snprintf(buf, buflen, "%s ", name); > - if (ret < 0) > + if (unlikely(ret < 0)) > return -1; > - if ((size_t)ret >=3D buflen) > + if (unlikely((size_t)ret >=3D buflen)) > return -1; > buf +=3D ret; > buflen -=3D ret; > @@ -440,7 +440,7 @@ > unsigned int i; > int ret; >=20 > - if (buflen =3D=3D 0) > + if (unlikely(buflen =3D=3D 0)) > return -1; >=20 > buf[0] =3D '\0'; > @@ -451,9 +451,9 @@ > if (name =3D=3D NULL) > name =3D tx_flags[i].default_name; > ret =3D snprintf(buf, buflen, "%s ", name); > - if (ret < 0) > + if (unlikely(ret < 0)) > return -1; > - if ((size_t)ret >=3D buflen) > + if (unlikely((size_t)ret >=3D buflen)) > return -1; > buf +=3D ret; > buflen -=3D ret; >=20 >=20 > Med venlig hilsen / kind regards > - Morten Br=C3=B8rup 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