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 AC613A0526; Wed, 8 Jul 2020 13:41:41 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EE0D81DA8B; Wed, 8 Jul 2020 13:41:40 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id AA0511DA7A for ; Wed, 8 Jul 2020 13:41:38 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 068Be982010022; Wed, 8 Jul 2020 04:41:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=date : from : to : cc : subject : message-id : references : content-type : in-reply-to : mime-version; s=pfpt0818; bh=Pni1/bOWYLVGCRkbt+0ILFMtkTlSsLygkAGIjyh1Md0=; b=tsJmywzDxyq3JXGGSQLDUR7z+Ij5QyI1flF+cSNhgeo5ik/te3fdS0UxfW2xt2bDqvnV 9g8lqfv4c8noU3Cm/qKxvU7cr1cQfo+S73BcVVAtDdp8onfUXb9WBdmn7Pgnkmbv12wt H4Q5lUa1rUOU06NXvqduHV94jFCr5X3na7GldQ3pQe/CU9aiD8bSqIuaEcoaM5uk9Fg/ qt4P14bTt1nw95RlIpoiWKfSckYcLwijLvJUhSJN/B8izVQPtB4KPAc4GSkd3GZ4Nx5r haH9ao0f7fChg3o86b6iP+R+F+rqNhkTxDRUe9nBLpplqUn7Sp3ndpfs1+wDWgoCUSGi qQ== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 322q4q0e3n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 08 Jul 2020 04:41:34 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 8 Jul 2020 04:41:33 -0700 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.108) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Wed, 8 Jul 2020 04:41:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UMs/Q92n4AzonKE7rAaflhk1TKQVHXnrkgd99CQDQKrcCo4GESpKg7eSr7M3O/hgr6LSDMLPawo6XpCaRXrkBgQy8EgB7CF8+ii2WAGZ/wIoAwUQQMAlWswnLjVsuzoVLBj8p438MXQJKUf6T0WSVtii3vmPXhPnwRSRO//L00vOKCf+dZ8W1n/XHxKolzHX4aW3IbQ70gVUL2ojLnRXMrcNm7Uz1jECTwSYVdwZvMkreGkC5gv6wA/417cGxOrMoRbHeKOXBFEIaCnWg2p0fQc5RWAJOhpTHCU93ytFAYRo7wQtbVq1TKM9iM/LWcHhL3Jr6sQXslfZ4cjlTReBnQ== 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=Pni1/bOWYLVGCRkbt+0ILFMtkTlSsLygkAGIjyh1Md0=; b=ENADCHHvZiDa85ZawKZUttaXhgyMjBW2uGVJGBcySgoq4FiATXFugPSZDCiy8B1rp22moFPsEroRcTaT/qu+AjPFgU7VLWnv7eEy7oddGZOfSQFHfP1LpbF7bXa2AmbdSn8tjlm/oqIs+8/R5KxSWlU7WmLmPBFjTHBtXomDoyZABzrmt+YkOTaCZtmaHgS0rCgPiQBMrfBClcIXYYHzW0XSa5y3zpRu+eTxfCXP/HxvDNrpXJ3cbYkx3B0k9leP/kVCJSIS3kLrpoydWAJukEuW9zqafUZSbpBMhIObTzLEfNsL2fhKj3+4DGOdr//cxbDkOtUctx+IAoU+AE2r5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Pni1/bOWYLVGCRkbt+0ILFMtkTlSsLygkAGIjyh1Md0=; b=uYSFAfH5D87ShpE6VAxd8uZZbrUhydUmAEqv86HhcnoPmA2PYXEKzXgLkSf9b6s2UfkIJywNnjw+kQlzRTVoSuPj7pFlu5kV0eX2rz3HYN8JRJcx+hYZWtOMTqOcM35Wg2udsaK3MgQfkg081XgRv3aluja2tqQZgVzpTrmoWxU= Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=marvell.com; Received: from MWHPR18MB1070.namprd18.prod.outlook.com (2603:10b6:300:a5::11) by MWHPR18MB1232.namprd18.prod.outlook.com (2603:10b6:320:2c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.20; Wed, 8 Jul 2020 11:41:32 +0000 Received: from MWHPR18MB1070.namprd18.prod.outlook.com ([fe80::e895:bdac:e157:2ed2]) by MWHPR18MB1070.namprd18.prod.outlook.com ([fe80::e895:bdac:e157:2ed2%11]) with mapi id 15.20.3153.030; Wed, 8 Jul 2020 11:41:31 +0000 Date: Wed, 8 Jul 2020 17:11:16 +0530 From: Harman Kalra To: Phil Yang CC: , , , , Message-ID: <20200708114114.GA49487@outlook.office365.com> References: <1591871065-12461-1-git-send-email-phil.yang@arm.com> <1591871065-12461-2-git-send-email-phil.yang@arm.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1591871065-12461-2-git-send-email-phil.yang@arm.com> User-Agent: Mutt/1.10.0 (2018-05-17) X-ClientProxiedBy: PN1PR0101CA0064.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:d::26) To MWHPR18MB1070.namprd18.prod.outlook.com (2603:10b6:300:a5::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from outlook.office365.com (115.113.156.2) by PN1PR0101CA0064.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:d::26) 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 11:41:29 +0000 X-Originating-IP: [115.113.156.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b1193f1a-fd29-4603-baae-08d82333dbf0 X-MS-TrafficTypeDiagnostic: MWHPR18MB1232: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-Forefront-PRVS: 04583CED1A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RepXAc4YzKiQGGd1iuHKb2XmwhzUJQC1YUB9oNFyJXGOjSRosz7o4FjEMjpfXJ5KpHgoCFnCDYj1lh3zOfJ6QzerA3R2JeNVAq2qvLJr9dCtcgAlpdJNKSkQzKjF7NAVt+dgsIyHSJqYyBrzEJk3iK6PuX0LVxqQjGUh0tCNwXiMnzkLssz1vrch1d/ch4PHfLnLzmrIwIwO5D0yBzErKRjwI70PpElEkW+ZjbQnLO3+7y2kweVPthJXqYxRcax0SDVyDupMX8ay+b/pwLlOc6CZQ1yLq6fttMH0pVpdsek6UHJCWiNFfO7mmzz3Zplav8HOgqWXK/27vh9RhmoXQZptTLK4h1GfH7dv90fB0GD1ZfucAjZq2HohNl+fQlri X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR18MB1070.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(39860400002)(396003)(376002)(346002)(366004)(136003)(186003)(16526019)(2906002)(83380400001)(55236004)(478600001)(55016002)(33656002)(956004)(26005)(6506007)(66946007)(9686003)(4326008)(316002)(1076003)(86362001)(7696005)(52116002)(6666004)(8936002)(66476007)(66556008)(5660300002)(6916009)(8676002)(87944003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Ns/OPFgSEJzKEHA8bO7GAIswmASFo+swJRELg9z1hBTIzN2TQ3IY0JkroWaOutt/jqcfzJvL8WxcIeSpsTjhbPG4MFPmZwC32d+W6cI4g7zfKATowAcmeT4EpFOz2zdvzZYaVro1HaF7pbzhzc8ZRQyZk1Y312SDNHfMbp+RQn0Wnj+GtufP0AoRGgtved3EV1si8pqWCmX7oIViAFX7FTASCI/AF3NHRIjDFGGG4oI5YBQTFvqt9Bm8FIkpCKjXzc47CUrsrtrD7bx3EBLhR+sqVTeU8b7iTEFByBc1TfHySmKejPqg689fWzqRHUVXaJY84U5VmMEYFLHZtPXJ2dG9kc6VSElAiodxJXv2pEOzzjvpDdYB9EaExq+mRDpswA2BsLUTmgPzNJ4U2OPZFWj8SeaCcFSa77YxFGYdjojw4t1zVcv/b5mfl50FGKFpKswxrx7FYUr/i34hfevrRI/0+XuVPhlWectClxBK7Vo= X-MS-Exchange-CrossTenant-Network-Message-Id: b1193f1a-fd29-4603-baae-08d82333dbf0 X-MS-Exchange-CrossTenant-AuthSource: MWHPR18MB1070.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2020 11:41:31.7474 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BZn/hNZaNQPuk063ZNgVKa2zVzOzsfVyjBKvKtlu2Jzj6e5b3eceo1aBdiSN+r8kGTJJsEygVAG7p43XzltlNA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR18MB1232 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-07-08_08:2020-07-08, 2020-07-08 signatures=0 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" On Thu, Jun 11, 2020 at 06:24:25PM +0800, Phil Yang wrote: > The event status is defined as a volatile variable and shared > between threads. Use c11 atomics with explicit ordering instead > of rte_atomic ops which enforce unnecessary barriers on aarch64. > > Signed-off-by: Phil Yang > Reviewed-by: Ruifeng Wang > --- Patches looks fine to me with commit message changes suggested by Honnappa, i.e. using C11 atomic built-ins. Since first patch of the series will not be backported, so I think both patches can be combined into one. Reviewed-by: Harman Kalra > lib/librte_eal/include/rte_eal_interrupts.h | 2 +- > lib/librte_eal/linux/eal_interrupts.c | 47 ++++++++++++++++++++--------- > 2 files changed, 34 insertions(+), 15 deletions(-) > > 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 { > > /** 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 = 0; > struct rte_epoll_event *rev; > + uint32_t valid_status; > > for (i = 0; i < n; i++) { > rev = evs[i].data.ptr; > - if (!rev || !rte_atomic32_cmpset(&rev->status, RTE_EPOLL_VALID, > - RTE_EPOLL_EXEC)) > + valid_status = 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; > > events[count].status = 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); > > - rte_compiler_barrier(); > - rev->status = 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_event *ev) > { > - while (!rte_atomic32_cmpset(&ev->status, RTE_EPOLL_VALID, > - RTE_EPOLL_INVALID)) > - while (ev->status != RTE_EPOLL_VALID) > + uint32_t valid_status = 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) != RTE_EPOLL_VALID) > rte_pause(); > + valid_status = RTE_EPOLL_VALID; > + } > memset(&ev->epdata, 0, sizeof(ev->epdata)); > ev->fd = -1; > ev->epfd = -1; > @@ -1333,7 +1346,8 @@ rte_epoll_ctl(int epfd, int op, int fd, > epfd = rte_intr_tls_epfd(); > > if (op == EPOLL_CTL_ADD) { > - event->status = RTE_EPOLL_VALID; > + __atomic_store_n(&event->status, RTE_EPOLL_VALID, > + __ATOMIC_RELAXED); > event->fd = fd; /* ignore fd in event */ > event->epfd = epfd; > ev.data.ptr = (void *)event; > @@ -1345,11 +1359,13 @@ rte_epoll_ctl(int epfd, int op, int fd, > op, fd, strerror(errno)); > if (op == EPOLL_CTL_ADD) > /* rollback status when CTL_ADD fail */ > - event->status = RTE_EPOLL_INVALID; > + __atomic_store_n(&event->status, RTE_EPOLL_INVALID, > + __ATOMIC_RELAXED); > return -1; > } > > - if (op == EPOLL_CTL_DEL && event->status != RTE_EPOLL_INVALID) > + if (op == EPOLL_CTL_DEL && __atomic_load_n(&event->status, > + __ATOMIC_RELAXED) != RTE_EPOLL_INVALID) > eal_epoll_data_safe_free(event); > > 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 = EPOLL_CTL_ADD; > rev = &intr_handle->elist[efd_idx]; > - if (rev->status != RTE_EPOLL_INVALID) { > + if (__atomic_load_n(&rev->status, > + __ATOMIC_RELAXED) != 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 = EPOLL_CTL_DEL; > rev = &intr_handle->elist[efd_idx]; > - if (rev->status == RTE_EPOLL_INVALID) { > + if (__atomic_load_n(&rev->status, > + __ATOMIC_RELAXED) == 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) > > for (i = 0; i < intr_handle->nb_efd; i++) { > rev = &intr_handle->elist[i]; > - if (rev->status == RTE_EPOLL_INVALID) > + if (__atomic_load_n(&rev->status, > + __ATOMIC_RELAXED) == 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 >