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))

net/sched/sch_fq_codel.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ static unsigned int fq_codel_drop(struct Qdisc *sch)
164164
q->backlogs[idx] -= len;
165165
kfree_skb(skb);
166166
sch->q.qlen--;
167-
sch->qstats.drops++;
168-
sch->qstats.backlog -= len;
167+
qdisc_qstats_drop(sch);
168+
qdisc_qstats_backlog_dec(sch, skb);
169169
flow->dropped++;
170170
return idx;
171171
}
@@ -180,7 +180,7 @@ static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch)
180180
idx = fq_codel_classify(skb, sch, &ret);
181181
if (idx == 0) {
182182
if (ret & __NET_XMIT_BYPASS)
183-
sch->qstats.drops++;
183+
qdisc_qstats_drop(sch);
184184
kfree_skb(skb);
185185
return ret;
186186
}
@@ -190,7 +190,7 @@ static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch)
190190
flow = &q->flows[idx];
191191
flow_queue_add(flow, skb);
192192
q->backlogs[idx] += qdisc_pkt_len(skb);
193-
sch->qstats.backlog += qdisc_pkt_len(skb);
193+
qdisc_qstats_backlog_inc(sch, skb);
194194

195195
if (list_empty(&flow->flowchain)) {
196196
list_add_tail(&flow->flowchain, &q->new_flows);

net/sched/sch_gred.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static int gred_enqueue(struct sk_buff *skb, struct Qdisc *sch)
209209
break;
210210

211211
case RED_PROB_MARK:
212-
sch->qstats.overlimits++;
212+
qdisc_qstats_overlimit(sch);
213213
if (!gred_use_ecn(t) || !INET_ECN_set_ce(skb)) {
214214
q->stats.prob_drop++;
215215
goto congestion_drop;
@@ -219,7 +219,7 @@ static int gred_enqueue(struct sk_buff *skb, struct Qdisc *sch)
219219
break;
220220

221221
case RED_HARD_MARK:
222-
sch->qstats.overlimits++;
222+
qdisc_qstats_overlimit(sch);
223223
if (gred_use_harddrop(t) || !gred_use_ecn(t) ||
224224
!INET_ECN_set_ce(skb)) {
225225
q->stats.forced_drop++;

net/sched/sch_hfsc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ hfsc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
15911591
cl = hfsc_classify(skb, sch, &err);
15921592
if (cl == NULL) {
15931593
if (err & __NET_XMIT_BYPASS)
1594-
sch->qstats.drops++;
1594+
qdisc_qstats_drop(sch);
15951595
kfree_skb(skb);
15961596
return err;
15971597
}
@@ -1600,7 +1600,7 @@ hfsc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
16001600
if (unlikely(err != NET_XMIT_SUCCESS)) {
16011601
if (net_xmit_drop_count(err)) {
16021602
cl->qstats.drops++;
1603-
sch->qstats.drops++;
1603+
qdisc_qstats_drop(sch);
16041604
}
16051605
return err;
16061606
}
@@ -1643,7 +1643,7 @@ hfsc_dequeue(struct Qdisc *sch)
16431643
*/
16441644
cl = vttree_get_minvt(&q->root, cur_time);
16451645
if (cl == NULL) {
1646-
sch->qstats.overlimits++;
1646+
qdisc_qstats_overlimit(sch);
16471647
hfsc_schedule_watchdog(sch);
16481648
return NULL;
16491649
}
@@ -1698,7 +1698,7 @@ hfsc_drop(struct Qdisc *sch)
16981698
list_move_tail(&cl->dlist, &q->droplist);
16991699
}
17001700
cl->qstats.drops++;
1701-
sch->qstats.drops++;
1701+
qdisc_qstats_drop(sch);
17021702
sch->q.qlen--;
17031703
return len;
17041704
}

net/sched/sch_hhf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ static unsigned int hhf_drop(struct Qdisc *sch)
376376
struct sk_buff *skb = dequeue_head(bucket);
377377

378378
sch->q.qlen--;
379-
sch->qstats.drops++;
380-
sch->qstats.backlog -= qdisc_pkt_len(skb);
379+
qdisc_qstats_drop(sch);
380+
qdisc_qstats_backlog_dec(sch, skb);
381381
kfree_skb(skb);
382382
}
383383

@@ -395,7 +395,7 @@ static int hhf_enqueue(struct sk_buff *skb, struct Qdisc *sch)
395395

396396
bucket = &q->buckets[idx];
397397
bucket_add(bucket, skb);
398-
sch->qstats.backlog += qdisc_pkt_len(skb);
398+
qdisc_qstats_backlog_inc(sch, skb);
399399

400400
if (list_empty(&bucket->bucketchain)) {
401401
unsigned int weight;
@@ -457,7 +457,7 @@ static struct sk_buff *hhf_dequeue(struct Qdisc *sch)
457457
if (bucket->head) {
458458
skb = dequeue_head(bucket);
459459
sch->q.qlen--;
460-
sch->qstats.backlog -= qdisc_pkt_len(skb);
460+
qdisc_qstats_backlog_dec(sch, skb);
461461
}
462462

463463
if (!skb) {

0 commit comments

Comments
 (0)