net_sched: convert packet counters to 64bit
Subsystems (3)
cover 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
Eric Dumazet (3):
net_sched: do not export gnet_stats_basic_packed to uapi
net_sched: extend packet counter to 64bit
net_sched: add TCA_STATS_PKT64 attribute
include/net/gen_stats.h | 6 ++++++ include/uapi/linux/gen_stats.h | 5 +---- net/core/gen_stats.c | 12 ++++++++---- net/sched/act_api.c | 2 ++ net/sched/act_simple.c | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-)
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
PATCH 1/3 net_sched: do not export gnet_stats_basic_packed to uapi
gnet_stats_basic_packed was really meant to be private kernel structure.
If this proves to be a problem, we will have to rename the in-kernel version.
--- include/net/gen_stats.h | 6 ++++++ include/uapi/linux/gen_stats.h | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-)
include/net/gen_stats.h +6 -0
@@ -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; +__u32 packets; +} __attribute__ ((packed)); +struct gnet_stats_basic_cpu {struct gnet_stats_basic_packed bstats;struct u64_stats_sync syncp;
include/uapi/linux/gen_stats.h +0 -4
@@ -26,10 +26,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
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
PATCH 2/3 net_sched: extend packet counter to 64bit
In reply to Eric DumazetAfter this change, qdisc packet counter is no longer a 32bit quantity. We still export 32bit values to user.
--- include/net/gen_stats.h | 4 ++-- net/core/gen_stats.c | 3 +-- net/sched/act_simple.c | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-)
include/net/gen_stats.h +2 -2
@@ -10,8 +10,8 @@/* Note: this used to be in include/uapi/linux/gen_stats.h */ struct gnet_stats_basic_packed {__u64 bytes; -__u32 packets; -} __attribute__ ((packed)); +__u64 packets; +};struct gnet_stats_basic_cpu {struct gnet_stats_basic_packed bstats;
net/core/gen_stats.c +1 -2
@@ -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);
net/sched/act_simple.c +1 -1
@@ -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;
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Re: [PATCH net-next 2/3] net_sched: extend packet counter to 64bit
include/net/gen_stats.h line 14
Quoted 12 lines · Eric Dumazet
include/net/gen_stats.h +2
-2@@ -10,8 +10,8 @@/* Note: this used to be in include/uapi/linux/gen_stats.h */ struct gnet_stats_basic_packed {__u64 bytes; -__u32 packets; -} __attribute__ ((packed)); +__u64 packets; +};
nit: if there needs to be a respin for other reason perhaps worth s/__u/u/ as this is no longer a uAPI structure?
Re: [PATCH net-next 2/3] net_sched: extend packet counter to 64bit
Quoted 17 lines · Jakub Kicinski
include/net/gen_stats.h line 14
Quoted 12 lines · Eric Dumazet
include/net/gen_stats.h +2
-2@@ -10,8 +10,8 @@/* Note: this used to be in include/uapi/linux/gen_stats.h */ struct gnet_stats_basic_packed {__u64 bytes; -__u32 packets; -} __attribute__ ((packed)); +__u64 packets; +};nit: if there needs to be a respin for other reason perhaps worth s/__u/u/ as this is no longer a uAPI structure?
Yes, I had this in my mind, we have __u32 all over the places, with a mix of u32/__u32 in some classes :/
Thanks.
PATCH 3/3 net_sched: add TCA_STATS_PKT64 attribute
In reply to Eric DumazetNow the kernel uses 64bit packet counters in scheduler layer, we want to export these counters to user space.
Instead risking breaking user space by adding fields to struct gnet_stats_basic, add a new TCA_STATS_PKT64.
--- include/uapi/linux/gen_stats.h | 1 + net/core/gen_stats.c | 9 +++++++-- net/sched/act_api.c | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-)
include/uapi/linux/gen_stats.h +1 -0
@@ -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)
net/core/gen_stats.c +7 -2
@@ -175,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 ; }
net/sched/act_api.c +2 -0
@@ -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 */
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Mon, 4 Nov 2019 19:13:12 -0800
Quoted 8 lines
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
Series applied.