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 AA75543E94; Wed, 17 Apr 2024 19:09:32 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1929B427E6; Wed, 17 Apr 2024 19:09:18 +0200 (CEST) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mails.dpdk.org (Postfix) with ESMTP id D72B640DDD for ; Wed, 17 Apr 2024 19:09:13 +0200 (CEST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1e5aa82d1f6so6995055ad.0 for ; Wed, 17 Apr 2024 10:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1713373753; x=1713978553; 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=CUdEJ0A0hLHDbZgXocEGwXmdOHskbeMSv840NwkxBf8=; b=Q8X1BBhdGDbAbEzwy9L0w9OeZv/+QeAcdSUk8mPW4GNFKEU3OmKnsx03BDRD2DDJ0p 228MoVPWfv4tMB21kjkOkswu6EQKGjPl6k6qq4cOsNUe0M0jbVr+8HbB8MAljTKzxcjA gpQ+i5+OpEmZhtzxbV7bjh+UvWcm9qSOGmdscsBs2BMOfK6V/odqXOT/Xyewmu8EdVVl O3AjYZTZK2r36eic03oDAerwUbAo3gljsrzGAWTSI+xHWtYccNo46DASNV9SwzOfG/gv LVvE/JGf+WKQAoILhYtSTacsiORprdMNxy+JuNGnrjBPvHN5w2VjlNvvZnKPJZYHOrCv FUkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713373753; x=1713978553; 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=CUdEJ0A0hLHDbZgXocEGwXmdOHskbeMSv840NwkxBf8=; b=wuuWgPu28cb5oW8FQ4Oe9wban5CMEQsdUJZLaiFJmdM6cjI6LE3hIg/GKhW7zVRo9H jp97v293PnTUKndZSyHRyOz6OKccRGw/ZlBeUULP8eYp6chH8jZbbze781N0HeExwsoe CUhDrUWucomcBB/P1Uvb6cSlUHXVuMtrpiONMLUO9hIC4lmW3ia8StAkh9yduBYEaycp 2YWwpEuVXpSVGazEwNZa6HAirAi5ACUAoSZUv8sePtpBu1VDEDonz3rEaS9i4qhL7PgD B8J8few6nmY7WGqkbCQSlnh+YFLAd29uQS9HXLCiTo/Nb0vjDRk/+DpibZzJLsBlFXTo Z6Cg== X-Gm-Message-State: AOJu0Yylbu0O+eDvg4Bwz2gHce2F1793WrCBKH89X5BfXGVZhHCJ0amj 6VMSQNxlmQmPdWodXECGdbULRmH4WZb0vwxbROC1hW0BfCC8oo4gaDARYT7tulwHAL9blj26ijH P X-Google-Smtp-Source: AGHT+IHyuvHB2TQXiluzn8KUjrmxn8B0pYht7btHDY6XOsHi9g4RMJp1VU1Nh6yOeA6idNbXwTFLtg== X-Received: by 2002:a17:902:e883:b0:1e3:e249:41eb with SMTP id w3-20020a170902e88300b001e3e24941ebmr1466plg.32.1713373752936; Wed, 17 Apr 2024 10:09:12 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 10:09:12 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v3 3/5] latencystats: do not use floating point Date: Wed, 17 Apr 2024 10:07:25 -0700 Message-ID: <20240417170908.76701-4-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 cycle counts do not need to be stored as floating point. Instead keep track of latency in cycles, and convert to nanoseconds when read. Change Exponential Weighted Moving Average weight from .2 to .25 to avoid use of floating point for that. Signed-off-by: Stephen Hemminger --- lib/latencystats/rte_latencystats.c | 37 +++++++++++------------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/lib/latencystats/rte_latencystats.c b/lib/latencystats/rte_latencystats.c index fe8c3c563a..11bd0ea4ae 100644 --- a/lib/latencystats/rte_latencystats.c +++ b/lib/latencystats/rte_latencystats.c @@ -47,10 +47,10 @@ static uint64_t timer_tsc; static uint64_t prev_tsc; struct rte_latency_stats { - float min_latency; /**< Minimum latency in nano seconds */ - float avg_latency; /**< Average latency in nano seconds */ - float max_latency; /**< Maximum latency in nano seconds */ - float jitter; /** Latency variation */ + uint64_t min_latency; /**< Minimum latency */ + uint64_t avg_latency; /**< Average latency */ + uint64_t max_latency; /**< Maximum latency */ + uint64_t jitter; /** Latency variation */ rte_spinlock_t lock; /** Latency calculation lock */ }; @@ -82,13 +82,12 @@ int32_t rte_latencystats_update(void) { unsigned int i; - float *stats_ptr = NULL; uint64_t values[NUM_LATENCY_STATS] = {0}; int ret; for (i = 0; i < NUM_LATENCY_STATS; i++) { - stats_ptr = RTE_PTR_ADD(glob_stats, - lat_stats_strings[i].offset); + const uint64_t *stats_ptr = RTE_PTR_ADD(glob_stats, + lat_stats_strings[i].offset); values[i] = floor(*stats_ptr / latencystat_cycles_per_ns()); } @@ -105,11 +104,10 @@ static void rte_latencystats_fill_values(struct rte_metric_value *values) { unsigned int i; - float *stats_ptr = NULL; for (i = 0; i < NUM_LATENCY_STATS; i++) { - stats_ptr = RTE_PTR_ADD(glob_stats, - lat_stats_strings[i].offset); + const uint64_t *stats_ptr = RTE_PTR_ADD(glob_stats, + lat_stats_strings[i].offset); values[i].key = i; values[i].value = floor(*stats_ptr / latencystat_cycles_per_ns()); } @@ -156,15 +154,8 @@ calc_latency(uint16_t pid __rte_unused, void *_ __rte_unused) { unsigned int i; - uint64_t now; - float latency; - static float prev_latency; - /* - * Alpha represents degree of weighting decrease in EWMA, - * a constant smoothing factor between 0 and 1. The value - * is used below for measuring average latency. - */ - const float alpha = 0.2; + uint64_t now, latency; + static uint64_t prev_latency; now = rte_rdtsc(); @@ -186,8 +177,7 @@ 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) - - glob_stats->jitter)/16; + glob_stats->jitter += ((prev_latency - latency) - glob_stats->jitter) / 16; if (glob_stats->min_latency == 0) glob_stats->min_latency = latency; else if (latency < glob_stats->min_latency) @@ -198,9 +188,10 @@ calc_latency(uint16_t pid __rte_unused, * The average latency is measured using exponential moving * average, i.e. using EWMA * https://en.wikipedia.org/wiki/Moving_average + * + * Alpha is .25 */ - glob_stats->avg_latency += - alpha * (latency - glob_stats->avg_latency); + glob_stats->avg_latency += (latency - glob_stats->avg_latency) / 4; prev_latency = latency; } rte_spinlock_unlock(&glob_stats->lock); -- 2.43.0