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 881BA44107; Thu, 30 May 2024 00:57:43 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 26B76402F1; Thu, 30 May 2024 00:57:38 +0200 (CEST) Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by mails.dpdk.org (Postfix) with ESMTP id 1EAC040289 for ; Thu, 30 May 2024 00:57:36 +0200 (CEST) Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-66629f45359so255671a12.3 for ; Wed, 29 May 2024 15:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1717023455; x=1717628255; 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=AX/RqP9vi9bMQ0mgv5ewy9DPg0OSgSf9xA+nKBv7llk=; b=h9YpCPCh5WQ8xIaADHLbf/GX/yedswww/P5XJE7h0UcGLgdw1UALUPhlPzL5l/mKN5 ZA/0ZnvPAcK3NOOlxtIZGQiuI0Ssli3xmH73c0npC6BxVhMADzzvwASQ4O1LwDmT5Wmo M67/zA3p1c30jBcwQbeChjvdK07IbGBDaDarsbCb/xYUVwfsyPRTaK3X3zhvk6KkzwQ9 rAQ2eXFizHQb0OMJYdljPnVdGE25zrGgfLw34+ebL0nXDBKPxM7NTqorHiOLlFmp97fz SW5OTVMHMlqS162nvMw65L+5CwwSNHV/GXngCgp/hUjXE4kMOmXHeoalRbMKZ339pcZc cKYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717023455; x=1717628255; 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=AX/RqP9vi9bMQ0mgv5ewy9DPg0OSgSf9xA+nKBv7llk=; b=S23rMT3JgY8cUzk/a+lUny7FJEgeqCPen9owyIivFhTr2kEG/AX39A/YTxQ9HLCCLJ Gg/PqGAShpVrLJXbWRHDmfteWalFhHOZDPF9bzIKak9jdkKNaQOJkBt8B7MWSE7APpjd moV18A9u6JoBZeSSVH2ll53sc3/ln031u04x6zlh1lGACfNr6A8nU1PCZ/XP+TfA25BY APkorLPUfqVrPKx8tIiV53DfVGqXYr8j7TAnEw8fqxn9lwuuwEq2RMb/hKBQ/M/yEsYx MxeJUIT5MQLpVA/eioAu6o45G5nYe1xYqjAHoxwosq/3fklNv/zSiVSkNcSp6O0IrCIt SmJw== X-Gm-Message-State: AOJu0YyDyHsE9FWWgs+eQAYfPzSNrB8FKu+guYgXJSQdGW1UiBbfaTOn EsjqhAhR99HpIa3irxmFc0V2QAjrXWLSy+JWXcLlcqZyVeKnO2sp+zBWqlvKjlicoWaddXF/9oo 8 X-Google-Smtp-Source: AGHT+IFHniJ1fGUk4w8puq5FYNZ3ClaSXU3nD9pxbw7LcPAzE9V6WQ5SL0Z2/AA/P54HicEDV3h5pw== X-Received: by 2002:a17:90a:5587:b0:2bf:fa80:61f8 with SMTP id 98e67ed59e1d1-2c1abc4e67bmr445288a91.46.1717023455098; Wed, 29 May 2024 15:57:35 -0700 (PDT) Received: from hermes.lan (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c1a77baebcsm351762a91.53.2024.05.29.15.57.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 15:57:34 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Tyler Retzlaff , Reshma Pattan Subject: [PATCH v6 1/8] latencystats: replace use of VLA Date: Wed, 29 May 2024 15:54:38 -0700 Message-ID: <20240529225732.442539-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240529225732.442539-1-stephen@networkplumber.org> References: <20240408195036.182545-1-stephen@networkplumber.org> <20240529225732.442539-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 cae4b50878..3fb8321484 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.2f; 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