Skip to content

Commit

Permalink
Merge branch 'net_sched-convert-packet-counters-to-64bit'
Browse files Browse the repository at this point in the history
Eric Dumazet says:

====================
net_sched: convert packet counters to 64bit

This small patch series add 64bit support for packet counts.

Fact that the counters were still 32bit has been quite painful.

tc -s -d qd sh dev eth0 | head -3
qdisc mq 1: root
 Sent 665706335338 bytes 6526520373 pkt (dropped 2441, overlimits 0 requeues 91)
 backlog 0b 0p requeues 91
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Nov 6, 2019
2 parents 973ff55 + b33e699 commit 5ea4b12
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
6 changes: 6 additions & 0 deletions include/net/gen_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
#include <linux/rtnetlink.h>
#include <linux/pkt_sched.h>

/* Note: this used to be in include/uapi/linux/gen_stats.h */
struct gnet_stats_basic_packed {
__u64 bytes;
__u64 packets;
};

struct gnet_stats_basic_cpu {
struct gnet_stats_basic_packed bstats;
struct u64_stats_sync syncp;
Expand Down
5 changes: 1 addition & 4 deletions include/uapi/linux/gen_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum {
TCA_STATS_RATE_EST64,
TCA_STATS_PAD,
TCA_STATS_BASIC_HW,
TCA_STATS_PKT64,
__TCA_STATS_MAX,
};
#define TCA_STATS_MAX (__TCA_STATS_MAX - 1)
Expand All @@ -26,10 +27,6 @@ struct gnet_stats_basic {
__u64 bytes;
__u32 packets;
};
struct gnet_stats_basic_packed {
__u64 bytes;
__u32 packets;
} __attribute__ ((packed));

/**
* struct gnet_stats_rate_est - rate estimator
Expand Down
12 changes: 8 additions & 4 deletions net/core/gen_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ __gnet_stats_copy_basic_cpu(struct gnet_stats_basic_packed *bstats,
for_each_possible_cpu(i) {
struct gnet_stats_basic_cpu *bcpu = per_cpu_ptr(cpu, i);
unsigned int start;
u64 bytes;
u32 packets;
u64 bytes, packets;

do {
start = u64_stats_fetch_begin_irq(&bcpu->syncp);
Expand Down Expand Up @@ -176,12 +175,17 @@ ___gnet_stats_copy_basic(const seqcount_t *running,

if (d->tail) {
struct gnet_stats_basic sb;
int res;

memset(&sb, 0, sizeof(sb));
sb.bytes = bstats.bytes;
sb.packets = bstats.packets;
return gnet_stats_copy(d, type, &sb, sizeof(sb),
TCA_STATS_PAD);
res = gnet_stats_copy(d, type, &sb, sizeof(sb), TCA_STATS_PAD);
if (res < 0 || sb.packets == bstats.packets)
return res;
/* emit 64bit stats only if needed */
return gnet_stats_copy(d, TCA_STATS_PKT64, &bstats.packets,
sizeof(bstats.packets), TCA_STATS_PAD);
}
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions net/sched/act_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ static size_t tcf_action_shared_attrs_size(const struct tc_action *act)
+ nla_total_size(0) /* TCA_ACT_STATS nested */
/* TCA_STATS_BASIC */
+ nla_total_size_64bit(sizeof(struct gnet_stats_basic))
/* TCA_STATS_PKT64 */
+ nla_total_size_64bit(sizeof(u64))
/* TCA_STATS_QUEUE */
+ nla_total_size_64bit(sizeof(struct gnet_stats_queue))
+ nla_total_size(0) /* TCA_OPTIONS nested */
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static int tcf_simp_act(struct sk_buff *skb, const struct tc_action *a,
* Example if this was the 3rd packet and the string was "hello"
* then it would look like "hello_3" (without quotes)
*/
pr_info("simple: %s_%d\n",
pr_info("simple: %s_%llu\n",
(char *)d->tcfd_defdata, d->tcf_bstats.packets);
spin_unlock(&d->tcf_lock);
return d->tcf_action;
Expand Down

0 comments on commit 5ea4b12

Please sign in to comment.