Commit 6d089f76 authored by Rusty Russell's avatar Rusty Russell Committed by David S. Miller

ipv4/route.c: Cleanup ip_rt_acct_read

parent 02262b73
...@@ -2418,10 +2418,15 @@ ctl_table ipv4_route_table[] = { ...@@ -2418,10 +2418,15 @@ ctl_table ipv4_route_table[] = {
#ifdef CONFIG_NET_CLS_ROUTE #ifdef CONFIG_NET_CLS_ROUTE
struct ip_rt_acct *ip_rt_acct; struct ip_rt_acct *ip_rt_acct;
/* This code sucks. But you should have seen it before! --RR */
/* IP route accounting ptr for this logical cpu number. */
#define IP_RT_ACCT_CPU(i) (ip_rt_acct + cpu_logical_map(i) * 256)
static int ip_rt_acct_read(char *buffer, char **start, off_t offset, static int ip_rt_acct_read(char *buffer, char **start, off_t offset,
int length, int *eof, void *data) int length, int *eof, void *data)
{ {
*start = buffer; unsigned int i;
if ((offset & 3) || (length & 3)) if ((offset & 3) || (length & 3))
return -EIO; return -EIO;
...@@ -2430,35 +2435,18 @@ static int ip_rt_acct_read(char *buffer, char **start, off_t offset, ...@@ -2430,35 +2435,18 @@ static int ip_rt_acct_read(char *buffer, char **start, off_t offset,
length = sizeof(struct ip_rt_acct) * 256 - offset; length = sizeof(struct ip_rt_acct) * 256 - offset;
*eof = 1; *eof = 1;
} }
if (length > 0) {
u32 *dst = (u32*)buffer;
u32 *src = (u32*)(((u8*)ip_rt_acct) + offset);
memcpy(dst, src, length);
#ifdef CONFIG_SMP
if (smp_num_cpus > 1 || cpu_logical_map(0) != 0) {
int i;
int cnt = length / 4;
for (i = 0; i < smp_num_cpus; i++) {
int cpu = cpu_logical_map(i);
int k;
if (cpu == 0) /* Copy first cpu. */
continue; *start = buffer;
memcpy(buffer, IP_RT_ACCT_CPU(0), length);
src = (u32*)(((u8*)ip_rt_acct) + offset +
cpu * 256 * sizeof(struct ip_rt_acct));
for (k = 0; k < cnt; k++) /* Add the other cpus in, one int at a time */
dst[k] += src[k]; for (i = 1; i < smp_num_cpus; i++) {
} unsigned int j;
for (j = 0; j < length/4; j++)
((u32*)buffer)[j] += ((u32*)IP_RT_ACCT_CPU(i))[j];
} }
#endif
return length; return length;
}
return 0;
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment