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 EE6C543E94; Wed, 17 Apr 2024 19:09:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 996B2427E0; Wed, 17 Apr 2024 19:09:16 +0200 (CEST) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mails.dpdk.org (Postfix) with ESMTP id 0754140DDA for ; Wed, 17 Apr 2024 19:09:13 +0200 (CEST) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1e51398cc4eso54155155ad.2 for ; Wed, 17 Apr 2024 10:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1713373752; x=1713978552; 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=xYrob5Igy97bVmNali5cqA6qBua8Lq4/b+oiBXDUq0Y=; b=Wz6eDsikRSevaWdBLk/cmYfQCUadl1RiuympMEtFgharKXDNxAEOeMfvz7FRVYrhCS fMOVAX6iUfkA34BOA/PnHqdmba5+W00RHDRtgUt9+s3SVfkAOvv4u5ZMOoSi6lmyhrNY HnHiGrt4PbbUmSJrq2p6cJRysduLSCOrUsOCUF70i/pNdk0GOnkom8A+Cqo3Ms5dVwqg sb/NuTsLxKjM6s+RZpdXCIeXKfo1YPYwZEDYhhTfHU4/Z/6KfEnQdS9YWI0Q/N3WyRha ZSwPJndQ1s/sOu0VTkfwiTYi1xl1qStip823FcL7lCbThxRMSfxoiunRlt/Fesc/Ya1w xqpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713373752; x=1713978552; 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=xYrob5Igy97bVmNali5cqA6qBua8Lq4/b+oiBXDUq0Y=; b=rcMVSi3tSHsJDBELkhFCyP1Gn4z+vkHPK5kZ+FcHOW5wh5/TqTc9w1PMFFI+nKu2Mr a05tBuaS6HvmZr9jd5ShW/ssuyCeGLxLHFNAo65unjn3cGoGuRhXsNb7rOlVsH3l5JOp 2Cj6jmk3T3iHIAR0hm6WPwWPxsilVaCep43PTAdIguYeqM8IX0XA6JYiRIj1Oi0VW8hI h2rAHEzSB0NK9OdsXVUhRVAwNMGrNw1wMyIRWzrKh7bZAuSySX5fL8U6d/ySwDPmhgUJ E7NlQXncpUEIcbnctLr1RK3Zw6jv82Qx1fUGKmCV4zMYQuhQuVjbKypUtnXDvHQKiADz ZvPg== X-Gm-Message-State: AOJu0Yy2hkBH4g/ujwobjxfP0vkUubWu9C2Aob2UsjLk5GgDdS3HX8bR FqO6qwKDwaXnQUQscEjjEHncOEyphXFfNtErOLjm73QGZJAXb5PZVVRNMA2UlwPQz7/v5hJ4XJJ g X-Google-Smtp-Source: AGHT+IE0RtU9OFX2rxjrZ7ebkMLw9SdSOKhmowmXa8RqjGR+8z53vWNsyjeGPl9nK3Mmk+VTkLGaAw== X-Received: by 2002:a17:902:cecb:b0:1e4:51ab:fffb with SMTP id d11-20020a170902cecb00b001e451abfffbmr101069plg.25.1713373752194; 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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 10:09:11 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v3 2/5] latencystats: handle fractional cycles per ns Date: Wed, 17 Apr 2024 10:07:24 -0700 Message-ID: <20240417170908.76701-3-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 timer_hz 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. Signed-off-by: Stephen Hemminger --- lib/latencystats/rte_latencystats.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/latencystats/rte_latencystats.c b/lib/latencystats/rte_latencystats.c index 9b345bfb33..fe8c3c563a 100644 --- a/lib/latencystats/rte_latencystats.c +++ b/lib/latencystats/rte_latencystats.c @@ -19,10 +19,10 @@ #define NS_PER_SEC 1E9 /** Clock cycles per nano second */ -static uint64_t +static float latencystat_cycles_per_ns(void) { - return rte_get_timer_hz() / NS_PER_SEC; + return (double)rte_get_timer_hz() / NS_PER_SEC; } RTE_LOG_REGISTER_DEFAULT(latencystat_logtype, INFO); @@ -89,8 +89,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 / latencystat_cycles_per_ns()); } ret = rte_metrics_update_values(RTE_METRICS_GLOBAL, @@ -112,8 +111,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 / latencystat_cycles_per_ns()); } } @@ -237,7 +235,7 @@ rte_latencystats_init(uint64_t app_samp_intvl, glob_stats = mz->addr; rte_spinlock_init(&glob_stats->lock); - samp_intvl = app_samp_intvl * latencystat_cycles_per_ns(); + samp_intvl = floor(app_samp_intvl * latencystat_cycles_per_ns()); /** Register latency stats with stats library */ for (i = 0; i < NUM_LATENCY_STATS; i++) -- 2.43.0