From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A65D343E94; Wed, 17 Apr 2024 19:09:44 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2D911427DA; Wed, 17 Apr 2024 19:09:21 +0200 (CEST) Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by mails.dpdk.org (Postfix) with ESMTP id 5EE0E427DD for ; Wed, 17 Apr 2024 19:09:15 +0200 (CEST) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1e2178b2cf2so52764335ad.0 for ; Wed, 17 Apr 2024 10:09:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1713373754; x=1713978554; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eWXQpRBTA/1MVLUFmfw6CtiM8QVScfWJV0ddb94LcXQ=; b=QiL8o1LSgxDf8HG2P9ai+EGxvW7zLTeYenTC/oLRWsIG+/vAm0SFFDbtuAR5RfnrsJ wol4eGu4JX0ZBriIAJt6gUXlTCFmr59eshqBiXZK4LHdTahDJ0yz/3sJEX5x31G4p+Ji 2ULy6ZBm4enctbC2URKfgJKoGAQe2jBXeRr1XKNKbFgXQaMLLvv8N75Naqji5OS45YlC jvchlyCl1UbBjbSbShZEUvfP6E3O9pgTe2a24C4gdCOfh/Ez9KVfhSERh+/vNmcLKAg3 UWT37M6xRwEM2fHBC+VnaiYnBTBWzosUkF7NO9MKVPeftlRQbsWRNndGQ5EQkTTlymFg /MBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713373754; x=1713978554; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eWXQpRBTA/1MVLUFmfw6CtiM8QVScfWJV0ddb94LcXQ=; b=hKRNuiheKptUKqXXjEuBg6/25c+M1jNWtrFo4l/KxneYNGyp0dQ+Wot69pXF3h+XTU nH0sO+O2wSLo8qFSZeuTlPXemp8m579k6KOim4XtLkZAIlj0x0fvzflxOPYSnIgk+eTE fnDFHJRjAZV2M3/HNoiZ3bVR8tMCa7zBuLu1DRa0QKNhHPWTZkk3hvmFkstIj5sQDNAo t8Wc8uZvWK8FqqW9wmXB492ogFNSlrfxWiMMYEmUJudFA5mUkqRjgep+uRDzTuVEKLB5 RMezhoLl/YI50ELElZ2rSdz4CKSSYwFmyUodf4z6eksSriDOwaT355hAcRrgCjZu0YLJ Djtg== X-Gm-Message-State: AOJu0YyBK3orujOO/vipnIf1wNjNBn9BYTiIDbtJu0v4XQT7VucvxWKv yLYHvVCAUqsOBOtTWBlnSKvI6D/pnoMWxp6bAthYKS/2aK4YbaK127u3vog4SwYhTbxExQ/ZjeF P X-Google-Smtp-Source: AGHT+IHBUjviD11CWpvmlRw+m2IlxLIhjty70mTBAhysOJrWd06EwMl42h5Kx3fz8406cagdUcZqQw== X-Received: by 2002:a17:902:e807:b0:1e7:d482:9e07 with SMTP id u7-20020a170902e80700b001e7d4829e07mr144097plg.12.1713373754501; Wed, 17 Apr 2024 10:09:14 -0700 (PDT) Received: from hermes.lan (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id l5-20020a170903120500b001e4458831afsm11832442plh.227.2024.04.17.10.09.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 10:09:14 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v3 5/5] latencystats: include file cleanup Date: Wed, 17 Apr 2024 10:07:27 -0700 Message-ID: <20240417170908.76701-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240417170908.76701-1-stephen@networkplumber.org> References: <0240408195036.182545-1-stephen@networkplumber.org> <20240417170908.76701-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Include what is used here. Signed-off-by: Stephen Hemminger --- lib/latencystats/rte_latencystats.c | 85 ++++++++++++++++++----------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/lib/latencystats/rte_latencystats.c b/lib/latencystats/rte_latencystats.c index 62038a9f5d..31e7a6eb88 100644 --- a/lib/latencystats/rte_latencystats.c +++ b/lib/latencystats/rte_latencystats.c @@ -2,16 +2,25 @@ * Copyright(c) 2018 Intel Corporation */ +#include #include +#include +#include +#include -#include -#include -#include +#include #include +#include +#include #include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include #include "rte_latencystats.h" @@ -148,14 +157,15 @@ add_time_stamps(uint16_t pid __rte_unused, static uint16_t calc_latency(uint16_t pid __rte_unused, - uint16_t qid __rte_unused, - struct rte_mbuf **pkts, - uint16_t nb_pkts, - void *_ __rte_unused) + uint16_t qid __rte_unused, + struct rte_mbuf **pkts, + uint16_t nb_pkts, + void *_ __rte_unused) { unsigned int i; uint64_t now, latency; static uint64_t prev_latency; + static bool first_sample = true; now = rte_rdtsc(); @@ -166,32 +176,41 @@ calc_latency(uint16_t pid __rte_unused, latency = now - *timestamp_dynfield(pkts[i]); - /* - * The jitter is calculated as statistical mean of interpacket - * delay variation. The "jitter estimate" is computed by taking - * the absolute values of the ipdv sequence and applying an - * exponential filter with parameter 1/16 to generate the - * estimate. i.e J=J+(|D(i-1,i)|-J)/16. Where J is jitter, - * D(i-1,i) is difference in latency of two consecutive packets - * i-1 and i. - * Reference: Calculated as per RFC 5481, sec 4.1, - * RFC 3393 sec 4.5, RFC 1889 sec. - */ - glob_stats->jitter += ((prev_latency - latency) - glob_stats->jitter) / 16; - if (glob_stats->min_latency == 0) - glob_stats->min_latency = latency; - else if (latency < glob_stats->min_latency) + if (first_sample) { + first_sample = false; + glob_stats->min_latency = latency; - else if (latency > glob_stats->max_latency) glob_stats->max_latency = latency; - /* - * The average latency is measured using exponential moving - * average, i.e. using EWMA - * https://en.wikipedia.org/wiki/Moving_average - * - * Alpha is .25 - */ - glob_stats->avg_latency += (latency - glob_stats->avg_latency) / 4; + glob_stats->avg_latency = latency; + glob_stats->jitter = 0; + } else { + /* + * The jitter is calculated as statistical mean of interpacket + * delay variation. The "jitter estimate" is computed by taking + * the absolute values of the ipdv sequence and applying an + * exponential filter with parameter 1/16 to generate the + * estimate. i.e J=J+(|D(i-1,i)|-J)/16. Where J is jitter, + * D(i-1,i) is difference in latency of two consecutive packets + * i-1 and i. + * Reference: Calculated as per RFC 5481, sec 4.1, + * RFC 3393 sec 4.5, RFC 1889 sec. + */ + glob_stats->jitter += ((prev_latency - latency) + - glob_stats->jitter) / 16; + if (latency < glob_stats->min_latency) + glob_stats->min_latency = latency; + if (latency > glob_stats->max_latency) + glob_stats->max_latency = latency; + /* + * The average latency is measured using exponential moving + * average, i.e. using EWMA + * https://en.wikipedia.org/wiki/Moving_average + * + * Alpha is .25 + */ + glob_stats->avg_latency += (latency - glob_stats->avg_latency) / 4; + } + prev_latency = latency; } rte_spinlock_unlock(&glob_stats->lock); -- 2.43.0