diff options
author | Julian Anastasov <ja@ssi.bg> | 2011-03-13 19:41:54 -0400 |
---|---|---|
committer | Simon Horman <horms@verge.net.au> | 2011-03-14 20:36:53 -0400 |
commit | ea9f22cce9c2530d659f9122819940b69506b2d9 (patch) | |
tree | 854e130b123d63f6a167f1deb72d15601d907c40 /net/netfilter | |
parent | 87d68a15e2d5a6bd08e59ec80c7a5073bcabb7c3 (diff) |
ipvs: optimize rates reading
Move the estimator reading from estimation_timer to user
context. ip_vs_read_estimator() will be used to decode the rate
values. As the decoded rates are not set by estimation timer
there is no need to reset them in ip_vs_zero_stats.
There is no need ip_vs_new_estimator() to encode stats
to rates, if the destination is in trash both the stats and the
rates are inactive.
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Simon Horman <horms@verge.net.au>
Diffstat (limited to 'net/netfilter')
-rw-r--r-- | net/netfilter/ipvs/ip_vs_ctl.c | 31 | ||||
-rw-r--r-- | net/netfilter/ipvs/ip_vs_est.c | 33 |
2 files changed, 25 insertions, 39 deletions
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c index 804fee7be694..c93d806e73bd 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c | |||
@@ -715,7 +715,6 @@ static void | |||
715 | ip_vs_copy_stats(struct ip_vs_stats_user *dst, struct ip_vs_stats *src) | 715 | ip_vs_copy_stats(struct ip_vs_stats_user *dst, struct ip_vs_stats *src) |
716 | { | 716 | { |
717 | #define IP_VS_SHOW_STATS_COUNTER(c) dst->c = src->ustats.c - src->ustats0.c | 717 | #define IP_VS_SHOW_STATS_COUNTER(c) dst->c = src->ustats.c - src->ustats0.c |
718 | #define IP_VS_SHOW_STATS_RATE(r) dst->r = src->ustats.r | ||
719 | 718 | ||
720 | spin_lock_bh(&src->lock); | 719 | spin_lock_bh(&src->lock); |
721 | 720 | ||
@@ -725,11 +724,7 @@ ip_vs_copy_stats(struct ip_vs_stats_user *dst, struct ip_vs_stats *src) | |||
725 | IP_VS_SHOW_STATS_COUNTER(inbytes); | 724 | IP_VS_SHOW_STATS_COUNTER(inbytes); |
726 | IP_VS_SHOW_STATS_COUNTER(outbytes); | 725 | IP_VS_SHOW_STATS_COUNTER(outbytes); |
727 | 726 | ||
728 | IP_VS_SHOW_STATS_RATE(cps); | 727 | ip_vs_read_estimator(dst, src); |
729 | IP_VS_SHOW_STATS_RATE(inpps); | ||
730 | IP_VS_SHOW_STATS_RATE(outpps); | ||
731 | IP_VS_SHOW_STATS_RATE(inbps); | ||
732 | IP_VS_SHOW_STATS_RATE(outbps); | ||
733 | 728 | ||
734 | spin_unlock_bh(&src->lock); | 729 | spin_unlock_bh(&src->lock); |
735 | } | 730 | } |
@@ -742,7 +737,6 @@ ip_vs_zero_stats(struct ip_vs_stats *stats) | |||
742 | /* get current counters as zero point, rates are zeroed */ | 737 | /* get current counters as zero point, rates are zeroed */ |
743 | 738 | ||
744 | #define IP_VS_ZERO_STATS_COUNTER(c) stats->ustats0.c = stats->ustats.c | 739 | #define IP_VS_ZERO_STATS_COUNTER(c) stats->ustats0.c = stats->ustats.c |
745 | #define IP_VS_ZERO_STATS_RATE(r) stats->ustats.r = 0 | ||
746 | 740 | ||
747 | IP_VS_ZERO_STATS_COUNTER(conns); | 741 | IP_VS_ZERO_STATS_COUNTER(conns); |
748 | IP_VS_ZERO_STATS_COUNTER(inpkts); | 742 | IP_VS_ZERO_STATS_COUNTER(inpkts); |
@@ -750,12 +744,6 @@ ip_vs_zero_stats(struct ip_vs_stats *stats) | |||
750 | IP_VS_ZERO_STATS_COUNTER(inbytes); | 744 | IP_VS_ZERO_STATS_COUNTER(inbytes); |
751 | IP_VS_ZERO_STATS_COUNTER(outbytes); | 745 | IP_VS_ZERO_STATS_COUNTER(outbytes); |
752 | 746 | ||
753 | IP_VS_ZERO_STATS_RATE(cps); | ||
754 | IP_VS_ZERO_STATS_RATE(inpps); | ||
755 | IP_VS_ZERO_STATS_RATE(outpps); | ||
756 | IP_VS_ZERO_STATS_RATE(inbps); | ||
757 | IP_VS_ZERO_STATS_RATE(outbps); | ||
758 | |||
759 | ip_vs_zero_estimator(stats); | 747 | ip_vs_zero_estimator(stats); |
760 | 748 | ||
761 | spin_unlock_bh(&stats->lock); | 749 | spin_unlock_bh(&stats->lock); |
@@ -2043,6 +2031,7 @@ static int ip_vs_stats_percpu_show(struct seq_file *seq, void *v) | |||
2043 | struct net *net = seq_file_single_net(seq); | 2031 | struct net *net = seq_file_single_net(seq); |
2044 | struct ip_vs_stats *tot_stats = &net_ipvs(net)->tot_stats; | 2032 | struct ip_vs_stats *tot_stats = &net_ipvs(net)->tot_stats; |
2045 | struct ip_vs_cpu_stats *cpustats = tot_stats->cpustats; | 2033 | struct ip_vs_cpu_stats *cpustats = tot_stats->cpustats; |
2034 | struct ip_vs_stats_user rates; | ||
2046 | int i; | 2035 | int i; |
2047 | 2036 | ||
2048 | /* 01234567 01234567 01234567 0123456701234567 0123456701234567 */ | 2037 | /* 01234567 01234567 01234567 0123456701234567 0123456701234567 */ |
@@ -2069,22 +2058,26 @@ static int ip_vs_stats_percpu_show(struct seq_file *seq, void *v) | |||
2069 | } | 2058 | } |
2070 | 2059 | ||
2071 | spin_lock_bh(&tot_stats->lock); | 2060 | spin_lock_bh(&tot_stats->lock); |
2061 | |||
2072 | seq_printf(seq, " ~ %8X %8X %8X %16LX %16LX\n\n", | 2062 | seq_printf(seq, " ~ %8X %8X %8X %16LX %16LX\n\n", |
2073 | tot_stats->ustats.conns, tot_stats->ustats.inpkts, | 2063 | tot_stats->ustats.conns, tot_stats->ustats.inpkts, |
2074 | tot_stats->ustats.outpkts, | 2064 | tot_stats->ustats.outpkts, |
2075 | (unsigned long long) tot_stats->ustats.inbytes, | 2065 | (unsigned long long) tot_stats->ustats.inbytes, |
2076 | (unsigned long long) tot_stats->ustats.outbytes); | 2066 | (unsigned long long) tot_stats->ustats.outbytes); |
2077 | 2067 | ||
2068 | ip_vs_read_estimator(&rates, tot_stats); | ||
2069 | |||
2070 | spin_unlock_bh(&tot_stats->lock); | ||
2071 | |||
2078 | /* 01234567 01234567 01234567 0123456701234567 0123456701234567 */ | 2072 | /* 01234567 01234567 01234567 0123456701234567 0123456701234567 */ |
2079 | seq_puts(seq, | 2073 | seq_puts(seq, |
2080 | " Conns/s Pkts/s Pkts/s Bytes/s Bytes/s\n"); | 2074 | " Conns/s Pkts/s Pkts/s Bytes/s Bytes/s\n"); |
2081 | seq_printf(seq, " %8X %8X %8X %16X %16X\n", | 2075 | seq_printf(seq, " %8X %8X %8X %16X %16X\n", |
2082 | tot_stats->ustats.cps, | 2076 | rates.cps, |
2083 | tot_stats->ustats.inpps, | 2077 | rates.inpps, |
2084 | tot_stats->ustats.outpps, | 2078 | rates.outpps, |
2085 | tot_stats->ustats.inbps, | 2079 | rates.inbps, |
2086 | tot_stats->ustats.outbps); | 2080 | rates.outbps); |
2087 | spin_unlock_bh(&tot_stats->lock); | ||
2088 | 2081 | ||
2089 | return 0; | 2082 | return 0; |
2090 | } | 2083 | } |
diff --git a/net/netfilter/ipvs/ip_vs_est.c b/net/netfilter/ipvs/ip_vs_est.c index a85008796370..fda75be231e8 100644 --- a/net/netfilter/ipvs/ip_vs_est.c +++ b/net/netfilter/ipvs/ip_vs_est.c | |||
@@ -117,27 +117,22 @@ static void estimation_timer(unsigned long arg) | |||
117 | rate = (n_conns - e->last_conns) << 9; | 117 | rate = (n_conns - e->last_conns) << 9; |
118 | e->last_conns = n_conns; | 118 | e->last_conns = n_conns; |
119 | e->cps += ((long)rate - (long)e->cps) >> 2; | 119 | e->cps += ((long)rate - (long)e->cps) >> 2; |
120 | s->ustats.cps = (e->cps + 0x1FF) >> 10; | ||
121 | 120 | ||
122 | rate = (n_inpkts - e->last_inpkts) << 9; | 121 | rate = (n_inpkts - e->last_inpkts) << 9; |
123 | e->last_inpkts = n_inpkts; | 122 | e->last_inpkts = n_inpkts; |
124 | e->inpps += ((long)rate - (long)e->inpps) >> 2; | 123 | e->inpps += ((long)rate - (long)e->inpps) >> 2; |
125 | s->ustats.inpps = (e->inpps + 0x1FF) >> 10; | ||
126 | 124 | ||
127 | rate = (n_outpkts - e->last_outpkts) << 9; | 125 | rate = (n_outpkts - e->last_outpkts) << 9; |
128 | e->last_outpkts = n_outpkts; | 126 | e->last_outpkts = n_outpkts; |
129 | e->outpps += ((long)rate - (long)e->outpps) >> 2; | 127 | e->outpps += ((long)rate - (long)e->outpps) >> 2; |
130 | s->ustats.outpps = (e->outpps + 0x1FF) >> 10; | ||
131 | 128 | ||
132 | rate = (n_inbytes - e->last_inbytes) << 4; | 129 | rate = (n_inbytes - e->last_inbytes) << 4; |
133 | e->last_inbytes = n_inbytes; | 130 | e->last_inbytes = n_inbytes; |
134 | e->inbps += ((long)rate - (long)e->inbps) >> 2; | 131 | e->inbps += ((long)rate - (long)e->inbps) >> 2; |
135 | s->ustats.inbps = (e->inbps + 0xF) >> 5; | ||
136 | 132 | ||
137 | rate = (n_outbytes - e->last_outbytes) << 4; | 133 | rate = (n_outbytes - e->last_outbytes) << 4; |
138 | e->last_outbytes = n_outbytes; | 134 | e->last_outbytes = n_outbytes; |
139 | e->outbps += ((long)rate - (long)e->outbps) >> 2; | 135 | e->outbps += ((long)rate - (long)e->outbps) >> 2; |
140 | s->ustats.outbps = (e->outbps + 0xF) >> 5; | ||
141 | spin_unlock(&s->lock); | 136 | spin_unlock(&s->lock); |
142 | } | 137 | } |
143 | spin_unlock(&ipvs->est_lock); | 138 | spin_unlock(&ipvs->est_lock); |
@@ -151,21 +146,6 @@ void ip_vs_new_estimator(struct net *net, struct ip_vs_stats *stats) | |||
151 | 146 | ||
152 | INIT_LIST_HEAD(&est->list); | 147 | INIT_LIST_HEAD(&est->list); |
153 | 148 | ||
154 | est->last_conns = stats->ustats.conns; | ||
155 | est->cps = stats->ustats.cps<<10; | ||
156 | |||
157 | est->last_inpkts = stats->ustats.inpkts; | ||
158 | est->inpps = stats->ustats.inpps<<10; | ||
159 | |||
160 | est->last_outpkts = stats->ustats.outpkts; | ||
161 | est->outpps = stats->ustats.outpps<<10; | ||
162 | |||
163 | est->last_inbytes = stats->ustats.inbytes; | ||
164 | est->inbps = stats->ustats.inbps<<5; | ||
165 | |||
166 | est->last_outbytes = stats->ustats.outbytes; | ||
167 | est->outbps = stats->ustats.outbps<<5; | ||
168 | |||
169 | spin_lock_bh(&ipvs->est_lock); | 149 | spin_lock_bh(&ipvs->est_lock); |
170 | list_add(&est->list, &ipvs->est_list); | 150 | list_add(&est->list, &ipvs->est_list); |
171 | spin_unlock_bh(&ipvs->est_lock); | 151 | spin_unlock_bh(&ipvs->est_lock); |
@@ -199,6 +179,19 @@ void ip_vs_zero_estimator(struct ip_vs_stats *stats) | |||
199 | est->outbps = 0; | 179 | est->outbps = 0; |
200 | } | 180 | } |
201 | 181 | ||
182 | /* Get decoded rates */ | ||
183 | void ip_vs_read_estimator(struct ip_vs_stats_user *dst, | ||
184 | struct ip_vs_stats *stats) | ||
185 | { | ||
186 | struct ip_vs_estimator *e = &stats->est; | ||
187 | |||
188 | dst->cps = (e->cps + 0x1FF) >> 10; | ||
189 | dst->inpps = (e->inpps + 0x1FF) >> 10; | ||
190 | dst->outpps = (e->outpps + 0x1FF) >> 10; | ||
191 | dst->inbps = (e->inbps + 0xF) >> 5; | ||
192 | dst->outbps = (e->outbps + 0xF) >> 5; | ||
193 | } | ||
194 | |||
202 | static int __net_init __ip_vs_estimator_init(struct net *net) | 195 | static int __net_init __ip_vs_estimator_init(struct net *net) |
203 | { | 196 | { |
204 | struct netns_ipvs *ipvs = net_ipvs(net); | 197 | struct netns_ipvs *ipvs = net_ipvs(net); |