net: Use __this_cpu_inc() in fast path
authorEric Dumazet <eric.dumazet@gmail.com>
Wed, 19 May 2010 22:07:23 +0000 (22:07 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 31 May 2010 07:24:01 +0000 (00:24 -0700)
This patch saves 224 bytes of text on my machine.

__this_cpu_inc() generates a single instruction, using no scratch
registers :

  65 ff 04 25 a8 30 01 00      incl   %gs:0x130a8

instead of :

  48 c7 c2 80 30 01 00         mov    $0x13080,%rdx
  65 48 8b 04 25 88 ea 00 00   mov    %gs:0xea88,%rax
  83 44 10 28 01               addl   $0x1,0x28(%rax,%rdx,1)

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/dev.c
net/ipv4/route.c

index 1845b08c624e1fa4c9dd398f4b61c2963dbfc1f2..7d76b056aa3d929deefdd6bb2ba41c38dd951d99 100644 (file)
@@ -2822,8 +2822,7 @@ static int __netif_receive_skb(struct sk_buff *skb)
                        skb->dev = master;
        }
 
-       __get_cpu_var(softnet_data).processed++;
-
+       __this_cpu_inc(softnet_data.processed);
        skb_reset_network_header(skb);
        skb_reset_transport_header(skb);
        skb->mac_len = skb->network_header - skb->mac_header;
index 560acc677ce485cce87a0161fa709f5e50b8e56f..8495bceec7643c43675821d50aec0a7ca8c66d1a 100644 (file)
@@ -253,8 +253,7 @@ static unsigned                     rt_hash_mask __read_mostly;
 static unsigned int            rt_hash_log  __read_mostly;
 
 static DEFINE_PER_CPU(struct rt_cache_stat, rt_cache_stat);
-#define RT_CACHE_STAT_INC(field) \
-       (__raw_get_cpu_var(rt_cache_stat).field++)
+#define RT_CACHE_STAT_INC(field) __this_cpu_inc(rt_cache_stat.field)
 
 static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
                                   int genid)