Commit fbf307c8 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by David S. Miller

gen_stats: Add instead Set the value in __gnet_stats_copy_basic().

__gnet_stats_copy_basic() always assigns the value to the bstats
argument overwriting the previous value. The later added per-CPU version
always accumulated the values in the returning gnet_stats_basic_packed
argument.

Based on review there are five users of that function as of today:
- est_fetch_counters(), ___gnet_stats_copy_basic()
  memsets() bstats to zero, single invocation.

- mq_dump(), mqprio_dump(), mqprio_dump_class_stats()
  memsets() bstats to zero, multiple invocation but does not use the
  function due to !qdisc_is_percpu_stats().

Add the values in __gnet_stats_copy_basic() instead overwriting. Rename
the function to gnet_stats_add_basic() to make it more obvious.
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 254ec036
...@@ -46,7 +46,7 @@ int gnet_stats_copy_basic(const seqcount_t *running, ...@@ -46,7 +46,7 @@ int gnet_stats_copy_basic(const seqcount_t *running,
struct gnet_dump *d, struct gnet_dump *d,
struct gnet_stats_basic_cpu __percpu *cpu, struct gnet_stats_basic_cpu __percpu *cpu,
struct gnet_stats_basic_packed *b); struct gnet_stats_basic_packed *b);
void __gnet_stats_copy_basic(const seqcount_t *running, void gnet_stats_add_basic(const seqcount_t *running,
struct gnet_stats_basic_packed *bstats, struct gnet_stats_basic_packed *bstats,
struct gnet_stats_basic_cpu __percpu *cpu, struct gnet_stats_basic_cpu __percpu *cpu,
struct gnet_stats_basic_packed *b); struct gnet_stats_basic_packed *b);
......
...@@ -66,7 +66,7 @@ static void est_fetch_counters(struct net_rate_estimator *e, ...@@ -66,7 +66,7 @@ static void est_fetch_counters(struct net_rate_estimator *e,
if (e->stats_lock) if (e->stats_lock)
spin_lock(e->stats_lock); spin_lock(e->stats_lock);
__gnet_stats_copy_basic(e->running, b, e->cpu_bstats, e->bstats); gnet_stats_add_basic(e->running, b, e->cpu_bstats, e->bstats);
if (e->stats_lock) if (e->stats_lock)
spin_unlock(e->stats_lock); spin_unlock(e->stats_lock);
......
...@@ -114,8 +114,7 @@ gnet_stats_start_copy(struct sk_buff *skb, int type, spinlock_t *lock, ...@@ -114,8 +114,7 @@ gnet_stats_start_copy(struct sk_buff *skb, int type, spinlock_t *lock,
} }
EXPORT_SYMBOL(gnet_stats_start_copy); EXPORT_SYMBOL(gnet_stats_start_copy);
static void static void gnet_stats_add_basic_cpu(struct gnet_stats_basic_packed *bstats,
__gnet_stats_copy_basic_cpu(struct gnet_stats_basic_packed *bstats,
struct gnet_stats_basic_cpu __percpu *cpu) struct gnet_stats_basic_cpu __percpu *cpu)
{ {
int i; int i;
...@@ -136,26 +135,30 @@ __gnet_stats_copy_basic_cpu(struct gnet_stats_basic_packed *bstats, ...@@ -136,26 +135,30 @@ __gnet_stats_copy_basic_cpu(struct gnet_stats_basic_packed *bstats,
} }
} }
void void gnet_stats_add_basic(const seqcount_t *running,
__gnet_stats_copy_basic(const seqcount_t *running,
struct gnet_stats_basic_packed *bstats, struct gnet_stats_basic_packed *bstats,
struct gnet_stats_basic_cpu __percpu *cpu, struct gnet_stats_basic_cpu __percpu *cpu,
struct gnet_stats_basic_packed *b) struct gnet_stats_basic_packed *b)
{ {
unsigned int seq; unsigned int seq;
u64 bytes = 0;
u64 packets = 0;
if (cpu) { if (cpu) {
__gnet_stats_copy_basic_cpu(bstats, cpu); gnet_stats_add_basic_cpu(bstats, cpu);
return; return;
} }
do { do {
if (running) if (running)
seq = read_seqcount_begin(running); seq = read_seqcount_begin(running);
bstats->bytes = b->bytes; bytes = b->bytes;
bstats->packets = b->packets; packets = b->packets;
} while (running && read_seqcount_retry(running, seq)); } while (running && read_seqcount_retry(running, seq));
bstats->bytes += bytes;
bstats->packets += packets;
} }
EXPORT_SYMBOL(__gnet_stats_copy_basic); EXPORT_SYMBOL(gnet_stats_add_basic);
static int static int
___gnet_stats_copy_basic(const seqcount_t *running, ___gnet_stats_copy_basic(const seqcount_t *running,
...@@ -166,7 +169,7 @@ ___gnet_stats_copy_basic(const seqcount_t *running, ...@@ -166,7 +169,7 @@ ___gnet_stats_copy_basic(const seqcount_t *running,
{ {
struct gnet_stats_basic_packed bstats = {0}; struct gnet_stats_basic_packed bstats = {0};
__gnet_stats_copy_basic(running, &bstats, cpu, b); gnet_stats_add_basic(running, &bstats, cpu, b);
if (d->compat_tc_stats && type == TCA_STATS_BASIC) { if (d->compat_tc_stats && type == TCA_STATS_BASIC) {
d->tc_stats.bytes = bstats.bytes; d->tc_stats.bytes = bstats.bytes;
......
...@@ -147,9 +147,8 @@ static int mq_dump(struct Qdisc *sch, struct sk_buff *skb) ...@@ -147,9 +147,8 @@ static int mq_dump(struct Qdisc *sch, struct sk_buff *skb)
if (qdisc_is_percpu_stats(qdisc)) { if (qdisc_is_percpu_stats(qdisc)) {
qlen = qdisc_qlen_sum(qdisc); qlen = qdisc_qlen_sum(qdisc);
__gnet_stats_copy_basic(NULL, &sch->bstats, gnet_stats_add_basic(NULL, &sch->bstats,
qdisc->cpu_bstats, qdisc->cpu_bstats, &qdisc->bstats);
&qdisc->bstats);
__gnet_stats_copy_queue(&sch->qstats, __gnet_stats_copy_queue(&sch->qstats,
qdisc->cpu_qstats, qdisc->cpu_qstats,
&qdisc->qstats, qlen); &qdisc->qstats, qlen);
......
...@@ -405,9 +405,8 @@ static int mqprio_dump(struct Qdisc *sch, struct sk_buff *skb) ...@@ -405,9 +405,8 @@ static int mqprio_dump(struct Qdisc *sch, struct sk_buff *skb)
if (qdisc_is_percpu_stats(qdisc)) { if (qdisc_is_percpu_stats(qdisc)) {
__u32 qlen = qdisc_qlen_sum(qdisc); __u32 qlen = qdisc_qlen_sum(qdisc);
__gnet_stats_copy_basic(NULL, &sch->bstats, gnet_stats_add_basic(NULL, &sch->bstats,
qdisc->cpu_bstats, qdisc->cpu_bstats, &qdisc->bstats);
&qdisc->bstats);
__gnet_stats_copy_queue(&sch->qstats, __gnet_stats_copy_queue(&sch->qstats,
qdisc->cpu_qstats, qdisc->cpu_qstats,
&qdisc->qstats, qlen); &qdisc->qstats, qlen);
...@@ -535,7 +534,7 @@ static int mqprio_dump_class_stats(struct Qdisc *sch, unsigned long cl, ...@@ -535,7 +534,7 @@ static int mqprio_dump_class_stats(struct Qdisc *sch, unsigned long cl,
if (qdisc_is_percpu_stats(qdisc)) { if (qdisc_is_percpu_stats(qdisc)) {
qlen = qdisc_qlen_sum(qdisc); qlen = qdisc_qlen_sum(qdisc);
__gnet_stats_copy_basic(NULL, &bstats, gnet_stats_add_basic(NULL, &bstats,
qdisc->cpu_bstats, qdisc->cpu_bstats,
&qdisc->bstats); &qdisc->bstats);
__gnet_stats_copy_queue(&qstats, __gnet_stats_copy_queue(&qstats,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment