[ovs-dev] [Single DP 13/15] ofproto: Add type "run" and "run_fast" provider methods.
Justin Pettit
jpettit at nicira.com
Thu Oct 18 19:51:58 UTC 2012
Add the ability for ofproto providers to have top-level "run" and
"run_fast" methods, similar to the current ofproto ones. There are no
current users, but this will be useful in a future commit.
Signed-off-by: Justin Pettit <jpettit at nicira.com>
---
ofproto/ofproto-dpif.c | 2 ++
ofproto/ofproto-provider.h | 22 ++++++++++++++++++++++
ofproto/ofproto.c | 34 ++++++++++++++++++++++++++++++++++
ofproto/ofproto.h | 3 +++
vswitchd/bridge.c | 19 +++++++++++++++++++
5 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 399ca75..4b15cf3 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -7472,6 +7472,8 @@ const struct ofproto_class ofproto_dpif_class = {
enumerate_types,
enumerate_names,
del,
+ NULL, /* type_run */
+ NULL, /* type_run_fast */
alloc,
construct,
destruct,
diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h
index d308428..db53939 100644
--- a/ofproto/ofproto-provider.h
+++ b/ofproto/ofproto-provider.h
@@ -358,6 +358,28 @@ struct ofproto_class {
int (*del)(const char *type, const char *name);
/* ## --------------------------- ## */
+/* ## Top-Level type Functions ## */
+/* ## --------------------------- ## */
+ /* Performs any periodic activity required on ofprotos of type
+ * 'type'.
+ *
+ * An ofproto provider may implement it or not, depending on whether
+ * it needs type-level maintenance.
+ *
+ * Returns 0 if successful, otherwise a positive errno value. */
+ int (*type_run)(const char *type);
+
+ /* Performs periodic activity required on ofprotos of type 'type'
+ * that needs to be done with the least possible latency.
+ *
+ * This is run multiple times per main loop. An ofproto provider may
+ * implement it or not, according to whether it provides a performance
+ * boost for that ofproto implementation.
+ *
+ * Returns 0 if successful, otherwise a positive errno value. */
+ int (*type_run_fast)(const char *type);
+
+/* ## --------------------------- ## */
/* ## Top-Level ofproto Functions ## */
/* ## --------------------------- ## */
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 42467dd..cbee967 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -1098,6 +1098,40 @@ process_port_change(struct ofproto *ofproto, int error, char *devname)
}
int
+ofproto_type_run(const char *datapath_type)
+{
+ const struct ofproto_class *class;
+ int error;
+
+ datapath_type = ofproto_normalize_type(datapath_type);
+ class = ofproto_class_find__(datapath_type);
+
+ error = class->type_run ? class->type_run(datapath_type) : 0;
+ if (error && error != EAGAIN) {
+ VLOG_ERR_RL(&rl, "%s: type_run failed (%s)",
+ datapath_type, strerror(error));
+ }
+ return error;
+}
+
+int
+ofproto_type_run_fast(const char *datapath_type)
+{
+ const struct ofproto_class *class;
+ int error;
+
+ datapath_type = ofproto_normalize_type(datapath_type);
+ class = ofproto_class_find__(datapath_type);
+
+ error = class->type_run_fast ? class->type_run_fast(datapath_type) : 0;
+ if (error && error != EAGAIN) {
+ VLOG_ERR_RL(&rl, "%s: type_run_fast failed (%s)",
+ datapath_type, strerror(error));
+ }
+ return error;
+}
+
+int
ofproto_run(struct ofproto *p)
{
struct sset changed_netdevs;
diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h
index 96dde6a..bc727a8 100644
--- a/ofproto/ofproto.h
+++ b/ofproto/ofproto.h
@@ -154,6 +154,9 @@ struct iface_hint {
void ofproto_init(const struct shash *iface_hints);
+int ofproto_type_run(const char *datapath_type);
+int ofproto_type_run_fast(const char *datapath_type);
+
int ofproto_create(const char *datapath, const char *datapath_type,
struct ofproto **ofprotop);
void ofproto_destroy(struct ofproto *);
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 42ac798..5e2b7af 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -2079,8 +2079,17 @@ refresh_instant_stats(void)
void
bridge_run_fast(void)
{
+ struct sset types;
+ const char *type;
struct bridge *br;
+ sset_init(&types);
+ ofproto_enumerate_types(&types);
+ SSET_FOR_EACH (type, &types) {
+ ofproto_type_run_fast(type);
+ }
+ sset_destroy(&types);
+
HMAP_FOR_EACH (br, node, &all_bridges) {
ofproto_run_fast(br->ofproto);
}
@@ -2092,6 +2101,8 @@ bridge_run(void)
static const struct ovsrec_open_vswitch null_cfg;
const struct ovsrec_open_vswitch *cfg;
struct ovsdb_idl_txn *reconf_txn = NULL;
+ struct sset types;
+ const char *type;
bool vlan_splinters_changed;
struct bridge *br;
@@ -2125,6 +2136,14 @@ bridge_run(void)
* returns immediately. */
bridge_init_ofproto(cfg);
+ /* Let each datapath type do the work that it needs to do. */
+ sset_init(&types);
+ ofproto_enumerate_types(&types);
+ SSET_FOR_EACH (type, &types) {
+ ofproto_type_run(type);
+ }
+ sset_destroy(&types);
+
/* Let each bridge do the work that it needs to do. */
HMAP_FOR_EACH (br, node, &all_bridges) {
ofproto_run(br->ofproto);
--
1.7.5.4
More information about the dev
mailing list