aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Wegener <sven.wegener@stealer.net>2008-09-08 07:39:04 -0400
committerSimon Horman <horms@verge.net.au>2008-09-08 19:53:08 -0400
commite9c0ce232e7a36daae1ca08282609d7f0c57c567 (patch)
tree63ddde69fadab5a68788b37fd6813814be191176
parent2206a3f5b75be5dadf11541961bd7c924857eb5d (diff)
ipvs: Embed user stats structure into kernel stats structure
Instead of duplicating the fields, integrate a user stats structure into the kernel stats structure. This is more robust when the members are changed, because they are now automatically kept in sync. Signed-off-by: Sven Wegener <sven.wegener@stealer.net> Reviewed-by: Julius Volz <juliusv@google.com> Signed-off-by: Simon Horman <horms@verge.net.au>
-rw-r--r--include/net/ip_vs.h21
-rw-r--r--net/ipv4/ipvs/ip_vs_core.c30
-rw-r--r--net/ipv4/ipvs/ip_vs_ctl.c53
-rw-r--r--net/ipv4/ipvs/ip_vs_est.c40
4 files changed, 58 insertions, 86 deletions
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index 38f4f690b186..33e2ac6ceb3e 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -254,27 +254,10 @@ struct ip_vs_estimator {
254 254
255struct ip_vs_stats 255struct ip_vs_stats
256{ 256{
257 __u32 conns; /* connections scheduled */ 257 struct ip_vs_stats_user ustats; /* statistics */
258 __u32 inpkts; /* incoming packets */ 258 struct ip_vs_estimator est; /* estimator */
259 __u32 outpkts; /* outgoing packets */
260 __u64 inbytes; /* incoming bytes */
261 __u64 outbytes; /* outgoing bytes */
262
263 __u32 cps; /* current connection rate */
264 __u32 inpps; /* current in packet rate */
265 __u32 outpps; /* current out packet rate */
266 __u32 inbps; /* current in byte rate */
267 __u32 outbps; /* current out byte rate */
268
269 /*
270 * Don't add anything before the lock, because we use memcpy() to copy
271 * the members before the lock to struct ip_vs_stats_user in
272 * ip_vs_ctl.c.
273 */
274 259
275 spinlock_t lock; /* spin lock */ 260 spinlock_t lock; /* spin lock */
276
277 struct ip_vs_estimator est; /* estimator */
278}; 261};
279 262
280struct dst_entry; 263struct dst_entry;
diff --git a/net/ipv4/ipvs/ip_vs_core.c b/net/ipv4/ipvs/ip_vs_core.c
index bdc92d73fbee..80a4fcf33a54 100644
--- a/net/ipv4/ipvs/ip_vs_core.c
+++ b/net/ipv4/ipvs/ip_vs_core.c
@@ -102,18 +102,18 @@ ip_vs_in_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
102 struct ip_vs_dest *dest = cp->dest; 102 struct ip_vs_dest *dest = cp->dest;
103 if (dest && (dest->flags & IP_VS_DEST_F_AVAILABLE)) { 103 if (dest && (dest->flags & IP_VS_DEST_F_AVAILABLE)) {
104 spin_lock(&dest->stats.lock); 104 spin_lock(&dest->stats.lock);
105 dest->stats.inpkts++; 105 dest->stats.ustats.inpkts++;
106 dest->stats.inbytes += skb->len; 106 dest->stats.ustats.inbytes += skb->len;
107 spin_unlock(&dest->stats.lock); 107 spin_unlock(&dest->stats.lock);
108 108
109 spin_lock(&dest->svc->stats.lock); 109 spin_lock(&dest->svc->stats.lock);
110 dest->svc->stats.inpkts++; 110 dest->svc->stats.ustats.inpkts++;
111 dest->svc->stats.inbytes += skb->len; 111 dest->svc->stats.ustats.inbytes += skb->len;
112 spin_unlock(&dest->svc->stats.lock); 112 spin_unlock(&dest->svc->stats.lock);
113 113
114 spin_lock(&ip_vs_stats.lock); 114 spin_lock(&ip_vs_stats.lock);
115 ip_vs_stats.inpkts++; 115 ip_vs_stats.ustats.inpkts++;
116 ip_vs_stats.inbytes += skb->len; 116 ip_vs_stats.ustats.inbytes += skb->len;
117 spin_unlock(&ip_vs_stats.lock); 117 spin_unlock(&ip_vs_stats.lock);
118 } 118 }
119} 119}
@@ -125,18 +125,18 @@ ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
125 struct ip_vs_dest *dest = cp->dest; 125 struct ip_vs_dest *dest = cp->dest;
126 if (dest && (dest->flags & IP_VS_DEST_F_AVAILABLE)) { 126 if (dest && (dest->flags & IP_VS_DEST_F_AVAILABLE)) {
127 spin_lock(&dest->stats.lock); 127 spin_lock(&dest->stats.lock);
128 dest->stats.outpkts++; 128 dest->stats.ustats.outpkts++;
129 dest->stats.outbytes += skb->len; 129 dest->stats.ustats.outbytes += skb->len;
130 spin_unlock(&dest->stats.lock); 130 spin_unlock(&dest->stats.lock);
131 131
132 spin_lock(&dest->svc->stats.lock); 132 spin_lock(&dest->svc->stats.lock);
133 dest->svc->stats.outpkts++; 133 dest->svc->stats.ustats.outpkts++;
134 dest->svc->stats.outbytes += skb->len; 134 dest->svc->stats.ustats.outbytes += skb->len;
135 spin_unlock(&dest->svc->stats.lock); 135 spin_unlock(&dest->svc->stats.lock);
136 136
137 spin_lock(&ip_vs_stats.lock); 137 spin_lock(&ip_vs_stats.lock);
138 ip_vs_stats.outpkts++; 138 ip_vs_stats.ustats.outpkts++;
139 ip_vs_stats.outbytes += skb->len; 139 ip_vs_stats.ustats.outbytes += skb->len;
140 spin_unlock(&ip_vs_stats.lock); 140 spin_unlock(&ip_vs_stats.lock);
141 } 141 }
142} 142}
@@ -146,15 +146,15 @@ static inline void
146ip_vs_conn_stats(struct ip_vs_conn *cp, struct ip_vs_service *svc) 146ip_vs_conn_stats(struct ip_vs_conn *cp, struct ip_vs_service *svc)
147{ 147{
148 spin_lock(&cp->dest->stats.lock); 148 spin_lock(&cp->dest->stats.lock);
149 cp->dest->stats.conns++; 149 cp->dest->stats.ustats.conns++;
150 spin_unlock(&cp->dest->stats.lock); 150 spin_unlock(&cp->dest->stats.lock);
151 151
152 spin_lock(&svc->stats.lock); 152 spin_lock(&svc->stats.lock);
153 svc->stats.conns++; 153 svc->stats.ustats.conns++;
154 spin_unlock(&svc->stats.lock); 154 spin_unlock(&svc->stats.lock);
155 155
156 spin_lock(&ip_vs_stats.lock); 156 spin_lock(&ip_vs_stats.lock);
157 ip_vs_stats.conns++; 157 ip_vs_stats.ustats.conns++;
158 spin_unlock(&ip_vs_stats.lock); 158 spin_unlock(&ip_vs_stats.lock);
159} 159}
160 160
diff --git a/net/ipv4/ipvs/ip_vs_ctl.c b/net/ipv4/ipvs/ip_vs_ctl.c
index e53efe41f01d..993a83fb0d56 100644
--- a/net/ipv4/ipvs/ip_vs_ctl.c
+++ b/net/ipv4/ipvs/ip_vs_ctl.c
@@ -744,18 +744,7 @@ ip_vs_zero_stats(struct ip_vs_stats *stats)
744{ 744{
745 spin_lock_bh(&stats->lock); 745 spin_lock_bh(&stats->lock);
746 746
747 stats->conns = 0; 747 memset(&stats->ustats, 0, sizeof(stats->ustats));
748 stats->inpkts = 0;
749 stats->outpkts = 0;
750 stats->inbytes = 0;
751 stats->outbytes = 0;
752
753 stats->cps = 0;
754 stats->inpps = 0;
755 stats->outpps = 0;
756 stats->inbps = 0;
757 stats->outbps = 0;
758
759 ip_vs_zero_estimator(stats); 748 ip_vs_zero_estimator(stats);
760 749
761 spin_unlock_bh(&stats->lock); 750 spin_unlock_bh(&stats->lock);
@@ -1964,20 +1953,20 @@ static int ip_vs_stats_show(struct seq_file *seq, void *v)
1964 " Conns Packets Packets Bytes Bytes\n"); 1953 " Conns Packets Packets Bytes Bytes\n");
1965 1954
1966 spin_lock_bh(&ip_vs_stats.lock); 1955 spin_lock_bh(&ip_vs_stats.lock);
1967 seq_printf(seq, "%8X %8X %8X %16LX %16LX\n\n", ip_vs_stats.conns, 1956 seq_printf(seq, "%8X %8X %8X %16LX %16LX\n\n", ip_vs_stats.ustats.conns,
1968 ip_vs_stats.inpkts, ip_vs_stats.outpkts, 1957 ip_vs_stats.ustats.inpkts, ip_vs_stats.ustats.outpkts,
1969 (unsigned long long) ip_vs_stats.inbytes, 1958 (unsigned long long) ip_vs_stats.ustats.inbytes,
1970 (unsigned long long) ip_vs_stats.outbytes); 1959 (unsigned long long) ip_vs_stats.ustats.outbytes);
1971 1960
1972/* 01234567 01234567 01234567 0123456701234567 0123456701234567 */ 1961/* 01234567 01234567 01234567 0123456701234567 0123456701234567 */
1973 seq_puts(seq, 1962 seq_puts(seq,
1974 " Conns/s Pkts/s Pkts/s Bytes/s Bytes/s\n"); 1963 " Conns/s Pkts/s Pkts/s Bytes/s Bytes/s\n");
1975 seq_printf(seq,"%8X %8X %8X %16X %16X\n", 1964 seq_printf(seq,"%8X %8X %8X %16X %16X\n",
1976 ip_vs_stats.cps, 1965 ip_vs_stats.ustats.cps,
1977 ip_vs_stats.inpps, 1966 ip_vs_stats.ustats.inpps,
1978 ip_vs_stats.outpps, 1967 ip_vs_stats.ustats.outpps,
1979 ip_vs_stats.inbps, 1968 ip_vs_stats.ustats.inbps,
1980 ip_vs_stats.outbps); 1969 ip_vs_stats.ustats.outbps);
1981 spin_unlock_bh(&ip_vs_stats.lock); 1970 spin_unlock_bh(&ip_vs_stats.lock);
1982 1971
1983 return 0; 1972 return 0;
@@ -2215,7 +2204,7 @@ static void
2215ip_vs_copy_stats(struct ip_vs_stats_user *dst, struct ip_vs_stats *src) 2204ip_vs_copy_stats(struct ip_vs_stats_user *dst, struct ip_vs_stats *src)
2216{ 2205{
2217 spin_lock_bh(&src->lock); 2206 spin_lock_bh(&src->lock);
2218 memcpy(dst, src, (char*)&src->lock - (char*)src); 2207 memcpy(dst, &src->ustats, sizeof(*dst));
2219 spin_unlock_bh(&src->lock); 2208 spin_unlock_bh(&src->lock);
2220} 2209}
2221 2210
@@ -2591,16 +2580,16 @@ static int ip_vs_genl_fill_stats(struct sk_buff *skb, int container_type,
2591 2580
2592 spin_lock_bh(&stats->lock); 2581 spin_lock_bh(&stats->lock);
2593 2582
2594 NLA_PUT_U32(skb, IPVS_STATS_ATTR_CONNS, stats->conns); 2583 NLA_PUT_U32(skb, IPVS_STATS_ATTR_CONNS, stats->ustats.conns);
2595 NLA_PUT_U32(skb, IPVS_STATS_ATTR_INPKTS, stats->inpkts); 2584 NLA_PUT_U32(skb, IPVS_STATS_ATTR_INPKTS, stats->ustats.inpkts);
2596 NLA_PUT_U32(skb, IPVS_STATS_ATTR_OUTPKTS, stats->outpkts); 2585 NLA_PUT_U32(skb, IPVS_STATS_ATTR_OUTPKTS, stats->ustats.outpkts);
2597 NLA_PUT_U64(skb, IPVS_STATS_ATTR_INBYTES, stats->inbytes); 2586 NLA_PUT_U64(skb, IPVS_STATS_ATTR_INBYTES, stats->ustats.inbytes);
2598 NLA_PUT_U64(skb, IPVS_STATS_ATTR_OUTBYTES, stats->outbytes); 2587 NLA_PUT_U64(skb, IPVS_STATS_ATTR_OUTBYTES, stats->ustats.outbytes);
2599 NLA_PUT_U32(skb, IPVS_STATS_ATTR_CPS, stats->cps); 2588 NLA_PUT_U32(skb, IPVS_STATS_ATTR_CPS, stats->ustats.cps);
2600 NLA_PUT_U32(skb, IPVS_STATS_ATTR_INPPS, stats->inpps); 2589 NLA_PUT_U32(skb, IPVS_STATS_ATTR_INPPS, stats->ustats.inpps);
2601 NLA_PUT_U32(skb, IPVS_STATS_ATTR_OUTPPS, stats->outpps); 2590 NLA_PUT_U32(skb, IPVS_STATS_ATTR_OUTPPS, stats->ustats.outpps);
2602 NLA_PUT_U32(skb, IPVS_STATS_ATTR_INBPS, stats->inbps); 2591 NLA_PUT_U32(skb, IPVS_STATS_ATTR_INBPS, stats->ustats.inbps);
2603 NLA_PUT_U32(skb, IPVS_STATS_ATTR_OUTBPS, stats->outbps); 2592 NLA_PUT_U32(skb, IPVS_STATS_ATTR_OUTBPS, stats->ustats.outbps);
2604 2593
2605 spin_unlock_bh(&stats->lock); 2594 spin_unlock_bh(&stats->lock);
2606 2595
diff --git a/net/ipv4/ipvs/ip_vs_est.c b/net/ipv4/ipvs/ip_vs_est.c
index 4fb620ec2086..2eb2860dabb5 100644
--- a/net/ipv4/ipvs/ip_vs_est.c
+++ b/net/ipv4/ipvs/ip_vs_est.c
@@ -65,37 +65,37 @@ static void estimation_timer(unsigned long arg)
65 s = container_of(e, struct ip_vs_stats, est); 65 s = container_of(e, struct ip_vs_stats, est);
66 66
67 spin_lock(&s->lock); 67 spin_lock(&s->lock);
68 n_conns = s->conns; 68 n_conns = s->ustats.conns;
69 n_inpkts = s->inpkts; 69 n_inpkts = s->ustats.inpkts;
70 n_outpkts = s->outpkts; 70 n_outpkts = s->ustats.outpkts;
71 n_inbytes = s->inbytes; 71 n_inbytes = s->ustats.inbytes;
72 n_outbytes = s->outbytes; 72 n_outbytes = s->ustats.outbytes;
73 73
74 /* scaled by 2^10, but divided 2 seconds */ 74 /* scaled by 2^10, but divided 2 seconds */
75 rate = (n_conns - e->last_conns)<<9; 75 rate = (n_conns - e->last_conns)<<9;
76 e->last_conns = n_conns; 76 e->last_conns = n_conns;
77 e->cps += ((long)rate - (long)e->cps)>>2; 77 e->cps += ((long)rate - (long)e->cps)>>2;
78 s->cps = (e->cps+0x1FF)>>10; 78 s->ustats.cps = (e->cps+0x1FF)>>10;
79 79
80 rate = (n_inpkts - e->last_inpkts)<<9; 80 rate = (n_inpkts - e->last_inpkts)<<9;
81 e->last_inpkts = n_inpkts; 81 e->last_inpkts = n_inpkts;
82 e->inpps += ((long)rate - (long)e->inpps)>>2; 82 e->inpps += ((long)rate - (long)e->inpps)>>2;
83 s->inpps = (e->inpps+0x1FF)>>10; 83 s->ustats.inpps = (e->inpps+0x1FF)>>10;
84 84
85 rate = (n_outpkts - e->last_outpkts)<<9; 85 rate = (n_outpkts - e->last_outpkts)<<9;
86 e->last_outpkts = n_outpkts; 86 e->last_outpkts = n_outpkts;
87 e->outpps += ((long)rate - (long)e->outpps)>>2; 87 e->outpps += ((long)rate - (long)e->outpps)>>2;
88 s->outpps = (e->outpps+0x1FF)>>10; 88 s->ustats.outpps = (e->outpps+0x1FF)>>10;
89 89
90 rate = (n_inbytes - e->last_inbytes)<<4; 90 rate = (n_inbytes - e->last_inbytes)<<4;
91 e->last_inbytes = n_inbytes; 91 e->last_inbytes = n_inbytes;
92 e->inbps += ((long)rate - (long)e->inbps)>>2; 92 e->inbps += ((long)rate - (long)e->inbps)>>2;
93 s->inbps = (e->inbps+0xF)>>5; 93 s->ustats.inbps = (e->inbps+0xF)>>5;
94 94
95 rate = (n_outbytes - e->last_outbytes)<<4; 95 rate = (n_outbytes - e->last_outbytes)<<4;
96 e->last_outbytes = n_outbytes; 96 e->last_outbytes = n_outbytes;
97 e->outbps += ((long)rate - (long)e->outbps)>>2; 97 e->outbps += ((long)rate - (long)e->outbps)>>2;
98 s->outbps = (e->outbps+0xF)>>5; 98 s->ustats.outbps = (e->outbps+0xF)>>5;
99 spin_unlock(&s->lock); 99 spin_unlock(&s->lock);
100 } 100 }
101 spin_unlock(&est_lock); 101 spin_unlock(&est_lock);
@@ -108,20 +108,20 @@ void ip_vs_new_estimator(struct ip_vs_stats *stats)
108 108
109 INIT_LIST_HEAD(&est->list); 109 INIT_LIST_HEAD(&est->list);
110 110
111 est->last_conns = stats->conns; 111 est->last_conns = stats->ustats.conns;
112 est->cps = stats->cps<<10; 112 est->cps = stats->ustats.cps<<10;
113 113
114 est->last_inpkts = stats->inpkts; 114 est->last_inpkts = stats->ustats.inpkts;
115 est->inpps = stats->inpps<<10; 115 est->inpps = stats->ustats.inpps<<10;
116 116
117 est->last_outpkts = stats->outpkts; 117 est->last_outpkts = stats->ustats.outpkts;
118 est->outpps = stats->outpps<<10; 118 est->outpps = stats->ustats.outpps<<10;
119 119
120 est->last_inbytes = stats->inbytes; 120 est->last_inbytes = stats->ustats.inbytes;
121 est->inbps = stats->inbps<<5; 121 est->inbps = stats->ustats.inbps<<5;
122 122
123 est->last_outbytes = stats->outbytes; 123 est->last_outbytes = stats->ustats.outbytes;
124 est->outbps = stats->outbps<<5; 124 est->outbps = stats->ustats.outbps<<5;
125 125
126 spin_lock_bh(&est_lock); 126 spin_lock_bh(&est_lock);
127 list_add(&est->list, &est_list); 127 list_add(&est->list, &est_list);