aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/sock.h
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2012-11-30 04:49:27 -0500
committerDavid S. Miller <davem@davemloft.net>2012-11-30 15:02:56 -0500
commitce43b03e8889475817d427b1f3724c7e294b76eb (patch)
tree0cd6679992bd810371620fcab52c24ce39a89aa8 /include/net/sock.h
parentb02a80674ea3905926c1a942426008d732c47339 (diff)
net: move inet_dport/inet_num in sock_common
commit 68835aba4d9b (net: optimize INET input path further) moved some fields used for tcp/udp sockets lookup in the first cache line of struct sock_common. This patch moves inet_dport/inet_num as well, filling a 32bit hole on 64 bit arches and reducing number of cache line misses in lookups. Also change INET_MATCH()/INET_TW_MATCH() to perform the ports match before addresses match, as this check is more discriminant. Remove the hash check from MATCH() macros because we dont need to re validate the hash value after taking a refcount on socket, and use likely/unlikely compiler hints, as the sk_hash/hash check makes the following conditional tests 100% predicted by cpu. Introduce skc_addrpair/skc_portpair pair values to better document the alignment requirements of the port/addr pairs used in the various MATCH() macros, and remove some casts. The namespace check can also be done at last. This slightly improves TCP/UDP lookup times. IP/TCP early demux needs inet->rx_dst_ifindex and TCP needs inet->min_ttl, lets group them together in same cache line. With help from Ben Hutchings & Joe Perches. Idea of this patch came after Ling Ma proposal to move skc_hash to the beginning of struct sock_common, and should allow him to submit a final version of his patch. My tests show an improvement doing so. Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Ben Hutchings <bhutchings@solarflare.com> Cc: Joe Perches <joe@perches.com> Cc: Ling Ma <ling.ma.program@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/sock.h')
-rw-r--r--include/net/sock.h25
1 files changed, 20 insertions, 5 deletions
diff --git a/include/net/sock.h b/include/net/sock.h
index c945fba4f543..c4132c1b63a8 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -132,6 +132,8 @@ struct net;
132 * @skc_rcv_saddr: Bound local IPv4 addr 132 * @skc_rcv_saddr: Bound local IPv4 addr
133 * @skc_hash: hash value used with various protocol lookup tables 133 * @skc_hash: hash value used with various protocol lookup tables
134 * @skc_u16hashes: two u16 hash values used by UDP lookup tables 134 * @skc_u16hashes: two u16 hash values used by UDP lookup tables
135 * @skc_dport: placeholder for inet_dport/tw_dport
136 * @skc_num: placeholder for inet_num/tw_num
135 * @skc_family: network address family 137 * @skc_family: network address family
136 * @skc_state: Connection state 138 * @skc_state: Connection state
137 * @skc_reuse: %SO_REUSEADDR setting 139 * @skc_reuse: %SO_REUSEADDR setting
@@ -149,16 +151,29 @@ struct net;
149 * for struct sock and struct inet_timewait_sock. 151 * for struct sock and struct inet_timewait_sock.
150 */ 152 */
151struct sock_common { 153struct sock_common {
152 /* skc_daddr and skc_rcv_saddr must be grouped : 154 /* skc_daddr and skc_rcv_saddr must be grouped on a 8 bytes aligned
153 * cf INET_MATCH() and INET_TW_MATCH() 155 * address on 64bit arches : cf INET_MATCH() and INET_TW_MATCH()
154 */ 156 */
155 __be32 skc_daddr; 157 union {
156 __be32 skc_rcv_saddr; 158 unsigned long skc_addrpair;
157 159 struct {
160 __be32 skc_daddr;
161 __be32 skc_rcv_saddr;
162 };
163 };
158 union { 164 union {
159 unsigned int skc_hash; 165 unsigned int skc_hash;
160 __u16 skc_u16hashes[2]; 166 __u16 skc_u16hashes[2];
161 }; 167 };
168 /* skc_dport && skc_num must be grouped as well */
169 union {
170 u32 skc_portpair;
171 struct {
172 __be16 skc_dport;
173 __u16 skc_num;
174 };
175 };
176
162 unsigned short skc_family; 177 unsigned short skc_family;
163 volatile unsigned char skc_state; 178 volatile unsigned char skc_state;
164 unsigned char skc_reuse; 179 unsigned char skc_reuse;