Skip to content

Commit bfe0d02

Browse files
Eric Dumazetdavem330
authored andcommitted
net_sched: factorize qdisc stats handling
HTB takes into account skb is segmented in stats updates. Generalize this to all schedulers. They should use qdisc_bstats_update() helper instead of manipulating bstats.bytes and bstats.packets Add bstats_update() helper too for classes that use gnet_stats_basic_packed fields. Note : Right now, TCQ_F_CAN_BYPASS shortcurt can be taken only if no stab is setup on qdisc. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f1593d2 commit bfe0d02

24 files changed

Lines changed: 50 additions & 72 deletions

‎include/net/sch_generic.h‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static inline int qdisc_qlen(struct Qdisc *q)
207207
return q->q.qlen;
208208
}
209209

210-
static inline struct qdisc_skb_cb *qdisc_skb_cb(struct sk_buff *skb)
210+
static inline struct qdisc_skb_cb *qdisc_skb_cb(const struct sk_buff *skb)
211211
{
212212
return (struct qdisc_skb_cb *)skb->cb;
213213
}
@@ -394,7 +394,7 @@ static inline bool qdisc_tx_is_noop(const struct net_device *dev)
394394
return true;
395395
}
396396

397-
static inline unsigned int qdisc_pkt_len(struct sk_buff *skb)
397+
static inline unsigned int qdisc_pkt_len(const struct sk_buff *skb)
398398
{
399399
return qdisc_skb_cb(skb)->pkt_len;
400400
}
@@ -426,18 +426,26 @@ static inline int qdisc_enqueue_root(struct sk_buff *skb, struct Qdisc *sch)
426426
return qdisc_enqueue(skb, sch) & NET_XMIT_MASK;
427427
}
428428

429-
static inline void __qdisc_update_bstats(struct Qdisc *sch, unsigned int len)
429+
430+
static inline void bstats_update(struct gnet_stats_basic_packed *bstats,
431+
const struct sk_buff *skb)
432+
{
433+
bstats->bytes += qdisc_pkt_len(skb);
434+
bstats->packets += skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1;
435+
}
436+
437+
static inline void qdisc_bstats_update(struct Qdisc *sch,
438+
const struct sk_buff *skb)
430439
{
431-
sch->bstats.bytes += len;
432-
sch->bstats.packets++;
440+
bstats_update(&sch->bstats, skb);
433441
}
434442

435443
static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch,
436444
struct sk_buff_head *list)
437445
{
438446
__skb_queue_tail(list, skb);
439447
sch->qstats.backlog += qdisc_pkt_len(skb);
440-
__qdisc_update_bstats(sch, qdisc_pkt_len(skb));
448+
qdisc_bstats_update(sch, skb);
441449

442450
return NET_XMIT_SUCCESS;
443451
}

‎net/core/dev.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,10 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
22972297
*/
22982298
if (!(dev->priv_flags & IFF_XMIT_DST_RELEASE))
22992299
skb_dst_force(skb);
2300-
__qdisc_update_bstats(q, skb->len);
2300+
2301+
qdisc_skb_cb(skb)->pkt_len = skb->len;
2302+
qdisc_bstats_update(q, skb);
2303+
23012304
if (sch_direct_xmit(skb, q, dev, txq, root_lock)) {
23022305
if (unlikely(contended)) {
23032306
spin_unlock(&q->busylock);

‎net/sched/act_csum.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,7 @@ static int tcf_csum(struct sk_buff *skb,
508508

509509
spin_lock(&p->tcf_lock);
510510
p->tcf_tm.lastuse = jiffies;
511-
p->tcf_bstats.bytes += qdisc_pkt_len(skb);
512-
p->tcf_bstats.packets++;
511+
bstats_update(&p->tcf_bstats, skb);
513512
action = p->tcf_action;
514513
update_flags = p->update_flags;
515514
spin_unlock(&p->tcf_lock);

‎net/sched/act_ipt.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ static int tcf_ipt(struct sk_buff *skb, struct tc_action *a,
209209
spin_lock(&ipt->tcf_lock);
210210

211211
ipt->tcf_tm.lastuse = jiffies;
212-
ipt->tcf_bstats.bytes += qdisc_pkt_len(skb);
213-
ipt->tcf_bstats.packets++;
212+
bstats_update(&ipt->tcf_bstats, skb);
214213

215214
/* yes, we have to worry about both in and out dev
216215
worry later - danger - this API seems to have changed

‎net/sched/act_mirred.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ static int tcf_mirred(struct sk_buff *skb, struct tc_action *a,
165165

166166
spin_lock(&m->tcf_lock);
167167
m->tcf_tm.lastuse = jiffies;
168-
m->tcf_bstats.bytes += qdisc_pkt_len(skb);
169-
m->tcf_bstats.packets++;
168+
bstats_update(&m->tcf_bstats, skb);
170169

171170
dev = m->tcfm_dev;
172171
if (!dev) {

‎net/sched/act_nat.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ static int tcf_nat(struct sk_buff *skb, struct tc_action *a,
125125
egress = p->flags & TCA_NAT_FLAG_EGRESS;
126126
action = p->tcf_action;
127127

128-
p->tcf_bstats.bytes += qdisc_pkt_len(skb);
129-
p->tcf_bstats.packets++;
128+
bstats_update(&p->tcf_bstats, skb);
130129

131130
spin_unlock(&p->tcf_lock);
132131

‎net/sched/act_pedit.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ static int tcf_pedit(struct sk_buff *skb, struct tc_action *a,
187187
bad:
188188
p->tcf_qstats.overlimits++;
189189
done:
190-
p->tcf_bstats.bytes += qdisc_pkt_len(skb);
191-
p->tcf_bstats.packets++;
190+
bstats_update(&p->tcf_bstats, skb);
192191
spin_unlock(&p->tcf_lock);
193192
return p->tcf_action;
194193
}

‎net/sched/act_police.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,7 @@ static int tcf_act_police(struct sk_buff *skb, struct tc_action *a,
298298

299299
spin_lock(&police->tcf_lock);
300300

301-
police->tcf_bstats.bytes += qdisc_pkt_len(skb);
302-
police->tcf_bstats.packets++;
301+
bstats_update(&police->tcf_bstats, skb);
303302

304303
if (police->tcfp_ewma_rate &&
305304
police->tcf_rate_est.bps >= police->tcfp_ewma_rate) {

‎net/sched/act_simple.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ static int tcf_simp(struct sk_buff *skb, struct tc_action *a, struct tcf_result
4242

4343
spin_lock(&d->tcf_lock);
4444
d->tcf_tm.lastuse = jiffies;
45-
d->tcf_bstats.bytes += qdisc_pkt_len(skb);
46-
d->tcf_bstats.packets++;
45+
bstats_update(&d->tcf_bstats, skb);
4746

4847
/* print policy string followed by _ then packet count
4948
* Example if this was the 3rd packet and the string was "hello"

‎net/sched/act_skbedit.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ static int tcf_skbedit(struct sk_buff *skb, struct tc_action *a,
4646

4747
spin_lock(&d->tcf_lock);
4848
d->tcf_tm.lastuse = jiffies;
49-
d->tcf_bstats.bytes += qdisc_pkt_len(skb);
50-
d->tcf_bstats.packets++;
49+
bstats_update(&d->tcf_bstats, skb);
5150

5251
if (d->flags & SKBEDIT_F_PRIORITY)
5352
skb->priority = d->priority;

0 commit comments

Comments
 (0)