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 9ED0843FAA; Tue, 7 May 2024 04:54:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5685D42E60; Tue, 7 May 2024 04:54:11 +0200 (CEST) Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) by mails.dpdk.org (Postfix) with ESMTP id 620284027B for ; Tue, 7 May 2024 04:54:09 +0200 (CEST) Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-6f08df79b9bso370607a34.3 for ; Mon, 06 May 2024 19:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1715050448; x=1715655248; 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=MxDLqd32CjV3eICTNbPcFS8d6P/kSMUXSwZ0OZ2IVT087dUI6Ku04aAu3WnY0DChMN zCBn21ZOMBf3zgVVHIQUc+vnUUOuD611b7SmAZPWkkiUwdMnF2/MMwGGBd3lWuC7Roal y8IoMMyS7nVxo9IoY2QTtPg6d2IAaJj4Pun6jI4Y+a+XRrwcdPtzZZEM+S0IqISGKuIT Jwb3nfeCbFxaHJlFsKm00NervLChmDi/ngPBPPqS4xbarTAlxyaV+igdRoXGja1YoO3Y I+ouWTXI9c8m3+WVz2MlXJZ+wYnSXb4BlrvFRQ5CNeJoL8LJP87K5szSaw6mn38wl9hs TgDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715050448; x=1715655248; 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=X0iOSGgLnx2ms/9riyYmORqqsHvvTFXcjirnGQfMHJq0hMNCehASdAONzioz+skcVy NhUXSSJln4Wu9Pw7AL59jT5/1Ydpfh3kMgTja+5//6JvUcneA1/I6sMdZ+juDxYFW2KM oDObzZwnQSXl0vz78UWE8kvOT2V3IvBLfcPiXaHREMMg3MxZ84SUr1DQL+SyPZjopSWS 4jeNj3qiCdp4IpbczBsiUGk0YT0GZL/P4aIF4ElEAslSAMa7IqzaOQpa5uIihVbKaMle j4081ZJWplqwrWqejOAveLBR4MJCO73xqlmmFz84zpZXUdERDa4HfOjgNq2gARoEqN69 sONg== X-Gm-Message-State: AOJu0YyrBPGOcWKxFEKoiraI1gBkNv+sO2WJMyAguuc8mgLMaE54NsPa mF661Ys7vNyQl/M4I0znZm7CQNXijhDa5V8435Wb+7AbVYDsehmEzN74EJdrzkY= X-Google-Smtp-Source: AGHT+IHxO9wondI8SZE9uNn6S8DWEd3swY9vRfvNXZBE3CdifMfILWgn4gpMZ7oLQRnn9u8gvm1RKg== X-Received: by 2002:a05:6808:3021:b0:3c9:69e4:33c2 with SMTP id ay33-20020a056808302100b003c969e433c2mr6924075oib.4.1715050448545; Mon, 06 May 2024 19:54:08 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id v8-20020aa78508000000b006ead792b6f2sm8466108pfn.1.2024.05.06.19.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 19:54:07 -0700 (PDT) From: Stephen Hemminger To: roretzla@linux.microsoft.com Cc: dev@dpdk.org, Stephen Hemminger , =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH 2/2] latencystats: replace use of VLA Date: Mon, 6 May 2024 19:53:55 -0700 Message-ID: <20240507025355.7145-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240507025355.7145-1-stephen@networkplumber.org> References: <1715019531-22796-1-git-send-email-roretzla@linux.microsoft.com> <20240507025355.7145-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 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); -- 2.43.0