[ovs-dev] [RFC 09/10] dpif-netdev: Use new ovs-thread-stats for datapath stats
Daniele Di Proietto
ddiproietto at vmware.com
Wed Oct 8 21:09:55 UTC 2014
Signed-off-by: Daniele Di Proietto <ddiproietto at vmware.com>
---
lib/dpif-netdev.c | 71 +++++++++++++++++++++++++++----------------------------
1 file changed, 35 insertions(+), 36 deletions(-)
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index a798c86..9880027 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -175,7 +175,7 @@ struct dp_netdev {
/* Statistics.
*
* ovsthread_stats is internally synchronized. */
- struct ovsthread_stats stats; /* Contains 'struct dp_netdev_stats *'. */
+ int stats; /* Contains 'struct dp_netdev_stats *'. */
/* Ports.
*
@@ -219,10 +219,8 @@ enum dp_stat_type {
/* Contained by struct dp_netdev's 'stats' member. */
struct dp_netdev_stats {
- struct ovs_mutex mutex; /* Protects 'n'. */
-
- /* Indexed by DP_STAT_*, protected by 'mutex'. */
- unsigned long long int n[DP_N_STATS] OVS_GUARDED;
+ /* Indexed by DP_STAT_*. */
+ unsigned long long int n[DP_N_STATS];
};
@@ -550,7 +548,7 @@ create_dp_netdev(const char *name, const struct dpif_class *class,
classifier_init(&dp->cls, NULL);
cmap_init(&dp->flow_table);
- ovsthread_stats_init(&dp->stats);
+ dp->stats = ovsthread_stats_create_bucket();
ovs_mutex_init(&dp->port_mutex);
cmap_init(&dp->ports);
@@ -627,8 +625,6 @@ dp_netdev_free(struct dp_netdev *dp)
OVS_REQUIRES(dp_netdev_mutex)
{
struct dp_netdev_port *port;
- struct dp_netdev_stats *bucket;
- int i;
shash_find_and_delete(&dp_netdevs, dp->name);
@@ -644,11 +640,7 @@ dp_netdev_free(struct dp_netdev *dp)
}
ovs_mutex_unlock(&dp->port_mutex);
- OVSTHREAD_STATS_FOR_EACH_BUCKET (bucket, i, &dp->stats) {
- ovs_mutex_destroy(&bucket->mutex);
- free_cacheline(bucket);
- }
- ovsthread_stats_destroy(&dp->stats);
+ ovsthread_stats_destroy_bucket(dp->stats);
classifier_destroy(&dp->cls);
cmap_destroy(&dp->flow_table);
@@ -702,23 +694,34 @@ dpif_netdev_destroy(struct dpif *dpif)
return 0;
}
+static void
+dp_netdev_stats_aggr_cb(void *aux, struct ovsthread_stats_bucket *b)
+{
+ struct dp_netdev_stats *dst = (struct dp_netdev_stats *) aux;
+ struct dp_netdev_stats *src
+ = OVSTHREAD_STATS_BUCKET_CAST(struct dp_netdev_stats *, b);
+ size_t i;
+
+ for (i = 0; i < DP_N_STATS; i++) {
+ dst->n[i] += src->n[i];
+ }
+}
+
static int
dpif_netdev_get_stats(const struct dpif *dpif, struct dpif_dp_stats *stats)
{
struct dp_netdev *dp = get_dp_netdev(dpif);
- struct dp_netdev_stats *bucket;
- size_t i;
+ struct dp_netdev_stats bucket;
stats->n_flows = cmap_count(&dp->flow_table);
- stats->n_hit = stats->n_missed = stats->n_lost = 0;
- OVSTHREAD_STATS_FOR_EACH_BUCKET (bucket, i, &dp->stats) {
- ovs_mutex_lock(&bucket->mutex);
- stats->n_hit += bucket->n[DP_STAT_HIT];
- stats->n_missed += bucket->n[DP_STAT_MISS];
- stats->n_lost += bucket->n[DP_STAT_LOST];
- ovs_mutex_unlock(&bucket->mutex);
- }
+ memset(&bucket, 0, sizeof(bucket));
+ ovsthread_stats_aggregate(dp->stats, &bucket, dp_netdev_stats_aggr_cb);
+
+ stats->n_hit = bucket.n[DP_STAT_HIT];
+ stats->n_missed = bucket.n[DP_STAT_MISS];
+ stats->n_lost = bucket.n[DP_STAT_LOST];
+
stats->n_masks = UINT32_MAX;
stats->n_mask_hit = UINT64_MAX;
@@ -2378,23 +2381,19 @@ dp_netdev_flow_used(struct dp_netdev_flow *netdev_flow, int cnt, int size,
ovsthread_stats_bucket_done(bucket, seq);
}
-static void *
-dp_netdev_stats_new_cb(void)
-{
- struct dp_netdev_stats *bucket = xzalloc_cacheline(sizeof *bucket);
- ovs_mutex_init(&bucket->mutex);
- return bucket;
-}
-
static void
dp_netdev_count_packet(struct dp_netdev *dp, enum dp_stat_type type, int cnt)
{
- struct dp_netdev_stats *bucket;
+ struct ovsthread_stats_bucket *bucket;
+ struct dp_netdev_stats *stats;
+ uint32_t seq;
+
+ bucket = ovsthread_stats_get_bucket(dp->stats, &seq);
+ stats = OVSTHREAD_STATS_BUCKET_CAST(struct dp_netdev_stats *, bucket);
- bucket = ovsthread_stats_bucket_get(&dp->stats, dp_netdev_stats_new_cb);
- ovs_mutex_lock(&bucket->mutex);
- bucket->n[type] += cnt;
- ovs_mutex_unlock(&bucket->mutex);
+ stats->n[type] += cnt;
+
+ ovsthread_stats_bucket_done(bucket, seq);
}
static int
--
2.1.0.rc1
More information about the dev
mailing list