diff options
author | Jarno Rajahalme <jrajahalme@nicira.com> | 2014-05-05 12:54:49 -0400 |
---|---|---|
committer | Pravin B Shelar <pshelar@nicira.com> | 2014-05-22 19:27:34 -0400 |
commit | 1139e241ec436b9e9610c7a33ac5c6657f87fda1 (patch) | |
tree | 55695454aef14f07009148a6919b52c04308152a /net/openvswitch/flow.h | |
parent | 091b64868b43ed84334c6623ea6a08497529d4ff (diff) |
openvswitch: Compact sw_flow_key.
Minimize padding in sw_flow_key and move 'tp' top the main struct.
These changes simplify code when accessing the transport port numbers
and the tcp flags, and makes the sw_flow_key 8 bytes smaller on 64-bit
systems (128->120 bytes). These changes also make the keys for IPv4
packets to fit in one cache line.
There is a valid concern for safety of packing the struct
ovs_key_ipv4_tunnel, as it would be possible to take the address of
the tun_id member as a __be64 * which could result in unaligned access
in some systems. However:
- sw_flow_key itself is 64-bit aligned, so the tun_id within is
always
64-bit aligned.
- We never make arrays of ovs_key_ipv4_tunnel (which would force
every
second tun_key to be misaligned).
- We never take the address of the tun_id in to a __be64 *.
- Whereever we use struct ovs_key_ipv4_tunnel outside the
sw_flow_key,
it is in stack (on tunnel input functions), where compiler has full
control of the alignment.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Diffstat (limited to 'net/openvswitch/flow.h')
-rw-r--r-- | net/openvswitch/flow.h | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/net/openvswitch/flow.h b/net/openvswitch/flow.h index ddcebc53224f..a292bf8ad75c 100644 --- a/net/openvswitch/flow.h +++ b/net/openvswitch/flow.h | |||
@@ -47,7 +47,7 @@ struct ovs_key_ipv4_tunnel { | |||
47 | __be16 tun_flags; | 47 | __be16 tun_flags; |
48 | u8 ipv4_tos; | 48 | u8 ipv4_tos; |
49 | u8 ipv4_ttl; | 49 | u8 ipv4_ttl; |
50 | }; | 50 | } __packed __aligned(4); /* Minimize padding. */ |
51 | 51 | ||
52 | static inline void ovs_flow_tun_key_init(struct ovs_key_ipv4_tunnel *tun_key, | 52 | static inline void ovs_flow_tun_key_init(struct ovs_key_ipv4_tunnel *tun_key, |
53 | const struct iphdr *iph, __be64 tun_id, | 53 | const struct iphdr *iph, __be64 tun_id, |
@@ -71,7 +71,7 @@ struct sw_flow_key { | |||
71 | u32 priority; /* Packet QoS priority. */ | 71 | u32 priority; /* Packet QoS priority. */ |
72 | u32 skb_mark; /* SKB mark. */ | 72 | u32 skb_mark; /* SKB mark. */ |
73 | u16 in_port; /* Input switch port (or DP_MAX_PORTS). */ | 73 | u16 in_port; /* Input switch port (or DP_MAX_PORTS). */ |
74 | } phy; | 74 | } __packed phy; /* Safe when right after 'tun_key'. */ |
75 | struct { | 75 | struct { |
76 | u8 src[ETH_ALEN]; /* Ethernet source address. */ | 76 | u8 src[ETH_ALEN]; /* Ethernet source address. */ |
77 | u8 dst[ETH_ALEN]; /* Ethernet destination address. */ | 77 | u8 dst[ETH_ALEN]; /* Ethernet destination address. */ |
@@ -84,23 +84,21 @@ struct sw_flow_key { | |||
84 | u8 ttl; /* IP TTL/hop limit. */ | 84 | u8 ttl; /* IP TTL/hop limit. */ |
85 | u8 frag; /* One of OVS_FRAG_TYPE_*. */ | 85 | u8 frag; /* One of OVS_FRAG_TYPE_*. */ |
86 | } ip; | 86 | } ip; |
87 | struct { | ||
88 | __be16 src; /* TCP/UDP/SCTP source port. */ | ||
89 | __be16 dst; /* TCP/UDP/SCTP destination port. */ | ||
90 | __be16 flags; /* TCP flags. */ | ||
91 | } tp; | ||
87 | union { | 92 | union { |
88 | struct { | 93 | struct { |
89 | struct { | 94 | struct { |
90 | __be32 src; /* IP source address. */ | 95 | __be32 src; /* IP source address. */ |
91 | __be32 dst; /* IP destination address. */ | 96 | __be32 dst; /* IP destination address. */ |
92 | } addr; | 97 | } addr; |
93 | union { | 98 | struct { |
94 | struct { | 99 | u8 sha[ETH_ALEN]; /* ARP source hardware address. */ |
95 | __be16 src; /* TCP/UDP/SCTP source port. */ | 100 | u8 tha[ETH_ALEN]; /* ARP target hardware address. */ |
96 | __be16 dst; /* TCP/UDP/SCTP destination port. */ | 101 | } arp; |
97 | __be16 flags; /* TCP flags. */ | ||
98 | } tp; | ||
99 | struct { | ||
100 | u8 sha[ETH_ALEN]; /* ARP source hardware address. */ | ||
101 | u8 tha[ETH_ALEN]; /* ARP target hardware address. */ | ||
102 | } arp; | ||
103 | }; | ||
104 | } ipv4; | 102 | } ipv4; |
105 | struct { | 103 | struct { |
106 | struct { | 104 | struct { |
@@ -109,11 +107,6 @@ struct sw_flow_key { | |||
109 | } addr; | 107 | } addr; |
110 | __be32 label; /* IPv6 flow label. */ | 108 | __be32 label; /* IPv6 flow label. */ |
111 | struct { | 109 | struct { |
112 | __be16 src; /* TCP/UDP/SCTP source port. */ | ||
113 | __be16 dst; /* TCP/UDP/SCTP destination port. */ | ||
114 | __be16 flags; /* TCP flags. */ | ||
115 | } tp; | ||
116 | struct { | ||
117 | struct in6_addr target; /* ND target address. */ | 110 | struct in6_addr target; /* ND target address. */ |
118 | u8 sll[ETH_ALEN]; /* ND source link layer address. */ | 111 | u8 sll[ETH_ALEN]; /* ND source link layer address. */ |
119 | u8 tll[ETH_ALEN]; /* ND target link layer address. */ | 112 | u8 tll[ETH_ALEN]; /* ND target link layer address. */ |