Open vSwitch
Subsystems (5)
A number of significant new features and optimizations for net-next/3.12. Highlights are:
* "Megaflows", an optimization that allows userspace to specify which flow fields were used to compute the results of the flow lookup. This allows for a major reduction in flow setups (the major performance bottleneck in Open vSwitch) without reducing flexibility.
* Converting netlink dump operations to use RCU, allowing for additional parallelism in userspace.
* Matching and modifying SCTP protocol fields.
The following changes since commit 2771399ac9986c75437a83b1c723493cfcdfa439:
fs_enet: cleanup clock API use (2013-08-22 22:13:54 -0700)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jesse/openvswitch.git master
for you to fetch changes up to 5828cd9a68873df1340b420371c02c47647878fb:
openvswitch: optimize flow compare and mask functions (2013-08-27 13:13:09 -0700)
----------------------------------------------------------------
Andy Zhou (3):
openvswitch: Mega flow implementation
openvswitch: Rename key_len to key_end
openvswitch: optimize flow compare and mask functions
Cong Wang (1):
openvswitch: check CONFIG_OPENVSWITCH_GRE in makefile
Jiri Pirko (1):
openvswitch:: link upper device for port devices
Joe Stringer (2):
net: Add NEXTHDR_SCTP to ipv6.h
openvswitch: Add SCTP support
Justin Pettit (1):
openvswitch: Fix argument descriptions in vport.c.
Pravin B Shelar (3):
openvswitch: Use RCU lock for flow dump operation.
openvswitch: Use RCU lock for dp dump operation.
openvswitch: Use non rcu hlist_del() flow table entry.
Documentation/networking/openvswitch.txt | 40 + include/net/ipv6.h | 1 + include/uapi/linux/openvswitch.h | 15 +- net/openvswitch/Kconfig | 1 + net/openvswitch/Makefile | 5 +- net/openvswitch/actions.c | 45 +- net/openvswitch/datapath.c | 176 ++-- net/openvswitch/datapath.h | 6 + net/openvswitch/flow.c | 1485 +++++++++++++++++++++--------- net/openvswitch/flow.h | 89 +- net/openvswitch/vport-gre.c | 3 - net/openvswitch/vport-netdev.c | 20 +- net/openvswitch/vport.c | 3 +- 13 files changed, 1346 insertions(+), 543 deletions(-)
A message that is not in the archive (sent off-list or not yet received): 1377634848-34327-1-git-send-email-jesse-l0M0P4e3n4LQT0dZR+AlfA@public.gmane.org
PATCH 1/11 openvswitch: Use RCU lock for flow dump operation.
From: Pravin B Shelar <[email protected]>
Flow dump operation is read-only operation. There is no need to take ovs-lock. Following patch use rcu-lock for dumping flows.
--- net/openvswitch/datapath.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
net/openvswitch/datapath.c +9 -8
@@ -1104,7 +1104,6 @@ static int ovs_flow_cmd_fill_info(struct sw_flow *flow, struct datapath *dp, u32 seq, u32 flags, u8 cmd) { const int skb_orig_len = skb->len; -const struct sw_flow_actions *sf_acts;struct nlattr *start;struct ovs_flow_stats stats;struct ovs_header *ovs_header;
@@ -1113,8 +1112,6 @@ static int ovs_flow_cmd_fill_info(struct sw_flow *flow, struct datapath *dp,u8 tcp_flags;int err; - sf_acts =ovsl_dereference (flow->sf_acts); - ovs_header =genlmsg_put (skb, portid, seq, &dp_flow_genl_family, flags, cmd);if (!ovs_header)return -EMSGSIZE ;
@@ -1161,6 +1158,11 @@ static int ovs_flow_cmd_fill_info(struct sw_flow *flow, struct datapath *dp,*/ start =nla_nest_start (skb,OVS_FLOW_ATTR_ACTIONS );if (start) { +const struct sw_flow_actions *sf_acts; + + sf_acts =rcu_dereference_check (flow->sf_acts, +lockdep_ovsl_is_held ()); + err =actions_to_attr (sf_acts->actions, sf_acts->actions_len, skb);if (!err)nla_nest_end (skb, start);
@@ -1440,15 +1442,14 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)struct datapath *dp;struct flow_table *table; -ovs_lock (); +rcu_read_lock (); dp =get_dp (sock_net (skb->sk), ovs_header->dp_ifindex);if (!dp) { -ovs_unlock (); +rcu_read_unlock ();return -ENODEV ; } - table =ovsl_dereference (dp->table); - + table =rcu_dereference (dp->table);for (;;) {struct sw_flow *flow;u32 bucket, obj;
@@ -1468,7 +1469,7 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) cb->args[0 ] = bucket; cb->args[1 ] = obj; } -ovs_unlock (); +rcu_read_unlock ();return skb->len; }
Signature · 1 line
1.8.1.2
PATCH 5/11 openvswitch: Fix argument descriptions in vport.c.
In reply to a message not in the archiveFrom: Justin Pettit <[email protected]>
--- net/openvswitch/vport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/openvswitch/vport.c +2 -1
@@ -203,7 +203,7 @@ out:* ovs_vport_set_options - modify existing vport device (for kernel callers) * * @vport: vport to modify. -* @port: New configuration. +* @options: New configuration. * * Modifies an existing device with the specified configuration (which is * dependent on device type). ovs_mutex must be held.
@@ -328,6 +328,7 @@ int ovs_vport_get_options(const struct vport *vport, struct sk_buff *skb)* * @vport: vport that received the packet * @skb: skb that was received +* @tun_key: tunnel (if any) that carried packet * * Must be called with rcu_read_lock. The packet cannot be shared and * skb->data should point to the Ethernet header.
Signature · 1 line
1.8.1.2
PATCH 2/11 openvswitch: Use RCU lock for dp dump operation.
In reply to Jesse GrossFrom: Pravin B Shelar <[email protected]>
RCUfy dp-dump operation which is already read-only. This makes all ovs dump operations lockless.
--- net/openvswitch/datapath.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
net/openvswitch/datapath.c +7 -6
@@ -951,9 +951,10 @@ static struct genl_ops dp_packet_genl_ops[] = {static void get_dp_stats (struct datapath *dp,struct ovs_dp_stats *stats) { +struct flow_table *table;int i; -struct flow_table *table =ovsl_dereference (dp->table); + table =rcu_dereference_check (dp->table,lockdep_ovsl_is_held ()); stats->n_flows =ovs_flow_tbl_count (table); stats->n_hit = stats->n_missed = stats->n_lost =0 ;
@@ -1665,7 +1666,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) goto err_destroy_local_port; ovs_net =net_generic (ovs_dp_get_net (dp), ovs_net_id); -list_add_tail (&dp->list_node, &ovs_net->dps); +list_add_tail_rcu (&dp->list_node, &ovs_net->dps);ovs_unlock ();
@@ -1703,7 +1704,7 @@ static void __dp_destroy(struct datapath *dp)ovs_dp_detach_port (vport); } -list_del (&dp->list_node); +list_del_rcu (&dp->list_node);/* OVSP_LOCAL is datapath internal port. We need to make sure that * all port in datapath are destroyed first before freeing datapath.
@@ -1808,8 +1809,8 @@ static int ovs_dp_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)int skip = cb->args[0 ];int i =0 ; -ovs_lock (); - list_for_each_entry(dp, &ovs_net->dps, list_node) { +rcu_read_lock (); + list_for_each_entry_rcu(dp, &ovs_net->dps, list_node) { if (i >= skip && ovs_dp_cmd_fill_info(dp, skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, NLM_F_MULTI,
@@ -1817,7 +1818,7 @@ static int ovs_dp_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)break ; i++; } -ovs_unlock (); +rcu_read_unlock (); cb->args[0 ] = i;
Signature · 1 line
1.8.1.2
PATCH 3/11 openvswitch: Use non rcu hlist_del() flow table entry.
In reply to Jesse GrossFrom: Pravin B Shelar <[email protected]>
Flow table destroy is done in rcu call-back context. Therefore there is no need to use rcu variant of hlist_del().
--- net/openvswitch/flow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/openvswitch/flow.c +1 -1
@@ -302,7 +302,7 @@ void ovs_flow_tbl_destroy(struct flow_table *table)int ver = table->node_ver;hlist_for_each_entry_safe (flow, n, head, hash_node[ver]) { -hlist_del_rcu (&flow->hash_node[ver]); +hlist_del (&flow->hash_node[ver]);ovs_flow_free (flow); } }
Signature · 1 line
1.8.1.2
PATCH 4/11 openvswitch:: link upper device for port devices
In reply to Jesse GrossFrom: Jiri Pirko <[email protected]>
Link upper device properly. That will make IFLA_MASTER filled up. Set the master to port 0 of the datapath under which the port belongs.
--- net/openvswitch/vport-netdev.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
net/openvswitch/vport-netdev.c +19 -1
@@ -25,6 +25,7 @@#include <linux/llc.h> #include <linux/rtnetlink.h> #include <linux/skbuff.h> +#include <linux/openvswitch.h> #include <net/llc.h>
@@ -74,6 +75,15 @@ static rx_handler_result_t netdev_frame_hook(struct sk_buff **pskb)return RX_HANDLER_CONSUMED ; } +static struct net_device *get_dpdev (struct datapath *dp) +{ +struct vport *local; + + local =ovs_vport_ovsl (dp,OVSP_LOCAL ); +BUG_ON (!local); +return netdev_vport_priv (local)->dev; +} +static struct vport *netdev_create (const struct vport_parms *parms) {struct vport *vport;
@@ -103,10 +113,15 @@ static struct vport *netdev_create(const struct vport_parms *parms) }rtnl_lock (); + err =netdev_master_upper_dev_link (netdev_vport->dev, +get_dpdev (vport->dp)); +if (err) + goto error_unlock; + err =netdev_rx_handler_register (netdev_vport->dev, netdev_frame_hook, vport);if (err) - goto error_unlock; + goto error_master_upper_dev_unlink;dev_set_promiscuity (netdev_vport->dev,1 ); netdev_vport->dev->priv_flags |=IFF_OVS_DATAPATH ;
@@ -114,6 +129,8 @@ static struct vport *netdev_create(const struct vport_parms *parms)return vport; +error_master_upper_dev_unlink: +netdev_upper_dev_unlink (netdev_vport->dev,get_dpdev (vport->dp)); error_unlock:rtnl_unlock (); error_put:
@@ -140,6 +157,7 @@ static void netdev_destroy(struct vport *vport)rtnl_lock (); netdev_vport->dev->priv_flags &= ~IFF_OVS_DATAPATH ;netdev_rx_handler_unregister (netdev_vport->dev); +netdev_upper_dev_unlink (netdev_vport->dev,get_dpdev (vport->dp));dev_set_promiscuity (netdev_vport->dev,-1 );rtnl_unlock ();
Signature · 1 line
1.8.1.2
PATCH 6/11 openvswitch: check CONFIG_OPENVSWITCH_GRE in makefile
In reply to Jesse GrossFrom: Cong Wang <[email protected]>
--- net/openvswitch/Makefile | 5 ++++- net/openvswitch/vport-gre.c | 3 --- 2 files changed, 4 insertions(+), 4 deletions(-)
net/openvswitch/Makefile +4 -1
@@ -10,10 +10,13 @@ openvswitch-y := \ dp_notify.o \ flow.o \ vport.o \ - vport-gre.o \ vport-internal_dev.o \ vport-netdev.o ifneq ($(CONFIG_OPENVSWITCH_VXLAN),) openvswitch-y += vport-vxlan.o endif + +ifneq ($(CONFIG_OPENVSWITCH_GRE),) +openvswitch-y += vport-gre.o +endif
net/openvswitch/vport-gre.c +0 -3
@@ -16,7 +16,6 @@* 02110-1301, USA */ -#ifdef CONFIG_OPENVSWITCH_GRE #define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/if.h>
@@ -271,5 +270,3 @@ const struct vport_ops ovs_gre_vport_ops = { .get_name = gre_get_name, .send = gre_tnl_send, }; - -#endif /* OPENVSWITCH_GRE */
Signature · 1 line
1.8.1.2
PATCH 7/11 openvswitch: Mega flow implementation
In reply to Jesse GrossFrom: Andy Zhou <[email protected]>
Add wildcarded flow support in kernel datapath.
Wildcarded flow can improve OVS flow set up performance by avoid sending matching new flows to the user space program. The exact performance boost will largely dependent on wildcarded flow hit rate.
In case all new flows hits wildcard flows, the flow set up rate is within 5% of that of linux bridge module.
Pravin has made significant contributions to this patch. Including API clean ups and bug fixes.
--- Documentation/networking/openvswitch.txt | 40 + include/uapi/linux/openvswitch.h | 9 +- net/openvswitch/actions.c | 6 +- net/openvswitch/datapath.c | 140 ++- net/openvswitch/datapath.h | 6 + net/openvswitch/flow.c | 1387 ++++++++++++++++++++---------- net/openvswitch/flow.h | 96 ++- 7 files changed, 1171 insertions(+), 513 deletions(-)
Documentation/networking/openvswitch.txt +40 -0
@@ -91,6 +91,46 @@ Often we ellipsize arguments not important to the discussion, e.g.: in_port(1), eth(...), eth_type(0x0800), ipv4(...), tcp(...) +Wildcarded flow key format +-------------------------- + +A wildcarded flow is described with two sequences of Netlink attributes +passed over the Netlink socket. A flow key, exactly as described above, and an +optional corresponding flow mask. + +A wildcarded flow can represent a group of exact match flows. Each '1' bit +in the mask specifies a exact match with the corresponding bit in the flow key. +A '0' bit specifies a don't care bit, which will match either a '1' or '0' bit +of a incoming packet. Using wildcarded flow can improve the flow set up rate +by reduce the number of new flows need to be processed by the user space program. + +Support for the mask Netlink attribute is optional for both the kernel and user +space program. The kernel can ignore the mask attribute, installing an exact +match flow, or reduce the number of don't care bits in the kernel to less than +what was specified by the user space program. In this case, variations in bits +that the kernel does not implement will simply result in additional flow setups. +The kernel module will also work with user space programs that neither support +nor supply flow mask attributes. + +Since the kernel may ignore or modify wildcard bits, it can be difficult for +the userspace program to know exactly what matches are installed. There are +two possible approaches: reactively install flows as they miss the kernel +flow table (and therefore not attempt to determine wildcard changes at all) +or use the kernel's response messages to determine the installed wildcards. + +When interacting with userspace, the kernel should maintain the match portion +of the key exactly as originally installed. This will provides a handle to +identify the flow for all future operations. However, when reporting the +mask of an installed flow, the mask should include any restrictions imposed +by the kernel. + +The behavior when using overlapping wildcarded flows is undefined. It is the +responsibility of the user space program to ensure that any incoming packet +can match at most one flow, wildcarded or not. The current implementation +performs best-effort detection of overlapping wildcarded flows and may reject +some but not all of them. However, this behavior may change in future versions. + + Basic rule for evolving flow keys ---------------------------------
include/uapi/linux/openvswitch.h +8 -1
@@ -1,6 +1,6 @@/* -* Copyright (c) 2007-2011 Nicira Networks. +* Copyright (c) 2007-2013 Nicira, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public
@@ -379,6 +379,12 @@ struct ovs_key_nd {* @OVS_FLOW_ATTR_CLEAR: If present in a %OVS_FLOW_CMD_SET request, clears the * last-used time, accumulated TCP flags, and statistics for this flow. * Otherwise ignored in requests. Never present in notifications. +* @OVS_FLOW_ATTR_MASK: Nested %OVS_KEY_ATTR_* attributes specifying the +* mask bits for wildcarded flow match. Mask bit value '1' specifies exact +* match with corresponding flow key bit, while mask bit value '0' specifies +* a wildcarded match. Omitting attribute is treated as wildcarding all +* corresponding fields. Optional for all requests. If not present, +* all flow key bits are exact match bits. * * These attributes follow the &struct ovs_header within the Generic Netlink * payload for %OVS_FLOW_* commands.
@@ -391,6 +397,7 @@ enum ovs_flow_attr {OVS_FLOW_ATTR_TCP_FLAGS ,/* 8-bit OR'd TCP flags. */ OVS_FLOW_ATTR_USED ,/* u64 msecs last used in monotonic time. */ OVS_FLOW_ATTR_CLEAR ,/* Flag to clear stats, tcp_flags, used. */ +OVS_FLOW_ATTR_MASK ,/* Sequence of OVS_KEY_ATTR_* attributes. */ __OVS_FLOW_ATTR_MAX };
net/openvswitch/actions.c +4 -2
@@ -1,5 +1,5 @@/* -* Copyright (c) 2007-2012 Nicira, Inc. +* Copyright (c) 2007-2013 Nicira, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public
@@ -376,8 +376,10 @@ static int output_userspace(struct datapath *dp, struct sk_buff *skb,const struct nlattr *a;int rem; +BUG_ON (!OVS_CB (skb)->pkt_key); + upcall.cmd =OVS_PACKET_CMD_ACTION ; - upcall.key = &OVS_CB (skb)->flow->key; + upcall.key =OVS_CB (skb)->pkt_key; upcall.userdata =NULL ; upcall.portid =0 ;
net/openvswitch/datapath.c +100 -40
373 lines not on this page · raw message
net/openvswitch/datapath.h +6 -0
@@ -88,11 +88,13 @@ struct datapath {/** * struct ovs_skb_cb - OVS data in skb CB * @flow: The flow associated with this packet. May be %NULL if no flow. +* @pkt_key: The flow information extracted from the packet. Must be nonnull. * @tun_key: Key for the tunnel that encapsulated this packet. NULL if the * packet is not being tunneled. */ struct ovs_skb_cb {struct sw_flow *flow; +struct sw_flow_key *pkt_key;struct ovs_key_ipv4_tunnel *tun_key; };#define OVS_CB (skb) ((struct ovs_skb_cb *)(skb)->cb)
@@ -183,4 +185,8 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *, u32 pid, u32 seq,int ovs_execute_actions (struct datapath *dp,struct sk_buff *skb);void ovs_dp_notify_wq (struct work_struct *work); + +#define OVS_NLERR (fmt, ...) \ + pr_info_once("netlink: " fmt, ##__VA_ARGS__) +#endif /* datapath.h */
net/openvswitch/flow.c +936 -451
1,909 lines not on this page · raw message
net/openvswitch/flow.h +77 -19
149 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 8/11 net: Add NEXTHDR_SCTP to ipv6.h
In reply to Jesse GrossFrom: Joe Stringer <[email protected]>
--- include/net/ipv6.h | 1 + 1 file changed, 1 insertion(+)
include/net/ipv6.h +1 -0
@@ -41,6 +41,7 @@#define NEXTHDR_ICMP 58/* ICMP for IPv6. */ #define NEXTHDR_NONE 59/* No next header */ #define NEXTHDR_DEST 60/* Destination options header. */ +#define NEXTHDR_SCTP 132/* SCTP message. */ #define NEXTHDR_MOBILITY 135/* Mobility header. */ #define NEXTHDR_MAX 255
Signature · 1 line
1.8.1.2
PATCH 9/11 openvswitch: Add SCTP support
In reply to Jesse GrossFrom: Joe Stringer <[email protected]>
This patch adds support for rewriting SCTP src,dst ports similar to the functionality already available for TCP/UDP.
Rewriting SCTP ports is expensive due to double-recalculation of the SCTP checksums; this is performed to ensure that packets traversing OVS with invalid checksums will continue to the destination with any checksum corruption intact.
--- include/uapi/linux/openvswitch.h | 6 ++++ net/openvswitch/Kconfig | 1 + net/openvswitch/actions.c | 39 ++++++++++++++++++++++++ net/openvswitch/datapath.c | 6 ++++ net/openvswitch/flow.c | 65 ++++++++++++++++++++++++++++++++++++++++ net/openvswitch/flow.h | 8 ++--- 6 files changed, 121 insertions(+), 4 deletions(-)
include/uapi/linux/openvswitch.h +6 -0
@@ -259,6 +259,7 @@ enum ovs_key_attr {OVS_KEY_ATTR_ND ,/* struct ovs_key_nd */ OVS_KEY_ATTR_SKB_MARK ,/* u32 skb mark */ OVS_KEY_ATTR_TUNNEL ,/* Nested set of ovs_tunnel attributes */ +OVS_KEY_ATTR_SCTP ,/* struct ovs_key_sctp */ #ifdef __KERNEL__ OVS_KEY_ATTR_IPV4_TUNNEL, /* struct ovs_key_ipv4_tunnel */
@@ -333,6 +334,11 @@ struct ovs_key_udp {__be16 udp_dst; }; +struct ovs_key_sctp { +__be16 sctp_src; +__be16 sctp_dst; +}; +struct ovs_key_icmp {__u8 icmp_type;__u8 icmp_code;
net/openvswitch/Kconfig +1 -0
@@ -4,6 +4,7 @@ config OPENVSWITCH tristate "Open vSwitch" + select LIBCRC32C ---help--- Open vSwitch is a multilayer Ethernet switch targeted at virtualized environments. In addition to supporting a variety of features
net/openvswitch/actions.c +39 -0
@@ -22,6 +22,7 @@#include <linux/in.h> #include <linux/ip.h> #include <linux/openvswitch.h> +#include <linux/sctp.h> #include <linux/tcp.h> #include <linux/udp.h> #include <linux/in6.h>
@@ -31,6 +32,7 @@#include <net/ipv6.h> #include <net/checksum.h> #include <net/dsfield.h> +#include <net/sctp/checksum.h> #include "datapath.h" #include "vport.h"
@@ -352,6 +354,39 @@ static int set_tcp(struct sk_buff *skb, const struct ovs_key_tcp *tcp_port_key)return 0 ; } +static int set_sctp (struct sk_buff *skb, +const struct ovs_key_sctp *sctp_port_key) +{ +struct sctphdr *sh; +int err; +unsigned int sctphoff =skb_transport_offset (skb); + + err =make_writable (skb, sctphoff +sizeof (struct sctphdr )); +if (unlikely (err)) +return err; + + sh =sctp_hdr (skb); +if (sctp_port_key->sctp_src != sh->source || + sctp_port_key->sctp_dst != sh->dest) { +__le32 old_correct_csum, new_csum, old_csum; + + old_csum = sh->checksum; + old_correct_csum =sctp_compute_cksum (skb, sctphoff); + + sh->source = sctp_port_key->sctp_src; + sh->dest = sctp_port_key->sctp_dst; + + new_csum =sctp_compute_cksum (skb, sctphoff); + +/* Carry any checksum errors through. */ + sh->checksum = old_csum ^ old_correct_csum ^ new_csum; + + skb->rxhash =0 ; + } + +return 0 ; +} +static int do_output (struct datapath *dp,struct sk_buff *skb,int out_port) {struct vport *vport;
@@ -461,6 +496,10 @@ static int execute_set_action(struct sk_buff *skb,case OVS_KEY_ATTR_UDP : err =set_udp (skb,nla_data (nested_attr));break ; + +case OVS_KEY_ATTR_SCTP : + err =set_sctp (skb,nla_data (nested_attr)); +break ; }return err;
net/openvswitch/datapath.c +6 -0
@@ -712,6 +712,12 @@ static int validate_set(const struct nlattr *a,return validate_tp_port (flow_key); +case OVS_KEY_ATTR_SCTP : +if (flow_key->ip.proto !=IPPROTO_SCTP ) +return -EINVAL ; + +return validate_tp_port (flow_key); +default :return -EINVAL ; }
net/openvswitch/flow.c +65 -0
125 lines not on this page · raw message
net/openvswitch/flow.h +4 -4
@@ -99,8 +99,8 @@ struct sw_flow_key { } addr;union {struct { -__be16 src;/* TCP/UDP source port. */ -__be16 dst;/* TCP/UDP destination port. */ +__be16 src;/* TCP/UDP/SCTP source port. */ +__be16 dst;/* TCP/UDP/SCTP destination port. */ } tp;struct {u8 sha[ETH_ALEN ];/* ARP source hardware address. */
@@ -115,8 +115,8 @@ struct sw_flow_key { } addr;__be32 label;/* IPv6 flow label. */ struct { -__be16 src;/* TCP/UDP source port. */ -__be16 dst;/* TCP/UDP destination port. */ +__be16 src;/* TCP/UDP/SCTP source port. */ +__be16 dst;/* TCP/UDP/SCTP destination port. */ } tp;struct {struct in6_addr target;/* ND target address. */
Signature · 1 line
1.8.1.2
PATCH 10/11 openvswitch: Rename key_len to key_end
In reply to Jesse GrossFrom: Andy Zhou <[email protected]>
Key_end is a better name describing the ending boundary than key_len. Rename those variables to make it less confusing.
--- net/openvswitch/flow.c | 31 ++++++++++++++++--------------- net/openvswitch/flow.h | 2 +- 2 files changed, 17 insertions(+), 16 deletions(-)
net/openvswitch/flow.c +16 -15
@@ -997,10 +997,11 @@ int ovs_flow_extract(struct sk_buff *skb, u16 in_port, struct sw_flow_key *key)return 0 ; } -static u32 ovs_flow_hash (const struct sw_flow_key *key,int key_start,int key_len) +static u32 ovs_flow_hash (const struct sw_flow_key *key,int key_start, +int key_end) {return jhash2 ((u32 *)((u8 *)key + key_start), -DIV_ROUND_UP (key_len - key_start,sizeof (u32)),0 ); +DIV_ROUND_UP (key_end - key_start,sizeof (u32)),0 ); }static int flow_key_start (const struct sw_flow_key *key)
@@ -1012,31 +1013,31 @@ static int flow_key_start(const struct sw_flow_key *key) }static bool __cmp_key (const struct sw_flow_key *key1, -const struct sw_flow_key *key2,int key_start,int key_len) +const struct sw_flow_key *key2,int key_start,int key_end) {return !memcmp ((u8 *)key1 + key_start, - (u8 *)key2 + key_start, (key_len - key_start)); + (u8 *)key2 + key_start, (key_end - key_start)); }static bool __flow_cmp_key (const struct sw_flow *flow, -const struct sw_flow_key *key,int key_start,int key_len) +const struct sw_flow_key *key,int key_start,int key_end) { -return __cmp_key (&flow->key, key, key_start, key_len); +return __cmp_key (&flow->key, key, key_start, key_end); }static bool __flow_cmp_unmasked_key (const struct sw_flow *flow, -const struct sw_flow_key *key,int key_start,int key_len) +const struct sw_flow_key *key,int key_start,int key_end) { -return __cmp_key (&flow->unmasked_key, key, key_start, key_len); +return __cmp_key (&flow->unmasked_key, key, key_start, key_end); }bool ovs_flow_cmp_unmasked_key (const struct sw_flow *flow, -const struct sw_flow_key *key,int key_len) +const struct sw_flow_key *key,int key_end) {int key_start; key_start =flow_key_start (key); -return __flow_cmp_unmasked_key (flow, key, key_start, key_len); +return __flow_cmp_unmasked_key (flow, key, key_start, key_end); }
@@ -1044,11 +1045,11 @@ struct sw_flow *ovs_flow_lookup_unmasked_key(struct flow_table *table, struct sw_flow_match *match) {struct sw_flow_key *unmasked = match->key; -int key_len = match->range.end; +int key_end = match->range.end;struct sw_flow *flow; flow =ovs_flow_lookup (table, unmasked); -if (flow && (!ovs_flow_cmp_unmasked_key (flow, unmasked, key_len))) +if (flow && (!ovs_flow_cmp_unmasked_key (flow, unmasked, key_end))) flow =NULL ;return flow;
@@ -1061,16 +1062,16 @@ static struct sw_flow *ovs_masked_flow_lookup(struct flow_table *table,struct sw_flow *flow;struct hlist_head *head;int key_start = mask->range.start; -int key_len = mask->range.end; +int key_end = mask->range.end;u32 hash;struct sw_flow_key masked_key;ovs_flow_key_mask (&masked_key, flow_key, mask); - hash =ovs_flow_hash (&masked_key, key_start, key_len); + hash =ovs_flow_hash (&masked_key, key_start, key_end); head =find_bucket (table, hash);hlist_for_each_entry_rcu (flow, head, hash_node[table->node_ver]) {if (flow->mask == mask && -__flow_cmp_key (flow, &masked_key, key_start, key_len)) +__flow_cmp_key (flow, &masked_key, key_start, key_end))return flow; }return NULL ;
net/openvswitch/flow.h +1 -1
@@ -243,7 +243,7 @@ int ovs_ipv4_tun_to_nlattr(struct sk_buff *skb, const struct ovs_key_ipv4_tunnel *output);bool ovs_flow_cmp_unmasked_key (const struct sw_flow *flow, -const struct sw_flow_key *key,int key_len); +const struct sw_flow_key *key,int key_end);struct sw_flow_mask {int ref_count;
Signature · 1 line
1.8.1.2
PATCH 11/11 openvswitch: optimize flow compare and mask functions
In reply to Jesse GrossFrom: Andy Zhou <[email protected]>
Make sure the sw_flow_key structure and valid mask boundaries are always machine word aligned. Optimize the flow compare and mask operations using machine word size operations. This patch improves throughput on average by 15% when CPU is the bottleneck of forwarding packets.
This patch is inspired by ideas and code from a patch submitted by Peter Klausler titled "replace memcmp() with specialized comparator". However, The original patch only optimizes for architectures support unaligned machine word access. This patch optimizes for all architectures.
--- net/openvswitch/flow.c | 64 +++++++++++++++++++++++++++++++++----------------- net/openvswitch/flow.h | 19 +-------------- 2 files changed, 44 insertions(+), 39 deletions(-)
net/openvswitch/flow.c +43 -21
@@ -54,8 +54,8 @@ static void update_range__(struct sw_flow_match *match, size_t offset, size_t size, bool is_mask) { struct sw_flow_key_range *range = NULL; -size_t start = offset; -size_t end = offset + size; +size_t start =rounddown (offset,sizeof (long )); +size_t end =roundup (offset + size,sizeof (long ));if (!is_mask) range = &match->range;
@@ -102,6 +102,11 @@ static void update_range__(struct sw_flow_match *match, } \ }while (0 ) +static u16 range_n_bytes(const struct sw_flow_key_range *range) +{ +return range->end - range->start; +} +void ovs_match_init (struct sw_flow_match *match,struct sw_flow_key *key,struct sw_flow_mask *mask)
@@ -370,16 +375,17 @@ static bool icmp6hdr_ok(struct sk_buff *skb)void ovs_flow_key_mask (struct sw_flow_key *dst,const struct sw_flow_key *src,const struct sw_flow_mask *mask) { -u8 *m = (u8 *)&mask->key + mask->range.start; -u8 *s = (u8 *)src + mask->range.start; -u8 *d = (u8 *)dst + mask->range.start; +const long *m = (long *)((u8 *)&mask->key + mask->range.start); +const long *s = (long *)((u8 *)src + mask->range.start); +long *d = (long *)((u8 *)dst + mask->range.start);int i; -memset (dst,0 ,sizeof (*dst)); -for (i =0 ; i <ovs_sw_flow_mask_size_roundup (mask); i++) { - *d = *s & *m; - d++, s++, m++; - } +/* The memory outside of the 'mask->range' are not set since +* further operations on 'dst' only uses contents within +* 'mask->range'. +*/ +for (i =0 ; i <range_n_bytes (&mask->range); i +=sizeof (long )) + *d++ = *s++ & *m++; }#define TCP_FLAGS_OFFSET 13
@@ -1000,8 +1006,13 @@ int ovs_flow_extract(struct sk_buff *skb, u16 in_port, struct sw_flow_key *key)static u32 ovs_flow_hash (const struct sw_flow_key *key,int key_start,int key_end) { -return jhash2 ((u32 *)((u8 *)key + key_start), -DIV_ROUND_UP (key_end - key_start,sizeof (u32)),0 ); +u32 *hash_key = (u32 *)((u8 *)key + key_start); +int hash_u32s = (key_end - key_start) >>2 ; + +/* Make sure number of hash bytes are multiple of u32. */ +BUILD_BUG_ON (sizeof (long ) %sizeof (u32)); + +return jhash2 (hash_key, hash_u32s,0 ); }static int flow_key_start (const struct sw_flow_key *key)
@@ -1009,17 +1020,25 @@ static int flow_key_start(const struct sw_flow_key *key)if (key->tun_key.ipv4_dst)return 0 ;else -return offsetof(struct sw_flow_key , phy); +return rounddown (offsetof(struct sw_flow_key , phy), +sizeof (long )); }static bool __cmp_key (const struct sw_flow_key *key1,const struct sw_flow_key *key2,int key_start,int key_end) { -return !memcmp ((u8 *)key1 + key_start, - (u8 *)key2 + key_start, (key_end - key_start)); +const long *cp1 = (long *)((u8 *)key1 + key_start); +const long *cp2 = (long *)((u8 *)key2 + key_start); +long diffs =0 ; +int i; + +for (i = key_start; i < key_end; i +=sizeof (long )) + diffs |= *cp1++ ^ *cp2++; + +return diffs ==0 ; } -static bool __flow_cmp_key (const struct sw_flow *flow, +static bool __flow_cmp_masked_key (const struct sw_flow *flow,const struct sw_flow_key *key,int key_start,int key_end) {return __cmp_key (&flow->key, key, key_start, key_end);
@@ -1056,7 +1075,7 @@ struct sw_flow *ovs_flow_lookup_unmasked_key(struct flow_table *table, }static struct sw_flow *ovs_masked_flow_lookup (struct flow_table *table, -const struct sw_flow_key *flow_key, +const struct sw_flow_key *unmasked,struct sw_flow_mask *mask) {struct sw_flow *flow;
@@ -1066,12 +1085,13 @@ static struct sw_flow *ovs_masked_flow_lookup(struct flow_table *table,u32 hash;struct sw_flow_key masked_key; -ovs_flow_key_mask (&masked_key, flow_key, mask); +ovs_flow_key_mask (&masked_key, unmasked, mask); hash =ovs_flow_hash (&masked_key, key_start, key_end); head =find_bucket (table, hash);hlist_for_each_entry_rcu (flow, head, hash_node[table->node_ver]) {if (flow->mask == mask && -__flow_cmp_key (flow, &masked_key, key_start, key_end)) +__flow_cmp_masked_key (flow, &masked_key, + key_start, key_end))return flow; }return NULL ;
@@ -1961,6 +1981,8 @@ nla_put_failure:* Returns zero if successful or a negative error code. */ int ovs_flow_init (void ) { +BUILD_BUG_ON (sizeof (struct sw_flow_key ) %sizeof (long )); + flow_cache =kmem_cache_create ("sw_flow" ,sizeof (struct sw_flow ),0 ,0 ,NULL );if (flow_cache ==NULL )
@@ -2016,7 +2038,7 @@ static bool ovs_sw_flow_mask_equal(const struct sw_flow_mask *a,return (a->range.end == b->range.end) && (a->range.start == b->range.start) - && (memcmp (a_, b_,ovs_sw_flow_mask_actual_size (a)) ==0 ); + && (memcmp (a_, b_,range_n_bytes (&a->range)) ==0 ); } struct sw_flow_mask *ovs_sw_flow_mask_find(const struct flow_table *tbl,
@@ -2053,5 +2075,5 @@ static void ovs_sw_flow_mask_set(struct sw_flow_mask *mask,u8 *m = (u8 *)&mask->key + range->start; mask->range = *range; -memset (m, val,ovs_sw_flow_mask_size_roundup (mask)); +memset (m, val,range_n_bytes (range)); }
net/openvswitch/flow.h +1 -18
@@ -125,7 +125,7 @@ struct sw_flow_key { } nd; } ipv6; }; -}; +}__aligned(__alignof__(long)) ;struct sw_flow {struct rcu_head rcu;
@@ -149,11 +149,6 @@ struct sw_flow_key_range {size_t end; }; -static inline u16 ovs_sw_flow_key_range_actual_size (const struct sw_flow_key_range *range) -{ -return range->end - range->start; -} -struct sw_flow_match {struct sw_flow_key *key;struct sw_flow_key_range range;
@@ -253,18 +248,6 @@ struct sw_flow_mask {struct sw_flow_key key; }; -static inline u16 -ovs_sw_flow_mask_actual_size (const struct sw_flow_mask *mask) -{ -return ovs_sw_flow_key_range_actual_size (&mask->range); -} - -static inline u16 -ovs_sw_flow_mask_size_roundup (const struct sw_flow_mask *mask) -{ -return roundup (ovs_sw_flow_mask_actual_size (mask),sizeof (u32)); -} -struct sw_flow_mask *ovs_sw_flow_mask_alloc (void );void ovs_sw_flow_mask_add_ref (struct sw_flow_mask *);void ovs_sw_flow_mask_del_ref (struct sw_flow_mask *,bool deferred);
Signature · 1 line
1.8.1.2
David Miller
maintainerFrom: Jesse Gross <[email protected]>
Date: Tue, 27 Aug 2013 13:20:37 -0700
Quoted 9 lines
A number of significant new features and optimizations for net-next/3.12. Highlights are:
* "Megaflows", an optimization that allows userspace to specify which flow fields were used to compute the results of the flow lookup. This allows for a major reduction in flow setups (the major performance bottleneck in Open vSwitch) without reducing flexibility.
* Converting netlink dump operations to use RCU, allowing for additional parallelism in userspace.
* Matching and modifying SCTP protocol fields.
Pulled, thanks Jesse.