Skip to content

Commit d59f5ff

Browse files
jrfastabdavem330
authored andcommitted
net: sched: a dflt qdisc may be used with per cpu stats
Enable dflt qdisc support for per cpu stats before this patch a dflt qdisc was required to use the global statistics qstats and bstats. This adds a static flags field to qdisc_ops that is propagated into qdisc->flags in qdisc allocate call. This allows the allocation block to completely allocate the qdisc object so we don't have dangling allocations after qdisc init. Signed-off-by: John Fastabend <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 40bd036 commit d59f5ff

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

include/net/sch_generic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ struct Qdisc_ops {
180180
const struct Qdisc_class_ops *cl_ops;
181181
char id[IFNAMSIZ];
182182
int priv_size;
183+
unsigned int static_flags;
183184

184185
int (*enqueue)(struct sk_buff *skb,
185186
struct Qdisc *sch,

net/sched/sch_generic.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,19 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
632632
qdisc_skb_head_init(&sch->q);
633633
spin_lock_init(&sch->q.lock);
634634

635+
if (ops->static_flags & TCQ_F_CPUSTATS) {
636+
sch->cpu_bstats =
637+
netdev_alloc_pcpu_stats(struct gnet_stats_basic_cpu);
638+
if (!sch->cpu_bstats)
639+
goto errout1;
640+
641+
sch->cpu_qstats = alloc_percpu(struct gnet_stats_queue);
642+
if (!sch->cpu_qstats) {
643+
free_percpu(sch->cpu_bstats);
644+
goto errout1;
645+
}
646+
}
647+
635648
spin_lock_init(&sch->busylock);
636649
lockdep_set_class(&sch->busylock,
637650
dev->qdisc_tx_busylock ?: &qdisc_tx_busylock);
@@ -641,13 +654,16 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
641654
dev->qdisc_running_key ?: &qdisc_running_key);
642655

643656
sch->ops = ops;
657+
sch->flags = ops->static_flags;
644658
sch->enqueue = ops->enqueue;
645659
sch->dequeue = ops->dequeue;
646660
sch->dev_queue = dev_queue;
647661
dev_hold(dev);
648662
refcount_set(&sch->refcnt, 1);
649663

650664
return sch;
665+
errout1:
666+
kfree(p);
651667
errout:
652668
return ERR_PTR(err);
653669
}

0 commit comments

Comments
 (0)