Skip to content

Commit 25331d6

Browse files
jrfastabdavem330
authored andcommitted
net: sched: implement qstat helper routines
This adds helpers to manipulate qstats logic and replaces locations that touch the counters directly. This simplifies future patches to push qstats onto per cpu counters. Signed-off-by: John Fastabend <john.r.fastabend@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 22e0f8b commit 25331d6

25 files changed

+108
-81
lines changed

include/net/sch_generic.h

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,38 @@ static inline void qdisc_bstats_update(struct Qdisc *sch,
521521
bstats_update(&sch->bstats, skb);
522522
}
523523

524+
static inline void qdisc_qstats_backlog_dec(struct Qdisc *sch,
525+
const struct sk_buff *skb)
526+
{
527+
sch->qstats.backlog -= qdisc_pkt_len(skb);
528+
}
529+
530+
static inline void qdisc_qstats_backlog_inc(struct Qdisc *sch,
531+
const struct sk_buff *skb)
532+
{
533+
sch->qstats.backlog += qdisc_pkt_len(skb);
534+
}
535+
536+
static inline void __qdisc_qstats_drop(struct Qdisc *sch, int count)
537+
{
538+
sch->qstats.drops += count;
539+
}
540+
541+
static inline void qdisc_qstats_drop(struct Qdisc *sch)
542+
{
543+
sch->qstats.drops++;
544+
}
545+
546+
static inline void qdisc_qstats_overlimit(struct Qdisc *sch)
547+
{
548+
sch->qstats.overlimits++;
549+
}
550+
524551
static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch,
525552
struct sk_buff_head *list)
526553
{
527554
__skb_queue_tail(list, skb);
528-
sch->qstats.backlog += qdisc_pkt_len(skb);
555+
qdisc_qstats_backlog_inc(sch, skb);
529556

530557
return NET_XMIT_SUCCESS;
531558
}
@@ -541,7 +568,7 @@ static inline struct sk_buff *__qdisc_dequeue_head(struct Qdisc *sch,
541568
struct sk_buff *skb = __skb_dequeue(list);
542569

543570
if (likely(skb != NULL)) {
544-
sch->qstats.backlog -= qdisc_pkt_len(skb);
571+
qdisc_qstats_backlog_dec(sch, skb);
545572
qdisc_bstats_update(sch, skb);
546573
}
547574

@@ -560,7 +587,7 @@ static inline unsigned int __qdisc_queue_drop_head(struct Qdisc *sch,
560587

561588
if (likely(skb != NULL)) {
562589
unsigned int len = qdisc_pkt_len(skb);
563-
sch->qstats.backlog -= len;
590+
qdisc_qstats_backlog_dec(sch, skb);
564591
kfree_skb(skb);
565592
return len;
566593
}
@@ -579,7 +606,7 @@ static inline struct sk_buff *__qdisc_dequeue_tail(struct Qdisc *sch,
579606
struct sk_buff *skb = __skb_dequeue_tail(list);
580607

581608
if (likely(skb != NULL))
582-
sch->qstats.backlog -= qdisc_pkt_len(skb);
609+
qdisc_qstats_backlog_dec(sch, skb);
583610

584611
return skb;
585612
}
@@ -661,14 +688,14 @@ static inline unsigned int qdisc_queue_drop(struct Qdisc *sch)
661688
static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch)
662689
{
663690
kfree_skb(skb);
664-
sch->qstats.drops++;
691+
qdisc_qstats_drop(sch);
665692

666693
return NET_XMIT_DROP;
667694
}
668695

669696
static inline int qdisc_reshape_fail(struct sk_buff *skb, struct Qdisc *sch)
670697
{
671-
sch->qstats.drops++;
698+
qdisc_qstats_drop(sch);
672699

673700
#ifdef CONFIG_NET_CLS_ACT
674701
if (sch->reshape_fail == NULL || sch->reshape_fail(skb, sch))

net/sched/sch_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ void qdisc_tree_decrease_qlen(struct Qdisc *sch, unsigned int n)
763763
cops->put(sch, cl);
764764
}
765765
sch->q.qlen -= n;
766-
sch->qstats.drops += drops;
766+
__qdisc_qstats_drop(sch, drops);
767767
}
768768
}
769769
EXPORT_SYMBOL(qdisc_tree_decrease_qlen);

net/sched/sch_atm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
417417
if (ret != NET_XMIT_SUCCESS) {
418418
drop: __maybe_unused
419419
if (net_xmit_drop_count(ret)) {
420-
sch->qstats.drops++;
420+
qdisc_qstats_drop(sch);
421421
if (flow)
422422
flow->qstats.drops++;
423423
}

net/sched/sch_cbq.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ cbq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
377377
#endif
378378
if (cl == NULL) {
379379
if (ret & __NET_XMIT_BYPASS)
380-
sch->qstats.drops++;
380+
qdisc_qstats_drop(sch);
381381
kfree_skb(skb);
382382
return ret;
383383
}
@@ -395,7 +395,7 @@ cbq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
395395
}
396396

397397
if (net_xmit_drop_count(ret)) {
398-
sch->qstats.drops++;
398+
qdisc_qstats_drop(sch);
399399
cbq_mark_toplevel(q, cl);
400400
cl->qstats.drops++;
401401
}
@@ -650,11 +650,11 @@ static int cbq_reshape_fail(struct sk_buff *skb, struct Qdisc *child)
650650
return 0;
651651
}
652652
if (net_xmit_drop_count(ret))
653-
sch->qstats.drops++;
653+
qdisc_qstats_drop(sch);
654654
return 0;
655655
}
656656

657-
sch->qstats.drops++;
657+
qdisc_qstats_drop(sch);
658658
return -1;
659659
}
660660
#endif
@@ -995,7 +995,7 @@ cbq_dequeue(struct Qdisc *sch)
995995
*/
996996

997997
if (sch->q.qlen) {
998-
sch->qstats.overlimits++;
998+
qdisc_qstats_overlimit(sch);
999999
if (q->wd_expires)
10001000
qdisc_watchdog_schedule(&q->watchdog,
10011001
now + q->wd_expires);

net/sched/sch_choke.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static void choke_drop_by_idx(struct Qdisc *sch, unsigned int idx)
127127
if (idx == q->tail)
128128
choke_zap_tail_holes(q);
129129

130-
sch->qstats.backlog -= qdisc_pkt_len(skb);
130+
qdisc_qstats_backlog_dec(sch, skb);
131131
qdisc_drop(skb, sch);
132132
qdisc_tree_decrease_qlen(sch, 1);
133133
--sch->q.qlen;
@@ -302,7 +302,7 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch)
302302
if (q->vars.qavg > p->qth_max) {
303303
q->vars.qcount = -1;
304304

305-
sch->qstats.overlimits++;
305+
qdisc_qstats_overlimit(sch);
306306
if (use_harddrop(q) || !use_ecn(q) ||
307307
!INET_ECN_set_ce(skb)) {
308308
q->stats.forced_drop++;
@@ -315,7 +315,7 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch)
315315
q->vars.qcount = 0;
316316
q->vars.qR = red_random(p);
317317

318-
sch->qstats.overlimits++;
318+
qdisc_qstats_overlimit(sch);
319319
if (!use_ecn(q) || !INET_ECN_set_ce(skb)) {
320320
q->stats.prob_drop++;
321321
goto congestion_drop;
@@ -332,7 +332,7 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch)
332332
q->tab[q->tail] = skb;
333333
q->tail = (q->tail + 1) & q->tab_mask;
334334
++sch->q.qlen;
335-
sch->qstats.backlog += qdisc_pkt_len(skb);
335+
qdisc_qstats_backlog_inc(sch, skb);
336336
return NET_XMIT_SUCCESS;
337337
}
338338

@@ -345,7 +345,7 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch)
345345

346346
other_drop:
347347
if (ret & __NET_XMIT_BYPASS)
348-
sch->qstats.drops++;
348+
qdisc_qstats_drop(sch);
349349
kfree_skb(skb);
350350
return ret;
351351
}
@@ -365,7 +365,7 @@ static struct sk_buff *choke_dequeue(struct Qdisc *sch)
365365
q->tab[q->head] = NULL;
366366
choke_zap_head_holes(q);
367367
--sch->q.qlen;
368-
sch->qstats.backlog -= qdisc_pkt_len(skb);
368+
qdisc_qstats_backlog_dec(sch, skb);
369369
qdisc_bstats_update(sch, skb);
370370

371371
return skb;
@@ -460,7 +460,7 @@ static int choke_change(struct Qdisc *sch, struct nlattr *opt)
460460
ntab[tail++] = skb;
461461
continue;
462462
}
463-
sch->qstats.backlog -= qdisc_pkt_len(skb);
463+
qdisc_qstats_backlog_dec(sch, skb);
464464
--sch->q.qlen;
465465
qdisc_drop(skb, sch);
466466
}

net/sched/sch_codel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static int codel_change(struct Qdisc *sch, struct nlattr *opt)
149149
while (sch->q.qlen > sch->limit) {
150150
struct sk_buff *skb = __skb_dequeue(&sch->q);
151151

152-
sch->qstats.backlog -= qdisc_pkt_len(skb);
152+
qdisc_qstats_backlog_dec(sch, skb);
153153
qdisc_drop(skb, sch);
154154
}
155155
qdisc_tree_decrease_qlen(sch, qlen - sch->q.qlen);

net/sched/sch_drr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static int drr_enqueue(struct sk_buff *skb, struct Qdisc *sch)
360360
cl = drr_classify(skb, sch, &err);
361361
if (cl == NULL) {
362362
if (err & __NET_XMIT_BYPASS)
363-
sch->qstats.drops++;
363+
qdisc_qstats_drop(sch);
364364
kfree_skb(skb);
365365
return err;
366366
}
@@ -369,7 +369,7 @@ static int drr_enqueue(struct sk_buff *skb, struct Qdisc *sch)
369369
if (unlikely(err != NET_XMIT_SUCCESS)) {
370370
if (net_xmit_drop_count(err)) {
371371
cl->qstats.drops++;
372-
sch->qstats.drops++;
372+
qdisc_qstats_drop(sch);
373373
}
374374
return err;
375375
}

net/sched/sch_dsmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static int dsmark_enqueue(struct sk_buff *skb, struct Qdisc *sch)
258258
err = qdisc_enqueue(skb, p->q);
259259
if (err != NET_XMIT_SUCCESS) {
260260
if (net_xmit_drop_count(err))
261-
sch->qstats.drops++;
261+
qdisc_qstats_drop(sch);
262262
return err;
263263
}
264264

net/sched/sch_fifo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static int pfifo_tail_enqueue(struct sk_buff *skb, struct Qdisc *sch)
4242

4343
/* queue full, remove one skb to fulfill the limit */
4444
__qdisc_queue_drop_head(sch, &sch->q);
45-
sch->qstats.drops++;
45+
qdisc_qstats_drop(sch);
4646
qdisc_enqueue_tail(skb, sch);
4747

4848
return NET_XMIT_CN;

net/sched/sch_fq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static struct sk_buff *fq_dequeue_head(struct Qdisc *sch, struct fq_flow *flow)
290290
flow->head = skb->next;
291291
skb->next = NULL;
292292
flow->qlen--;
293-
sch->qstats.backlog -= qdisc_pkt_len(skb);
293+
qdisc_qstats_backlog_dec(sch, skb);
294294
sch->q.qlen--;
295295
}
296296
return skb;
@@ -371,7 +371,7 @@ static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
371371
f->qlen++;
372372
if (skb_is_retransmit(skb))
373373
q->stat_tcp_retrans++;
374-
sch->qstats.backlog += qdisc_pkt_len(skb);
374+
qdisc_qstats_backlog_inc(sch, skb);
375375
if (fq_flow_is_detached(f)) {
376376
fq_flow_add_tail(&q->new_flows, f);
377377
if (time_after(jiffies, f->age + q->flow_refill_delay))

0 commit comments

Comments
 (0)