From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CAD4EA00C5; Thu, 30 Apr 2020 03:12:36 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 707D41D9B2; Thu, 30 Apr 2020 03:12:36 +0200 (CEST) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40064.outbound.protection.outlook.com [40.107.4.64]) by dpdk.org (Postfix) with ESMTP id BCA171D965 for ; Thu, 30 Apr 2020 03:12:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ax2/q2/WUfQePPuk64u+/fL2yWYWwmbxM4loIJeJZKo=; b=PPvPAzyMEopz5cijLSlQKiePS6iPLhltwGb50bRD25GeFs2D18AzcWm7Xu1CnQmC7JTMsapn3zMeSR4Ufb5hNHid56+uKaUxVD3fLQbxw97nLeXDIod27WgTLodgYli8w08YraM7JVKcRjAz1q974VuGMW+ujcrsMd+WuRn9tyM= Received: from AM5PR0402CA0004.eurprd04.prod.outlook.com (2603:10a6:203:90::14) by VI1PR0802MB2318.eurprd08.prod.outlook.com (2603:10a6:800:9e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Thu, 30 Apr 2020 01:12:32 +0000 Received: from AM5EUR03FT023.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:90:cafe::f5) by AM5PR0402CA0004.outlook.office365.com (2603:10a6:203:90::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 01:12:32 +0000 Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dpdk.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dpdk.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT023.mail.protection.outlook.com (10.152.16.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Thu, 30 Apr 2020 01:12:32 +0000 Received: ("Tessian outbound e88319d7ccd0:v54"); Thu, 30 Apr 2020 01:12:32 +0000 X-CR-MTA-TID: 64aa7808 Received: from e52b50014227.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D7BA9A06-ECC9-4569-9552-35B8F96433E0.1; Thu, 30 Apr 2020 01:12:27 +0000 Received: from EUR03-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e52b50014227.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 30 Apr 2020 01:12:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lYu2x47wvHgJhMWO+ucA+J/N5pqksW8rOgiGk+93nh+2EUNizcLJaTWGeeuQ/UX+FrqNIKOeLwVRUU2o1YWrG5PPfjq0LTRTNYDq8Xwmjs631W2MGmn2uLyTK2gCBy/f7FdrnJKw8OpkiINkrWfSNCd99cgnWRqrY1GqNaIBPGBqfFNGMp3IQbzsI7WZzEZrXw03kEy5J0M1j9I2NtZN7+z7t0HTGG3/CUsKDmb5myMiTiNtz8lgyolBm/AOV3dsQc94ZYuY53Rv9FNWYuAg0ZN73Ox4oOKLJzGGCCLVoTK8sAUaFqmUV4+4sVouPjIsSR8kOVzisn9USkKXP1vibw== 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-SenderADCheck; bh=Ax2/q2/WUfQePPuk64u+/fL2yWYWwmbxM4loIJeJZKo=; b=oOL3uuATwYjGjY3auQJwNNOrinbtZJ2Cs3mqL4HzzoD1q+x4Y39czaQPuurFjvJD84LmeEYaN7to0jpGqnIcST5qrLGNLZ1bu7j8eUtsL06n5B81UETYxD4PmHbj9aP0VjVctb/LdAYcMlKZZizIFdQmCG+ILmiESTRbOlQg5msP23dNceZPN67eBshm1J73Ox5nCH7mfBlbB1zkv0fQ9buTRWgyBt/W0tPkJbLtGhMo9cJASIOtJSHlAkpMfQgG2a4Hlmz52TALfZG4uplz+ACnpGIaWalLiBgeePR4xcji+ZNUpwoEjEfDmp1/5wvq+8DAYWR9nhg70iCzh8AYJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ax2/q2/WUfQePPuk64u+/fL2yWYWwmbxM4loIJeJZKo=; b=PPvPAzyMEopz5cijLSlQKiePS6iPLhltwGb50bRD25GeFs2D18AzcWm7Xu1CnQmC7JTMsapn3zMeSR4Ufb5hNHid56+uKaUxVD3fLQbxw97nLeXDIod27WgTLodgYli8w08YraM7JVKcRjAz1q974VuGMW+ujcrsMd+WuRn9tyM= Received: from DBBPR08MB4646.eurprd08.prod.outlook.com (10.255.79.144) by DBBPR08MB5222.eurprd08.prod.outlook.com (20.179.47.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20; Thu, 30 Apr 2020 01:12:25 +0000 Received: from DBBPR08MB4646.eurprd08.prod.outlook.com ([fe80::1870:afc4:b90f:609d]) by DBBPR08MB4646.eurprd08.prod.outlook.com ([fe80::1870:afc4:b90f:609d%5]) with mapi id 15.20.2958.020; Thu, 30 Apr 2020 01:12:25 +0000 From: Honnappa Nagarahalli To: Olivier Matz , =?iso-8859-1?Q?Morten_Br=F8rup?= CC: "dev@dpdk.org" , "Ananyev, Konstantin" , nd , Honnappa Nagarahalli , nd Thread-Topic: [RFC] ring: count and empty optimizations Thread-Index: AQHWHit+xWqi/EWuOEaPe4IgVQQmAaiQ2hpQ Date: Thu, 30 Apr 2020 01:12:25 +0000 Message-ID: References: <98CBD80474FA8B44BF855DF32C47DC35C60F96@smartserver.smartshare.dk> <20200429133837.GY6327@platinum> In-Reply-To: <20200429133837.GY6327@platinum> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: 78749eb7-e6a6-4d85-8b0e-6aaa0bd1ca43.0 x-checkrecipientchecked: true Authentication-Results-Original: 6wind.com; dkim=none (message not signed) header.d=none;6wind.com; dmarc=none action=none header.from=arm.com; x-originating-ip: [217.140.111.135] x-ms-publictraffictype: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 59e61b33-6fd1-4169-feaf-08d7eca38f45 x-ms-traffictypediagnostic: DBBPR08MB5222:|DBBPR08MB5222:|VI1PR0802MB2318: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:10000;OLM:10000; x-forefront-prvs: 0389EDA07F X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: cKa8TeDz1UuHrlFyA6BPxib271uYBf9AkI0vlT3PVgvvuhH7nh9T2/AsoCqSSxoG0V2M3uPX2w4tuWN+JoNHoR9Qu0tJzCf/oPNyCzOv/7xEbcasSSBvLqoOZ2ikfcfTIbp47nFy6HzfKugGlyv17UT7pKT6MyoLw6GhyBaKDoiHDxTtZ0jwIQBOlNKxW5yVuaI2Xh9rpiHpwkCMQ5eZWxI8s5LHMk7CDy4m5JbMP/5MPBZgL6IdFwfuG8vOX9Z4zcPcyHD2YkndbWjwgtGeM6iH9GZAnlvtP83z0WKLBxTusdXn5TvpIc0MhYwkscrQkY75vlfc5o1D285LWPYAGnOthoqipnoJx0TQ1Fn1mSGSYDTttFc6UvqK9RQUiLwyNI1QQIKj4nBLxuHo1EOk2kTBjnHdWvUafry1YXESGWmKbHPwlBnWy/YMBMXTx7K7 X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DBBPR08MB4646.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(376002)(366004)(136003)(346002)(39860400002)(396003)(8676002)(478600001)(86362001)(5660300002)(6506007)(316002)(71200400001)(7696005)(110136005)(66574012)(26005)(186003)(54906003)(2906002)(4326008)(8936002)(66946007)(76116006)(66476007)(64756008)(33656002)(66446008)(52536014)(66556008)(55016002)(9686003); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: fQzvXORhnsFHOq/v+OvmPlCL3RYUtFlekr+IaCYkUUV+S2Kl3kdnjfeY2BbbinqUa2859nw9PXWxwOg+othd42uyhWgPg2gdy72VM8eg7MhTOH2H/pR148Ip4vRyrQT15FHdqt2e00xrIDXXukayVBTi7PaX3xSBhvcR88jURsGBRblmzCyF+wSooa+5hg+Yd2EWbUm9VBVmafjNwVZMgEvJfHHNj282biFKZZ8KLUdF57Xi2rkqHCZHEdFzBqd/Pp+eoBYVhSJUw55n+DHJWasWToaJ2aQhlHBBtx8amFYlnm/vysDqq1pBi5BTwBaWQ/Hcr/kv6/jy7ghMuR/jglipx/9X0kPhlY1u2A54oEyVG7+u2/vag+cfoYcWCEfelO/6Y3x3WSXhEwU/YRwH5rQ2llX0Fl62AXa+QOFTzD6wtUXEZx0ZtSprgRxXbHBJSJ2osJPpAxVY5jUjMvp6vC7OmxxInKMPk5HP8/RChni2hvV4Iejm7a5nT8ug2SfzywL6+CZOZuXSLu3IFzo7pCTinV7kx08FqguIC24Nu6q5q6FPUivxuzLjG7DrXkCXk9/YmUpOc9OVec+KjDrTU1cUP5nSEAF/MPkt6tRnQa14roNyu9Dddd86Y/gyhFWJkMCIWEAra98kesdwiIGdKxPpywgWhyYfzmlo8sTM3pqnuTVNoeJ9EirOzgA5nXxkp82VaglkZpPp0bN8UWRqaAGF3Zb/kI8JifLPJw3VQoKc0G+wJ6eVe79pTISlUFh7RtfO8zjh+rXDKYCVl/myqrYUXmgv1jKyis3vzA5KaDm5Bh+XEzIuSx9nQctyct1o Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB5222 Original-Authentication-Results: 6wind.com; dkim=none (message not signed) header.d=none;6wind.com; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT023.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFTY:; SFS:(4636009)(376002)(346002)(39860400002)(396003)(136003)(46966005)(316002)(36906005)(5660300002)(110136005)(54906003)(8676002)(336012)(52536014)(8936002)(86362001)(7696005)(478600001)(2906002)(66574012)(33656002)(82310400002)(70206006)(356005)(4326008)(186003)(6506007)(70586007)(81166007)(9686003)(55016002)(82740400003)(26005)(47076004); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: fc7cca52-429e-48a4-0f0a-08d7eca38b11 X-Forefront-PRVS: 0389EDA07F X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uyTB4NXouC5Jt7lGpd1tWneb2nrrQBXv0p8TNL8JHI1xFc6vKG9d4302qtO7EqxIRJNd2yxDEN94ECwD3rTftIbYHj6BWs4K+2y1jLsCmJgr4+d9tBcVwPKoYmHava6EDk5KywlXIp5vvbJrScGs+nZXKAqrax/dpLXMGSIoyIesv8j1LMWnBshTwwQJLAEh/kuXR/cTDjwnI2QNR/Lj+jwnnnt7e8W58gvc1LuT+yBFipQNW5FOoOs8+gC3RSoXvLvCSTNsoUTnlHl0bc+5f3yjO2JM8+f6K7htVt0cJVDikSoRm115OhjpZnnd9BvoQ3outb1BWeN0aju1i7fy6JaCoO44jjGMf0ts3+t4n1uzyO9WjqsAYXQR2AuzZPTCXDa37GGFvJDfxsuuSUjCCfr66aARIkV31EMlygL/PZNyo+CfQ3hRpSwTe7B56t7moar3S8ZZ/n+lnvByK80KQLP233gEo5azz2WGet3Sf5Sq5gh+56Z2mUJj0mRa447MsjGLHN537+qgA1oL5vcZ7A== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 01:12:32.3148 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 59e61b33-6fd1-4169-feaf-08d7eca38f45 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2318 Subject: Re: [dpdk-dev] [RFC] ring: count and empty optimizations 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" >=20 > Hi Morten, >=20 > On Tue, Apr 28, 2020 at 03:53:15PM +0200, Morten Br=F8rup wrote: > > Olivier (maintainer of the Ring), >=20 > I'm not anymore, CC'ing Konstantin and Honnappa. >=20 > > I would like to suggest a couple of minor optimizations to the ring lib= rary. > > > > > > 1. Testing if the ring is empty is as simple as comparing the producer = and > consumer pointers: > > > > static inline int > > rte_ring_empty(const struct rte_ring *r) { > > - return rte_ring_count(r) =3D=3D 0; > > + uint32_t prod_tail =3D r->prod.tail; > > + uint32_t cons_tail =3D r->cons.tail; > > + return cons_tail =3D=3D prod_tail; > > } > > > > In theory, this optimization reduces the number of potential cache miss= es > from 3 to 2 by not having to read r->mask in rte_ring_count(). >=20 > This one looks correct to me. >=20 >=20 > > 2. It is not possible to enqueue more elements than the capacity of a r= ing, > so the count function does not need to test if the capacity is exceeded: > > > > static inline unsigned > > rte_ring_count(const struct rte_ring *r) { > > uint32_t prod_tail =3D r->prod.tail; > > uint32_t cons_tail =3D r->cons.tail; > > uint32_t count =3D (prod_tail - cons_tail) & r->mask; > > - return (count > r->capacity) ? r->capacity : count; > > + return count; > > } > > > > I cannot even come up with a race condition in this function where the > count would exceed the capacity. Maybe I missed something? >=20 > Since there is no memory barrier, the order in which prod_tail and cons_t= ail > are fetched is not guaranteed. Or the thread could be interrupted by the > kernel in between. The '__rte_ring_move_prod_head' function ensures that the distance between = prod.head and cons.tail is always within the capacity irrespective of wheth= er the consumers/producers are sleeping. >=20 > This function may probably return invalid results in MC/MP cases. > We just ensure that the result is between 0 and r->capacity.