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 9E12EA00BE; Wed, 8 Jul 2020 07:24:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 251B91DE74; Wed, 8 Jul 2020 07:24:16 +0200 (CEST) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150074.outbound.protection.outlook.com [40.107.15.74]) by dpdk.org (Postfix) with ESMTP id 91D881DE05 for ; Wed, 8 Jul 2020 07:24:15 +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=QLMSL0yu/smGSdW5eFZTr1fp+En21ZCewo+SsUaBExk=; b=sfAYmoDdB1zsz+rkQd1+4AB0n/ZmJ/aD5BrhhX6h6oMDZLza8kk6uPPbLzHAUYWRrhbKWgUmIxjilkIPp3xMjm4/jXmwzuYuL7Jem+gfB7D5TpYu+jvAp6JxK4O0VevxvgAGASDlZknCr83/OsZ19cpnzpDA3TkuXZWw1CBAF54= Received: from DB6PR0202CA0018.eurprd02.prod.outlook.com (2603:10a6:4:29::28) by VI1PR0801MB1757.eurprd08.prod.outlook.com (2603:10a6:800:5a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.20; Wed, 8 Jul 2020 05:24:14 +0000 Received: from DB5EUR03FT035.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:29:cafe::1b) by DB6PR0202CA0018.outlook.office365.com (2603:10a6:4:29::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Wed, 8 Jul 2020 05:24:14 +0000 X-MS-Exchange-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 DB5EUR03FT035.mail.protection.outlook.com (10.152.20.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Wed, 8 Jul 2020 05:24:14 +0000 Received: ("Tessian outbound a4b10e5b482d:v62"); Wed, 08 Jul 2020 05:24:14 +0000 X-CR-MTA-TID: 64aa7808 Received: from 5aa9c1fa632a.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 97F53F01-F15D-44E2-9F43-EB74FA54B7C1.1; Wed, 08 Jul 2020 05:24:09 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 5aa9c1fa632a.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 08 Jul 2020 05:24:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B/fxpc6+XpiBPrBd9OcBoqke2g+9pFwDX89CgaZcNAvpJBmC+KTA6Ht7WymAMOYOUHFO9m+/1h3CrxPih5LXP3J8orqk2gVS4yED31foSc54CmaPFIFlPGHUnvse5MdTpYxKCEoqb6XlV9ty3Jjy11GR5KFaW1M9GSRja75lMZKPKDTs/WnrU2GL5NJGD89g1KYjETYnDwV+92UyW8hK6ovclmM/NErAtclPIMTDlFUp565yeajbGJapFT5TfX56wfh7cTkbGGSIV4ul48lT9oeNFh9P8Pa8qAUvTiJLhVm6ooGQM0ueAI4SAz0XkJJxSxz1Rap952bqoBo8QVE2ZQ== 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=QLMSL0yu/smGSdW5eFZTr1fp+En21ZCewo+SsUaBExk=; b=fo55KUjlIibgl6qZzqfYhpc+iOqBEATIUw9Fg91THVPpa8ZesVuHmni2oHFE87qq41uaqkozm8VZwGpyiT02v/o8CJRlb843SnudPWsHSJyP+9kH3YB2ySQRqEUwAn0GDNGan/Zg9NoDB+y0evavQ+bCJtzQlCAO5EsPhtZsVlIswwRraDbBhwQzWqZd3LpviF1zXms+t0Sk/sOpZWA54p6bnXOgUIc7VHv7TOKcbnXXprjDgHGjUBUEq56xdzcvJFhbzCVwXuOV2ZttXHwYwa65kJW20D9qRGcoLYxqX0Rm3Y0Q5WtEzJJu/lYVjx34FMjSB8sBqicL2kFfPCufqw== 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=QLMSL0yu/smGSdW5eFZTr1fp+En21ZCewo+SsUaBExk=; b=sfAYmoDdB1zsz+rkQd1+4AB0n/ZmJ/aD5BrhhX6h6oMDZLza8kk6uPPbLzHAUYWRrhbKWgUmIxjilkIPp3xMjm4/jXmwzuYuL7Jem+gfB7D5TpYu+jvAp6JxK4O0VevxvgAGASDlZknCr83/OsZ19cpnzpDA3TkuXZWw1CBAF54= Received: from DB6PR0802MB2216.eurprd08.prod.outlook.com (2603:10a6:4:85::9) by DB8PR08MB5290.eurprd08.prod.outlook.com (2603:10a6:10:a5::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.28; Wed, 8 Jul 2020 05:24:08 +0000 Received: from DB6PR0802MB2216.eurprd08.prod.outlook.com ([fe80::9d1d:207b:e89d:199d]) by DB6PR0802MB2216.eurprd08.prod.outlook.com ([fe80::9d1d:207b:e89d:199d%10]) with mapi id 15.20.3153.030; Wed, 8 Jul 2020 05:24:07 +0000 From: Honnappa Nagarahalli To: Phil Yang , "dev@dpdk.org" CC: "drc@linux.vnet.ibm.com" , Ruifeng Wang , nd , Honnappa Nagarahalli , nd Thread-Topic: [PATCH 2/2] eal: use c11 atomics for interrupt status Thread-Index: AQHWP9qU3Ls/gHjRPkG3SMMqUJi2Fqj9TjWg Date: Wed, 8 Jul 2020 05:24:07 +0000 Message-ID: References: <1591871065-12461-1-git-send-email-phil.yang@arm.com> <1591871065-12461-2-git-send-email-phil.yang@arm.com> In-Reply-To: <1591871065-12461-2-git-send-email-phil.yang@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: 1423d039-8ce0-4bc4-8634-b50acef650c4.0 x-checkrecipientchecked: true Authentication-Results-Original: arm.com; dkim=none (message not signed) header.d=none;arm.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: 6ed254d3-fe13-4b8b-7dca-08d822ff272e x-ms-traffictypediagnostic: DB8PR08MB5290:|VI1PR0801MB1757: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:9508;OLM:9508; x-forefront-prvs: 04583CED1A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: aADourNYjsRRFPJufxx7Y9e33UbxRW1l+fZti0B+leLPlL8k6vQnJEeAnIn5/l54BzPrq5KcZxHkls6a1Z+NiYvjqI0Sr3RCQiOS8bzjmNWXtTaLP0t9/n6MvlrLnt9+Fjxp3v2tmjDOKdNc2W6SfFUt4dWMAmxJbVRX5wuCVrhLTgx5znQcwknDMnyT+FpHxRIMJCSgdT77CyN9LLMlp0+/HLEGm0ev2OfWqRIXTAgeHcgsP+BEmTTFkwUqIGUqS/nFmnDouMYeim/BVtgtIz3GcSiWzrG85ZbVu60eso5tW33LPbYZgl/teYmzV7II3bvLaPa2ajrWTNBwnFI25lyh/V0Qm+A+5r4AxhS7yQ60ZmRn5eZMDUWiium459N/ X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB6PR0802MB2216.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(396003)(39850400004)(366004)(376002)(346002)(136003)(186003)(26005)(6506007)(4326008)(8936002)(71200400001)(54906003)(316002)(110136005)(86362001)(7696005)(478600001)(33656002)(83380400001)(55016002)(9686003)(5660300002)(8676002)(2906002)(76116006)(66476007)(66556008)(64756008)(66446008)(66946007)(52536014)(87944003); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: 00g/uSfsQMBOrsYGCznbYGCkLPkvn+M2rDV+txIm87bwvRo0d8Iwn2Z7yqB/5DYIFjDco5nAKF5N+Aqi551wf6IubFofmbQD6dlA8aKdLYWlq0BEPXnnOBNpLJT6cDMz5iNNLcM4WgWArVlzjsxU3CK4OAtJwTs/IbkHfn/Tgj6GWdIOpsxCAqSZy+uQyZWzpyTQUdir7PO/haOymX1scVBvmnvCIqHhiL6Y221eReNXvF0PV/+JEEDbClK1RHEaEbG/DZzA1Ir21WPt6bbE7bwCXB53jugu6pVczP4nhRrpG0H1Ar2wH1LnuNp4GpldphAS9vfwVIedTguN/uJ8BBZpgJyBtGW3Yj7uZhhdnlC5yHFQ8ZXwV3w0jTmSajFdQSIVPd3w6m4ExxljiZQWr9iRIC4Ah6Uc3x7bXo1Qc85RWHwx/BfjuyZ4ksxJ+4gwpIM03AFG0WMUjEmpc15OUu3squcQreGV/0lHpwTz/wx6eZ5sSjamMUi/rDYxCjm3 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5290 Original-Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT035.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)(39850400004)(396003)(136003)(346002)(376002)(46966005)(82310400002)(70206006)(356005)(52536014)(186003)(70586007)(8676002)(8936002)(316002)(54906003)(47076004)(83380400001)(478600001)(86362001)(82740400003)(81166007)(110136005)(7696005)(336012)(9686003)(55016002)(2906002)(6506007)(4326008)(26005)(5660300002)(33656002)(87944003); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 6eea8607-7488-4c86-65bd-08d822ff2345 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OnLMZ1KWVUpFxD1vcQBEjFI7ZtexKM7NIgkAFNfFyhXJcMnnGcoq6Id9mb3UW+Ub70hEvqJIbd/5XW5/giGXJCW7boyTGO+Od9TwnFpeLNrcHhm0IOu7h81QVMxCS1XuR3f9OjkZSZp23B7vqIqkHBeprTuq5Mpib1TrLgpb3QTcGTSopsls0iki+9Z3/ch2lup2Q8zjTWuLoC0+ZcXjOgFYbbjxX9edqelohcOVpfWa9pVUhx+0I2z/yvO0b24LnMkXrdUgQ9Sem9Z6F2UkkDaBP+fsinBWt2MVHdm+PYzGS3XY4uP8q7jmoqRC6iLiX2SEWlL7RgCbfQ5GX3Z8NQ1+GVBndq+SiEfUi5rKn5SKWkqmY2FS9PNJDK3n+eFQhm2kogrV5UW468VwUH6Vl9PAFMLEdmAA7L11cCPblNY= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2020 05:24:14.2228 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ed254d3-fe13-4b8b-7dca-08d822ff272e 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-AuthSource: DB5EUR03FT035.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1757 Subject: Re: [dpdk-dev] [PATCH 2/2] eal: use c11 atomics for interrupt status 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" > Subject: [PATCH 2/2] eal: use c11 atomics for interrupt status nit, C11 atomic built-ins ^^^^^^^^^^ >=20 > The event status is defined as a volatile variable and shared between thr= eads. > Use c11 atomics with explicit ordering instead of rte_atomic ops which nit, ^^^^^^^^^^ same here > enforce unnecessary barriers on aarch64. >=20 > Signed-off-by: Phil Yang > Reviewed-by: Ruifeng Wang Otherwise, it looks fine. Reviewed-by: Honnappa Nagarahalli > --- > lib/librte_eal/include/rte_eal_interrupts.h | 2 +- > lib/librte_eal/linux/eal_interrupts.c | 47 ++++++++++++++++++++---= ------ > 2 files changed, 34 insertions(+), 15 deletions(-) >=20 > diff --git a/lib/librte_eal/include/rte_eal_interrupts.h > b/lib/librte_eal/include/rte_eal_interrupts.h > index 773a34a..b1e8a29 100644 > --- a/lib/librte_eal/include/rte_eal_interrupts.h > +++ b/lib/librte_eal/include/rte_eal_interrupts.h > @@ -59,7 +59,7 @@ enum { >=20 > /** interrupt epoll event obj, taken by epoll_event.ptr */ struct > rte_epoll_event { > - volatile uint32_t status; /**< OUT: event status */ > + uint32_t status; /**< OUT: event status */ > int fd; /**< OUT: event fd */ > int epfd; /**< OUT: epoll instance the ev associated with */ > struct rte_epoll_data epdata; > diff --git a/lib/librte_eal/linux/eal_interrupts.c > b/lib/librte_eal/linux/eal_interrupts.c > index 2f369dc..1486acf 100644 > --- a/lib/librte_eal/linux/eal_interrupts.c > +++ b/lib/librte_eal/linux/eal_interrupts.c > @@ -26,7 +26,6 @@ > #include > #include > #include > -#include > #include > #include > #include > @@ -1221,11 +1220,18 @@ eal_epoll_process_event(struct epoll_event > *evs, unsigned int n, { > unsigned int i, count =3D 0; > struct rte_epoll_event *rev; > + uint32_t valid_status; >=20 > for (i =3D 0; i < n; i++) { > rev =3D evs[i].data.ptr; > - if (!rev || !rte_atomic32_cmpset(&rev->status, > RTE_EPOLL_VALID, > - RTE_EPOLL_EXEC)) > + valid_status =3D RTE_EPOLL_VALID; > + /* ACQUIRE memory ordering here pairs with RELEASE > + * ordering bellow acting as a lock to synchronize > + * the event data updating. > + */ > + if (!rev || !__atomic_compare_exchange_n(&rev->status, > + &valid_status, RTE_EPOLL_EXEC, 0, > + __ATOMIC_ACQUIRE, > __ATOMIC_RELAXED)) > continue; >=20 > events[count].status =3D RTE_EPOLL_VALID; > @@ -1237,8 +1243,11 @@ eal_epoll_process_event(struct epoll_event *evs, > unsigned int n, > rev->epdata.cb_fun(rev->fd, > rev->epdata.cb_arg); >=20 > - rte_compiler_barrier(); > - rev->status =3D RTE_EPOLL_VALID; > + /* the status update should be observed after > + * the other fields changes. > + */ > + __atomic_store_n(&rev->status, RTE_EPOLL_VALID, > + __ATOMIC_RELEASE); > count++; > } > return count; > @@ -1308,10 +1317,14 @@ rte_epoll_wait(int epfd, struct rte_epoll_event > *events, static inline void eal_epoll_data_safe_free(struct rte_epoll_e= vent > *ev) { > - while (!rte_atomic32_cmpset(&ev->status, RTE_EPOLL_VALID, > - RTE_EPOLL_INVALID)) > - while (ev->status !=3D RTE_EPOLL_VALID) > + uint32_t valid_status =3D RTE_EPOLL_VALID; > + while (!__atomic_compare_exchange_n(&ev->status, &valid_status, > + RTE_EPOLL_INVALID, 0, __ATOMIC_ACQUIRE, > __ATOMIC_RELAXED)) { > + while (__atomic_load_n(&ev->status, > + __ATOMIC_RELAXED) !=3D RTE_EPOLL_VALID) > rte_pause(); > + valid_status =3D RTE_EPOLL_VALID; > + } > memset(&ev->epdata, 0, sizeof(ev->epdata)); > ev->fd =3D -1; > ev->epfd =3D -1; > @@ -1333,7 +1346,8 @@ rte_epoll_ctl(int epfd, int op, int fd, > epfd =3D rte_intr_tls_epfd(); >=20 > if (op =3D=3D EPOLL_CTL_ADD) { > - event->status =3D RTE_EPOLL_VALID; > + __atomic_store_n(&event->status, RTE_EPOLL_VALID, > + __ATOMIC_RELAXED); > event->fd =3D fd; /* ignore fd in event */ > event->epfd =3D epfd; > ev.data.ptr =3D (void *)event; > @@ -1345,11 +1359,13 @@ rte_epoll_ctl(int epfd, int op, int fd, > op, fd, strerror(errno)); > if (op =3D=3D EPOLL_CTL_ADD) > /* rollback status when CTL_ADD fail */ > - event->status =3D RTE_EPOLL_INVALID; > + __atomic_store_n(&event->status, > RTE_EPOLL_INVALID, > + __ATOMIC_RELAXED); > return -1; > } >=20 > - if (op =3D=3D EPOLL_CTL_DEL && event->status !=3D RTE_EPOLL_INVALID) > + if (op =3D=3D EPOLL_CTL_DEL && __atomic_load_n(&event->status, > + __ATOMIC_RELAXED) !=3D RTE_EPOLL_INVALID) > eal_epoll_data_safe_free(event); >=20 > return 0; > @@ -1378,7 +1394,8 @@ rte_intr_rx_ctl(struct rte_intr_handle *intr_handle= , > int epfd, > case RTE_INTR_EVENT_ADD: > epfd_op =3D EPOLL_CTL_ADD; > rev =3D &intr_handle->elist[efd_idx]; > - if (rev->status !=3D RTE_EPOLL_INVALID) { > + if (__atomic_load_n(&rev->status, > + __ATOMIC_RELAXED) !=3D RTE_EPOLL_INVALID) > { > RTE_LOG(INFO, EAL, "Event already been added.\n"); > return -EEXIST; > } > @@ -1401,7 +1418,8 @@ rte_intr_rx_ctl(struct rte_intr_handle *intr_handle= , > int epfd, > case RTE_INTR_EVENT_DEL: > epfd_op =3D EPOLL_CTL_DEL; > rev =3D &intr_handle->elist[efd_idx]; > - if (rev->status =3D=3D RTE_EPOLL_INVALID) { > + if (__atomic_load_n(&rev->status, > + __ATOMIC_RELAXED) =3D=3D > RTE_EPOLL_INVALID) { > RTE_LOG(INFO, EAL, "Event does not exist.\n"); > return -EPERM; > } > @@ -1426,7 +1444,8 @@ rte_intr_free_epoll_fd(struct rte_intr_handle > *intr_handle) >=20 > for (i =3D 0; i < intr_handle->nb_efd; i++) { > rev =3D &intr_handle->elist[i]; > - if (rev->status =3D=3D RTE_EPOLL_INVALID) > + if (__atomic_load_n(&rev->status, > + __ATOMIC_RELAXED) =3D=3D > RTE_EPOLL_INVALID) > continue; > if (rte_epoll_ctl(rev->epfd, EPOLL_CTL_DEL, rev->fd, rev)) { > /* force free if the entry valid */ > -- > 2.7.4