From: Alex Wang Date: Thu, 3 Apr 2014 20:27:22 +0000 (-0700) Subject: bridge: Allow users to configure statistics update to OVSDB. X-Git-Tag: sliver-openvswitch-2.2.90-1~3^2~2 X-Git-Url: http://git.onelab.eu/?p=sliver-openvswitch.git;a=commitdiff_plain;h=12eb035b810ff9d537d6ff9f1eb8ad5564c1f644 bridge: Allow users to configure statistics update to OVSDB. This commit adds a new configuration "stats-update-interval" in "other_config" of Open_Vswitch table. So users can control the statistics update frequency. A possible use case is that, users can lower the update frequency to reduce the cpu consumption of the ovs-vswitchd thread. The configured value should always be greater than or equal to 5000 ms. And more frequent statistics update should be achieved via OpenFlow. Signed-off-by: Alex Wang Acked-by: Joe Stringer --- diff --git a/tests/ovs-vswitchd.at b/tests/ovs-vswitchd.at index c55274164..a90477d86 100644 --- a/tests/ovs-vswitchd.at +++ b/tests/ovs-vswitchd.at @@ -25,3 +25,44 @@ AT_CAPTURE_FILE([ovs-vswitchd.log]) dnl ovs-vswitchd detached OK or we wouldn't have made it this far. Success. AT_CLEANUP + + +dnl ---------------------------------------------------------------------- +m4_define([OVS_VSCTL_CHECK_RX_PKT], [ +AT_CHECK([ovs-vsctl list int $1 | grep statistics | sed -n 's/^.*\(rx_packets=[[0-9]]\+\).*$/\1/p'],[0], +[dnl +rx_packets=$2 +]) +]) + +AT_SETUP([ovs-vswitchd -- stats-update-interval]) +OVS_VSWITCHD_START([add-port br0 p1 -- set int p1 type=internal]) +ovs-appctl time/stop + +dnl at the beginning, the udpate of rx_packets should happen every 5 seconds. +for i in `seq 0 10`; do ovs-appctl time/warp 1000; done +OVS_VSCTL_CHECK_RX_PKT([p1], [0]) +AT_CHECK([ovs-appctl netdev-dummy/receive p1 'eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)']) +for i in `seq 0 10`; do ovs-appctl time/warp 1000; done +OVS_VSCTL_CHECK_RX_PKT([p1], [1]) + +dnl set the stats update interval to 100K ms, the following 'recv' should not be updated. +AT_CHECK([ovs-vsctl set O . other_config:stats-update-interval=100000]) +for i in `seq 0 50`; do ovs-appctl time/warp 1000; done +for i in `seq 1 5`; do + AT_CHECK([ovs-appctl netdev-dummy/receive p1 'eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)']) +done + +OVS_VSCTL_CHECK_RX_PKT([p1], [1]) +dnl advance the clock by 100K ms, the previous 'recv' should be updated. +for i in `seq 0 99`; do ovs-appctl time/warp 1000; done +OVS_VSCTL_CHECK_RX_PKT([p1], [6]) + +dnl now remove the configuration. 'recv' one packet. there should be an update after 5000 ms. +AT_CHECK([ovs-vsctl clear O . other_config]) +AT_CHECK([ovs-appctl netdev-dummy/receive p1 'eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)']) +for i in `seq 0 10`; do ovs-appctl time/warp 1000; done +OVS_VSCTL_CHECK_RX_PKT([p1], [7]) + +OVS_VSWITCHD_STOP +AT_CLEANUP \ No newline at end of file diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 12852b420..1145e98db 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -182,8 +182,8 @@ static struct ovsdb_idl_txn *status_txn; /* 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. */ -static long long int iface_stats_timer = LLONG_MIN; +static int stats_timer_interval; +static long long int stats_timer = LLONG_MIN; /* Set to true to allow experimental use of OpenFlow 1.4. * This is false initially because OpenFlow 1.4 is not yet safe to use: it can @@ -2275,6 +2275,7 @@ bridge_run(void) bool vlan_splinters_changed; struct bridge *br; + int stats_interval; ovsrec_open_vswitch_init(&null_cfg); @@ -2380,8 +2381,17 @@ bridge_run(void) } } + /* Statistics update interval should always be greater than or equal to + * 5000 ms. */ + stats_interval = MAX(smap_get_int(&cfg->other_config, + "stats-update-interval", 5000), 5000); + if (stats_timer_interval != stats_interval) { + stats_timer_interval = stats_interval; + stats_timer = LLONG_MIN; + } + /* Refresh interface and mirror stats if necessary. */ - if (time_msec() >= iface_stats_timer) { + if (time_msec() >= stats_timer) { if (cfg) { struct ovsdb_idl_txn *txn; @@ -2410,7 +2420,7 @@ bridge_run(void) ovsdb_idl_txn_destroy(txn); /* XXX */ } - iface_stats_timer = time_msec() + IFACE_STATS_INTERVAL; + stats_timer = time_msec() + stats_timer_interval; } if (!status_txn) { @@ -2477,7 +2487,8 @@ bridge_wait(void) HMAP_FOR_EACH (br, node, &all_bridges) { ofproto_wait(br->ofproto); } - poll_timer_wait_until(iface_stats_timer); + + poll_timer_wait_until(stats_timer); } /* If the status database transaction is 'TXN_INCOMPLETE' in this run, diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml index 7f2fd587d..a3518130f 100644 --- a/vswitchd/vswitch.xml +++ b/vswitchd/vswitch.xml @@ -72,6 +72,22 @@ host as displayed by xe host-list. + +

+ Interval for updating statistics to the database, in milliseconds. + This option will affect the update of the statistics + column in the following tables: Port, Interface + , Mirror. +

+

+ Default value is 5000 ms. +

+

+ Getting statistics more frequently can be achieved via OpenFlow. +

+
+

@@ -1211,7 +1227,9 @@

- Key-value pairs that report port statistics. + Key-value pairs that report port statistics. The update period + is controlled by in the Open_vSwitch table.

@@ -1769,12 +1787,14 @@

Key-value pairs that report interface statistics. The current - implementation updates these counters periodically. Future - implementations may update them when an interface is created, when they - are queried (e.g. using an OVSDB select operation), and - just before an interface is deleted due to virtual interface hot-unplug - or VM shutdown, and perhaps at other times, but not on any regular - periodic basis. + implementation updates these counters periodically. The update period + is controlled by in the Open_vSwitch table. + Future implementations may update them when an interface is created, + when they are queried (e.g. using an OVSDB select + operation), and just before an interface is deleted due to virtual + interface hot-unplug or VM shutdown, and perhaps at other times, but + not on any regular periodic basis.

These are the same statistics reported by OpenFlow in its struct @@ -2898,7 +2918,9 @@

- Key-value pairs that report mirror statistics. + Key-value pairs that report mirror statistics. The update period + is controlled by in the Open_vSwitch table.

Number of packets transmitted through this mirror.