Signed-off-by: Ethan Jackson <et...@nicira.com> --- ofproto/ofproto-dpif.c | 13 +++++++++++-- ofproto/ofproto-dpif.h | 6 ++++-- 2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 1d3f4ca..439adf7 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -4864,9 +4864,11 @@ push_all_stats(void) void rule_credit_stats(struct rule_dpif *rule, const struct dpif_flow_stats *stats) { + ovs_mutex_lock(&rule->stats_mutex); rule->packet_count += stats->n_packets; rule->byte_count += stats->n_bytes; ofproto_rule_update_used(&rule->up, stats->used); + ovs_mutex_unlock(&rule->stats_mutex); } /* Subfacets. */ @@ -5224,16 +5226,21 @@ static enum ofperr rule_construct(struct rule *rule_) { struct rule_dpif *rule = rule_dpif_cast(rule_); + ovs_mutex_init(&rule->stats_mutex, PTHREAD_MUTEX_NORMAL); + ovs_mutex_lock(&rule->stats_mutex); rule->packet_count = 0; rule->byte_count = 0; + ovs_mutex_unlock(&rule->stats_mutex); complete_operation(rule); return 0; } static void -rule_destruct(struct rule *rule) +rule_destruct(struct rule *rule_) { - complete_operation(rule_dpif_cast(rule)); + struct rule_dpif *rule = rule_dpif_cast(rule_); + ovs_mutex_destroy(&rule->stats_mutex); + complete_operation(rule); } static void @@ -5249,8 +5256,10 @@ rule_get_stats(struct rule *rule_, uint64_t *packets, uint64_t *bytes) /* Start from historical data for 'rule' itself that are no longer tracked * in facets. This counts, for example, facets that have expired. */ + ovs_mutex_lock(&rule->stats_mutex); *packets = rule->packet_count; *bytes = rule->byte_count; + ovs_mutex_unlock(&rule->stats_mutex); } static void diff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h index 0c6af62..18b1829 100644 --- a/ofproto/ofproto-dpif.h +++ b/ofproto/ofproto-dpif.h @@ -19,6 +19,7 @@ #include "hmapx.h" #include "ofproto/ofproto-provider.h" +#include "ovs-thread.h" #include "timer.h" #include "util.h" @@ -42,8 +43,9 @@ struct rule_dpif { * packet_count or byte_count member or that can be obtained from the * datapath by, e.g., dpif_flow_get() for any subfacet. */ - uint64_t packet_count; /* Number of packets received. */ - uint64_t byte_count; /* Number of bytes received. */ + struct ovs_mutex stats_mutex; + uint64_t packet_count OVS_GUARDED; /* Number of packets received. */ + uint64_t byte_count OVS_GUARDED; /* Number of bytes received. */ }; static inline struct rule_dpif *rule_dpif_cast(const struct rule *rule) -- 1.7.9.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev