From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1on0090.outbound.protection.outlook.com [157.56.110.90]) by dpdk.org (Postfix) with ESMTP id 1318391D7 for ; Fri, 6 Nov 2015 10:42:02 +0100 (CET) Received: from BLUPR0701MB1969.namprd07.prod.outlook.com (10.163.121.20) by BLUPR0701MB1890.namprd07.prod.outlook.com (10.162.88.151) with Microsoft SMTP Server (TLS) id 15.1.312.18; Fri, 6 Nov 2015 09:42:01 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jerin.Jacob@caviumnetworks.com; Received: from jerin.caveonetworks.com (111.93.218.67) by BLUPR0701MB1969.namprd07.prod.outlook.com (10.163.121.20) with Microsoft SMTP Server (TLS) id 15.1.318.15; Fri, 6 Nov 2015 09:41:58 +0000 From: Jerin Jacob To: Date: Fri, 6 Nov 2015 15:10:32 +0530 Message-ID: <1446802833-22265-14-git-send-email-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1446802833-22265-1-git-send-email-jerin.jacob@caviumnetworks.com> References: <1446802833-22265-1-git-send-email-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: MA1PR01CA0066.INDPRD01.PROD.OUTLOOK.COM (25.164.116.166) To BLUPR0701MB1969.namprd07.prod.outlook.com (25.163.121.20) X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1969; 2:BSPX4VwYR9qSHQX4S0W4OLBc/9OCWD4j3qwrU7ouBJHf8QcpJn4tXEABe/k1WHIjaNmDhspRPZb7ODDTR/yzCEYWe26SmlOALjg2J/gCVpZCOVOuXff6wrc/6CT/uXfZHPKBpNf5tfGujY/PPd18sTb+3GTFI2MJxRNvZOhEvnk=; 3:lbJLgYU0DyhHMniutkFVp6yynAu9HKze4sFZftduqt5iSNG6cGSNxrAdW/DobV+d2zPleMiYjUsUNaPBrF9VhNfJrILV3VJAhdEjRSmX09f9Pph21e8lCOIbO7OPFDGnXYFs/7d3v3WGzdBFbOEp1g==; 25:G+HG+6m4n65cHuCTHg1FnBoPXZTWQUrz7cIed3YWhYJ+5YzAAzXOMXzwmJfiEkrejceVXSs4yHDVK7zr8+U0VYdXRyhpR1gUcJ/zn5kOlPmotPD+Ctfo5ZaeOr4fDJ/GPC5Q5R3qvstvPAwaHo4s6fUu1ToSrHGqzfgssR24P2xd5O1pVI+6T0VPP3tRwPKFwsR5+h/SspdYvBrFeCqxAFc1P66N0rt8GMFKNMwJXYq1mke/BDqfKi0yZc7zfQuRb+5tM18spO5wYXhPm4qtIA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0701MB1969; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1969; 20:5nBexZtebfnhIqZuCQnIcHX2ScZphKSunbOpzvDOMjiQXtoNyPh1hG1d+mAzQonlzLzf7au9gsj9wyGuoeVffm9abZVh8J3kmJyYzSI9OT/cAJwF+TZB3QOIjuVIcf2FHa+30HK6w8RDTQgOONGJ/AptwmGvx/2a6r19B6njyptVg8Sb/ZTHKwXloIGGyvb4XXjKhwfCeGqHu215AddwpjYeAPd5F0pOwqGpY8y6IW/vwP0yz4cISleSselaGpzkp0m8oLopaS97sXTPlaheBunSIX+JtdkxzoKho6al6FXpDbfByKw+UB66DBdG1aD9gZEaydVSoBhuD2z7lem7XZGcUpf1K5QppqbEsV8RfYN9yTAz/daIqsuL8tC4w2hpXbOV/7Dxo6iZ41ci4AoeX+WyqATHdQwMFiD6REWc7HxhhTpUCsdhJLv4b40cxARSHAR6ZZwvD0GqObBB4j4HqFF7+/m4GfoUF1orcnTh91laZDY/zicJEZUb0MogkJ7ooc6ZkySFhClHFF1dB0j+FVksKj8xWJ9mdzqV84UX+77aFOHckHwX3cAxassBp6iBIYQ8Uwubuhc0fAmZwSZNxTVl1i358K13Xom7vEMno34= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(236414709691187)(228905959029699); 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:ycPbKjA59LUceC8tUFBBErmPrj9QomXbuLKo0MIqyuUuwvmpKdJhzuCVh+ayVGNBq9zImXceU5IMJvYR8iApfcf5h79WGZNqv0WOSmkEXgM9dqj10EZk267fpfqrfcm1hPPusDyQS5sTigXDRm0DEw1d4pNsJiZrvT7OpKiSTQubEys9rORMIgEbXYmvI5ngeeMrGmfxyxgQ8C0O6SNqu90HMEMfVoV+GCyolE69/wGdDXQJ8ugRk+H+wrHTnA/VZoiavZOtcGnq91hG4xOCw2J3elwP04cZAoyZsF+WW0oms3mo/1Brkk6nmmjEA5l0gOgjhVuQNbWAfO9IfcuAx91zKVIcV7qU020zKDBurr9zxV+n8ZaC62WsyKWzQggC X-Forefront-PRVS: 07521929C1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(189002)(199003)(50226001)(122386002)(48376002)(50986999)(50466002)(106356001)(229853001)(110136002)(19580405001)(40100003)(76176999)(87976001)(105586002)(5004730100002)(77096005)(19580395003)(2351001)(5003940100001)(92566002)(107886002)(189998001)(5007970100001)(33646002)(5001960100002)(66066001)(5009440100003)(42186005)(2950100001)(4001430100002)(97736004)(575784001)(101416001)(69596002)(47776003)(36756003)(5008740100001)(53416004)(81156007)(86362001)(7099028); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0701MB1969; H:jerin.caveonetworks.com; 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:TZ9Y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HgbvqqpWDx?= =?us-ascii?Q?GUL/gVdU5BqujkupJLiDX1278MLpJ08p8AfDUh5b3W6B4ghj7c3vDW0Ksqba?= =?us-ascii?Q?bwS7nqcR6jKosedEzZpf7PDsScNGAIqe3c0/MPM1QBZrRTFtAIaLAfHd5QOd?= =?us-ascii?Q?yLZ5CLQbeJb4wH2+Hd+K6bcJMrWWNPJ6nxiq/XFrVvpBnxkYhvl/B28lVkgA?= =?us-ascii?Q?hNVyuL1r3Lqzbw5K8lLEYMs8UKY+/RV3nJzo70nwPi7970J33OjPPONWYyu/?= =?us-ascii?Q?741c7Z0pdKSK7zkq1pCKHZx59cUT6sfLNSXUo/mhWik0J9azG2JCtmw=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1969; 5:lQ7HLjsVFYdLza4vfhign3f4fV3JNPLp5QRMXzCGxzHTwrvevMzAAfwQc6x3fJp2jiJTnPeWFDFksvGj8S4fi03G0++JGyD9gS2p2p3kbvtvLeOBvPH7N7BtDbySoWd+JrM00sHUNdL5K65j7iw3Ww==; 24:RfrBmpHOCSw7GfylrrcgVBkop/1L+gLr/Uwk6L5vGXwlqPD/RPGkl5YoZVcjjDNALtBfEw7vsG7jsOX1xp6kNsS+oV89c9oXefgTSymSX+c=; 20:ghiG4rrgy1dPkXB0bGPZbXlUWBZjw78ontdSPUyhtoBjxDiq6XVqicrX1S728xE+qg5Q5wQsJJ8gpgbVGeKvGA== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Nov 2015 09:41:58.0392 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0701MB1969 X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1890; 2:ubzYnVw2dygJwaEoFqYiHV2MuFAfbi+xEa05Oef3zoHElCtvzl855fnVlVf3SdTJh97rEVKhhkRm7RmZHt0rIGxSpm0luLS/YFo4Nuasg7Q9EdCNLK1LzXCJWiqIH9Q0Sk4vOC7sm62vHvadVtZtS9PELhepA9uY9vNHxD75dpI=; 23:52hhnDdATCAKvaN/jWIqY82xNOq6Vx51FiBlFxL0dcU21esyvhnD2fidLVPlMfvZL8YvYbCCN5HY5Jw+c6l5V7pSJuLi9xEl40mxaKXIDpYvcUn3HRGFc+SqCZw7ZLyiwWWnXZh8MvcvSD/vL+n2HeLYihlcNfRF9SXrrUAZnC5TNuQECKSrE+FKrN8jPWyz X-OriginatorOrg: caviumnetworks.com Subject: [dpdk-dev] [PATCH v3 13/14] eal: 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: Fri, 06 Nov 2015 09:42:02 -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 Acked-by: Konstantin Ananyev --- 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 7789411..d233be6 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 73e8bce..8c33a02 100644 --- a/drivers/net/xenvirt/rte_eth_xenvirt.c +++ b/drivers/net/xenvirt/rte_eth_xenvirt.c @@ -99,7 +99,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; @@ -150,7 +150,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 af68888..19ea1bb 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -457,7 +457,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)) { @@ -552,7 +552,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)) { @@ -643,7 +643,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, @@ -727,7 +727,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; -- 1.9.3