From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5E426A04F3 for ; Thu, 5 Dec 2019 18:18:19 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 332A01BF88; Thu, 5 Dec 2019 18:18:19 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id B22482BE9; Thu, 5 Dec 2019 18:18:15 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Dec 2019 09:18:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,282,1571727600"; d="scan'208";a="236737924" Received: from silpixa00400214.ir.intel.com (HELO silpixa00400214.ger.corp.intel.com) ([10.237.222.119]) by fmsmga004.fm.intel.com with ESMTP; 05 Dec 2019 09:18:13 -0800 From: Reshma Pattan To: dev@dpdk.org Cc: ferruh.yigit@intel.com, Reshma Pattan , stable@dpdk.org Date: Thu, 5 Dec 2019 17:18:11 +0000 Message-Id: <20191205171811.28045-1-reshma.pattan@intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] [PATCH] latencystats: fix latency calculation for multithread X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" 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 --- 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