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 8F3CA43E94; Wed, 17 Apr 2024 19:09:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 485F8427DB; Wed, 17 Apr 2024 19:09:15 +0200 (CEST) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mails.dpdk.org (Postfix) with ESMTP id 5A24140DDA for ; Wed, 17 Apr 2024 19:09:12 +0200 (CEST) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1e65b29f703so32053865ad.3 for ; Wed, 17 Apr 2024 10:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1713373751; x=1713978551; 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=09UyrYX1Vh02PraxkSf5Xu2VMzlVl81VvnMGrlBxTxw=; b=GlwPLgFM41wqVhvIYODY37nYnF3jFXSXRO5mjZH4CDT9SacJPKmEzPKqvdryFynq88 18gv7QrU6fuy5CXJcAZZ1n9YfYc/c2O47FByCoOKMNndmewo8KlMQpT8KBJNxlWfwq7k zX0cG6wWTVVxfZvad217OTgiHKBKxQGYNT4odL84p80YzSiVMYExxfXm8zT+eBjQKdb7 h9lT9sXyG3/+zXIm8fSMGVNMwo4JBZDIvlg0h+omhkR35ehHpBTW/zwqwL91rmPC4LpL V4Ej1Zb7O1fZZRuP32aRNof1COMU/r3TzpuZ1Uhf0J4TYNbwsXmkVx27U4399NjtkxKi fLSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713373751; x=1713978551; 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=09UyrYX1Vh02PraxkSf5Xu2VMzlVl81VvnMGrlBxTxw=; b=HJ2DCsvH9DvzRkdnWCiw2cWVhw+Uae5aU9K6/bufvKSLQKEbn4Es2lCqjp4rAnBRuU 8ELWCziwwu7fCUPX6cXGepp91c+Tay8Hg6iupAFMrt68TSYl9aIwc2yvSrFkDeRQxNmr GStpeHHS3NBeTJvr4rKsptS9gP1DE2TrJZh83qCwBfPTggRkFHmX6bvyw7pxmbebvf2Z E4ncNVx5A64TtIN4DH5pc9HB6o92UME20cjQMDLuomrwttr8IWhThabd+76Dc5t1Gic0 kyGxkpak2XLnPfUpQKSPOInQFN2e+S95IGrZNmGSOPAQn8Io7VpOMnEq+2kFiM/rJpp5 Jdkw== X-Gm-Message-State: AOJu0YyYtwtClxX+JNtrXbCdUFGI9Mp4CJsusCsrn12oiN/Mk45AiZz3 rZfo7MIwUAyxgVxIUotf5p7Zhr19vtWlrm9CHUsDCXeihp6dyXqZ/9QR6moaBL0mHvFd4rOyyCj e X-Google-Smtp-Source: AGHT+IFYwn+vOt+uax703s4Mgo51/1oMquSccnGY1kZKhsAo1VzXO+7c73ZWHRDbbYtBP/4erSg9xw== X-Received: by 2002:a17:902:8c94:b0:1e2:bf94:487 with SMTP id t20-20020a1709028c9400b001e2bf940487mr76871plo.57.1713373751411; Wed, 17 Apr 2024 10:09:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 10:09:11 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v3 1/5] latencystats: replace use of VLA Date: Wed, 17 Apr 2024 10:07:23 -0700 Message-ID: <20240417170908.76701-2-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 The temporary array latencystats is not needed if the algorithm is converted into one pass. Signed-off-by: Stephen Hemminger --- 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); -- 2.43.0