From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from stargate3.asicdesigners.com (stargate.chelsio.com [67.207.115.98]) by dpdk.org (Postfix) with ESMTP id 3F90C8E67 for ; Fri, 20 Nov 2015 14:14:05 +0100 (CET) Received: from localhost (scalar.blr.asicdesigners.com [10.193.185.94]) by stargate3.asicdesigners.com (8.13.8/8.13.8) with ESMTP id tAKDE12p016238; Fri, 20 Nov 2015 05:14:02 -0800 From: Rahul Lakkireddy To: dev@dpdk.org Date: Fri, 20 Nov 2015 18:43:38 +0530 Message-Id: <2275ec371b5d8a65d275dece6a8bd5fbd906c24d.1448007179.git.rahul.lakkireddy@chelsio.com> X-Mailer: git-send-email 2.5.3 In-Reply-To: References: In-Reply-To: References: Cc: Felix Marti , Kumar Sanghvi , Nirranjan Kirubaharan Subject: [dpdk-dev] [PATCH 2/2] cxgbe: fix unnecessary spinning for a lock with trylock instead 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, 20 Nov 2015 13:14:05 -0000 CXGBE PMD depends on an alarm to periodically transmit any pending coalesced packets and hence spins for a lock for each tx queue in the alarm callback. A better solution is to try to get a lock whenever possible, instead of spinning for it. Signed-off-by: Rahul Lakkireddy Signed-off-by: Kumar Sanghvi --- drivers/net/cxgbe/base/adapter.h | 9 +++++++++ drivers/net/cxgbe/sge.c | 21 ++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/net/cxgbe/base/adapter.h b/drivers/net/cxgbe/base/adapter.h index a1e8ef7..a5225c0 100644 --- a/drivers/net/cxgbe/base/adapter.h +++ b/drivers/net/cxgbe/base/adapter.h @@ -473,6 +473,15 @@ static inline void t4_os_unlock(rte_spinlock_t *lock) } /** + * t4_os_trylock - try to get a lock + * @lock: the spinlock + */ +static inline int t4_os_trylock(rte_spinlock_t *lock) +{ + return rte_spinlock_trylock(lock); +} + +/** * t4_os_init_list_head - initialize * @head: head of list to initialize [to empty] */ diff --git a/drivers/net/cxgbe/sge.c b/drivers/net/cxgbe/sge.c index aa0c2e5..51449e0 100644 --- a/drivers/net/cxgbe/sge.c +++ b/drivers/net/cxgbe/sge.c @@ -808,20 +808,23 @@ static void tx_timer_cb(void *data) struct adapter *adap = (struct adapter *)data; struct sge_eth_txq *txq = &adap->sge.ethtxq[0]; int i; + unsigned int coal_idx; /* monitor any pending tx */ for (i = 0; i < adap->sge.max_ethqsets; i++, txq++) { - t4_os_lock(&txq->txq_lock); - if (txq->q.coalesce.idx) { - if (txq->q.coalesce.idx == txq->q.last_coal_idx && - txq->q.pidx == txq->q.last_pidx) { - ship_tx_pkt_coalesce_wr(adap, txq); - } else { - txq->q.last_coal_idx = txq->q.coalesce.idx; - txq->q.last_pidx = txq->q.pidx; + if (t4_os_trylock(&txq->txq_lock)) { + coal_idx = txq->q.coalesce.idx; + if (coal_idx) { + if (coal_idx == txq->q.last_coal_idx && + txq->q.pidx == txq->q.last_pidx) { + ship_tx_pkt_coalesce_wr(adap, txq); + } else { + txq->q.last_coal_idx = coal_idx; + txq->q.last_pidx = txq->q.pidx; + } } + t4_os_unlock(&txq->txq_lock); } - t4_os_unlock(&txq->txq_lock); } rte_eal_alarm_set(50, tx_timer_cb, (void *)adap); } -- 2.5.3