DPDK patches and discussions
 help / color / mirror / Atom feed
From: Reshma Pattan <reshma.pattan@intel.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, Reshma Pattan <reshma.pattan@intel.com>,
	stable@dpdk.org
Subject: [dpdk-dev] [PATCH] latencystats: fix latency calculation for multithread
Date: Thu,  5 Dec 2019 17:18:11 +0000	[thread overview]
Message-ID: <20191205171811.28045-1-reshma.pattan@intel.com> (raw)

Make latency calculation multithread safe by
using spinlock.

Fixes: 5cd3cac9ed ("latency: added new library for latency stats")
Cc: stable@dpdk.org

Signed-off-by: reshma pattan <reshma.pattan@intel.com>
---
 lib/librte_latencystats/rte_latencystats.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/librte_latencystats/rte_latencystats.c b/lib/librte_latencystats/rte_latencystats.c
index 98e018939..ba2fff3bc 100644
--- a/lib/librte_latencystats/rte_latencystats.c
+++ b/lib/librte_latencystats/rte_latencystats.c
@@ -42,6 +42,7 @@ struct rte_latency_stats {
 	float avg_latency; /**< Average latency in nano seconds */
 	float max_latency; /**< Maximum latency in nano seconds */
 	float jitter; /** Latency variation */
+	rte_spinlock_t lock; /** Latency calculation lock */
 };
 
 static struct rte_latency_stats *glob_stats;
@@ -164,6 +165,7 @@ calc_latency(uint16_t pid __rte_unused,
 			latency[cnt++] = now - pkts[i]->timestamp;
 	}
 
+	rte_spinlock_lock(&glob_stats->lock);
 	for (i = 0; i < cnt; i++) {
 		/*
 		 * The jitter is calculated as statistical mean of interpacket
@@ -193,6 +195,7 @@ calc_latency(uint16_t pid __rte_unused,
 			alpha * (latency[i] - glob_stats->avg_latency);
 		prev_latency = latency[i];
 	}
+	rte_spinlock_unlock(&glob_stats->lock);
 
 	return nb_pkts;
 }
@@ -223,6 +226,7 @@ rte_latencystats_init(uint64_t app_samp_intvl,
 	}
 
 	glob_stats = mz->addr;
+	rte_spinlock_init(&glob_stats->lock);
 	samp_intvl = app_samp_intvl * latencystat_cycles_per_ns();
 
 	/** Register latency stats with stats library */
-- 
2.21.0


             reply	other threads:[~2019-12-05 17:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-05 17:18 Reshma Pattan [this message]
2020-01-20  0:28 ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191205171811.28045-1-reshma.pattan@intel.com \
    --to=reshma.pattan@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).