From patchwork Fri Apr 19 17:28:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139547 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B4D0443EB2; Fri, 19 Apr 2024 19:29:44 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C7193406B4; Fri, 19 Apr 2024 19:29:40 +0200 (CEST) Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.48]) by mails.dpdk.org (Postfix) with ESMTP id 7023740689 for ; Fri, 19 Apr 2024 19:29:38 +0200 (CEST) Received: by mail-oo1-f48.google.com with SMTP id 006d021491bc7-5ad21f3e5dcso397363eaf.3 for ; Fri, 19 Apr 2024 10:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1713547777; x=1714152577; 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=1iMXXGjOoTwNd9pOuzO/FsZahJFsBN6I19d6MX2wr/Q=; b=d19Og84AG4Zines8JX1JFDLRMDNe8v9d9q8gVJgvfzNJtcgTytesvQu17Fm+DrCmM8 R2hcsgv/Gi/NH/LRd+KmVLxhpBs2mfSB2Cwk79iGQDXtHX6IbEZHhAbQF6WC9KcQNLd5 U0FUibA4x54us6cWyoe7iJqs4orXrtXY4hbW8Lb3Z5APyv/GDx81DndIEr4t5lO6itA/ ZWYlh1MpKXFogAMfxHyQUhJ8QAZMgfX1ybMDvkHnY0bJBE/FpKwRrDIfajb2tYyv/Evi O+/plt3AHfqwhPCKyN+o0wpFwDLIBu7WicgbAdAjlpvASDyexPTEgZVxqA8zc2T2MCkk JTFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713547777; x=1714152577; 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=1iMXXGjOoTwNd9pOuzO/FsZahJFsBN6I19d6MX2wr/Q=; b=naoY8ajd7xPHuBsB54+5lvjz6dxoMfKjEk4Ug9H5Mp5F0h8nDvWsvN4Gar6BiX/FRS 7Rf7VXYYAEEusK0H1W8lM++aKvwumVbLMKIbxUHFO5XpMuGuHmEIHrUM4pNDGyQdHiWB X6zvmVMQk05KYUpN0dnn/Nm/vrnpJHcPZM7eHzwXppwjSFTJfMFuzYi3dP1Z8Lk0BB5z IDpiNHRhnLU0DSMhgzAZdnapJumzoFVvG5DnFoQ5liPW/3JTHkgj4DaqT67RbySkvnrv WqU3Dr2lTf4z6sx98S6n+PHMmC5OBPyEtUw8+VPTymifb1ZlHw78hyGn+9JNVHpLDAEP gDfA== X-Gm-Message-State: AOJu0YyThPeSaFBsUG8KZ7/unfnEGdOAF6VRgPoo9LLjfnD15mwN/Q58 kBlz5rrgRDJUMx4OTa663Ak/5k2Y86hPITBjWg2VnlgpqtdOii/6WdFTiN9L6KgCINpMOonD7SO 8 X-Google-Smtp-Source: AGHT+IFVteU+QkJvgt5Rl+XaOJb89OaONKtlhOBBbEY3wHeByCLpxRVo26NbTX6dcecBG+WrhmQEEw== X-Received: by 2002:a05:6870:e99:b0:222:1353:ad0f with SMTP id mm25-20020a0568700e9900b002221353ad0fmr3408676oab.24.1713547777603; Fri, 19 Apr 2024 10:29:37 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id h16-20020a632110000000b005f3c5cf33b5sm3383074pgh.37.2024.04.19.10.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 10:29:37 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Morten_Br?= =?utf-8?q?=C3=B8rup?= , Tyler Retzlaff , Reshma Pattan Subject: [PATCH v4 1/6] latencystats: replace use of VLA Date: Fri, 19 Apr 2024 10:28:21 -0700 Message-ID: <20240419172926.55447-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240419172926.55447-1-stephen@networkplumber.org> References: <20240408195036.182545-1-stephen@networkplumber.org> <20240419172926.55447-1-stephen@networkplumber.org> MIME-Version: 1.0 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 The temporary array latencystats is not needed if the algorithm is converted into one pass. Signed-off-by: Stephen Hemminger Acked-by: Morten Brørup Acked-by: Tyler Retzlaff --- lib/latencystats/rte_latencystats.c | 31 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/latencystats/rte_latencystats.c b/lib/latencystats/rte_latencystats.c index 4ea9b0d75b..9b345bfb33 100644 --- a/lib/latencystats/rte_latencystats.c +++ b/lib/latencystats/rte_latencystats.c @@ -157,9 +157,9 @@ calc_latency(uint16_t pid __rte_unused, uint16_t nb_pkts, void *_ __rte_unused) { - unsigned int i, cnt = 0; + unsigned int i; uint64_t now; - float latency[nb_pkts]; + float latency; static float prev_latency; /* * Alpha represents degree of weighting decrease in EWMA, @@ -169,13 +169,14 @@ calc_latency(uint16_t pid __rte_unused, const float alpha = 0.2; now = rte_rdtsc(); - for (i = 0; i < nb_pkts; i++) { - if (pkts[i]->ol_flags & timestamp_dynflag) - latency[cnt++] = now - *timestamp_dynfield(pkts[i]); - } rte_spinlock_lock(&glob_stats->lock); - for (i = 0; i < cnt; i++) { + for (i = 0; i < nb_pkts; i++) { + if (!(pkts[i]->ol_flags & timestamp_dynflag)) + continue; + + latency = now - *timestamp_dynfield(pkts[i]); + /* * The jitter is calculated as statistical mean of interpacket * delay variation. The "jitter estimate" is computed by taking @@ -187,22 +188,22 @@ calc_latency(uint16_t pid __rte_unused, * Reference: Calculated as per RFC 5481, sec 4.1, * RFC 3393 sec 4.5, RFC 1889 sec. */ - glob_stats->jitter += (fabsf(prev_latency - latency[i]) + glob_stats->jitter += (fabsf(prev_latency - latency) - glob_stats->jitter)/16; if (glob_stats->min_latency == 0) - glob_stats->min_latency = latency[i]; - else if (latency[i] < glob_stats->min_latency) - glob_stats->min_latency = latency[i]; - else if (latency[i] > glob_stats->max_latency) - glob_stats->max_latency = latency[i]; + glob_stats->min_latency = latency; + else if (latency < glob_stats->min_latency) + 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 */ glob_stats->avg_latency += - alpha * (latency[i] - glob_stats->avg_latency); - prev_latency = latency[i]; + alpha * (latency - glob_stats->avg_latency); + prev_latency = latency; } rte_spinlock_unlock(&glob_stats->lock);