From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hiroshi Shimamoto Subject: [memnic PATCH] pmd: use rte_atomic32_cmpset instead of cmpxchg Date: Thu, 3 Apr 2014 07:34:56 +0000 Message-ID: <7F861DC0615E0C47A872E6F3C5FCDDBD0109D67F@BPXM14GP.gisp.nec.co.jp> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: quoted-printable Cc: Hayato Momma To: "dev-VfR2kkLFssw@public.gmane.org" Return-path: Content-Language: ja-JP List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" 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