From: hawkes@sgi.com In 'net' change the explicit use of for-loops and NR_CPUS into the general for_each_cpu() or for_each_online_cpu() constructs, as appropriate. This widens the scope of potential future optimizations of the general constructs, as well as takes advantage of the existing optimizations of first_cpu() and next_cpu(), which is advantageous when the true CPU count is much smaller than NR_CPUS. Signed-off-by: John Hawkes Cc: "David S. Miller" Signed-off-by: Andrew Morton --- net/core/neighbour.c | 5 +---- net/core/pktgen.c | 5 +---- net/ipv4/icmp.c | 5 +---- net/ipv4/proc.c | 4 +--- net/ipv6/icmp.c | 9 ++------- net/ipv6/proc.c | 4 +--- net/sctp/proc.c | 4 +--- 7 files changed, 8 insertions(+), 28 deletions(-) diff -puN net/core/neighbour.c~net-wider-use-of-for_each_cpu net/core/neighbour.c --- 25/net/core/neighbour.c~net-wider-use-of-for_each_cpu Tue Oct 18 15:17:52 2005 +++ 25-akpm/net/core/neighbour.c Tue Oct 18 15:17:52 2005 @@ -1641,12 +1641,9 @@ static int neightbl_fill_info(struct nei memset(&ndst, 0, sizeof(ndst)); - for (cpu = 0; cpu < NR_CPUS; cpu++) { + for_each_cpu(cpu) { struct neigh_statistics *st; - if (!cpu_possible(cpu)) - continue; - st = per_cpu_ptr(tbl->stats, cpu); ndst.ndts_allocs += st->allocs; ndst.ndts_destroys += st->destroys; diff -puN net/core/pktgen.c~net-wider-use-of-for_each_cpu net/core/pktgen.c --- 25/net/core/pktgen.c~net-wider-use-of-for_each_cpu Tue Oct 18 15:17:52 2005 +++ 25-akpm/net/core/pktgen.c Tue Oct 18 15:17:52 2005 @@ -3065,12 +3065,9 @@ static int __init pg_init(void) /* Register us to receive netdevice events */ register_netdevice_notifier(&pktgen_notifier_block); - for (cpu = 0; cpu < NR_CPUS ; cpu++) { + for_each_online_cpu(cpu) { char buf[30]; - if (!cpu_online(cpu)) - continue; - sprintf(buf, "kpktgend_%i", cpu); pktgen_create_thread(buf, cpu); } diff -puN net/ipv4/icmp.c~net-wider-use-of-for_each_cpu net/ipv4/icmp.c --- 25/net/ipv4/icmp.c~net-wider-use-of-for_each_cpu Tue Oct 18 15:17:52 2005 +++ 25-akpm/net/ipv4/icmp.c Tue Oct 18 15:17:52 2005 @@ -1108,12 +1108,9 @@ void __init icmp_init(struct net_proto_f struct inet_sock *inet; int i; - for (i = 0; i < NR_CPUS; i++) { + for_each_cpu(i) { int err; - if (!cpu_possible(i)) - continue; - err = sock_create_kern(PF_INET, SOCK_RAW, IPPROTO_ICMP, &per_cpu(__icmp_socket, i)); diff -puN net/ipv4/proc.c~net-wider-use-of-for_each_cpu net/ipv4/proc.c --- 25/net/ipv4/proc.c~net-wider-use-of-for_each_cpu Tue Oct 18 15:17:52 2005 +++ 25-akpm/net/ipv4/proc.c Tue Oct 18 15:17:52 2005 @@ -90,9 +90,7 @@ fold_field(void *mib[], int offt) unsigned long res = 0; int i; - for (i = 0; i < NR_CPUS; i++) { - if (!cpu_possible(i)) - continue; + for_each_cpu(i) { res += *(((unsigned long *) per_cpu_ptr(mib[0], i)) + offt); res += *(((unsigned long *) per_cpu_ptr(mib[1], i)) + offt); } diff -puN net/ipv6/icmp.c~net-wider-use-of-for_each_cpu net/ipv6/icmp.c --- 25/net/ipv6/icmp.c~net-wider-use-of-for_each_cpu Tue Oct 18 15:17:52 2005 +++ 25-akpm/net/ipv6/icmp.c Tue Oct 18 15:17:52 2005 @@ -700,10 +700,7 @@ int __init icmpv6_init(struct net_proto_ struct sock *sk; int err, i, j; - for (i = 0; i < NR_CPUS; i++) { - if (!cpu_possible(i)) - continue; - + for_each_cpu(i) { err = sock_create_kern(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6, &per_cpu(__icmpv6_socket, i)); if (err < 0) { @@ -749,9 +746,7 @@ void icmpv6_cleanup(void) { int i; - for (i = 0; i < NR_CPUS; i++) { - if (!cpu_possible(i)) - continue; + for_each_cpu(i) { sock_release(per_cpu(__icmpv6_socket, i)); } inet6_del_protocol(&icmpv6_protocol, IPPROTO_ICMPV6); diff -puN net/ipv6/proc.c~net-wider-use-of-for_each_cpu net/ipv6/proc.c --- 25/net/ipv6/proc.c~net-wider-use-of-for_each_cpu Tue Oct 18 15:17:52 2005 +++ 25-akpm/net/ipv6/proc.c Tue Oct 18 15:17:52 2005 @@ -140,9 +140,7 @@ fold_field(void *mib[], int offt) unsigned long res = 0; int i; - for (i = 0; i < NR_CPUS; i++) { - if (!cpu_possible(i)) - continue; + for_each_cpu(i) { res += *(((unsigned long *)per_cpu_ptr(mib[0], i)) + offt); res += *(((unsigned long *)per_cpu_ptr(mib[1], i)) + offt); } diff -puN net/sctp/proc.c~net-wider-use-of-for_each_cpu net/sctp/proc.c --- 25/net/sctp/proc.c~net-wider-use-of-for_each_cpu Tue Oct 18 15:17:52 2005 +++ 25-akpm/net/sctp/proc.c Tue Oct 18 15:17:52 2005 @@ -69,9 +69,7 @@ fold_field(void *mib[], int nr) unsigned long res = 0; int i; - for (i = 0; i < NR_CPUS; i++) { - if (!cpu_possible(i)) - continue; + for_each_cpu(i) { res += *((unsigned long *) (((void *) per_cpu_ptr(mib[0], i)) + sizeof (unsigned long) * nr)); _