[ovs-dev] [ovsdb-server multithreading RFC 8/9] ovsdb: Add ovsdb-server/list-threads command.

Andy Zhou azhou at ovn.org
Thu Mar 3 08:13:27 UTC 2016


Signed-off-by: Andy Zhou <azhou at ovn.org>
---
 ovsdb/jsonrpc-server.c  |  9 +++++++++
 ovsdb/jsonrpc-server.h  |  4 ++++
 ovsdb/ovsdb-server.1.in |  5 +++++
 ovsdb/ovsdb-server.c    | 18 ++++++++++++++++++
 4 files changed, 36 insertions(+)

diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c
index 09b89b2..e117b62 100644
--- a/ovsdb/jsonrpc-server.c
+++ b/ovsdb/jsonrpc-server.c
@@ -41,6 +41,7 @@
 #include "timeval.h"
 #include "transaction.h"
 #include "trigger.h"
+#include "util.h"
 #include "openvswitch/vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(ovsdb_jsonrpc_server);
@@ -370,6 +371,14 @@ ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *svr)
     free(svr);
 }
 
+void
+ovsdb_jsonrpc_server_get_threads_info(struct ds *ds,
+                                      struct ovsdb_jsonrpc_server *svr)
+{
+     ds_put_format(ds, "Max number of threads: %"PRIuSIZE",", svr->n_max_threads);
+     ds_put_format(ds, "Threads in use:  %"PRIuSIZE, svr->n_active_threads);
+}
+
 struct ovsdb_jsonrpc_options *
 ovsdb_jsonrpc_default_options(const char *target)
 {
diff --git a/ovsdb/jsonrpc-server.h b/ovsdb/jsonrpc-server.h
index 3be34e7..04d2813 100644
--- a/ovsdb/jsonrpc-server.h
+++ b/ovsdb/jsonrpc-server.h
@@ -22,6 +22,7 @@
 struct ovsdb;
 struct shash;
 struct simap;
+struct ds;
 
 struct ovsdb_jsonrpc_server *ovsdb_jsonrpc_server_create(size_t n_max_threads);
 bool ovsdb_jsonrpc_server_add_db(struct ovsdb_jsonrpc_server *,
@@ -69,6 +70,9 @@ void ovsdb_jsonrpc_server_wait(struct ovsdb_jsonrpc_server *);
 void ovsdb_jsonrpc_server_get_memory_usage(const struct ovsdb_jsonrpc_server *,
                                            struct simap *usage);
 
+void ovsdb_jsonrpc_server_get_threads_info(struct ds *ds,
+                                           struct ovsdb_jsonrpc_server *);
+
 struct ovsdb_jsonrpc_monitor;
 void ovsdb_jsonrpc_monitor_destroy(struct ovsdb_jsonrpc_monitor *);
 void ovsdb_jsonrpc_disable_monitor2(void);
diff --git a/ovsdb/ovsdb-server.1.in b/ovsdb/ovsdb-server.1.in
index 0a06e52..a3d89ed 100644
--- a/ovsdb/ovsdb-server.1.in
+++ b/ovsdb/ovsdb-server.1.in
@@ -188,6 +188,11 @@ again (with \fBovsdb\-server/add\-db\fR).
 Outputs a list of the currently configured databases added either through
 the command line or through the \fBovsdb\-server/add\-db\fR command.
 .
+.IP "\fBovsdb\-server/list\-threads"
+Outputs the maximum allowed number of threads that is specified via
+the command line \fI\-\-max-num-threads\fR argument, and the current
+number of threads in use.
+.
 .so lib/vlog-unixctl.man
 .so lib/memory-unixctl.man
 .so lib/coverage-unixctl.man
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index 414106a..123741b 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -97,6 +97,8 @@ static unixctl_cb_func ovsdb_server_add_database;
 static unixctl_cb_func ovsdb_server_remove_database;
 static unixctl_cb_func ovsdb_server_list_databases;
 
+static unixctl_cb_func ovsdb_server_list_threads;
+
 static char *open_db(struct server_config *config, const char *filename);
 static void close_db(struct db *db);
 
@@ -319,6 +321,8 @@ main(int argc, char *argv[])
                              ovsdb_server_compact, &all_dbs);
     unixctl_command_register("ovsdb-server/reconnect", "", 0, 0,
                              ovsdb_server_reconnect, jsonrpc);
+    unixctl_command_register("ovsdb-server/list-threads", "", 0, 0,
+                             ovsdb_server_list_threads, jsonrpc);
 
     unixctl_command_register("ovsdb-server/add-remote", "REMOTE", 1, 1,
                              ovsdb_server_add_remote, &server_config);
@@ -1274,6 +1278,20 @@ ovsdb_server_list_databases(struct unixctl_conn *conn, int argc OVS_UNUSED,
 }
 
 static void
+ovsdb_server_list_threads(struct unixctl_conn *conn, int argc OVS_UNUSED,
+                          const char *argv[] OVS_UNUSED, void *jsonrpc_)
+{
+    struct ovsdb_jsonrpc_server *jsonrpc = jsonrpc_;
+    struct ds s;
+
+    ds_init(&s);
+
+    ovsdb_jsonrpc_server_get_threads_info(&s, jsonrpc);
+    unixctl_command_reply(conn, ds_cstr(&s));
+    ds_destroy(&s);
+}
+
+static void
 parse_options(int *argcp, char **argvp[],
               struct sset *remotes, char **unixctl_pathp, char **run_command,
               size_t *n_max_threads)
-- 
1.9.1




More information about the dev mailing list