From: Ben Pfaff Date: Mon, 3 May 2010 18:47:56 +0000 (-0700) Subject: bridge: Optimize trunk port common case. X-Git-Tag: v1.0.0~48 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=3e9c481c70473b5faa29c72a1e609a31ddb6b990;p=sliver-openvswitch.git bridge: Optimize trunk port common case. Profiling with qprof showed that bitmap_set_multiple() and bitmap_equal() were eating up quite a bit of CPU time during bridge reconfiguration (up to about 10% of total runtime). This is completely avoidable in the common case where a port trunks all VLANs, where we don't really need a bitmap at all. This commit implements that optimization. --- diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 7fcfd58ed..e20d40738 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -122,7 +122,8 @@ struct port { struct bridge *bridge; size_t port_idx; int vlan; /* -1=trunk port, else a 12-bit VLAN ID. */ - unsigned long *trunks; /* Bitmap of trunked VLANs, if 'vlan' == -1. */ + unsigned long *trunks; /* Bitmap of trunked VLANs, if 'vlan' == -1. + * NULL if all VLANs are trunked. */ char *name; /* An ordinary bridge port has 1 interface. @@ -2073,7 +2074,8 @@ dst_is_duplicate(const struct dst *dsts, size_t n_dsts, static bool port_trunks_vlan(const struct port *port, uint16_t vlan) { - return port->vlan < 0 && bitmap_is_set(port->trunks, vlan); + return (port->vlan < 0 + && (!port->trunks || bitmap_is_set(port->trunks, vlan))); } static bool @@ -3354,7 +3356,7 @@ port_reconfigure(struct port *port, const struct ovsrec_port *cfg) /* Get trunked VLANs. */ trunks = NULL; - if (vlan < 0) { + if (vlan < 0 && cfg->n_trunks) { size_t n_errors; size_t i; @@ -3373,17 +3375,14 @@ port_reconfigure(struct port *port, const struct ovsrec_port *cfg) port->name, cfg->n_trunks); } if (n_errors == cfg->n_trunks) { - if (n_errors) { - VLOG_ERR("port %s: no valid trunks, trunking all VLANs", - port->name); - } - bitmap_set_multiple(trunks, 0, 4096, 1); - } - } else { - if (cfg->n_trunks) { - VLOG_ERR("port %s: ignoring trunks in favor of implicit vlan", + VLOG_ERR("port %s: no valid trunks, trunking all VLANs", port->name); + bitmap_free(trunks); + trunks = NULL; } + } else if (vlan >= 0 && cfg->n_trunks) { + VLOG_ERR("port %s: ignoring trunks in favor of implicit vlan", + port->name); } if (trunks == NULL ? port->trunks != NULL