From: Joe Stringer Date: Fri, 13 Dec 2013 03:33:49 +0000 (+0000) Subject: bridge: Only store instant_stats on device changes X-Git-Tag: sliver-openvswitch-2.1.90-1~10^2~205 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;ds=sidebyside;h=7f8f2757f3d6749f832f9fe2c0229d6587cfbad9;p=sliver-openvswitch.git bridge: Only store instant_stats on device changes Previously, we iterated through all interfaces in instant_stats_run(), grabbing up-to-date information about device and port status. After assembling all of this information for all interfaces, we would determine whether anything changed and only send an update to ovsdb-server if something changed. This patch uses the new global connectivity_seq to determine whether there have been any changes before polling all interfaces, which reduces unnecessary processing in the average case. In a test environment of 5000 internal ports and 50 tunnel ports with bfd, this reduces average CPU usage of the main thread from about 15% to about 5%. When ports change status more often than every 100ms, CPU usage is expected to increase to previous rates. Signed-off-by: Joe Stringer Signed-off-by: Ethan Jackson Acked-by: Ethan Jackson --- diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index f3b03af03..eb631054e 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -22,6 +22,7 @@ #include "bfd.h" #include "bitmap.h" #include "cfm.h" +#include "connectivity.h" #include "coverage.h" #include "daemon.h" #include "dirs.h" @@ -41,6 +42,7 @@ #include "ofproto/bond.h" #include "ofproto/ofproto.h" #include "poll-loop.h" +#include "seq.h" #include "sha1.h" #include "shash.h" #include "smap.h" @@ -155,6 +157,9 @@ static struct ovsdb_idl_txn *daemonize_txn; /* Most recently processed IDL sequence number. */ static unsigned int idl_seqno; +/* Track changes to port connectivity. */ +static uint64_t connectivity_seqno = LLONG_MIN; + /* Each time this timer expires, the bridge fetches interface and mirror * statistics and pushes them into the database. */ #define IFACE_STATS_INTERVAL (5 * 1000) /* In milliseconds. */ @@ -2164,12 +2169,19 @@ instant_stats_run(void) if (!instant_txn) { struct bridge *br; + uint64_t seq; if (time_msec() < instant_next_txn) { return; } instant_next_txn = time_msec() + INSTANT_INTERVAL_MSEC; + seq = seq_read(connectivity_seq_get()); + if (seq == connectivity_seqno) { + return; + } + connectivity_seqno = seq; + instant_txn = ovsdb_idl_txn_create(idl); HMAP_FOR_EACH (br, node, &all_bridges) { struct iface *iface;