From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2315AA0350; Mon, 10 Jan 2022 16:09:59 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A809B4115E; Mon, 10 Jan 2022 16:09:58 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 2DB4E40041 for ; Mon, 10 Jan 2022 16:09:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641827397; x=1673363397; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=/mBLmBPhiRXb3quV/7ehYs+quEMGhuG+YUSGGPVFrHo=; b=U4Zr8qHu5nU1as3Yd+hRKX2XA7dkWz4sAyh/hobi3qdcSXcRyi/Ut0Oi EdWMcykYt7KJy2t76pO/tyIOVfESZUHukxPmRtpHfKQB2rtGzYz6pz4M0 VWyxkpW7D/WX/e00hVD4yKfcuR4/foMbEcCOsK9mg68WYofa+NIJlpPNh 9s8477ZOtiCNHI5CU1p3vOUt7jkXXJ3sguvjHkoRIgML0q6HLKig2fIUi W13QId7xLY/jSzUgrgoOPi9/1KWlyxIr+F3V4340Hh8+I5QIuaIpXUz9a I8e+Vi57QROI5u5RfWpu2kK/b6Kb3xR8Ryixmlffr1PdjGXbEnC54EWUL A==; X-IronPort-AV: E=McAfee;i="6200,9189,10222"; a="306599342" X-IronPort-AV: E=Sophos;i="5.88,277,1635231600"; d="scan'208";a="306599342" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2022 07:09:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,277,1635231600"; d="scan'208";a="619465204" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmsmga002.fm.intel.com with ESMTP; 10 Jan 2022 07:09:55 -0800 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 10 Jan 2022 07:09:55 -0800 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 10 Jan 2022 07:09:54 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Mon, 10 Jan 2022 07:09:54 -0800 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.45) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Mon, 10 Jan 2022 07:09:52 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iMwJatK9OzC0XE4no01DGeXyOnEsB21UeP/WPfI9LwyBUlautox0Ghbqh/SNYkoYLSWCC2UTMVD14WhwWxz7cNFPbMy1mX7ChQMPPFpEnQmnsCLnKHGF6W9MKUgpn1Mp20L/PclPljFNdSvME2EfI7fVOuj/gz+MhuP8HCx0Pt+wIEMaix7pwC0lEc4+TofO9fKJILH8hjQqlwniW8IIFKVWs3DeVH5NLLmxToSZSoV3uqaInaM6B8RLhtij7DNiF7yEomHeriRHLEe0EMMcjVWkycrpnfpixloHNjD28XwnCo1dEk22L8qoY2GtIJFXWDtG2hDsCI9nmocwJJgPPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OpE5qGO4zYo55mN6cLoNPnzyLMrXeSgLKoFSzjGFulk=; b=e+8OUr01Qx8LWJv60+Xn226/m7pHgxM5W8a8N9Qcv11zlfJVVqfVKqhuJ/phz5/xYd7o6GqqnjiUYFxsTrO9W+yGr7praLqLzny23whjCX9VKurLsePuw3rEplqArnRZacfIn+bahBscPAwv2a3FCvpH+Yrgc7QBbZqUdUKWiu4qB1frIf3MEZmsNvMM/tbMaZijHyWsSwCybniItLzAGpBk+03Y976lTyDiubhm8pL3ku5mVS9tVtf91MtC+O+YB0A1vnVHNRng4/VcvI7lKfZUD09oiuIfNRkRmzhqy96iAZC26G98Cg8LfrZ10Bnh4ysHx5V6XzpD512pJooi5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from DM6PR11MB4491.namprd11.prod.outlook.com (2603:10b6:5:204::19) by DM5PR1101MB2170.namprd11.prod.outlook.com (2603:10b6:4:54::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.9; Mon, 10 Jan 2022 15:09:51 +0000 Received: from DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::7de4:731c:cee2:49c2]) by DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::7de4:731c:cee2:49c2%3]) with mapi id 15.20.4867.012; Mon, 10 Jan 2022 15:09:50 +0000 From: "Ananyev, Konstantin" To: Andrzej Ostruszka , "dev@dpdk.org" CC: "upstream@semihalf.com" Subject: RE: [PATCH 1/1] ring: fix off by 1 mistake Thread-Topic: [PATCH 1/1] ring: fix off by 1 mistake Thread-Index: AQHYAK2Jh20iE/0+g0m9mzlxDWF1wKxcZq+g Date: Mon, 10 Jan 2022 15:09:50 +0000 Message-ID: References: <20220103142201.475552-1-amo@semihalf.com> <20220103142201.475552-2-amo@semihalf.com> In-Reply-To: <20220103142201.475552-2-amo@semihalf.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.200.16 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 78d53b81-05ee-469f-d383-08d9d44b3fe2 x-ms-traffictypediagnostic: DM5PR1101MB2170:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5236; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 5jgU2ymgBU8W+AkMbOngq86pFcMap58PE8KIBWzhJF3opcsmapooSyWBk3f7kzfiU0LgNPAmGua2LITjTntb+riVj8Z6w1QyIY0XUpJYAxMv6M7v6+dWDp3GauAMOTKwMfY+3HCzPZGHbaqkmTmDOuF9ZvtqqvNg4ybgtgF9qhTp4MYljw/3hISpVG9+rH9K5DqXrooHP2DlHI/FDYmEGMY4lK/hYkWT+MkqJmAsqYIl57AoLoMWudt7WHmJ4XjPCC1XaU2zqcyJnjruehQqRdESg3ywpq7ePMpjRmS7S6vx1EjbCm5SMRCTOafTifZC4xA3N7RIxw4iDCFRyvb6U3IBG4PKmKLjjzIJUr8UyuDMZBIYWqUKMgbWUDf+r00eptyYRRZKTu7RXkZO2Hteeg/tHGIeNAVfKXneiWLzpyKJIGn4zITg8xo4Lt1uUkphZceC9Oi3n9Odswwbcp8VvS3yrN8H/ZFZCsazypxm53uT3aEpC28iQarCQYNs3nts2ykjIftl/MBlHG65LdaxjuEMpUpz2Vec9N5fzDjdQYd3+9ZTE/2hAnoc64UqEyE1VUgO7Jcv5ZDGJJ/TV8aLwEQ+e4zwDIWc05eWeSRlz276P+/T+B4mlJllahcbgyLBr+0EBEBX4Efu+XpjMYhrquR9SuRvdnjn6iWoGuTAC9PAe5rlUbMigMkhXgpC69IehHYQpem7kSr9WygEOAXJ9w== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR11MB4491.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(82960400001)(5660300002)(66946007)(76116006)(66476007)(7696005)(83380400001)(52536014)(122000001)(9686003)(38100700002)(4326008)(38070700005)(64756008)(66556008)(66446008)(110136005)(55016003)(33656002)(8936002)(316002)(86362001)(26005)(71200400001)(6506007)(186003)(8676002)(508600001)(2906002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?OmKMFDbDq4AHCZNyJqq0ON76GkOy9Xvzekh1rVAEfurahZ8mfjrKnhU0JS6j?= =?us-ascii?Q?kBa1SzcgJRkvpvtSOsEb3DvgmFXSe9nom7Zg5g4v68GI7evHyVPYuSyfCI7V?= =?us-ascii?Q?ne6kk6f5qsSoyOL0SbM7OOCt2vQ+Pcv85Amlr7nNL7PvBpZQxjzsGdbBCCIw?= =?us-ascii?Q?UGVWV415BOsZAlGAzAKI1Gw+quuKaYQ1oDMdLc2z5qqlOqiSFhgvRzBcYxKR?= =?us-ascii?Q?pGFGu7Jra9FGHwFPC3GgOUYk33tld2BXeW7/msjMrPrgVKjeOWaEPbDHgocv?= =?us-ascii?Q?j3EPoscXkp5eINtnJOje5H4BBisztM7DH0lS+blhRCmDOqNUkVvfAbku2j5x?= =?us-ascii?Q?4bC2XqLewAZgU8lVDWsw8YBGwZPVP5HbaEKHgs/rgyYRW8FGlP4Olf/rX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/2OmyvMTMrL/XNLPzmi62/lew?= =?us-ascii?Q?36U8XnfzCO6J5tH5PfxP7tL52MEqQItkl5u3kyXqj1qR18NxIT3dsyE3DZPB?= =?us-ascii?Q?LCLw0kBR3w941htCv+uJtLPORq9DmJmFTMfZNuM5V7WE6a4DqTGaPhYTBJsn?= =?us-ascii?Q?v1YszY4mVLMqu7UsCQgZt+prVIBbsqRGulUcfjzih+UgoewikFzg+GSrybbu?= =?us-ascii?Q?jNYSBBPwVUZg1ExDhyq2nLSVCsFBbZejyEZ2xm1pR9PnXkqY4w4VZ5Tt/mxP?= =?us-ascii?Q?8QUwnbQAJ/OZTyRtoZiVzeVLvXE9sUyHtj3aB7hTBV1GX/Y76/+2gAOU+v1V?= =?us-ascii?Q?v6qtgVLd4Iog9ApDDfxwz0fY/CjQkOb5XMjJc4MIkppnF/rAWZzlO3PxWdRd?= =?us-ascii?Q?mECJ4Q=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4491.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 78d53b81-05ee-469f-d383-08d9d44b3fe2 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Jan 2022 15:09:50.8164 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: gp2usllHNcxYqsclENjqYIb0XjDy7LaQmEiqh4ubVoFd0LgIyDmu9xuApRNj/ylrQ65Z//TQuwTbo7+BC/EQOdJlhmHjy+/WcQBFmY5TXO8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1101MB2170 X-OriginatorOrg: intel.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org > When enqueueing/dequeueing to/from the ring we try to optimize by manual > loop unrolling. The check for this optimization looks like: >=20 > if (likely(idx + n < size)) { >=20 > where 'idx' points to the first usable element (empty slot for enqueue, > data for dequeue). The correct comparison here should be '<=3D' instead > of '<'. >=20 > This is not a functional error since we fall back to the loop with > correct checks on indexes. Just a minor suboptimal behaviour for the > case when we want to enqueue/dequeue exactly the number of elements that > we have in the ring before wrapping to its beginning. >=20 > Signed-off-by: Andrzej Ostruszka > --- > lib/ring/rte_ring_elem_pvt.h | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) >=20 > diff --git a/lib/ring/rte_ring_elem_pvt.h b/lib/ring/rte_ring_elem_pvt.h > index 275ec55393..83788c56e6 100644 > --- a/lib/ring/rte_ring_elem_pvt.h > +++ b/lib/ring/rte_ring_elem_pvt.h > @@ -17,7 +17,7 @@ __rte_ring_enqueue_elems_32(struct rte_ring *r, const u= int32_t size, > unsigned int i; > uint32_t *ring =3D (uint32_t *)&r[1]; > const uint32_t *obj =3D (const uint32_t *)obj_table; > - if (likely(idx + n < size)) { > + if (likely(idx + n <=3D size)) { > for (i =3D 0; i < (n & ~0x7); i +=3D 8, idx +=3D 8) { > ring[idx] =3D obj[i]; > ring[idx + 1] =3D obj[i + 1]; > @@ -62,7 +62,7 @@ __rte_ring_enqueue_elems_64(struct rte_ring *r, uint32_= t prod_head, > uint32_t idx =3D prod_head & r->mask; > uint64_t *ring =3D (uint64_t *)&r[1]; > const unaligned_uint64_t *obj =3D (const unaligned_uint64_t *)obj_table= ; > - if (likely(idx + n < size)) { > + if (likely(idx + n <=3D size)) { > for (i =3D 0; i < (n & ~0x3); i +=3D 4, idx +=3D 4) { > ring[idx] =3D obj[i]; > ring[idx + 1] =3D obj[i + 1]; > @@ -95,7 +95,7 @@ __rte_ring_enqueue_elems_128(struct rte_ring *r, uint32= _t prod_head, > uint32_t idx =3D prod_head & r->mask; > rte_int128_t *ring =3D (rte_int128_t *)&r[1]; > const rte_int128_t *obj =3D (const rte_int128_t *)obj_table; > - if (likely(idx + n < size)) { > + if (likely(idx + n <=3D size)) { > for (i =3D 0; i < (n & ~0x1); i +=3D 2, idx +=3D 2) > memcpy((void *)(ring + idx), > (const void *)(obj + i), 32); > @@ -151,7 +151,7 @@ __rte_ring_dequeue_elems_32(struct rte_ring *r, const= uint32_t size, > unsigned int i; > uint32_t *ring =3D (uint32_t *)&r[1]; > uint32_t *obj =3D (uint32_t *)obj_table; > - if (likely(idx + n < size)) { > + if (likely(idx + n <=3D size)) { > for (i =3D 0; i < (n & ~0x7); i +=3D 8, idx +=3D 8) { > obj[i] =3D ring[idx]; > obj[i + 1] =3D ring[idx + 1]; > @@ -196,7 +196,7 @@ __rte_ring_dequeue_elems_64(struct rte_ring *r, uint3= 2_t prod_head, > uint32_t idx =3D prod_head & r->mask; > uint64_t *ring =3D (uint64_t *)&r[1]; > unaligned_uint64_t *obj =3D (unaligned_uint64_t *)obj_table; > - if (likely(idx + n < size)) { > + if (likely(idx + n <=3D size)) { > for (i =3D 0; i < (n & ~0x3); i +=3D 4, idx +=3D 4) { > obj[i] =3D ring[idx]; > obj[i + 1] =3D ring[idx + 1]; > @@ -229,7 +229,7 @@ __rte_ring_dequeue_elems_128(struct rte_ring *r, uint= 32_t prod_head, > uint32_t idx =3D prod_head & r->mask; > rte_int128_t *ring =3D (rte_int128_t *)&r[1]; > rte_int128_t *obj =3D (rte_int128_t *)obj_table; > - if (likely(idx + n < size)) { > + if (likely(idx + n <=3D size)) { > for (i =3D 0; i < (n & ~0x1); i +=3D 2, idx +=3D 2) > memcpy((void *)(obj + i), (void *)(ring + idx), 32); > switch (n & 0x1) { > -- Acked-by: Konstantin Ananyev > 2.34.1.448.ga2b2bfdf31-goog