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 170F045AA0; Thu, 3 Oct 2024 14:30:32 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F1AB54060A; Thu, 3 Oct 2024 14:30:29 +0200 (CEST) Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by mails.dpdk.org (Postfix) with ESMTP id 815F44060C for ; Thu, 3 Oct 2024 14:30:28 +0200 (CEST) Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a8a7cdfdd80so166220166b.0 for ; Thu, 03 Oct 2024 05:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727958628; x=1728563428; 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=IHRnmR2tpJqQEbPxfxlGk/85LKtCMnQXx0rKY8eH/X0R66MNRxF1SU+bRGa6ZK8fPt y9NKFKIQ3YMbUl85B//vrAIqncPVvKgFCYUUFZyzn5+lMm0l3SDeizCxDO+tobHrFI6T bQQH79a4Fky5Poq53NFsPq9T68UVoVIo49Ic6jb94aS/3ZBV/0EapVmHnG8rMOfvMyUL 2BIuZ0Qgs0c3gWr8mPW+KwTgR4OY2QRcrVwjw69MS/nAGX0DJ7rwJYXd/rVgkODmTKoR 6WfeLJWb0L665GHQSy/SvqTeSv5SKfpCD1sGxqvbCLhzdSVn/Ag+pd82pOY0iobDRDPn trpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727958628; x=1728563428; 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=wbejqQF6STvwdURlAdyizXF23yKln7oHSUhOmIHpA1hlqBbYn2DNnQjUa9aGmmBwFb kDL0JBq3u7kC6ErXqmJzOVEozHeN4r4dkoLB0R96aJvjIjojaOHGo+iXc18jqj9tkbnN J4H5e502SXfsfLeOUfNlqE+kev743/p3/2uzTJng04P45U6y08wsLS47whngd7qgnIQF GAPZAIChVkiuJNACfKn9czeh72K8ky58GuvxHEXVsSGyrK9nDqNipjr37w/KIBdMok07 Uxu/NIGKTQ58QkJ03QeAlpArZYseXXEXeZWn80s/BmFYIOUQWu65BvUakiK+bfvblzrc EU+w== X-Gm-Message-State: AOJu0Ywk0xfWFWAzkV1Cqlf8XPJNc+QdSPQO0TmlJ4hMtHrQ4uDnRSqN Ydxj//497gntaxNelLTCEaeHehxU0Uu561lOIwrdsPNO7P6eJCeqjdvvLJph X-Google-Smtp-Source: AGHT+IHQDgXi+0ueGlR2TXSylminYhL6KrSwZTsf725nLL5l6yWI6juY6McfRig+5tFxt2c4Hw9CCQ== X-Received: by 2002:a17:906:c103:b0:a86:7b71:7b77 with SMTP id a640c23a62f3a-a98f83db7bfmr613236966b.44.1727958627582; Thu, 03 Oct 2024 05:30:27 -0700 (PDT) Received: from localhost.localdomain (85-250-24-111.bb.netvision.net.il. [85.250.24.111]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a9910473a94sm79668566b.169.2024.10.03.05.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 05:30:27 -0700 (PDT) From: Isaac Boukris 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 Subject: [PATCH v5 1/2] timer: lower rounding of TSC estimation to 100KHz Date: Thu, 3 Oct 2024 15:26:03 +0300 Message-ID: <20241003122819.354499-2-iboukris@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241003122819.354499-1-iboukris@gmail.com> References: <20240921140022.107239-1-iboukris@gmail.com> <20241003122819.354499-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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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 --- 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