From: Ethan Jackson Date: Thu, 21 Nov 2013 01:41:02 +0000 (-0800) Subject: ofproto-dpif-upcall: Add memory usage stats. X-Git-Tag: sliver-openvswitch-2.1.90-1~10^2~192 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=1c030aa5704db05b41671133df32e2a1b64aa60d;p=sliver-openvswitch.git ofproto-dpif-upcall: Add memory usage stats. Signed-off-by: Ethan Jackson Acked-by: Ben Pfaff --- diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index 65fb236fe..ca39f1faa 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -265,6 +265,23 @@ udpif_revalidate(struct udpif *udpif) udpif_drop_key_clear(udpif); } +void +udpif_get_memory_usage(struct udpif *udpif, struct simap *usage) +{ + size_t i; + + simap_increase(usage, "dispatchers", 1); + simap_increase(usage, "flow_dumpers", 1); + + simap_increase(usage, "handlers", udpif->n_handlers); + for (i = 0; i < udpif->n_handlers; i++) { + struct handler *handler = &udpif->handlers[i]; + ovs_mutex_lock(&handler->mutex); + simap_increase(usage, "handler upcalls", handler->n_upcalls); + ovs_mutex_unlock(&handler->mutex); + } +} + /* Destroys and deallocates 'upcall'. */ static void upcall_destroy(struct upcall *upcall) diff --git a/ofproto/ofproto-dpif-upcall.h b/ofproto/ofproto-dpif-upcall.h index da7571937..805530bff 100644 --- a/ofproto/ofproto-dpif-upcall.h +++ b/ofproto/ofproto-dpif-upcall.h @@ -39,6 +39,8 @@ void udpif_destroy(struct udpif *); void udpif_wait(struct udpif *); void udpif_revalidate(struct udpif *); + +void udpif_get_memory_usage(struct udpif *, struct simap *usage); /* udpif figures out how to forward packets, and does forward them, but it * can't set up datapath flows on its own. This interface passes packet diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 6af49747f..11484cb6e 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -1545,6 +1545,17 @@ get_memory_usage(const struct ofproto *ofproto_, struct simap *usage) simap_increase(usage, "subfacets", n_subfacets); } +static void +type_get_memory_usage(const char *type, struct simap *usage) +{ + struct dpif_backer *backer; + + backer = shash_find_data(&all_dpif_backers, type); + if (backer) { + udpif_get_memory_usage(backer->udpif, usage); + } +} + static void flush(struct ofproto *ofproto_) { @@ -6146,6 +6157,7 @@ const struct ofproto_class ofproto_dpif_class = { run, wait, get_memory_usage, + type_get_memory_usage, flush, get_features, get_tables, diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h index 713af8767..cc1967f5f 100644 --- a/ofproto/ofproto-provider.h +++ b/ofproto/ofproto-provider.h @@ -783,6 +783,12 @@ struct ofproto_class { void (*get_memory_usage)(const struct ofproto *ofproto, struct simap *usage); + /* Adds some memory usage statistics for the implementation of 'type' + * into 'usage', for use with memory_report(). + * + * This function is optional. */ + void (*type_get_memory_usage)(const char *type, struct simap *usage); + /* Every "struct rule" in 'ofproto' is about to be deleted, one by one. * This function may prepare for that, for example by clearing state in * advance. It should *not* actually delete any "struct rule"s from diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 8fc9916d5..6d25daba5 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -1619,6 +1619,19 @@ ofproto_get_memory_usage(const struct ofproto *ofproto, struct simap *usage) connmgr_get_memory_usage(ofproto->connmgr, usage); } +void +ofproto_type_get_memory_usage(const char *datapath_type, struct simap *usage) +{ + const struct ofproto_class *class; + + datapath_type = ofproto_normalize_type(datapath_type); + class = ofproto_class_find__(datapath_type); + + if (class && class->type_get_memory_usage) { + class->type_get_memory_usage(datapath_type, usage); + } +} + void ofproto_get_ofproto_controller_info(const struct ofproto *ofproto, struct shash *info) diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h index 63ae793a5..219940aba 100644 --- a/ofproto/ofproto.h +++ b/ofproto/ofproto.h @@ -177,6 +177,7 @@ void ofproto_wait(struct ofproto *); bool ofproto_is_alive(const struct ofproto *); void ofproto_get_memory_usage(const struct ofproto *, struct simap *); +void ofproto_type_get_memory_usage(const char *datapath_type, struct simap *); /* A port within an OpenFlow switch. * diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index e337ab5ac..3e1613442 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -2453,6 +2453,15 @@ void bridge_get_memory_usage(struct simap *usage) { struct bridge *br; + struct sset types; + const char *type; + + sset_init(&types); + ofproto_enumerate_types(&types); + SSET_FOR_EACH (type, &types) { + ofproto_type_get_memory_usage(type, usage); + } + sset_destroy(&types); HMAP_FOR_EACH (br, node, &all_bridges) { ofproto_get_memory_usage(br->ofproto, usage);