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 3FF3F43EDB; Mon, 22 Apr 2024 17:23:53 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 095E0409FA; Mon, 22 Apr 2024 17:23:51 +0200 (CEST) Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) by mails.dpdk.org (Postfix) with ESMTP id 9CA7B40265 for ; Mon, 22 Apr 2024 17:23:47 +0200 (CEST) Received: by mail-il1-f170.google.com with SMTP id e9e14a558f8ab-36c00924fc1so12998825ab.2 for ; Mon, 22 Apr 2024 08:23:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1713799427; x=1714404227; 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=Mzvff90E265up4jZ4XcI4E+lBam5XFhclXsYYqAfpzCumz+OMcoTPkgeeqBDoQpI+F oKlsTUY1riL5gwY/bFbV2P310G0Ypfiv3yo9ZhYE2ro/4BY3yW0Z2v4OTLfToXjb2wCu lq6fZ+ARS9gIEKC7aAQu7J+Cz4RzGK3kJfSKsxqHAKmhTighQOD7ty9LG8tmWg2KVprl IPk4XvgTO++P4xrxv6JIGpQdDZqVyISoupnyDrm0iK+qoU7zbqUHORdcss1E47mn1ewl UN8xwDa5CpYc/rX6Lj0EyiV4T44wqAwyuz9kRp3OEbWOub4s7bLTBjuW+GN82MpJqtE8 S2og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713799427; x=1714404227; 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=HpQT20p8vTMGuUkG17ylo4nrcZHBXFxteH5z+NSsrLpao5aN/B7PQL4f8MXFmsXjy5 xZFiR7Y/u/quHCjwugJvFZ4QRw8c1IRLfLdQ7BJbW4SYUBLLhSKSxoqh574PJ2nZnZsM mWzUp70qiDJ20obm/j5gwtxyjXh0AXs+FSMtWE0ZzO576uhjCrexlU4RKjoJTYPQ6wEF b/0IIthhWSW7O6k8Og+uxZ6j5EV5QZY9WJcAStFTasMrhKZ3JM02ffWJsfsbohf03lWk VoUNNLeemkg9opKeABEaTIWhBIDcU2OTe141KBdeG43AM4ZAcB6OMs5LMJgpLn2ycr5b CjFQ== X-Gm-Message-State: AOJu0YxK+P3lilotUJGAwRgp0cjXdfgRhYsG0P33DihAkk5q9WqONSNI lDv0zUCd9PlnWvZE0s1hasItRYADzktG89nJ42aKFEEhZYoEO0T9hdBNh/04xu7cNiC458dsR/d G X-Google-Smtp-Source: AGHT+IF6FYf/p7LJCAitcrAQ2HtL9rElVICoKZQaNWbqFb6jFumIVMcO5FpnmiS8rI4XWwMB0wGQlQ== X-Received: by 2002:a05:6e02:1609:b0:368:a724:f757 with SMTP id t9-20020a056e02160900b00368a724f757mr15310076ilu.6.1713799426951; Mon, 22 Apr 2024 08:23:46 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id cb17-20020a056a02071100b0060063c4be3bsm1402783pgb.14.2024.04.22.08.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 08:23:46 -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 v5 1/9] latencystats: replace use of VLA Date: Mon, 22 Apr 2024 08:21:31 -0700 Message-ID: <20240422152336.147553-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240422152336.147553-1-stephen@networkplumber.org> References: <20240408195036.182545-1-stephen@networkplumber.org> <20240422152336.147553-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