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 0CAFA44107; Thu, 30 May 2024 00:57:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 27D5040691; Thu, 30 May 2024 00:57:39 +0200 (CEST) Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by mails.dpdk.org (Postfix) with ESMTP id D965C40289 for ; Thu, 30 May 2024 00:57:36 +0200 (CEST) Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2bdb57f496eso187846a91.2 for ; Wed, 29 May 2024 15:57:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1717023456; x=1717628256; 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=Q0Q50GmIVbnt3NSHcpRZY2pfgVHGqgyKjZhLQeiYYDo=; b=qdOhqzNLtNwnGrrNCOWzoiQt6pIhFPc1kRF/9t2SPmqXRq6kdXSZzbG8vsAIqgPB9N infIvNAl1MwOCys24nHVt87tpU1l788qE8xjWvH9QIK5bl4NOZC16r9kBoMGe3J2B4dd jGINHF5RXEq5MPQtxiWDvzMY/InErgYmgd3CqxxPvWd2L+J9z9Olv+M6CoqdgWLuYzRe +Pzp7/lSFMwyZS9ukon2NHike8eWoDYit7e/QZ8OtXYc7hMfQTl0O9c4ZMQuvBjHDOEY HlNbU3V3H07k0J/8y7I2vhmKWvAqo0C9ZVfXymlZUiKVS8vD5AI1qbKojw8Qbacka1W3 CIRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717023456; x=1717628256; 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=Q0Q50GmIVbnt3NSHcpRZY2pfgVHGqgyKjZhLQeiYYDo=; b=aTARImJUHBDnjbXlnSXyaxHU5n43dNi/U2Q5h1ygMR42mrUBwtEHyU82aKKE8xtS/l fVisC4KvcMVfGM2L00LR+kJ5Y5ot0wDWU72KbFAzqSjQrwYsb5FrrtYSSLk3ik7bfQyc Fcd4Ni6kXv6rl7v+cqHSjJYaoy2dpHpXwRTtPVfd79gMToC9hnmxB12FIFhwE0PosikS M9SK63YnVA8jH/9weWx3epzZFb3Xw0rIOTZ3/A+GqrVL5zEQYeBmqGqz+Okn2/d5bd9R 2vIBItskaOYQUAa3VybOmTNj0IJdKhzG2cwdReB4EaYSQSK997tOVuDx0aORYSvpv/Xj YxlA== X-Gm-Message-State: AOJu0YxsSqguHWiuIKtcXkXaJY+6NhwV9InWkIGxfaPvq7/f+keqIxIr q2WuVcVldHmE9SUsMakkGacUTqjaLMmdxmpxNU41QjUS8+DXKID0iutuCjLGh3KX6z8b7aHE0gK h X-Google-Smtp-Source: AGHT+IEyVQBwKGNdFzJwjKzt+64SCe3AJ5ByMD/OVAQuPNfClnOm4+y4gO9DfAEYmf1VYGKET5n3OQ== X-Received: by 2002:a17:90b:2d89:b0:2bf:8824:c0a5 with SMTP id 98e67ed59e1d1-2c1ab9d9fafmr609862a91.6.1717023456036; Wed, 29 May 2024 15:57:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 15:57:35 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v6 2/8] latencystats: handle fractional cycles per ns Date: Wed, 29 May 2024 15:54:39 -0700 Message-ID: <20240529225732.442539-3-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-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 TSC frequency is not always an integral number of nanoseconds. For examples, cycles per nanoseconds on my test system is 2.8. Fix by using floating point where needed and calculate value once. Signed-off-by: Stephen Hemminger --- lib/latencystats/rte_latencystats.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/latencystats/rte_latencystats.c b/lib/latencystats/rte_latencystats.c index 3fb8321484..c897df03c6 100644 --- a/lib/latencystats/rte_latencystats.c +++ b/lib/latencystats/rte_latencystats.c @@ -18,12 +18,7 @@ /** Nano seconds per second */ #define NS_PER_SEC 1E9 -/** Clock cycles per nano second */ -static uint64_t -latencystat_cycles_per_ns(void) -{ - return rte_get_timer_hz() / NS_PER_SEC; -} +static double cycles_per_ns; RTE_LOG_REGISTER_DEFAULT(latencystat_logtype, INFO); #define RTE_LOGTYPE_LATENCY_STATS latencystat_logtype @@ -89,8 +84,7 @@ rte_latencystats_update(void) for (i = 0; i < NUM_LATENCY_STATS; i++) { stats_ptr = RTE_PTR_ADD(glob_stats, lat_stats_strings[i].offset); - values[i] = (uint64_t)floor((*stats_ptr)/ - latencystat_cycles_per_ns()); + values[i] = floor(*stats_ptr / cycles_per_ns); } ret = rte_metrics_update_values(RTE_METRICS_GLOBAL, @@ -112,8 +106,7 @@ rte_latencystats_fill_values(struct rte_metric_value *values) stats_ptr = RTE_PTR_ADD(glob_stats, lat_stats_strings[i].offset); values[i].key = i; - values[i].value = (uint64_t)floor((*stats_ptr)/ - latencystat_cycles_per_ns()); + values[i].value = floor(*stats_ptr / cycles_per_ns); } } @@ -235,9 +228,11 @@ rte_latencystats_init(uint64_t app_samp_intvl, return -ENOMEM; } + cycles_per_ns = (double)rte_get_tsc_hz() / NS_PER_SEC; + glob_stats = mz->addr; rte_spinlock_init(&glob_stats->lock); - samp_intvl = app_samp_intvl * latencystat_cycles_per_ns(); + samp_intvl = (uint64_t)(app_samp_intvl * cycles_per_ns); /** Register latency stats with stats library */ for (i = 0; i < NUM_LATENCY_STATS; i++) -- 2.43.0