aboutsummaryrefslogtreecommitdiffstats
path: root/include/net
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2016-12-04 12:48:16 -0500
committerDavid S. Miller <davem@davemloft.net>2016-12-05 15:21:59 -0500
commit1c0d32fde5bdf1184bc274f864c09799278a1114 (patch)
tree47367d46dfc125e19294c3f5fa9a021520bd5660 /include/net
parenta6e169312971219a34927e8fdece60046fafb8ba (diff)
net_sched: gen_estimator: complete rewrite of rate estimators
1) Old code was hard to maintain, due to complex lock chains. (We probably will be able to remove some kfree_rcu() in callers) 2) Using a single timer to update all estimators does not scale. 3) Code was buggy on 32bit kernel (WRITE_ONCE() on 64bit quantity is not supposed to work well) In this rewrite : - I removed the RB tree that had to be scanned in gen_estimator_active(). qdisc dumps should be much faster. - Each estimator has its own timer. - Estimations are maintained in net_rate_estimator structure, instead of dirtying the qdisc. Minor, but part of the simplification. - Reading the estimator uses RCU and a seqcount to provide proper support for 32bit kernels. - We reduce memory need when estimators are not used, since we store a pointer, instead of the bytes/packets counters. - xt_rateest_mt() no longer has to grab a spinlock. (In the future, xt_rateest_tg() could be switched to per cpu counters) Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net')
-rw-r--r--include/net/act_api.h2
-rw-r--r--include/net/gen_stats.h17
-rw-r--r--include/net/netfilter/xt_rateest.h10
-rw-r--r--include/net/sch_generic.h2
4 files changed, 18 insertions, 13 deletions
diff --git a/include/net/act_api.h b/include/net/act_api.h
index 9dddf77a69cc..1d716449209e 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -36,7 +36,7 @@ struct tc_action {
36 struct tcf_t tcfa_tm; 36 struct tcf_t tcfa_tm;
37 struct gnet_stats_basic_packed tcfa_bstats; 37 struct gnet_stats_basic_packed tcfa_bstats;
38 struct gnet_stats_queue tcfa_qstats; 38 struct gnet_stats_queue tcfa_qstats;
39 struct gnet_stats_rate_est64 tcfa_rate_est; 39 struct net_rate_estimator __rcu *tcfa_rate_est;
40 spinlock_t tcfa_lock; 40 spinlock_t tcfa_lock;
41 struct rcu_head tcfa_rcu; 41 struct rcu_head tcfa_rcu;
42 struct gnet_stats_basic_cpu __percpu *cpu_bstats; 42 struct gnet_stats_basic_cpu __percpu *cpu_bstats;
diff --git a/include/net/gen_stats.h b/include/net/gen_stats.h
index 231e121cc7d9..8b7aa370e7a4 100644
--- a/include/net/gen_stats.h
+++ b/include/net/gen_stats.h
@@ -11,6 +11,8 @@ struct gnet_stats_basic_cpu {
11 struct u64_stats_sync syncp; 11 struct u64_stats_sync syncp;
12}; 12};
13 13
14struct net_rate_estimator;
15
14struct gnet_dump { 16struct gnet_dump {
15 spinlock_t * lock; 17 spinlock_t * lock;
16 struct sk_buff * skb; 18 struct sk_buff * skb;
@@ -42,8 +44,7 @@ void __gnet_stats_copy_basic(const seqcount_t *running,
42 struct gnet_stats_basic_cpu __percpu *cpu, 44 struct gnet_stats_basic_cpu __percpu *cpu,
43 struct gnet_stats_basic_packed *b); 45 struct gnet_stats_basic_packed *b);
44int gnet_stats_copy_rate_est(struct gnet_dump *d, 46int gnet_stats_copy_rate_est(struct gnet_dump *d,
45 const struct gnet_stats_basic_packed *b, 47 struct net_rate_estimator __rcu **ptr);
46 struct gnet_stats_rate_est64 *r);
47int gnet_stats_copy_queue(struct gnet_dump *d, 48int gnet_stats_copy_queue(struct gnet_dump *d,
48 struct gnet_stats_queue __percpu *cpu_q, 49 struct gnet_stats_queue __percpu *cpu_q,
49 struct gnet_stats_queue *q, __u32 qlen); 50 struct gnet_stats_queue *q, __u32 qlen);
@@ -53,16 +54,16 @@ int gnet_stats_finish_copy(struct gnet_dump *d);
53 54
54int gen_new_estimator(struct gnet_stats_basic_packed *bstats, 55int gen_new_estimator(struct gnet_stats_basic_packed *bstats,
55 struct gnet_stats_basic_cpu __percpu *cpu_bstats, 56 struct gnet_stats_basic_cpu __percpu *cpu_bstats,
56 struct gnet_stats_rate_est64 *rate_est, 57 struct net_rate_estimator __rcu **rate_est,
57 spinlock_t *stats_lock, 58 spinlock_t *stats_lock,
58 seqcount_t *running, struct nlattr *opt); 59 seqcount_t *running, struct nlattr *opt);
59void gen_kill_estimator(struct gnet_stats_basic_packed *bstats, 60void gen_kill_estimator(struct net_rate_estimator __rcu **ptr);
60 struct gnet_stats_rate_est64 *rate_est);
61int gen_replace_estimator(struct gnet_stats_basic_packed *bstats, 61int gen_replace_estimator(struct gnet_stats_basic_packed *bstats,
62 struct gnet_stats_basic_cpu __percpu *cpu_bstats, 62 struct gnet_stats_basic_cpu __percpu *cpu_bstats,
63 struct gnet_stats_rate_est64 *rate_est, 63 struct net_rate_estimator __rcu **ptr,
64 spinlock_t *stats_lock, 64 spinlock_t *stats_lock,
65 seqcount_t *running, struct nlattr *opt); 65 seqcount_t *running, struct nlattr *opt);
66bool gen_estimator_active(const struct gnet_stats_basic_packed *bstats, 66bool gen_estimator_active(struct net_rate_estimator __rcu **ptr);
67 const struct gnet_stats_rate_est64 *rate_est); 67bool gen_estimator_read(struct net_rate_estimator __rcu **ptr,
68 struct gnet_stats_rate_est64 *sample);
68#endif 69#endif
diff --git a/include/net/netfilter/xt_rateest.h b/include/net/netfilter/xt_rateest.h
index 79f45e19f31e..130e58361f99 100644
--- a/include/net/netfilter/xt_rateest.h
+++ b/include/net/netfilter/xt_rateest.h
@@ -1,19 +1,23 @@
1#ifndef _XT_RATEEST_H 1#ifndef _XT_RATEEST_H
2#define _XT_RATEEST_H 2#define _XT_RATEEST_H
3 3
4#include <net/gen_stats.h>
5
4struct xt_rateest { 6struct xt_rateest {
5 /* keep lock and bstats on same cache line to speedup xt_rateest_tg() */ 7 /* keep lock and bstats on same cache line to speedup xt_rateest_tg() */
6 struct gnet_stats_basic_packed bstats; 8 struct gnet_stats_basic_packed bstats;
7 spinlock_t lock; 9 spinlock_t lock;
8 /* keep rstats and lock on same cache line to speedup xt_rateest_mt() */ 10
9 struct gnet_stats_rate_est64 rstats;
10 11
11 /* following fields not accessed in hot path */ 12 /* following fields not accessed in hot path */
13 unsigned int refcnt;
12 struct hlist_node list; 14 struct hlist_node list;
13 char name[IFNAMSIZ]; 15 char name[IFNAMSIZ];
14 unsigned int refcnt;
15 struct gnet_estimator params; 16 struct gnet_estimator params;
16 struct rcu_head rcu; 17 struct rcu_head rcu;
18
19 /* keep this field far away to speedup xt_rateest_mt() */
20 struct net_rate_estimator __rcu *rate_est;
17}; 21};
18 22
19struct xt_rateest *xt_rateest_lookup(const char *name); 23struct xt_rateest *xt_rateest_lookup(const char *name);
diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h
index e6aa0a249672..498f81b229a4 100644
--- a/include/net/sch_generic.h
+++ b/include/net/sch_generic.h
@@ -76,7 +76,7 @@ struct Qdisc {
76 76
77 struct netdev_queue *dev_queue; 77 struct netdev_queue *dev_queue;
78 78
79 struct gnet_stats_rate_est64 rate_est; 79 struct net_rate_estimator __rcu *rate_est;
80 struct gnet_stats_basic_cpu __percpu *cpu_bstats; 80 struct gnet_stats_basic_cpu __percpu *cpu_bstats;
81 struct gnet_stats_queue __percpu *cpu_qstats; 81 struct gnet_stats_queue __percpu *cpu_qstats;
82 82