Skip to content

Commit 29b86cd

Browse files
jrfastabdavem330
authored andcommitted
net: sched: remove remaining uses for qdisc_qlen in xmit path
sch_direct_xmit() uses qdisc_qlen as a return value but all call sites of the routine only check if it is zero or not. Simplify the logic so that we don't need to return an actual queue length value. This introduces a case now where sch_direct_xmit would have returned a qlen of zero but now it returns true. However in this case all call sites of sch_direct_xmit will implement a dequeue() and get a null skb and abort. This trades tracking qlen in the hotpath for an extra dequeue operation. Overall this seems to be good for performance. Signed-off-by: John Fastabend <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6b3ba91 commit 29b86cd

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

include/net/pkt_sched.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ struct qdisc_rate_table *qdisc_get_rtab(struct tc_ratespec *r,
105105
void qdisc_put_rtab(struct qdisc_rate_table *tab);
106106
void qdisc_put_stab(struct qdisc_size_table *tab);
107107
void qdisc_warn_nonwc(const char *txt, struct Qdisc *qdisc);
108-
int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
109-
struct net_device *dev, struct netdev_queue *txq,
110-
spinlock_t *root_lock, bool validate);
108+
bool sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
109+
struct net_device *dev, struct netdev_queue *txq,
110+
spinlock_t *root_lock, bool validate);
111111

112112
void __qdisc_run(struct Qdisc *q);
113113

net/sched/sch_generic.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ static struct sk_buff *dequeue_skb(struct Qdisc *q, bool *validate,
164164
* only one CPU can execute this function.
165165
*
166166
* Returns to the caller:
167-
* 0 - queue is empty or throttled.
168-
* >0 - queue is not empty.
167+
* false - hardware queue frozen backoff
168+
* true - feel free to send more pkts
169169
*/
170-
int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
171-
struct net_device *dev, struct netdev_queue *txq,
172-
spinlock_t *root_lock, bool validate)
170+
bool sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
171+
struct net_device *dev, struct netdev_queue *txq,
172+
spinlock_t *root_lock, bool validate)
173173
{
174174
int ret = NETDEV_TX_BUSY;
175175

@@ -190,28 +190,26 @@ int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
190190
} else {
191191
if (root_lock)
192192
spin_lock(root_lock);
193-
return qdisc_qlen(q);
193+
return true;
194194
}
195195

196196
if (root_lock)
197197
spin_lock(root_lock);
198198

199-
if (dev_xmit_complete(ret)) {
200-
/* Driver sent out skb successfully or skb was consumed */
201-
ret = qdisc_qlen(q);
202-
} else {
199+
if (!dev_xmit_complete(ret)) {
203200
/* Driver returned NETDEV_TX_BUSY - requeue skb */
204201
if (unlikely(ret != NETDEV_TX_BUSY))
205202
net_warn_ratelimited("BUG %s code %d qlen %d\n",
206203
dev->name, ret, q->q.qlen);
207204

208-
ret = dev_requeue_skb(skb, q);
205+
dev_requeue_skb(skb, q);
206+
return false;
209207
}
210208

211209
if (ret && netif_xmit_frozen_or_stopped(txq))
212-
ret = 0;
210+
return false;
213211

214-
return ret;
212+
return true;
215213
}
216214

217215
/*
@@ -233,7 +231,7 @@ int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,
233231
* >0 - queue is not empty.
234232
*
235233
*/
236-
static inline int qdisc_restart(struct Qdisc *q, int *packets)
234+
static inline bool qdisc_restart(struct Qdisc *q, int *packets)
237235
{
238236
spinlock_t *root_lock = NULL;
239237
struct netdev_queue *txq;
@@ -244,7 +242,7 @@ static inline int qdisc_restart(struct Qdisc *q, int *packets)
244242
/* Dequeue packet */
245243
skb = dequeue_skb(q, &validate, packets);
246244
if (unlikely(!skb))
247-
return 0;
245+
return false;
248246

249247
if (!(q->flags & TCQ_F_NOLOCK))
250248
root_lock = qdisc_lock(q);

0 commit comments

Comments
 (0)