diff options
author | Eric Dumazet <dada1@cosmosbay.com> | 2006-10-18 23:51:57 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2006-10-18 23:51:57 -0400 |
commit | 5175c3786c244f8b689854db24c9e79b1c6a084f (patch) | |
tree | 459975fe6a7b6dd5294b362397b185959b4ab96d /drivers/net | |
parent | 9ce8ade015a3f82dbdf856df7a685878dd1cc0e1 (diff) |
[NET]: reduce per cpu ram used for loopback stats
We dont need a full struct net_device_stats (currently 23 long : 184 bytes on
x86_64) per possible CPU, but only two counters : bytes and packets
We save few CPU cycles too in loopback_xmit() not updating 4 fields, but 2.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/loopback.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 4178b4b1d2df..93fbea1c9271 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c | |||
@@ -58,7 +58,11 @@ | |||
58 | #include <linux/tcp.h> | 58 | #include <linux/tcp.h> |
59 | #include <linux/percpu.h> | 59 | #include <linux/percpu.h> |
60 | 60 | ||
61 | static DEFINE_PER_CPU(struct net_device_stats, loopback_stats); | 61 | struct pcpu_lstats { |
62 | unsigned long packets; | ||
63 | unsigned long bytes; | ||
64 | }; | ||
65 | static DEFINE_PER_CPU(struct pcpu_lstats, pcpu_lstats); | ||
62 | 66 | ||
63 | #define LOOPBACK_OVERHEAD (128 + MAX_HEADER + 16 + 16) | 67 | #define LOOPBACK_OVERHEAD (128 + MAX_HEADER + 16 + 16) |
64 | 68 | ||
@@ -128,7 +132,7 @@ static void emulate_large_send_offload(struct sk_buff *skb) | |||
128 | */ | 132 | */ |
129 | static int loopback_xmit(struct sk_buff *skb, struct net_device *dev) | 133 | static int loopback_xmit(struct sk_buff *skb, struct net_device *dev) |
130 | { | 134 | { |
131 | struct net_device_stats *lb_stats; | 135 | struct pcpu_lstats *lb_stats; |
132 | 136 | ||
133 | skb_orphan(skb); | 137 | skb_orphan(skb); |
134 | 138 | ||
@@ -149,11 +153,9 @@ static int loopback_xmit(struct sk_buff *skb, struct net_device *dev) | |||
149 | #endif | 153 | #endif |
150 | dev->last_rx = jiffies; | 154 | dev->last_rx = jiffies; |
151 | 155 | ||
152 | lb_stats = &per_cpu(loopback_stats, get_cpu()); | 156 | lb_stats = &per_cpu(pcpu_lstats, get_cpu()); |
153 | lb_stats->rx_bytes += skb->len; | 157 | lb_stats->bytes += skb->len; |
154 | lb_stats->tx_bytes = lb_stats->rx_bytes; | 158 | lb_stats->packets++; |
155 | lb_stats->rx_packets++; | ||
156 | lb_stats->tx_packets = lb_stats->rx_packets; | ||
157 | put_cpu(); | 159 | put_cpu(); |
158 | 160 | ||
159 | netif_rx(skb); | 161 | netif_rx(skb); |
@@ -166,20 +168,21 @@ static struct net_device_stats loopback_stats; | |||
166 | static struct net_device_stats *get_stats(struct net_device *dev) | 168 | static struct net_device_stats *get_stats(struct net_device *dev) |
167 | { | 169 | { |
168 | struct net_device_stats *stats = &loopback_stats; | 170 | struct net_device_stats *stats = &loopback_stats; |
171 | unsigned long bytes = 0; | ||
172 | unsigned long packets = 0; | ||
169 | int i; | 173 | int i; |
170 | 174 | ||
171 | memset(stats, 0, sizeof(struct net_device_stats)); | ||
172 | |||
173 | for_each_possible_cpu(i) { | 175 | for_each_possible_cpu(i) { |
174 | struct net_device_stats *lb_stats; | 176 | const struct pcpu_lstats *lb_stats; |
175 | 177 | ||
176 | lb_stats = &per_cpu(loopback_stats, i); | 178 | lb_stats = &per_cpu(pcpu_lstats, i); |
177 | stats->rx_bytes += lb_stats->rx_bytes; | 179 | bytes += lb_stats->bytes; |
178 | stats->tx_bytes += lb_stats->tx_bytes; | 180 | packets += lb_stats->packets; |
179 | stats->rx_packets += lb_stats->rx_packets; | ||
180 | stats->tx_packets += lb_stats->tx_packets; | ||
181 | } | 181 | } |
182 | 182 | stats->rx_packets = packets; | |
183 | stats->tx_packets = packets; | ||
184 | stats->rx_bytes = bytes; | ||
185 | stats->tx_bytes = bytes; | ||
183 | return stats; | 186 | return stats; |
184 | } | 187 | } |
185 | 188 | ||