From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0072.outbound.protection.outlook.com [65.55.169.72]) by dpdk.org (Postfix) with ESMTP id D218D8E5D for ; Wed, 4 Nov 2015 14:30:40 +0100 (CET) Received: from BLUPR0701MB1969.namprd07.prod.outlook.com (10.163.121.20) by BLUPR0701MB1779.namprd07.prod.outlook.com (10.162.87.149) with Microsoft SMTP Server (TLS) id 15.1.312.18; Wed, 4 Nov 2015 13:30:39 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jerin.Jacob@caviumnetworks.com; Received: from localhost.localdomain.localdomain (122.166.133.227) by BLUPR0701MB1969.namprd07.prod.outlook.com (10.163.121.20) with Microsoft SMTP Server (TLS) id 15.1.318.15; Wed, 4 Nov 2015 13:30:34 +0000 From: Jerin Jacob To: Date: Wed, 4 Nov 2015 18:58:48 +0530 Message-ID: <1446643728-15701-2-git-send-email-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1446643728-15701-1-git-send-email-jerin.jacob@caviumnetworks.com> References: <1446643728-15701-1-git-send-email-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [122.166.133.227] X-ClientProxiedBy: MAXPR01CA0066.INDPRD01.PROD.OUTLOOK.COM (25.164.146.166) To BLUPR0701MB1969.namprd07.prod.outlook.com (25.163.121.20) X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1969; 2:eyNY+UOsyaYJCpEK6BY74lypKs86z9voO3+8JNSiwNZkqXl4KUfGQvbfne8Q6bmjqt8UxFqi1HQJf7Km/cZZPD4aUNoqSZg1GnIP1G3ei6r8306eNZQQglBZHVLaKnAp4QMuRyEC/DUxVi1N56W11oG89u2CaSn88pi9cdX5f9U=; 3:DCyP2YvDCJ49XD56drgOp2wr+sTckn5s3od7y+mTNX8faZGaIu+0fVapl485YaNj5kwL4853mavufYXcOD0/DPudPQ1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Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(236414709691187); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(3002001)(10201501046); SRVR:BLUPR0701MB1969; BCL:0; PCL:0; RULEID:; SRVR:BLUPR0701MB1969; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1969; 4:OYnjtWUeB5mT0e1wOLgslDiOqGptMoZ4Bp18y4++3QRVg1+cCrDAurv6gfW/E5XReVF/IVsIL6T+urMesMl1baRHfJx7UWknMLFidFxwN7y5G12+92+6Epa41i0LtM4Al2Sznxxwpo+DfIsvZFwPXusRe86Fb6/kbYfhcQHZAVHskJ4DfkZm2tfgpzZT20hiyUkNgJt+Ujtq2qrHf+WULtHjfJFAV2yNkjM6NJ4MAUbI1zM6NplGpG5ApE9viFv7jDr82VXslp43i3PKMVplCLnb7EUy/cXX38M9Cpg2j7sEj8HFcJ6y9/rGfYQHglkqz7D4X7CELqJmDv7GupAQleOVzUCJeDPzWVp2cysowkoD5tucDcYnEG+ZpTwV7xDk X-Forefront-PRVS: 0750463DC9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(6069001)(189002)(199003)(50466002)(50986999)(5004730100002)(229853001)(19580405001)(106356001)(40100003)(76176999)(2351001)(110136002)(107886002)(5001960100002)(77096005)(5007970100001)(92566002)(5003940100001)(105586002)(19580395003)(87976001)(189998001)(33646002)(122386002)(81156007)(50226001)(42186005)(97736004)(2950100001)(575784001)(86362001)(4001430100002)(101416001)(47776003)(66066001)(36756003)(48376002)(5008740100001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0701MB1969; H:localhost.localdomain.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: caviumnetworks.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR0701MB1969; 23:c/xr5tIm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?us-ascii?Q?W4Pcgz47aWO0RUfS6t/9CsGP4nxg/EKOu+jUGAAmY9Wb9qvv3mqQ+Lrw83SL?= =?us-ascii?Q?qJNwcfBRCZMjp6uKNohfZfa49SYEmxnK/ZuYvy5BsX0pSRQdjcQpmVOD2/Kb?= =?us-ascii?Q?MIqoBExNtJt27VViY/5TiLy8+Rm3eBJ58qLQy7lzOlrjin3KLMS7G2pjmiJ6?= =?us-ascii?Q?PD6jlA6cdy9LdBmlTNYaL7MPVAwaa5yskTzfrx7iCG5qqs2gLfQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1969; 5:xvtlau2PAu10lNFkMC0hsw7D3TG45pujJQ/6AlplOPH3pZwSiVDK1oEeXKFh0W4XhxtypwtTSuCQtQUU2vmfNHQ4Pg1Spoyse+PqQIe0hyDHAQRnmJeE5qyMp7Ym9TjFSJtM75vs7OR0Tq+OholK5w==; 24:uD1ioQmiNk3rFYcoScbFttGUU9xsRqlso4WMJwZ7Ha8wSAJhc/AzWQJBdzQR7BJlvQGezLyw51njsxJeMTP02LUOMdRilr4SxSjdz9jwl0c=; 20:kNUnUn9VbCQO1OesPelkI587GEGH3IIIq9kVyi5fs7Q2ZhvCBe+Rsd+Epv/oPvyaTpzo82xMGA6FPeqgecoBVg== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2015 13:30:34.5913 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0701MB1969 X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1779; 2:J0rdhZbd3IS7xKvqiUiZtD2htYCZ2Kv1vvQNnkD/bVRlf7mWAtMX5WXHpXMUqfFghGfEMyzb2X6sGiZO/+EseqLtx5ikMURgTO+gc8iENiXQAnkM+f5YEas/uqH6eE7W56PHgK8nuJYwsnYzWb8FZfstXZ5IWrScKuk3LtGxwbs=; 23:731J/LwHKcRZyYTPbDDreODfCx0ypg2Pr7P54vN0l00wNEf4M9b5cOiDRTTeuSEt25C6kJeGgqggT9804ejEWLwZdeold/SWeyZ/lwKCp0x/fvWl+bfqrJ6z4ov66uIzViquH4XYrwizkjSdYvkK/sFuIcNChcfZ7UolEHMr9nRCsALGTM2w5A6fOyLBXjgx X-OriginatorOrg: caviumnetworks.com Cc: changchun.ouyang@intel.com Subject: [dpdk-dev] [PATCH] Introduce rte_smp_*mb() for memory barriers to use between lcores X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Nov 2015 13:30:41 -0000 This commit introduce rte_smp_mb(), rte_smp_wmb() and rte_smp_rmb(), in order to enable memory barriers between lcores. The patch does not provide any functional change for IA, the goal is to have infrastructure for weakly ordered machines like ARM to work on DPDK. Signed-off-by: Jerin Jacob --- drivers/net/virtio/virtqueue.h | 8 +++---- drivers/net/xenvirt/rte_eth_xenvirt.c | 4 ++-- drivers/net/xenvirt/virtqueue.h | 2 +- .../common/include/arch/ppc_64/rte_atomic.h | 6 +++++ .../common/include/arch/tile/rte_atomic.h | 6 +++++ .../common/include/arch/x86/rte_atomic.h | 6 +++++ lib/librte_eal/common/include/generic/rte_atomic.h | 27 ++++++++++++++++++++++ lib/librte_ring/rte_ring.h | 8 +++---- 8 files changed, 55 insertions(+), 12 deletions(-) diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h index 689c321..61b3137 100644 --- a/drivers/net/virtio/virtqueue.h +++ b/drivers/net/virtio/virtqueue.h @@ -53,12 +53,10 @@ struct rte_mbuf; * accesses through relaxed memory I/O windows, so smp_mb() et al are * sufficient. * - * This driver is for virtio_pci on SMP and therefore can assume - * weaker (compiler barriers) */ -#define virtio_mb() rte_mb() -#define virtio_rmb() rte_compiler_barrier() -#define virtio_wmb() rte_compiler_barrier() +#define virtio_mb() rte_smp_mb() +#define virtio_rmb() rte_smp_rmb() +#define virtio_wmb() rte_smp_wmb() #ifdef RTE_PMD_PACKET_PREFETCH #define rte_packet_prefetch(p) rte_prefetch1(p) diff --git a/drivers/net/xenvirt/rte_eth_xenvirt.c b/drivers/net/xenvirt/rte_eth_xenvirt.c index 264aeda..e83c08c 100644 --- a/drivers/net/xenvirt/rte_eth_xenvirt.c +++ b/drivers/net/xenvirt/rte_eth_xenvirt.c @@ -102,7 +102,7 @@ eth_xenvirt_rx(void *q, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) nb_used = VIRTQUEUE_NUSED(rxvq); - rte_compiler_barrier(); /* rmb */ + rte_smp_rmb(); num = (uint16_t)(likely(nb_used <= nb_pkts) ? nb_used : nb_pkts); num = (uint16_t)(likely(num <= VIRTIO_MBUF_BURST_SZ) ? num : VIRTIO_MBUF_BURST_SZ); if (unlikely(num == 0)) return 0; @@ -153,7 +153,7 @@ eth_xenvirt_tx(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) PMD_TX_LOG(DEBUG, "%d packets to xmit", nb_pkts); nb_used = VIRTQUEUE_NUSED(txvq); - rte_compiler_barrier(); /* rmb */ + rte_smp_rmb(); num = (uint16_t)(likely(nb_used <= VIRTIO_MBUF_BURST_SZ) ? nb_used : VIRTIO_MBUF_BURST_SZ); num = virtqueue_dequeue_burst(txvq, snd_pkts, len, num); diff --git a/drivers/net/xenvirt/virtqueue.h b/drivers/net/xenvirt/virtqueue.h index eff6208..6dcb0ef 100644 --- a/drivers/net/xenvirt/virtqueue.h +++ b/drivers/net/xenvirt/virtqueue.h @@ -151,7 +151,7 @@ vq_ring_update_avail(struct virtqueue *vq, uint16_t desc_idx) */ avail_idx = (uint16_t)(vq->vq_ring.avail->idx & (vq->vq_nentries - 1)); vq->vq_ring.avail->ring[avail_idx] = desc_idx; - rte_compiler_barrier(); /* wmb , for IA memory model barrier is enough*/ + rte_smp_wmb(); vq->vq_ring.avail->idx++; } diff --git a/lib/librte_eal/common/include/arch/ppc_64/rte_atomic.h b/lib/librte_eal/common/include/arch/ppc_64/rte_atomic.h index fb7af2b..b8bc2c0 100644 --- a/lib/librte_eal/common/include/arch/ppc_64/rte_atomic.h +++ b/lib/librte_eal/common/include/arch/ppc_64/rte_atomic.h @@ -72,6 +72,12 @@ extern "C" { */ #define rte_rmb() {asm volatile("sync" : : : "memory"); } +#define rte_smp_mb() rte_mb() + +#define rte_smp_wmb() rte_compiler_barrier() + +#define rte_smp_rmb() rte_compiler_barrier() + /*------------------------- 16 bit atomic operations -------------------------*/ /* To be compatible with Power7, use GCC built-in functions for 16 bit * operations */ diff --git a/lib/librte_eal/common/include/arch/tile/rte_atomic.h b/lib/librte_eal/common/include/arch/tile/rte_atomic.h index 3dc8eb8..28825ff 100644 --- a/lib/librte_eal/common/include/arch/tile/rte_atomic.h +++ b/lib/librte_eal/common/include/arch/tile/rte_atomic.h @@ -79,6 +79,12 @@ static inline void rte_rmb(void) __sync_synchronize(); } +#define rte_smp_mb() rte_mb() + +#define rte_smp_wmb() rte_compiler_barrier() + +#define rte_smp_rmb() rte_compiler_barrier() + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/common/include/arch/x86/rte_atomic.h b/lib/librte_eal/common/include/arch/x86/rte_atomic.h index e93e8ee..41178c7 100644 --- a/lib/librte_eal/common/include/arch/x86/rte_atomic.h +++ b/lib/librte_eal/common/include/arch/x86/rte_atomic.h @@ -53,6 +53,12 @@ extern "C" { #define rte_rmb() _mm_lfence() +#define rte_smp_mb() rte_mb() + +#define rte_smp_wmb() rte_compiler_barrier() + +#define rte_smp_rmb() rte_compiler_barrier() + /*------------------------- 16 bit atomic operations -------------------------*/ #ifndef RTE_FORCE_INTRINSICS diff --git a/lib/librte_eal/common/include/generic/rte_atomic.h b/lib/librte_eal/common/include/generic/rte_atomic.h index 6c7581a..26d1f56 100644 --- a/lib/librte_eal/common/include/generic/rte_atomic.h +++ b/lib/librte_eal/common/include/generic/rte_atomic.h @@ -72,6 +72,33 @@ static inline void rte_wmb(void); */ static inline void rte_rmb(void); +/** + * General memory barrier between lcores + * + * Guarantees that the LOAD and STORE operations that precede the + * rte_smp_mb() call are globally visible across the lcores + * before the the LOAD and STORE operations that follows it. + */ +static inline void rte_smp_mb(void); + +/** + * Write memory barrier between lcores + * + * Guarantees that the STORE operations that precede the + * rte_smp_wmb() call are globally visible across the lcores + * before the the STORE operations that follows it. + */ +static inline void rte_smp_wmb(void); + +/** + * Read memory barrier between lcores + * + * Guarantees that the LOAD operations that precede the + * rte_smp_rmb() call are globally visible across the lcores + * before the the LOAD operations that follows it. + */ +static inline void rte_smp_rmb(void); + #endif /* __DOXYGEN__ */ /** diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index fb5a626..de036ce 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -468,7 +468,7 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table, /* write entries in ring */ ENQUEUE_PTRS(); - rte_compiler_barrier(); + rte_smp_wmb(); /* if we exceed the watermark */ if (unlikely(((mask + 1) - free_entries + n) > r->prod.watermark)) { @@ -563,7 +563,7 @@ __rte_ring_sp_do_enqueue(struct rte_ring *r, void * const *obj_table, /* write entries in ring */ ENQUEUE_PTRS(); - rte_compiler_barrier(); + rte_smp_wmb(); /* if we exceed the watermark */ if (unlikely(((mask + 1) - free_entries + n) > r->prod.watermark)) { @@ -654,7 +654,7 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table, /* copy in table */ DEQUEUE_PTRS(); - rte_compiler_barrier(); + rte_smp_rmb(); /* * If there are other dequeues in progress that preceded us, @@ -738,7 +738,7 @@ __rte_ring_sc_do_dequeue(struct rte_ring *r, void **obj_table, /* copy in table */ DEQUEUE_PTRS(); - rte_compiler_barrier(); + rte_smp_rmb(); __RING_STAT_ADD(r, deq_success, n); r->cons.tail = cons_next; -- 2.1.0