Skip to content

Commit

Permalink
Merge branch 'refactor-duplicate-codes-in-the-qdisc-class-walk-function'
Browse files Browse the repository at this point in the history
Zhengchao Shao says:

====================
refactor duplicate codes in the qdisc class walk function

The walk implementation of most qdisc class modules is basically the
same. That is, the values of count and skip are checked first. If count
is greater than or equal to skip, the registered fn function is
executed. Otherwise, increase the value of count. So the code can be
refactored.

The walk function is invoked during dump. Therefore, test cases related
 to the tdc filter need to be added.
====================

Link: https://lore.kernel.org/r/20220921024040.385296-1-shaozhengchao@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Sep 23, 2022
2 parents a2c2a4d + d3f8325 commit 3f5b606
Show file tree
Hide file tree
Showing 39 changed files with 2,769 additions and 148 deletions.
13 changes: 13 additions & 0 deletions include/net/pkt_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,17 @@ static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb)
return cb;
}

static inline bool tc_qdisc_stats_dump(struct Qdisc *sch,
unsigned long cl,
struct qdisc_walker *arg)
{
if (arg->count >= arg->skip && arg->fn(sch, cl, arg) < 0) {
arg->stop = 1;
return false;
}

arg->count++;
return true;
}

#endif
6 changes: 1 addition & 5 deletions net/sched/sch_atm.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,8 @@ static void atm_tc_walk(struct Qdisc *sch, struct qdisc_walker *walker)
if (walker->stop)
return;
list_for_each_entry(flow, &p->flows, list) {
if (walker->count >= walker->skip &&
walker->fn(sch, (unsigned long)flow, walker) < 0) {
walker->stop = 1;
if (!tc_qdisc_stats_dump(sch, (unsigned long)flow, walker))
break;
}
walker->count++;
}
}

Expand Down
9 changes: 3 additions & 6 deletions net/sched/sch_cake.c
Original file line number Diff line number Diff line change
Expand Up @@ -3061,16 +3061,13 @@ static void cake_walk(struct Qdisc *sch, struct qdisc_walker *arg)
struct cake_tin_data *b = &q->tins[q->tin_order[i]];

for (j = 0; j < CAKE_QUEUES; j++) {
if (list_empty(&b->flows[j].flowchain) ||
arg->count < arg->skip) {
if (list_empty(&b->flows[j].flowchain)) {
arg->count++;
continue;
}
if (arg->fn(sch, i * CAKE_QUEUES + j + 1, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, i * CAKE_QUEUES + j + 1,
arg))
break;
}
arg->count++;
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions net/sched/sch_cbq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1676,15 +1676,8 @@ static void cbq_walk(struct Qdisc *sch, struct qdisc_walker *arg)

for (h = 0; h < q->clhash.hashsize; h++) {
hlist_for_each_entry(cl, &q->clhash.hash[h], common.hnode) {
if (arg->count < arg->skip) {
arg->count++;
continue;
}
if (arg->fn(sch, (unsigned long)cl, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, (unsigned long)cl, arg))
return;
}
arg->count++;
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions net/sched/sch_cbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,7 @@ static unsigned long cbs_find(struct Qdisc *sch, u32 classid)
static void cbs_walk(struct Qdisc *sch, struct qdisc_walker *walker)
{
if (!walker->stop) {
if (walker->count >= walker->skip) {
if (walker->fn(sch, 1, walker) < 0) {
walker->stop = 1;
return;
}
}
walker->count++;
tc_qdisc_stats_dump(sch, 1, walker);
}
}

Expand Down
9 changes: 1 addition & 8 deletions net/sched/sch_drr.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,8 @@ static void drr_walk(struct Qdisc *sch, struct qdisc_walker *arg)

for (i = 0; i < q->clhash.hashsize; i++) {
hlist_for_each_entry(cl, &q->clhash.hash[i], common.hnode) {
if (arg->count < arg->skip) {
arg->count++;
continue;
}
if (arg->fn(sch, (unsigned long)cl, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, (unsigned long)cl, arg))
return;
}
arg->count++;
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions net/sched/sch_dsmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,12 @@ static void dsmark_walk(struct Qdisc *sch, struct qdisc_walker *walker)
return;

for (i = 0; i < p->indices; i++) {
if (p->mv[i].mask == 0xff && !p->mv[i].value)
goto ignore;
if (walker->count >= walker->skip) {
if (walker->fn(sch, i + 1, walker) < 0) {
walker->stop = 1;
break;
}
if (p->mv[i].mask == 0xff && !p->mv[i].value) {
walker->count++;
continue;
}
ignore:
walker->count++;
if (!tc_qdisc_stats_dump(sch, i + 1, walker))
break;
}
}

Expand Down
9 changes: 1 addition & 8 deletions net/sched/sch_ets.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,8 @@ static void ets_qdisc_walk(struct Qdisc *sch, struct qdisc_walker *arg)
return;

for (i = 0; i < q->nbands; i++) {
if (arg->count < arg->skip) {
arg->count++;
continue;
}
if (arg->fn(sch, i + 1, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, i + 1, arg))
break;
}
arg->count++;
}
}

Expand Down
8 changes: 2 additions & 6 deletions net/sched/sch_fq_codel.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,16 +673,12 @@ static void fq_codel_walk(struct Qdisc *sch, struct qdisc_walker *arg)
return;

for (i = 0; i < q->flows_cnt; i++) {
if (list_empty(&q->flows[i].flowchain) ||
arg->count < arg->skip) {
if (list_empty(&q->flows[i].flowchain)) {
arg->count++;
continue;
}
if (arg->fn(sch, i + 1, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, i + 1, arg))
break;
}
arg->count++;
}
}

Expand Down
9 changes: 1 addition & 8 deletions net/sched/sch_hfsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1349,15 +1349,8 @@ hfsc_walk(struct Qdisc *sch, struct qdisc_walker *arg)
for (i = 0; i < q->clhash.hashsize; i++) {
hlist_for_each_entry(cl, &q->clhash.hash[i],
cl_common.hnode) {
if (arg->count < arg->skip) {
arg->count++;
continue;
}
if (arg->fn(sch, (unsigned long)cl, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, (unsigned long)cl, arg))
return;
}
arg->count++;
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions net/sched/sch_htb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2119,15 +2119,8 @@ static void htb_walk(struct Qdisc *sch, struct qdisc_walker *arg)

for (i = 0; i < q->clhash.hashsize; i++) {
hlist_for_each_entry(cl, &q->clhash.hash[i], common.hnode) {
if (arg->count < arg->skip) {
arg->count++;
continue;
}
if (arg->fn(sch, (unsigned long)cl, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, (unsigned long)cl, arg))
return;
}
arg->count++;
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions net/sched/sch_mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,8 @@ static void mq_walk(struct Qdisc *sch, struct qdisc_walker *arg)

arg->count = arg->skip;
for (ntx = arg->skip; ntx < dev->num_tx_queues; ntx++) {
if (arg->fn(sch, ntx + 1, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, ntx + 1, arg))
break;
}
arg->count++;
}
}

Expand Down
5 changes: 1 addition & 4 deletions net/sched/sch_mqprio.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,8 @@ static void mqprio_walk(struct Qdisc *sch, struct qdisc_walker *arg)
/* Walk hierarchy with a virtual class per tc */
arg->count = arg->skip;
for (ntx = arg->skip; ntx < netdev_get_num_tc(dev); ntx++) {
if (arg->fn(sch, ntx + TC_H_MIN_PRIORITY, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, ntx + TC_H_MIN_PRIORITY, arg))
return;
}
arg->count++;
}

/* Pad the values and skip over unused traffic classes */
Expand Down
9 changes: 1 addition & 8 deletions net/sched/sch_multiq.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,8 @@ static void multiq_walk(struct Qdisc *sch, struct qdisc_walker *arg)
return;

for (band = 0; band < q->bands; band++) {
if (arg->count < arg->skip) {
arg->count++;
continue;
}
if (arg->fn(sch, band + 1, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, band + 1, arg))
break;
}
arg->count++;
}
}

Expand Down
8 changes: 2 additions & 6 deletions net/sched/sch_netem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1251,12 +1251,8 @@ static unsigned long netem_find(struct Qdisc *sch, u32 classid)
static void netem_walk(struct Qdisc *sch, struct qdisc_walker *walker)
{
if (!walker->stop) {
if (walker->count >= walker->skip)
if (walker->fn(sch, 1, walker) < 0) {
walker->stop = 1;
return;
}
walker->count++;
if (!tc_qdisc_stats_dump(sch, 1, walker))
return;
}
}

Expand Down
9 changes: 1 addition & 8 deletions net/sched/sch_prio.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,8 @@ static void prio_walk(struct Qdisc *sch, struct qdisc_walker *arg)
return;

for (prio = 0; prio < q->bands; prio++) {
if (arg->count < arg->skip) {
arg->count++;
continue;
}
if (arg->fn(sch, prio + 1, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, prio + 1, arg))
break;
}
arg->count++;
}
}

Expand Down
9 changes: 1 addition & 8 deletions net/sched/sch_qfq.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,15 +659,8 @@ static void qfq_walk(struct Qdisc *sch, struct qdisc_walker *arg)

for (i = 0; i < q->clhash.hashsize; i++) {
hlist_for_each_entry(cl, &q->clhash.hash[i], common.hnode) {
if (arg->count < arg->skip) {
arg->count++;
continue;
}
if (arg->fn(sch, (unsigned long)cl, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, (unsigned long)cl, arg))
return;
}
arg->count++;
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions net/sched/sch_red.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,7 @@ static unsigned long red_find(struct Qdisc *sch, u32 classid)
static void red_walk(struct Qdisc *sch, struct qdisc_walker *walker)
{
if (!walker->stop) {
if (walker->count >= walker->skip)
if (walker->fn(sch, 1, walker) < 0) {
walker->stop = 1;
return;
}
walker->count++;
tc_qdisc_stats_dump(sch, 1, walker);
}
}

Expand Down
7 changes: 1 addition & 6 deletions net/sched/sch_sfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,12 +659,7 @@ static int sfb_delete(struct Qdisc *sch, unsigned long cl,
static void sfb_walk(struct Qdisc *sch, struct qdisc_walker *walker)
{
if (!walker->stop) {
if (walker->count >= walker->skip)
if (walker->fn(sch, 1, walker) < 0) {
walker->stop = 1;
return;
}
walker->count++;
tc_qdisc_stats_dump(sch, 1, walker);
}
}

Expand Down
8 changes: 2 additions & 6 deletions net/sched/sch_sfq.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,16 +888,12 @@ static void sfq_walk(struct Qdisc *sch, struct qdisc_walker *arg)
return;

for (i = 0; i < q->divisor; i++) {
if (q->ht[i] == SFQ_EMPTY_SLOT ||
arg->count < arg->skip) {
if (q->ht[i] == SFQ_EMPTY_SLOT) {
arg->count++;
continue;
}
if (arg->fn(sch, i + 1, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, i + 1, arg))
break;
}
arg->count++;
}
}

Expand Down
9 changes: 1 addition & 8 deletions net/sched/sch_skbprio.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,8 @@ static void skbprio_walk(struct Qdisc *sch, struct qdisc_walker *arg)
return;

for (i = 0; i < SKBPRIO_MAX_PRIORITY; i++) {
if (arg->count < arg->skip) {
arg->count++;
continue;
}
if (arg->fn(sch, i + 1, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, i + 1, arg))
break;
}
arg->count++;
}
}

Expand Down
5 changes: 1 addition & 4 deletions net/sched/sch_taprio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1953,11 +1953,8 @@ static void taprio_walk(struct Qdisc *sch, struct qdisc_walker *arg)

arg->count = arg->skip;
for (ntx = arg->skip; ntx < dev->num_tx_queues; ntx++) {
if (arg->fn(sch, ntx + 1, arg) < 0) {
arg->stop = 1;
if (!tc_qdisc_stats_dump(sch, ntx + 1, arg))
break;
}
arg->count++;
}
}

Expand Down
7 changes: 1 addition & 6 deletions net/sched/sch_tbf.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,12 +580,7 @@ static unsigned long tbf_find(struct Qdisc *sch, u32 classid)
static void tbf_walk(struct Qdisc *sch, struct qdisc_walker *walker)
{
if (!walker->stop) {
if (walker->count >= walker->skip)
if (walker->fn(sch, 1, walker) < 0) {
walker->stop = 1;
return;
}
walker->count++;
tc_qdisc_stats_dump(sch, 1, walker);
}
}

Expand Down
Loading

0 comments on commit 3f5b606

Please sign in to comment.