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 2150945A86; Wed, 2 Oct 2024 00:00:14 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B128B402B8; Wed, 2 Oct 2024 00:00:13 +0200 (CEST) Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by mails.dpdk.org (Postfix) with ESMTP id 8D106402AF for ; Wed, 2 Oct 2024 00:00:11 +0200 (CEST) Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2e0b93157caso195741a91.0 for ; Tue, 01 Oct 2024 15:00:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727820010; x=1728424810; darn=dpdk.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=cL+6f2rwKTVAvPCtbvwEOdwu3aJc8FbQa6V/tL8uuow=; b=QN6iVdoPil7cU/vv0nPEgqFupdYlSxlnDO+pdGhZQND/qB4djw/jeXV9pOr/Dh5Slv rXpBD3zPOh6s2PFSC3TaMD6PsajXR6X2dDxHpxMtZOqzc1enYo2nO+L52wWbBUh5G3Fv jqCaXPxw6HSx5XyMO3lJ8NvNzuITFiMNtySCLTV2aLAacDFKxpD7VAK5rxMs8F6WEJ8O p5cpq/Ln5iAn4paTQdmD7P7kpiO5NYJWhGmEGhcGJOXHWafXPRlIQMFUB6OPUFynf6Sj KtQTwAWLjsKTBN+dRJvjnfnYhTIdS7duVZaULXPpJ9wqyyX0PeuKG2TIUBJQm7833RYu qUqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727820010; x=1728424810; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cL+6f2rwKTVAvPCtbvwEOdwu3aJc8FbQa6V/tL8uuow=; b=bZw571vJp6BNlnP78lwax+PzkuDr/I6B8yKgTBkXo90gnGhOjnmEGcilMHS6jdEXQZ 8r7qMHqbilY/1SlwHaxkC2r1hUDh/ZXzjJD0vazqUrYnJn2AcKNbgLBFfYiBveY1DjyI tBsfpFB5hDU7Y3FUAQ64sFfv/OQgFJs/12SRu70bN2YLJmK2NK/KGT6alaMrbjl+z7xp z9nEVssuVUX7LP6QMNSBrl6imU7Usa2YURtNOcjnPlBzwqrDv1M03GGkzdOld096GwuI oKAAoyvqZOLueUrFnttUIWmbo3J+pVj42OFRPVDAtkVhTYIR2uNGCGExnfJkXo6pRsd+ YUhw== X-Gm-Message-State: AOJu0YzURIR53Z3Il44JrKww679crogcRJBzPkNHookJbdLZR/w32TnT /m3HPj3OnJNUu4SgVHrnZ+e1v/cwXdSAXyBlqKVgXREHsxdgfW13dBaVBTT7Q+fqL4N1/Br+H/d luNyivnB8l0YKc9Wc+eLuhIrxn6o= X-Google-Smtp-Source: AGHT+IHX4BywM63ZBsYr3C0oydGFGtSXmClwmRx7sfqrOqlFkLQjkYWRKdp3TYooQFQCZmV9kOpvEfepMTz+ZR1btI0= X-Received: by 2002:a17:90b:520e:b0:2c9:5a71:1500 with SMTP id 98e67ed59e1d1-2e184ce93b6mr1718095a91.0.1727820010231; Tue, 01 Oct 2024 15:00:10 -0700 (PDT) MIME-Version: 1.0 References: <20240921140022.107239-1-iboukris@gmail.com> <20241001002527.277838-1-iboukris@gmail.com> <20241001002527.277838-3-iboukris@gmail.com> In-Reply-To: From: Isaac Boukris Date: Wed, 2 Oct 2024 00:59:58 +0300 Message-ID: Subject: Re: [PATCH v3 2/2] timer/linux/x86: override TSC freq if no tsc_known_freq To: Bruce Richardson Cc: dev@dpdk.org, stephen@networkplumber.org, roretzla@linux.microsoft.com, dmitry.kozliuk@gmail.com, david.marchand@redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Tue, Oct 1, 2024 at 11:01=E2=80=AFPM Bruce Richardson wrote: > > On Tue, Oct 01, 2024 at 03:22:51AM +0300, Isaac Boukris wrote: > > If the tsc_known_freq cpu flag is missing, it means the kernel doesn't > > trust it and calculates its own. We should do the same to avoid drift. > > > > Signed-off-by: Isaac Boukris > > --- > > lib/eal/common/eal_common_timer.c | 3 +- > > lib/eal/common/eal_private.h | 2 +- > > lib/eal/freebsd/eal_timer.c | 5 ++- > > lib/eal/linux/eal_timer.c | 53 +++++++++++++++++++++++++++++-- > > lib/eal/windows/eal_timer.c | 5 ++- > > 5 files changed, 60 insertions(+), 8 deletions(-) > > > > diff --git a/lib/eal/common/eal_common_timer.c b/lib/eal/common/eal_com= mon_timer.c > > index c5c4703f15..e00be0a5c8 100644 > > --- a/lib/eal/common/eal_common_timer.c > > +++ b/lib/eal/common/eal_common_timer.c > > @@ -66,8 +66,7 @@ set_tsc_freq(void) > > } > > > > freq =3D get_tsc_freq_arch(); > > - if (!freq) > > - freq =3D get_tsc_freq(); > > + freq =3D get_tsc_freq(freq); > > if (!freq) > > freq =3D estimate_tsc_freq(); > > > > diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.= h > > index af09620426..bb315dab04 100644 > > --- a/lib/eal/common/eal_private.h > > +++ b/lib/eal/common/eal_private.h > > @@ -374,7 +374,7 @@ void set_tsc_freq(void); > > * > > * This function is private to the EAL. > > */ > > -uint64_t get_tsc_freq(void); > > +uint64_t get_tsc_freq(uint64_t arch_hz); > > > > /** > > * Get TSC frequency if the architecture supports. > > diff --git a/lib/eal/freebsd/eal_timer.c b/lib/eal/freebsd/eal_timer.c > > index 3dd70e24ba..5a8aea03e1 100644 > > --- a/lib/eal/freebsd/eal_timer.c > > +++ b/lib/eal/freebsd/eal_timer.c > > @@ -26,12 +26,15 @@ > > enum timer_source eal_timer_source =3D EAL_TIMER_TSC; > > > > uint64_t > > -get_tsc_freq(void) > > +get_tsc_freq(uint64_t arch_hz) > > { > > size_t sz; > > int tmp; > > uint64_t tsc_hz; > > > > + if (arch_hz) > > + return arch_hz; > > + > > sz =3D sizeof(tmp); > > tmp =3D 0; > > > > On FreeBSD I'm not sure this is the best behaviour. On BSD we read the TS= C > value from the kernel, which, one assumes, has measured it accurately. > Therefore I'd tend toward just using the kernel value in all cases, maybe > check the arch value (if non-zero) against that and warning if they have > significant divergence. WDYT? Makes sense, I'll add a patch for that. We could also use the arch value if for some reason the sysctlbyname() failed.