Commit 03c05f0d authored by Jarek Poplawski's avatar Jarek Poplawski Committed by David S. Miller

pkt_sched: Use qdisc->ops->peek() instead of ->dequeue() & ->requeue()

Use qdisc->ops->peek() instead of ->dequeue() & ->requeue() pair.
After this patch the only remaining user of qdisc->ops->requeue() is
netem_enqueue(). Based on ideas of Herbert Xu, Patrick McHardy and
David S. Miller.
Signed-off-by: default avatarJarek Poplawski <jarkao2@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8e3af978
...@@ -480,11 +480,14 @@ static void sch_atm_dequeue(unsigned long data) ...@@ -480,11 +480,14 @@ static void sch_atm_dequeue(unsigned long data)
* If traffic is properly shaped, this won't generate nasty * If traffic is properly shaped, this won't generate nasty
* little bursts. Otherwise, it may ... (but that's okay) * little bursts. Otherwise, it may ... (but that's okay)
*/ */
while ((skb = flow->q->dequeue(flow->q))) { while ((skb = flow->q->ops->peek(flow->q))) {
if (!atm_may_send(flow->vcc, skb->truesize)) { if (!atm_may_send(flow->vcc, skb->truesize))
(void)flow->q->ops->requeue(skb, flow->q);
break; break;
}
skb = flow->q->dequeue(flow->q);
if (unlikely(!skb))
break;
pr_debug("atm_tc_dequeue: sending on class %p\n", flow); pr_debug("atm_tc_dequeue: sending on class %p\n", flow);
/* remove any LL header somebody else has attached */ /* remove any LL header somebody else has attached */
skb_pull(skb, skb_network_offset(skb)); skb_pull(skb, skb_network_offset(skb));
......
...@@ -880,28 +880,20 @@ set_passive(struct hfsc_class *cl) ...@@ -880,28 +880,20 @@ set_passive(struct hfsc_class *cl)
*/ */
} }
/*
* hack to get length of first packet in queue.
*/
static unsigned int static unsigned int
qdisc_peek_len(struct Qdisc *sch) qdisc_peek_len(struct Qdisc *sch)
{ {
struct sk_buff *skb; struct sk_buff *skb;
unsigned int len; unsigned int len;
skb = sch->dequeue(sch); skb = sch->ops->peek(sch);
if (skb == NULL) { if (skb == NULL) {
if (net_ratelimit()) if (net_ratelimit())
printk("qdisc_peek_len: non work-conserving qdisc ?\n"); printk("qdisc_peek_len: non work-conserving qdisc ?\n");
return 0; return 0;
} }
len = qdisc_pkt_len(skb); len = qdisc_pkt_len(skb);
if (unlikely(sch->ops->requeue(skb, sch) != NET_XMIT_SUCCESS)) {
if (net_ratelimit())
printk("qdisc_peek_len: failed to requeue\n");
qdisc_tree_decrease_qlen(sch, 1);
return 0;
}
return len; return len;
} }
......
...@@ -283,25 +283,22 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch) ...@@ -283,25 +283,22 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch)
if (sch->flags & TCQ_F_THROTTLED) if (sch->flags & TCQ_F_THROTTLED)
return NULL; return NULL;
skb = q->qdisc->dequeue(q->qdisc); skb = q->qdisc->ops->peek(q->qdisc);
if (skb) { if (skb) {
const struct netem_skb_cb *cb = netem_skb_cb(skb); const struct netem_skb_cb *cb = netem_skb_cb(skb);
psched_time_t now = psched_get_time(); psched_time_t now = psched_get_time();
/* if more time remaining? */ /* if more time remaining? */
if (cb->time_to_send <= now) { if (cb->time_to_send <= now) {
skb = q->qdisc->dequeue(q->qdisc);
if (!skb)
return NULL;
pr_debug("netem_dequeue: return skb=%p\n", skb); pr_debug("netem_dequeue: return skb=%p\n", skb);
sch->q.qlen--; sch->q.qlen--;
return skb; return skb;
} }
if (unlikely(q->qdisc->ops->requeue(skb, q->qdisc) != NET_XMIT_SUCCESS)) {
qdisc_tree_decrease_qlen(q->qdisc, 1);
sch->qstats.drops++;
printk(KERN_ERR "netem: %s could not requeue\n",
q->qdisc->ops->id);
}
qdisc_watchdog_schedule(&q->watchdog, cb->time_to_send); qdisc_watchdog_schedule(&q->watchdog, cb->time_to_send);
} }
......
...@@ -169,7 +169,7 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch) ...@@ -169,7 +169,7 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch)
struct tbf_sched_data *q = qdisc_priv(sch); struct tbf_sched_data *q = qdisc_priv(sch);
struct sk_buff *skb; struct sk_buff *skb;
skb = q->qdisc->dequeue(q->qdisc); skb = q->qdisc->ops->peek(q->qdisc);
if (skb) { if (skb) {
psched_time_t now; psched_time_t now;
...@@ -192,6 +192,10 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch) ...@@ -192,6 +192,10 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch)
toks -= L2T(q, len); toks -= L2T(q, len);
if ((toks|ptoks) >= 0) { if ((toks|ptoks) >= 0) {
skb = q->qdisc->dequeue(q->qdisc);
if (unlikely(!skb))
return NULL;
q->t_c = now; q->t_c = now;
q->tokens = toks; q->tokens = toks;
q->ptokens = ptoks; q->ptokens = ptoks;
...@@ -214,12 +218,6 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch) ...@@ -214,12 +218,6 @@ static struct sk_buff *tbf_dequeue(struct Qdisc* sch)
(cf. CSZ, HPFQ, HFSC) (cf. CSZ, HPFQ, HFSC)
*/ */
if (q->qdisc->ops->requeue(skb, q->qdisc) != NET_XMIT_SUCCESS) {
/* When requeue fails skb is dropped */
qdisc_tree_decrease_qlen(q->qdisc, 1);
sch->qstats.drops++;
}
sch->qstats.overlimits++; sch->qstats.overlimits++;
} }
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment