From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 3FDD345A9E;
	Wed,  2 Oct 2024 18:58:56 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 7740C4064C;
	Wed,  2 Oct 2024 18:58:52 +0200 (CEST)
Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com
 [209.85.221.51]) by mails.dpdk.org (Postfix) with ESMTP id B6F5240616
 for <dev@dpdk.org>; Wed,  2 Oct 2024 18:58:51 +0200 (CEST)
Received: by mail-wr1-f51.google.com with SMTP id
 ffacd0b85a97d-37ce8458ae3so28460f8f.1
 for <dev@dpdk.org>; Wed, 02 Oct 2024 09:58:51 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1727888331; x=1728493131; 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=097tv44whgm8NlW4/pvNtBVFjTfAKs/+i9ES/OkSWXw=;
 b=PDiBZ6RMh/DLLIntRGJamwzzKTp5EZw/bkyGvVObLwYaneFr3VwlyvOkkBMHPFk7ik
 23pP+X7DxYREtCcAWFnkcEtizEpRyFkYS+x+IhbVv4kF9qVh+9FCJr39K5rrdH8rXxMS
 mkNqwaCLrne9f/AanU+OHuF4saEmB0g8Df/aiohNS/12P/JTrOVhzCpsgiP/KpBIl7tl
 +DTaeTpXwhF+9EomHUjYvEseGkPWSyWPuuHpi2qjSuO9dtC1vms4t0C+T2TUZUZTkChL
 K0QsLYEL8J/uBHBB32Qnyl0HiW9jPwvPz0clyq2/NH9s1do+wEsfZl0tugVCI/ummnrQ
 RZdA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1727888331; x=1728493131;
 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=097tv44whgm8NlW4/pvNtBVFjTfAKs/+i9ES/OkSWXw=;
 b=OnSaTPQjWu7D1q65D8hA/gaQHUVASWV0xcedo+r2Vq4IkmfajH/z4/IAflkzzONyPe
 LBoq2zXbrAJOfz230XSlndK7ykSM7m5vBiZmlHWdn1vUHP07kQ6x7U9ZgFXEnQIej1oD
 toKR3ktREyhfRg1f5fda1Y8YY9h7gR5AneUjfQD1XlS2yE9XPRM+TPEnkUTi7t/TPNls
 4b8k+D8Fi2p8O1iiSKFmTI5KVzcaTKLuyXS5mQqiZPD1vuJ5KzC/h7eKAIPMjmJ1DTdL
 cUk9tXN6cv1kq1NgciI2i4XGp3wE1QVnUpuYiPdnbRsL2GRL0WE48ZGT7dYoEKk6RKyT
 pFgQ==
X-Gm-Message-State: AOJu0YwPMK2geAD2C93707XafHDoSxa6/iwiK0b/GZCSn+FTKFLqU/TQ
 GT3SYuysPSgt35iW7iHbDULqLzv8+rewfnE3GB3iLFcTFnNW+KV+iC0MHZcJ
X-Google-Smtp-Source: AGHT+IGsyK5bYtLQrdMLDqq3LcvLIGvZxaLpA326GfJbJoBRICWbmCTl7ddTasaYvZ0SFrbzZd/H/w==
X-Received: by 2002:adf:e712:0:b0:37c:d1c6:7e45 with SMTP id
 ffacd0b85a97d-37cfba0a614mr2971517f8f.40.1727888330679; 
 Wed, 02 Oct 2024 09:58:50 -0700 (PDT)
Received: from localhost.localdomain (85-250-29-188.bb.netvision.net.il.
 [85.250.29.188]) by smtp.googlemail.com with ESMTPSA id
 a640c23a62f3a-a93c2777254sm889947166b.9.2024.10.02.09.58.49
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 02 Oct 2024 09:58:50 -0700 (PDT)
From: Isaac Boukris <iboukris@gmail.com>
To: dev@dpdk.org
Cc: stephen@networkplumber.org, bruce.richardson@intel.com,
 roretzla@linux.microsoft.com, dmitry.kozliuk@gmail.com,
 david.marchand@redhat.com, Isaac Boukris <iboukris@gmail.com>
Subject: [PATCH v4 1/2] timer: lower rounding of TSC estimation to 100KHz
Date: Wed,  2 Oct 2024 19:56:35 +0300
Message-ID: <20241002165840.341116-2-iboukris@gmail.com>
X-Mailer: git-send-email 2.45.0
In-Reply-To: <20241002165840.341116-1-iboukris@gmail.com>
References: <20240921140022.107239-1-iboukris@gmail.com>
 <20241002165840.341116-1-iboukris@gmail.com>
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 <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

In practice, the frequency is often not a nice round number, while
the estimation results are rather accurate, just a couple of KHz
away from the kernel's tsc_khz value, so it should suffice.

Rounding to 10MHz can cause a significant drift from real time,
up to a second per 10 minutes.

See also bugzilla: 959

Signed-off-by: Isaac Boukris <iboukris@gmail.com>
---
 lib/eal/linux/eal_timer.c   | 6 +++---
 lib/eal/windows/eal_timer.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/eal/linux/eal_timer.c b/lib/eal/linux/eal_timer.c
index 1cb1e92193..f56a7ae15b 100644
--- a/lib/eal/linux/eal_timer.c
+++ b/lib/eal/linux/eal_timer.c
@@ -192,7 +192,7 @@ get_tsc_freq(void)
 {
 #ifdef CLOCK_MONOTONIC_RAW
 #define NS_PER_SEC 1E9
-#define CYC_PER_10MHZ 1E7
+#define CYC_PER_100KHZ 1E5
 
 	struct timespec sleeptime = {.tv_nsec = NS_PER_SEC / 10 }; /* 1/10 second */
 
@@ -209,8 +209,8 @@ get_tsc_freq(void)
 
 		double secs = (double)ns/NS_PER_SEC;
 		tsc_hz = (uint64_t)((end - start)/secs);
-		/* Round up to 10Mhz. 1E7 ~ 10Mhz */
-		return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_10MHZ);
+		/* Round up to 100Khz. 1E5 ~ 100Khz */
+		return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_100KHZ);
 	}
 #endif
 	return 0;
diff --git a/lib/eal/windows/eal_timer.c b/lib/eal/windows/eal_timer.c
index b070cb7751..4003541b08 100644
--- a/lib/eal/windows/eal_timer.c
+++ b/lib/eal/windows/eal_timer.c
@@ -12,7 +12,7 @@
 #include "eal_private.h"
 
 #define US_PER_SEC 1E6
-#define CYC_PER_10MHZ 1E7
+#define CYC_PER_100KHZ 1E5
 
 void
 rte_delay_us_sleep(unsigned int us)
@@ -81,8 +81,8 @@ get_tsc_freq(void)
 	double secs = ((double)elapsed_us.QuadPart)/US_PER_SEC;
 	tsc_hz = (uint64_t)((end - start)/secs);
 
-	/* Round up to 10Mhz. 1E7 ~ 10Mhz */
-	return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_10MHZ);
+	/* Round up to 100Khz. 1E5 ~ 100Khz */
+	return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_100KHZ);
 }
 
 
-- 
2.45.0