This command adds a new appctl sub-command "stats/require_update", which
allows users to force statistics update to the database when the
'disable-stats-update' is set.

Signed-off-by: Alex Wang <al...@nicira.com>
---
 vswitchd/bridge.c          |   39 +++++++++++++++++++++++++++++++++++++--
 vswitchd/ovs-vswitchd.8.in |    4 ++++
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index ba680cd..f6960e0 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -158,6 +158,13 @@ static struct ovsdb_idl_txn *daemonize_txn;
 /* Most recently processed IDL sequence number. */
 static unsigned int idl_seqno;
 
+/* Used to force an update of statistics to database when the
+ * 'disable-stats-udpate' is set. */
+static struct seq *stats_update_seq;
+
+/* Last read from 'stats_update_seq'. */
+static uint64_t stats_update_seqno = LLONG_MIN;
+
 /* Track changes to port connectivity. */
 static uint64_t connectivity_seqno = LLONG_MIN;
 
@@ -274,6 +281,8 @@ static ofp_port_t iface_get_requested_ofp_port(
     const struct ovsrec_interface *);
 static ofp_port_t iface_pick_ofport(const struct ovsrec_interface *);
 
+static unixctl_cb_func stats_unixctl_require_update;
+
 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
  *
  * This is deprecated.  It is only for compatibility with broken device drivers
@@ -343,6 +352,9 @@ bridge_init_ofproto(const struct ovsrec_open_vswitch *cfg)
 void
 bridge_init(const char *remote)
 {
+    stats_update_seq = seq_create();
+    stats_update_seqno = seq_read(stats_update_seq);
+
     /* Create connection to database. */
     idl = ovsdb_idl_create(remote, &ovsrec_idl_class, true, true);
     idl_seqno = ovsdb_idl_get_seqno(idl);
@@ -412,6 +424,8 @@ bridge_init(const char *remote)
     ovsdb_idl_omit(idl, &ovsrec_ssl_col_external_ids);
 
     /* Register unixctl commands. */
+    unixctl_command_register("stats/require-update", NULL, 0, 0,
+                             stats_unixctl_require_update, NULL);
     unixctl_command_register("qos/show", "interface", 1, 1,
                              qos_unixctl_show, NULL);
     unixctl_command_register("bridge/dump-flows", "bridge", 1, 1,
@@ -429,6 +443,7 @@ bridge_exit(void)
 {
     struct bridge *br, *next_br;
 
+    seq_destroy(stats_update_seq);
     HMAP_FOR_EACH_SAFE (br, next_br, node, &all_bridges) {
         bridge_destroy(br);
     }
@@ -2338,8 +2353,17 @@ bridge_run(void)
 
     disable_stats_update = smap_get_bool(&cfg->other_config,
                                          "disable-stats-update", false);
-    /* Refresh interface and mirror stats if necessary. */
-    if (time_msec() >= iface_stats_timer && !disable_stats_update) {
+    seq = seq_read(stats_update_seq);
+
+    /* The update of statistics to database is very expensive.  So, the update
+     * is run every IFACE_STATS_INTERVAL.  Users can disable the update via
+     * setting the "other_config:disable-stats-update=true" in the Open_Vswitch
+     * table and use the "ovs-appctl stats/require-update" to force an update
+     * on demand. */
+    if (time_msec() >= iface_stats_timer
+        && (!disable_stats_update || stats_update_seqno != seq)) {
+        stats_update_seqno = seq;
+
         if (cfg) {
             struct ovsdb_idl_txn *txn;
 
@@ -2426,6 +2450,8 @@ bridge_wait(void)
 
         if (!disable_stats_update) {
             poll_timer_wait_until(iface_stats_timer);
+        } else {
+            seq_wait(stats_update_seq, stats_update_seqno);
         }
     }
 
@@ -4191,3 +4217,12 @@ mirror_refresh_stats(struct mirror *m)
 
     ovsrec_mirror_set_statistics(m->cfg, keys, values, stat_cnt);
 }
+
+static void
+stats_unixctl_require_update(struct unixctl_conn *conn, int argc OVS_UNUSED,
+                             const char *argv[] OVS_UNUSED,
+                             void *aux OVS_UNUSED)
+{
+    seq_change(stats_update_seq);
+    unixctl_command_reply(conn, NULL);
+}
diff --git a/vswitchd/ovs-vswitchd.8.in b/vswitchd/ovs-vswitchd.8.in
index 817cec2..568286d 100644
--- a/vswitchd/ovs-vswitchd.8.in
+++ b/vswitchd/ovs-vswitchd.8.in
@@ -115,6 +115,10 @@ how to configure Open vSwitch.
 .SS "GENERAL COMMANDS"
 .IP "\fBexit\fR"
 Causes \fBovs\-vswitchd\fR to gracefully terminate.
+.IP "\fBstats/require-update\fR"
+Forces an update of the statistics to the database.  The command will
+only be effective when the \fIdisable-stats-update\fR (in Open_Vswitch
+table) is set.
 .IP "\fBqos/show\fR \fIinterface\fR"
 Queries the kernel for Quality of Service configuration and statistics
 associated with the given \fIinterface\fR.
-- 
1.7.9.5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to