Skip to content

Commit 9dd6ad6

Browse files
vladimirolteandavem330
authored andcommitted
net/sched: refactor mqprio qopt reconstruction to a library function
The taprio qdisc will need to reconstruct a struct tc_mqprio_qopt from netdev settings once more in a future patch, but this code was already written twice, once in taprio and once in mqprio. Refactor the code to a helper in the common mqprio library. Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1dfe086 commit 9dd6ad6

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

net/sched/sch_mqprio.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ static int mqprio_dump(struct Qdisc *sch, struct sk_buff *skb)
406406
struct nlattr *nla = (struct nlattr *)skb_tail_pointer(skb);
407407
struct tc_mqprio_qopt opt = { 0 };
408408
struct Qdisc *qdisc;
409-
unsigned int ntx, tc;
409+
unsigned int ntx;
410410

411411
sch->q.qlen = 0;
412412
gnet_stats_basic_sync_init(&sch->bstats);
@@ -430,15 +430,9 @@ static int mqprio_dump(struct Qdisc *sch, struct sk_buff *skb)
430430
spin_unlock_bh(qdisc_lock(qdisc));
431431
}
432432

433-
opt.num_tc = netdev_get_num_tc(dev);
434-
memcpy(opt.prio_tc_map, dev->prio_tc_map, sizeof(opt.prio_tc_map));
433+
mqprio_qopt_reconstruct(dev, &opt);
435434
opt.hw = priv->hw_offload;
436435

437-
for (tc = 0; tc < netdev_get_num_tc(dev); tc++) {
438-
opt.count[tc] = dev->tc_to_txq[tc].count;
439-
opt.offset[tc] = dev->tc_to_txq[tc].offset;
440-
}
441-
442436
if (nla_put(skb, TCA_OPTIONS, sizeof(opt), &opt))
443437
goto nla_put_failure;
444438

net/sched/sch_mqprio_lib.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,18 @@ int mqprio_validate_qopt(struct net_device *dev, struct tc_mqprio_qopt *qopt,
100100
}
101101
EXPORT_SYMBOL_GPL(mqprio_validate_qopt);
102102

103+
void mqprio_qopt_reconstruct(struct net_device *dev, struct tc_mqprio_qopt *qopt)
104+
{
105+
int tc, num_tc = netdev_get_num_tc(dev);
106+
107+
qopt->num_tc = num_tc;
108+
memcpy(qopt->prio_tc_map, dev->prio_tc_map, sizeof(qopt->prio_tc_map));
109+
110+
for (tc = 0; tc < num_tc; tc++) {
111+
qopt->count[tc] = dev->tc_to_txq[tc].count;
112+
qopt->offset[tc] = dev->tc_to_txq[tc].offset;
113+
}
114+
}
115+
EXPORT_SYMBOL_GPL(mqprio_qopt_reconstruct);
116+
103117
MODULE_LICENSE("GPL");

net/sched/sch_mqprio_lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ int mqprio_validate_qopt(struct net_device *dev, struct tc_mqprio_qopt *qopt,
1212
bool validate_queue_counts,
1313
bool allow_overlapping_txqs,
1414
struct netlink_ext_ack *extack);
15+
void mqprio_qopt_reconstruct(struct net_device *dev,
16+
struct tc_mqprio_qopt *qopt);
1517

1618
#endif

net/sched/sch_taprio.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,18 +1948,11 @@ static int taprio_dump(struct Qdisc *sch, struct sk_buff *skb)
19481948
struct sched_gate_list *oper, *admin;
19491949
struct tc_mqprio_qopt opt = { 0 };
19501950
struct nlattr *nest, *sched_nest;
1951-
unsigned int i;
19521951

19531952
oper = rtnl_dereference(q->oper_sched);
19541953
admin = rtnl_dereference(q->admin_sched);
19551954

1956-
opt.num_tc = netdev_get_num_tc(dev);
1957-
memcpy(opt.prio_tc_map, dev->prio_tc_map, sizeof(opt.prio_tc_map));
1958-
1959-
for (i = 0; i < netdev_get_num_tc(dev); i++) {
1960-
opt.count[i] = dev->tc_to_txq[i].count;
1961-
opt.offset[i] = dev->tc_to_txq[i].offset;
1962-
}
1955+
mqprio_qopt_reconstruct(dev, &opt);
19631956

19641957
nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
19651958
if (!nest)

0 commit comments

Comments
 (0)