Skip to content

Commit 79640a4

Browse files
Eric Dumazetdavem330
authored andcommitted
net: add additional lock to qdisc to increase throughput
When many cpus compete for sending frames on a given qdisc, the qdisc spinlock suffers from very high contention. The cpu owning __QDISC_STATE_RUNNING bit has same priority to acquire the lock, and cannot dequeue packets fast enough, since it must wait for this lock for each dequeued packet. One solution to this problem is to force all cpus spinning on a second lock before trying to get the main lock, when/if they see __QDISC_STATE_RUNNING already set. The owning cpu then compete with at most one other cpu for the main lock, allowing for higher dequeueing rate. Based on a previous patch from Alexander Duyck. I added the heuristic to avoid the atomic in fast path, and put the new lock far away from the cache line used by the dequeue worker. Also try to release the busylock lock as late as possible. Tests with following script gave a boost from ~50.000 pps to ~600.000 pps on a dual quad core machine (E5450 @3.00GHz), tg3 driver. (A single netperf flow can reach ~800.000 pps on this platform) for j in `seq 0 3`; do for i in `seq 0 7`; do netperf -H 192.168.0.1 -t UDP_STREAM -l 60 -N -T $i -- -m 6 & done done Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Acked-by: Alexander Duyck <alexander.h.duyck@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 097811b commit 79640a4

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

include/net/sch_generic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ struct Qdisc {
8080
struct gnet_stats_basic_packed bstats;
8181
unsigned long __state;
8282
struct gnet_stats_queue qstats;
83-
struct rcu_head rcu_head;
83+
struct rcu_head rcu_head;
84+
spinlock_t busylock;
8485
};
8586

8687
static inline bool qdisc_is_running(struct Qdisc *qdisc)

net/core/dev.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,8 +2040,18 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
20402040
struct netdev_queue *txq)
20412041
{
20422042
spinlock_t *root_lock = qdisc_lock(q);
2043+
bool contended = qdisc_is_running(q);
20432044
int rc;
20442045

2046+
/*
2047+
* Heuristic to force contended enqueues to serialize on a
2048+
* separate lock before trying to get qdisc main lock.
2049+
* This permits __QDISC_STATE_RUNNING owner to get the lock more often
2050+
* and dequeue packets faster.
2051+
*/
2052+
if (unlikely(contended))
2053+
spin_lock(&q->busylock);
2054+
20452055
spin_lock(root_lock);
20462056
if (unlikely(test_bit(__QDISC_STATE_DEACTIVATED, &q->state))) {
20472057
kfree_skb(skb);
@@ -2056,19 +2066,30 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
20562066
if (!(dev->priv_flags & IFF_XMIT_DST_RELEASE))
20572067
skb_dst_force(skb);
20582068
__qdisc_update_bstats(q, skb->len);
2059-
if (sch_direct_xmit(skb, q, dev, txq, root_lock))
2069+
if (sch_direct_xmit(skb, q, dev, txq, root_lock)) {
2070+
if (unlikely(contended)) {
2071+
spin_unlock(&q->busylock);
2072+
contended = false;
2073+
}
20602074
__qdisc_run(q);
2061-
else
2075+
} else
20622076
qdisc_run_end(q);
20632077

20642078
rc = NET_XMIT_SUCCESS;
20652079
} else {
20662080
skb_dst_force(skb);
20672081
rc = qdisc_enqueue_root(skb, q);
2068-
qdisc_run(q);
2082+
if (qdisc_run_begin(q)) {
2083+
if (unlikely(contended)) {
2084+
spin_unlock(&q->busylock);
2085+
contended = false;
2086+
}
2087+
__qdisc_run(q);
2088+
}
20692089
}
20702090
spin_unlock(root_lock);
2071-
2091+
if (unlikely(contended))
2092+
spin_unlock(&q->busylock);
20722093
return rc;
20732094
}
20742095

net/sched/sch_generic.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
561561

562562
INIT_LIST_HEAD(&sch->list);
563563
skb_queue_head_init(&sch->q);
564+
spin_lock_init(&sch->busylock);
564565
sch->ops = ops;
565566
sch->enqueue = ops->enqueue;
566567
sch->dequeue = ops->dequeue;

0 commit comments

Comments
 (0)