[ovs-dev] [RFC 07/10] dpif-netdev: Use new ovs-thread-stats for flow statistics
Daniele Di Proietto
ddiproietto at vmware.com
Wed Oct 8 21:09:53 UTC 2014
Signed-off-by: Daniele Di Proietto <ddiproietto at vmware.com>
---
lib/dpif-netdev.c | 97 +++++++++++++++++++++----------------------------------
1 file changed, 36 insertions(+), 61 deletions(-)
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 11aacc3..a798c86 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -54,6 +54,7 @@
#include "ofpbuf.h"
#include "ovs-numa.h"
#include "ovs-rcu.h"
+#include "ovs-thread-stats.h"
#include "packet-dpif.h"
#include "packets.h"
#include "poll-loop.h"
@@ -288,10 +289,8 @@ struct dp_netdev_flow {
* reference. */
struct ovs_refcount ref_cnt;
- /* Statistics.
- *
- * Reading or writing these members requires 'mutex'. */
- struct ovsthread_stats stats; /* Contains "struct dp_netdev_flow_stats". */
+ /* Statistics. */
+ int stats; /* Contains 'struct dp_netdev_flow_stats'. */
/* Actions. */
OVSRCU_TYPE(struct dp_netdev_actions *) actions;
@@ -302,12 +301,10 @@ static bool dp_netdev_flow_ref(struct dp_netdev_flow *);
/* Contained by struct dp_netdev_flow's 'stats' member. */
struct dp_netdev_flow_stats {
- struct ovs_mutex mutex; /* Guards all the other members. */
-
- long long int used OVS_GUARDED; /* Last used time, in monotonic msecs. */
- long long int packet_count OVS_GUARDED; /* Number of packets matched. */
- long long int byte_count OVS_GUARDED; /* Number of bytes matched. */
- uint16_t tcp_flags OVS_GUARDED; /* Bitwise-OR of seen tcp_flags values. */
+ long long int used; /* Last used time, in monotonic msecs. */
+ long long int packet_count; /* Number of packets matched. */
+ long long int byte_count; /* Number of bytes matched. */
+ uint16_t tcp_flags; /* Bitwise-OR of seen tcp_flags values. */
};
/* A set of datapath actions within a "struct dp_netdev_flow".
@@ -1083,16 +1080,8 @@ dpif_netdev_port_query_by_name(const struct dpif *dpif, const char *devname,
static void
dp_netdev_flow_free(struct dp_netdev_flow *flow)
{
- struct dp_netdev_flow_stats *bucket;
- size_t i;
-
- OVSTHREAD_STATS_FOR_EACH_BUCKET (bucket, i, &flow->stats) {
- ovs_mutex_destroy(&bucket->mutex);
- free_cacheline(bucket);
- }
- ovsthread_stats_destroy(&flow->stats);
-
cls_rule_destroy(CONST_CAST(struct cls_rule *, &flow->cr));
+ ovsthread_stats_destroy_bucket(flow->stats);
dp_netdev_actions_free(dp_netdev_flow_get_actions(flow));
free(flow);
}
@@ -1398,21 +1387,24 @@ dp_netdev_find_flow(const struct dp_netdev *dp, const struct flow *flow)
}
static void
+dp_netdev_flow_aggregate_cb(void *aux, struct ovsthread_stats_bucket *b)
+{
+ struct dpif_flow_stats *dst = (struct dpif_flow_stats *)aux;
+ struct dp_netdev_flow_stats *src
+ = OVSTHREAD_STATS_BUCKET_CAST(struct dp_netdev_flow_stats *, b);
+ dst->used = MAX(dst->used, src->used);
+ dst->n_packets += src->packet_count;
+ dst->n_bytes += src->byte_count;
+ dst->tcp_flags |= src->tcp_flags;
+}
+
+static void
get_dpif_flow_stats(const struct dp_netdev_flow *netdev_flow,
struct dpif_flow_stats *stats)
{
- struct dp_netdev_flow_stats *bucket;
- size_t i;
-
memset(stats, 0, sizeof *stats);
- OVSTHREAD_STATS_FOR_EACH_BUCKET (bucket, i, &netdev_flow->stats) {
- ovs_mutex_lock(&bucket->mutex);
- stats->n_packets += bucket->packet_count;
- stats->n_bytes += bucket->byte_count;
- stats->used = MAX(stats->used, bucket->used);
- stats->tcp_flags |= bucket->tcp_flags;
- ovs_mutex_unlock(&bucket->mutex);
- }
+ ovsthread_stats_aggregate(netdev_flow->stats, stats,
+ dp_netdev_flow_aggregate_cb);
}
static void
@@ -1564,7 +1556,7 @@ dp_netdev_flow_add(struct dp_netdev *dp, struct match *match,
ovs_refcount_init(&netdev_flow->ref_cnt);
- ovsthread_stats_init(&netdev_flow->stats);
+ netdev_flow->stats = ovsthread_stats_create_bucket();
ovsrcu_set(&netdev_flow->actions,
dp_netdev_actions_create(actions, actions_len));
@@ -1596,17 +1588,7 @@ dp_netdev_flow_add(struct dp_netdev *dp, struct match *match,
static void
clear_stats(struct dp_netdev_flow *netdev_flow)
{
- struct dp_netdev_flow_stats *bucket;
- size_t i;
-
- OVSTHREAD_STATS_FOR_EACH_BUCKET (bucket, i, &netdev_flow->stats) {
- ovs_mutex_lock(&bucket->mutex);
- bucket->used = 0;
- bucket->packet_count = 0;
- bucket->byte_count = 0;
- bucket->tcp_flags = 0;
- ovs_mutex_unlock(&bucket->mutex);
- }
+ ovsthread_stats_clear(netdev_flow->stats);
}
static int
@@ -2360,14 +2342,6 @@ dp_netdev_set_pmds_on_numa(struct dp_netdev *dp, int numa_id)
}
-static void *
-dp_netdev_flow_stats_new_cb(void)
-{
- struct dp_netdev_flow_stats *bucket = xzalloc_cacheline(sizeof *bucket);
- ovs_mutex_init(&bucket->mutex);
- return bucket;
-}
-
/* Called after pmd threads config change. Restarts pmd threads with
* new configuration. */
static void
@@ -2385,22 +2359,23 @@ dp_netdev_reset_pmd_threads(struct dp_netdev *dp)
}
static void
-dp_netdev_flow_used(struct dp_netdev_flow *netdev_flow,
- int cnt, int size,
+dp_netdev_flow_used(struct dp_netdev_flow *netdev_flow, int cnt, int size,
uint16_t tcp_flags)
{
long long int now = time_msec();
- struct dp_netdev_flow_stats *bucket;
+ struct ovsthread_stats_bucket *bucket;
+ struct dp_netdev_flow_stats *stats;
+ uint32_t seq;
- bucket = ovsthread_stats_bucket_get(&netdev_flow->stats,
- dp_netdev_flow_stats_new_cb);
+ bucket = ovsthread_stats_get_bucket(netdev_flow->stats, &seq);
+ stats = OVSTHREAD_STATS_BUCKET_CAST(struct dp_netdev_flow_stats *, bucket);
- ovs_mutex_lock(&bucket->mutex);
- bucket->used = MAX(now, bucket->used);
- bucket->packet_count += cnt;
- bucket->byte_count += size;
- bucket->tcp_flags |= tcp_flags;
- ovs_mutex_unlock(&bucket->mutex);
+ stats->used = MAX(now, stats->used);
+ stats->packet_count += cnt;
+ stats->byte_count += size;
+ stats->tcp_flags |= tcp_flags;
+
+ ovsthread_stats_bucket_done(bucket, seq);
}
static void *
--
2.1.0.rc1
More information about the dev
mailing list