From patchwork Fri Sep 21 16:01:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pattan, Reshma" X-Patchwork-Id: 45124 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B61C15398; Fri, 21 Sep 2018 18:02:19 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id EF9485323 for ; Fri, 21 Sep 2018 18:02:17 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Sep 2018 09:02:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,285,1534834800"; d="scan'208";a="265591898" Received: from sivswdev02.ir.intel.com (HELO localhost.localdomain) ([10.237.217.46]) by fmsmga006.fm.intel.com with ESMTP; 21 Sep 2018 09:01:48 -0700 From: Reshma Pattan To: longtb5@viettel.com.vn, konstantin.ananyev@intel.com, dev@dpdk.org Cc: Reshma Pattan Date: Fri, 21 Sep 2018 17:01:43 +0100 Message-Id: <1537545703-9599-1-git-send-email-reshma.pattan@intel.com> X-Mailer: git-send-email 1.7.0.7 Subject: [dpdk-dev] [PATCH] latencystats: fix timestamp marking and latency calculation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Latency calculation logic is not correct for the case where packets gets dropped before TX. As for the dropped packets, the timestamp is not cleared, and such packets still gets counted for latency calculation in next runs, that will result in inaccurate latency measurement. So fix this issue as below, Before setting timestamp in mbuf, check mbuf don't have any prior valid time stamp flag set and after marking the timestamp, set mbuf flags to indicate timestamp is valid. Before calculating timestamp check mbuf flags are set to indicate timestamp is valid. With the above logic it is guaranteed that correct timestamps have been used. Fixes: 5cd3cac9ed ("latency: added new library for latency stats") Reported-by: Bao-Long Tran Signed-off-by: Reshma Pattan Tested-by: Bao-Long Tran --- lib/librte_latencystats/rte_latencystats.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/librte_latencystats/rte_latencystats.c b/lib/librte_latencystats/rte_latencystats.c index 1fdec68e3..8870226bb 100644 --- a/lib/librte_latencystats/rte_latencystats.c +++ b/lib/librte_latencystats/rte_latencystats.c @@ -125,8 +125,11 @@ add_time_stamps(uint16_t pid __rte_unused, for (i = 0; i < nb_pkts; i++) { diff_tsc = now - prev_tsc; timer_tsc += diff_tsc; - if (timer_tsc >= samp_intvl) { + + if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) == 0 + && (timer_tsc >= samp_intvl)) { pkts[i]->timestamp = now; + pkts[i]->ol_flags |= PKT_RX_TIMESTAMP; timer_tsc = 0; } prev_tsc = now; @@ -156,7 +159,8 @@ calc_latency(uint16_t pid __rte_unused, now = rte_rdtsc(); for (i = 0; i < nb_pkts; i++) { - if (pkts[i]->timestamp) + if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) && + pkts[i]->timestamp) latency[cnt++] = now - pkts[i]->timestamp; }