From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from tyo201.gate.nec.co.jp (TYO201.gate.nec.co.jp [210.143.35.51]) by dpdk.org (Postfix) with ESMTP id 45C336930 for ; Thu, 3 Apr 2014 09:35:03 +0200 (CEST) Received: from mailgate3.nec.co.jp ([10.7.69.160]) by tyo201.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id s337abno010820 for ; Thu, 3 Apr 2014 16:36:37 +0900 (JST) Received: from mailsv4.nec.co.jp (imss61.nec.co.jp [10.7.69.156]) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) with ESMTP id s337aa704100 for ; Thu, 3 Apr 2014 16:36:36 +0900 (JST) Received: from mail01b.kamome.nec.co.jp (mail01b.kamome.nec.co.jp [10.25.43.2]) by mailsv4.nec.co.jp (8.13.8/8.13.4) with ESMTP id s337aaeW019106 for ; Thu, 3 Apr 2014 16:36:36 +0900 (JST) Received: from bpxc99gp.gisp.nec.co.jp ([10.38.151.141] [10.38.151.141]) by mail01b.kamome.nec.co.jp with ESMTP id BT-MMP-650822; Thu, 3 Apr 2014 16:34:57 +0900 Received: from BPXM14GP.gisp.nec.co.jp ([169.254.1.238]) by BPXC13GP.gisp.nec.co.jp ([10.38.151.141]) with mapi id 14.02.0328.011; Thu, 3 Apr 2014 16:34:56 +0900 From: Hiroshi Shimamoto To: "dev@dpdk.org" Thread-Topic: [memnic PATCH] pmd: use rte_atomic32_cmpset instead of cmpxchg Thread-Index: Ac9PDyJr1ochMC0eQgqx9LDhIwrkOQ== Date: Thu, 3 Apr 2014 07:34:56 +0000 Message-ID: <7F861DC0615E0C47A872E6F3C5FCDDBD0109D67F@BPXM14GP.gisp.nec.co.jp> Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.205.5.123] Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: Hayato Momma Subject: [dpdk-dev] [memnic PATCH] pmd: use rte_atomic32_cmpset instead of cmpxchg 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: Thu, 03 Apr 2014 07:35:03 -0000 From: Hiroshi Shimamoto Because DPDK has its own compare and set function to optimize to dedicated processor type, use that rte_atomic32_cmpset() instead of cmpxchg macro which is specially introduced for MEMNIC. Signed-off-by: Hiroshi Shimamoto --- common/memnic.h | 12 ------------ pmd/pmd_memnic.c | 10 ++++++---- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/common/memnic.h b/common/memnic.h index 2187ac1..84e941c 100644 --- a/common/memnic.h +++ b/common/memnic.h @@ -120,18 +120,6 @@ struct memnic_area { /* for userspace */ #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) =20 -static inline uint32_t cmpxchg(uint32_t *dst, uint32_t old, uint32_t new) -{ - volatile uint32_t *ptr =3D (volatile uint32_t *)dst; - uint32_t ret; - - asm volatile("lock; cmpxchgl %2, %1" - : "=3Da" (ret), "+m" (*ptr) - : "r" (new), "0" (old) - : "memory"); - - return ret; -} #endif /* __KERNEL__ */ =20 #endif /* MEMNIC_H */ diff --git a/pmd/pmd_memnic.c b/pmd/pmd_memnic.c index 4a1c1e4..4abdf26 100644 --- a/pmd/pmd_memnic.c +++ b/pmd/pmd_memnic.c @@ -314,7 +314,7 @@ static uint16_t memnic_xmit_pkts(void *tx_queue, struct memnic_data *data =3D &adapter->nic->down; struct memnic_packet *p; uint16_t nr; - int idx, old; + int idx; struct rte_eth_stats *st =3D &adapter->stats[rte_lcore_id()]; uint64_t pkts, bytes, errs; =20 @@ -335,10 +335,12 @@ static uint16_t memnic_xmit_pkts(void *tx_queue, retry: idx =3D ACCESS_ONCE(adapter->down_idx); p =3D &data->packets[idx]; - old =3D cmpxchg(&p->status, MEMNIC_PKT_ST_FREE, MEMNIC_PKT_ST_USED); - if (old !=3D MEMNIC_PKT_ST_FREE) { - if (old =3D=3D MEMNIC_PKT_ST_FILLED && + if (unlikely(rte_atomic32_cmpset(&p->status, + MEMNIC_PKT_ST_FREE, MEMNIC_PKT_ST_USED) =3D=3D 0)) { + /* cmpxchg failed */ + if (p->status =3D=3D MEMNIC_PKT_ST_FILLED && idx =3D=3D ACCESS_ONCE(adapter->down_idx)) { + /* what we're seeing is FILLED means queue full */ errs++; break; } --=20 1.8.4