From 8844e035421b9f2bf15edb1513146d865c5886d5 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Sat, 30 Mar 2013 15:13:00 -0700 Subject: [PATCH] ofproto-dpif: Systematically push stats upon request. Commit bf1e8ff (ofproto-dpif: Push statistics in rule_get_stats()), started down the road towards pushing stats on demand, but it didn't go quite far enough. First, it neglected to push stats in port_get_stats() and mirror_get_stats(). Second, it only pushes stats for a single ofproto, making it incomplete when patch ports are used. Signed-off-by: Ethan Jackson --- ofproto/ofproto-dpif.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index d6121f1f8..0b16bfa79 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -515,6 +515,7 @@ static void facet_reset_counters(struct facet *); static void facet_push_stats(struct facet *); static void facet_learn(struct facet *); static void facet_account(struct facet *); +static void push_all_stats(void); static struct subfacet *facet_get_subfacet(struct facet *); @@ -2937,6 +2938,8 @@ mirror_get_stats(struct ofproto *ofproto_, void *aux, return 0; } + push_all_stats(); + *packets = mirror->packet_count; *bytes = mirror->byte_count; @@ -3195,6 +3198,8 @@ port_get_stats(const struct ofport *ofport_, struct netdev_stats *stats) struct ofport_dpif *ofport = ofport_dpif_cast(ofport_); int error; + push_all_stats(); + error = netdev_get_stats(ofport->up.netdev, stats); if (!error && ofport_->ofp_port == OFPP_LOCAL) { @@ -5037,6 +5042,27 @@ facet_push_stats(struct facet *facet) } } +static void +push_all_stats(void) +{ + static long long int rl = LLONG_MIN; + struct ofproto_dpif *ofproto; + + if (time_msec() < rl) { + return; + } + + HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) { + struct facet *facet; + + HMAP_FOR_EACH (facet, hmap_node, &ofproto->facets) { + facet_push_stats(facet); + } + } + + rl = time_msec() + 100; +} + static void rule_credit_stats(struct rule_dpif *rule, const struct dpif_flow_stats *stats) { @@ -5515,13 +5541,10 @@ rule_destruct(struct rule *rule_) static void rule_get_stats(struct rule *rule_, uint64_t *packets, uint64_t *bytes) { - struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule_->ofproto); struct rule_dpif *rule = rule_dpif_cast(rule_); struct facet *facet; - HMAP_FOR_EACH (facet, hmap_node, &ofproto->facets) { - facet_push_stats(facet); - } + push_all_stats(); /* Start from historical data for 'rule' itself that are no longer tracked * in facets. This counts, for example, facets that have expired. */ -- 2.43.0