From: Hayes Wang <hayeswang@realtek.com>
To: <netdev@vger.kernel.org>
Cc: <nic_swsd@realtek.com>, <linux-kernel@vger.kernel.org>,
<linux-usb@vger.kernel.org>, Hayes Wang <hayeswang@realtek.com>
Subject: [PATCH net-next 05/14] r8152: reduce the frequency of spin_lock
Date: Tue, 18 Feb 2014 21:49:02 +0800 [thread overview]
Message-ID: <1392731351-25502-6-git-send-email-hayeswang@realtek.com> (raw)
In-Reply-To: <1392731351-25502-1-git-send-email-hayeswang@realtek.com>
Replace getting one item from a list with getting the whole list one time.
Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
drivers/net/usb/r8152.c | 47 ++++++++++++++++++++++++++++++++++++++---------
1 file changed, 38 insertions(+), 9 deletions(-)
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 3847c35..2a778fa 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -1299,9 +1299,16 @@ r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc, struct sk_buff *skb)
static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg)
{
+ struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue;
+ unsigned long flags;
int remain;
u8 *tx_data;
+ __skb_queue_head_init(&skb_head);
+ spin_lock_irqsave(&tx_queue->lock, flags);
+ skb_queue_splice_init(tx_queue, &skb_head);
+ spin_unlock_irqrestore(&tx_queue->lock, flags);
+
tx_data = agg->head;
agg->skb_num = agg->skb_len = 0;
remain = rx_buf_sz;
@@ -1311,14 +1318,14 @@ static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg)
struct sk_buff *skb;
unsigned int len;
- skb = skb_dequeue(&tp->tx_queue);
+ skb = __skb_dequeue(&skb_head);
if (!skb)
break;
remain -= sizeof(*tx_desc);
len = skb->len;
if (remain < len) {
- skb_queue_head(&tp->tx_queue, skb);
+ __skb_queue_head(&skb_head, skb);
break;
}
@@ -1336,6 +1343,12 @@ static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg)
remain = rx_buf_sz - (int)(tx_agg_align(tx_data) - agg->head);
}
+ if (!skb_queue_empty(&skb_head)) {
+ spin_lock_irqsave(&tx_queue->lock, flags);
+ skb_queue_splice(&skb_head, tx_queue);
+ spin_unlock_irqrestore(&tx_queue->lock, flags);
+ }
+
netif_tx_lock(tp->netdev);
if (netif_queue_stopped(tp->netdev) &&
@@ -1354,10 +1367,17 @@ static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg)
static void rx_bottom(struct r8152 *tp)
{
unsigned long flags;
- struct list_head *cursor, *next;
+ struct list_head *cursor, *next, rx_queue;
+ if (list_empty(&tp->rx_done))
+ return;
+
+ INIT_LIST_HEAD(&rx_queue);
spin_lock_irqsave(&tp->rx_lock, flags);
- list_for_each_safe(cursor, next, &tp->rx_done) {
+ list_splice_init(&tp->rx_done, &rx_queue);
+ spin_unlock_irqrestore(&tp->rx_lock, flags);
+
+ list_for_each_safe(cursor, next, &rx_queue) {
struct rx_desc *rx_desc;
struct rx_agg *agg;
int len_used = 0;
@@ -1366,7 +1386,6 @@ static void rx_bottom(struct r8152 *tp)
int ret;
list_del_init(cursor);
- spin_unlock_irqrestore(&tp->rx_lock, flags);
agg = list_entry(cursor, struct rx_agg, list);
urb = agg->urb;
@@ -1416,13 +1435,13 @@ static void rx_bottom(struct r8152 *tp)
submit:
ret = r8152_submit_rx(tp, agg, GFP_ATOMIC);
- spin_lock_irqsave(&tp->rx_lock, flags);
if (ret && ret != -ENODEV) {
- list_add_tail(&agg->list, next);
+ spin_lock_irqsave(&tp->rx_lock, flags);
+ list_add_tail(&agg->list, &tp->rx_done);
+ spin_unlock_irqrestore(&tp->rx_lock, flags);
tasklet_schedule(&tp->tl);
}
}
- spin_unlock_irqrestore(&tp->rx_lock, flags);
}
static void tx_bottom(struct r8152 *tp)
@@ -1496,9 +1515,19 @@ int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags)
static void rtl_drop_queued_tx(struct r8152 *tp)
{
struct net_device_stats *stats = &tp->netdev->stats;
+ struct sk_buff_head skb_head, *tx_queue = &tp->tx_queue;
+ unsigned long flags;
struct sk_buff *skb;
- while ((skb = skb_dequeue(&tp->tx_queue))) {
+ if (skb_queue_empty(tx_queue))
+ return;
+
+ __skb_queue_head_init(&skb_head);
+ spin_lock_irqsave(&tx_queue->lock, flags);
+ skb_queue_splice_init(tx_queue, &skb_head);
+ spin_unlock_irqrestore(&tx_queue->lock, flags);
+
+ while ((skb = __skb_dequeue(&skb_head))) {
dev_kfree_skb(skb);
stats->tx_dropped++;
}
--
1.8.4.2
next prev parent reply other threads:[~2014-02-18 13:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-18 13:48 [PATCH net-next 00/14] r8152: improvement and new features Hayes Wang
2014-02-18 13:48 ` [PATCH net-next 01/14] r8152: move some functions Hayes Wang
2014-02-18 13:48 ` [PATCH net-next 02/14] r8152: add three functions Hayes Wang
2014-02-18 13:49 ` [PATCH net-next 03/14] r8152: replace some types from int to bool Hayes Wang
2014-02-18 13:49 ` [PATCH net-next 04/14] r8152: load the default MAC address Hayes Wang
2014-02-18 13:49 ` Hayes Wang [this message]
2014-02-18 13:49 ` [PATCH net-next 06/14] r8152: clear BMCR_PDOWN Hayes Wang
2014-02-18 13:49 ` [PATCH net-next 07/14] r8152: combine PHY reset with set_speed Hayes Wang
[not found] ` <1392731351-25502-8-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2014-02-18 17:19 ` Florian Fainelli
[not found] ` <201402190209.s1J29EVG032292@rtits1.realtek.com>
2014-02-19 2:41 ` hayeswang
2014-02-18 13:49 ` [PATCH net-next 08/14] r8152: move some functions from probe to open Hayes Wang
2014-02-18 13:49 ` [PATCH net-next 09/14] r8152: support WOL Hayes Wang
2014-02-18 13:49 ` [PATCH net-next 10/14] r8152: support runtime suspend Hayes Wang
2014-02-18 13:49 ` [PATCH net-next 11/14] r8152: disable teredo for RTL8152 Hayes Wang
2014-02-18 13:49 ` [PATCH net-next 12/14] r8152: replace netif_rx with netif_receive_skb Hayes Wang
2014-02-18 23:28 ` Francois Romieu
2014-02-19 3:01 ` [PATCH net-next 12/14] r8152: replace netif_rx withnetif_receive_skb hayeswang
2014-02-19 7:46 ` Francois Romieu
2014-02-19 12:45 ` [PATCH net-next 12/14] r8152: replace netif_rxwithnetif_receive_skb hayeswang
2014-02-18 13:49 ` [PATCH net-next 13/14] r8152: set disable_hub_initiated_lpm Hayes Wang
2014-02-18 13:49 ` [PATCH net-next 14/14] r8152: support get_msglevel and set_msglevel Hayes Wang
2014-02-18 21:41 ` [PATCH net-next 00/14] r8152: improvement and new features David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1392731351-25502-6-git-send-email-hayeswang@realtek.com \
--to=hayeswang@realtek.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nic_swsd@realtek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).