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 89B0043EB2; Fri, 19 Apr 2024 19:29:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4BE1340691; Fri, 19 Apr 2024 19:29:42 +0200 (CEST) Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by mails.dpdk.org (Postfix) with ESMTP id 09DF340698 for ; Fri, 19 Apr 2024 19:29:39 +0200 (CEST) Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6eb93ec8804so1281766a34.2 for ; Fri, 19 Apr 2024 10:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1713547778; x=1714152578; 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=sSasOgCHLIZFkxb9gF3dyAkJenIQv2QQ2b/rkOQt9Ps=; b=hsaRTQ3qE6Qrw2DTsG0L3/QPDztEncXNrRBCpsUGsIZbPBh056mm48O6H6mkSq8pBf AABrPm1zdbHGR2k0Zg6Dsv9QLsJmNVdkzVG/bTc5Dy6SCHUXTarMkyM+j+LuuxZnvh8G KmkJds/qUq0rlA9nHcjNK7JgCDYiGpOgmxMDJ8mi72gRlCKLyiIM9bjj6rMfWcAPADgd +pF7YwyXFpIdejtj8KcCKNyfV4mM66Al+gUdIIf6vtds3Gv6+7OGwSqLgxwF3x6DponB BLz9j9eeXo9DCyXO8Qxy4tKLi1xl+gcRs3C8QWSiKNdEWe4X3REIdI37FjT3uPjjsH8L d/dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713547778; x=1714152578; 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=sSasOgCHLIZFkxb9gF3dyAkJenIQv2QQ2b/rkOQt9Ps=; b=kcOA8jfE92SpuoSVKRzJFe38NrUCrfzFg22p18z/DYAOeo10hbe1hvMzoZFrYOJkNc UwY1lHkNqpa8+swhcthhUTc3O1AkH1uSwpL6on6264cMnBf5GHJLWzCzFwt3iWFUOK7l 79Tw9Lu/4bDjoL7/RVFDAYjjhFWXh1hnQ3bl1ZrcBnNJGgPloAcvqc3owdhu/lSsO+T+ mPHDvTAMapP7JOq7qHpULD4jLILvNksaPfFuh3w3HDNHtBed6BIDAYx6/bTEXG0qku8d hepPRGBROBh9yQahNXZH1gnCiTFf4K3QE1mUmQFtUrvdY6KzCXhNojBoRb1j7REDSr4k BTyg== X-Gm-Message-State: AOJu0YwpnM/13vhjr/8ew7yPcO4aJI7+hfJJZVX92/wh9TBuZbHcwjbh /w3AcRaDDly6Zc6LH9NW0qBWcXA6qBt8Vuytj6CNRjX7EsHVY/PtQoowhiFXODvl9ZeKuAiZqLE F X-Google-Smtp-Source: AGHT+IGtHOAQZYIiYfqUzlefXLi1zgDTLT1yoI9ksZj6r87jKr41RkHfyjPV1w8aEglh7Eg/R19U3g== X-Received: by 2002:a05:6830:1208:b0:6eb:8435:60 with SMTP id r8-20020a056830120800b006eb84350060mr3374751otp.24.1713547778380; Fri, 19 Apr 2024 10:29:38 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id h16-20020a632110000000b005f3c5cf33b5sm3383074pgh.37.2024.04.19.10.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 10:29:38 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v4 2/6] latencystats: handle fractional cycles per ns Date: Fri, 19 Apr 2024 10:28:22 -0700 Message-ID: <20240419172926.55447-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240419172926.55447-1-stephen@networkplumber.org> References: <20240408195036.182545-1-stephen@networkplumber.org> <20240419172926.55447-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 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..55a099c818 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_timer_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