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 664F943EDB; Mon, 22 Apr 2024 17:23:59 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 84273406B8; Mon, 22 Apr 2024 17:23:52 +0200 (CEST) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by mails.dpdk.org (Postfix) with ESMTP id E0655406B7 for ; Mon, 22 Apr 2024 17:23:48 +0200 (CEST) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6ed20fb620fso3771960b3a.2 for ; Mon, 22 Apr 2024 08:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1713799428; x=1714404228; 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=ocyY0DhAG7lN0AWqTRQZr22OaiU0tcYLefQmVVvcZvc=; b=CD8udf6cPqQAUrskSbGzVcMt//Q3aGmSFqZWrB5SZnFTHsfvrLXx8Nah2sdJ881DQi 6CRr0ZLKaEE8pcffqjPM0O2A0BFulGOYkkFyixkbrNGzFsMpRf2z7rYFGOvl8odtS4er TR+WCPhFpcPfgWzyCz6CBnipK8R4FsARkQCt1r3jtUYgB4PZuRG4jbFwSN/a+HxfdfcZ vPobNpkcTFmcMkwxg9PK5PtMN+IUz8+ZjALTpq38ZnV+ZuC19WVsX1/XUHzEZczAicNN aIWsWm4x1vw+bXAIE+H6QLnGsB/uqfb/Ut2bD1W1945sVH+xuZZhvh+imFAcGPT0iVuH IAwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713799428; x=1714404228; 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=ocyY0DhAG7lN0AWqTRQZr22OaiU0tcYLefQmVVvcZvc=; b=Hf0V4I7yXHU3tNVkBY9ye4Fo1bODfvI9Ej9qmXSDrDlW2q4Z+lz4Q61Lmfp1QI08AJ AWYYX3Vo1RGk8fgJG5ggaaTJrh13zwAgJ+VxlxBO46isAqcye5KRZVG6VApwySGyrK4+ bGqLmqsb/E3eU6SQJoOfJNtprjwC28uHar4guh58Hd2PulWXMPUbsl+AHK9HJDHdlgu/ uA2cjmskS+o12XPqJulj3SYaOrkC6QyAHsH5iVsjS2Yw7DydOKFlv+oZx30deZn9YNvl /+BAu4ASuGp/RcS/xHk4Ey9V47cNZ1zQXbRzuGr50pxm+pLJxXxmO4b1XJjK88BWl1Hg ygZA== X-Gm-Message-State: AOJu0YxBPKBCNS2dfs1L2NTmBF3wRagM3qgXWHsB1SSeNZY9tS3MKqhu ljAmtLDIfYya0rIV/n5ClPDN3VrS9f+cq0gBL/nwz8jcSbTAUygW2qnKAgQ/TiNWPkv8+NYBQt+ q X-Google-Smtp-Source: AGHT+IHf/IPgv7Fr7fG1/16WlMz7j3a6w8IGahgPyD7+3uV5lNlJRQ30BKNIt1/u7Az2yknaMK5Xbw== X-Received: by 2002:a05:6a20:c70e:b0:1a9:c214:b7d with SMTP id hi14-20020a056a20c70e00b001a9c2140b7dmr10458338pzb.2.1713799428106; Mon, 22 Apr 2024 08:23:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 08:23:47 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v5 2/9] latencystats: handle fractional cycles per ns Date: Mon, 22 Apr 2024 08:21:32 -0700 Message-ID: <20240422152336.147553-3-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-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 9b345bfb33..3152256066 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