DPDK patches and discussions
 help / color / mirror / Atom feed
From: Isaac Boukris <iboukris@gmail.com>
To: Bruce Richardson <bruce.richardson@intel.com>
Cc: dev@dpdk.org, stephen@networkplumber.org,
	roretzla@linux.microsoft.com,  dmitry.kozliuk@gmail.com,
	david.marchand@redhat.com
Subject: Re: [PATCH v4 2/2] timer: allow platform to override cpu TSC frequency
Date: Wed, 2 Oct 2024 22:14:57 +0300	[thread overview]
Message-ID: <CAC-fF8SVfaTdwmh4+YVPpvsmw6wjVAGaKrWqbQAif0JxaEptOQ@mail.gmail.com> (raw)
In-Reply-To: <Zv1-07BoFTr5DI8F@bricha3-mobl1.ger.corp.intel.com>

On Wed, Oct 2, 2024 at 8:11 PM Bruce Richardson
<bruce.richardson@intel.com> wrote:
>
> On Wed, Oct 02, 2024 at 07:56:36PM +0300, Isaac Boukris wrote:
> > The CPU value is often not accurate, allow overriding it based
> > on info from the host OS.
> >
> > On Linux X86, 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.
> >
> > On freebsd we have access to the kernel tsc_hz value, just use it.
> >
> > Signed-off-by: Isaac Boukris <iboukris@gmail.com>
> > ---
>
> Looks good to me. Hope to test it out soon on my systems to see how it
> goes.
>
> One comment inline below.
>
> /Bruce
>
> >  lib/eal/common/eal_common_timer.c |  3 +-
> >  lib/eal/common/eal_private.h      |  2 +-
> >  lib/eal/freebsd/eal_timer.c       |  8 +++--
> >  lib/eal/linux/eal_timer.c         | 53 +++++++++++++++++++++++++++++--
> >  lib/eal/windows/eal_timer.c       |  5 ++-
> >  5 files changed, 62 insertions(+), 9 deletions(-)
> >
> > diff --git a/lib/eal/common/eal_common_timer.c b/lib/eal/common/eal_common_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 = get_tsc_freq_arch();
> > -     if (!freq)
> > -             freq = get_tsc_freq();
> > +     freq = get_tsc_freq(freq);
> >       if (!freq)
> >               freq = 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..19fc9a7228 100644
> > --- a/lib/eal/freebsd/eal_timer.c
> > +++ b/lib/eal/freebsd/eal_timer.c
> > @@ -26,7 +26,7 @@
> >  enum timer_source eal_timer_source = EAL_TIMER_TSC;
> >
> >  uint64_t
> > -get_tsc_freq(void)
> > +get_tsc_freq(uint64_t arch_hz)
> >  {
> >       size_t sz;
> >       int tmp;
> > @@ -50,9 +50,13 @@ get_tsc_freq(void)
> >       sz = sizeof(tsc_hz);
> >       if (sysctlbyname("machdep.tsc_freq", &tsc_hz, &sz, NULL, 0)) {
> >               EAL_LOG(WARNING, "%s", strerror(errno));
> > -             return 0;
> > +             return arch_hz;
> >       }
> >
> > +     if (arch_hz && arch_hz - tsc_hz > arch_hz / 100)
>
> Do we not need an "abs()" call on the "arch_hz - tsc_hz" in case tsc_hz is
> the bigger value?

As they are unsigned it will overflow and result the absolute value, I
actually did use abs() at first, and the compiler yelled at me:
warning: taking the absolute value of unsigned type ‘uint64_t’ {aka
‘long unsigned int’} has no effect [-Wabsolute-value]

  reply	other threads:[~2024-10-02 19:15 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-21 14:00 [PATCH 1/2] timer/linux: lower rounding of tsc estimation to 10KHz Isaac Boukris
2024-09-21 14:00 ` [PATCH 2/2] timer/linux: override TSC freq if no tsc_known_freq Isaac Boukris
2024-09-24 17:04   ` Isaac Boukris
2024-09-30 15:04     ` Bruce Richardson
2024-09-30 22:08 ` [PATCH v2 0/2] Improve TSC frequency accuracy on Linux Isaac Boukris
2024-09-30 22:08   ` [PATCH v2 1/2] timer/linux: lower rounding of tsc estimation to 100KHz Isaac Boukris
2024-09-30 22:08   ` [PATCH v2 2/2] timer/linux/x86: override TSC freq if no tsc_known_freq Isaac Boukris
2024-10-01  0:10     ` Stephen Hemminger
2024-10-01  0:22 ` [PATCH v3 0/2] Improve TSC frequency accuracy on Linux Isaac Boukris
2024-10-01  0:22   ` [PATCH v3 1/2] timer/linux: lower rounding of tsc estimation to 100KHz Isaac Boukris
2024-10-01 15:18     ` Stephen Hemminger
2024-10-01  0:22   ` [PATCH v3 2/2] timer/linux/x86: override TSC freq if no tsc_known_freq Isaac Boukris
2024-10-01 15:19     ` Stephen Hemminger
2024-10-01 21:56       ` Isaac Boukris
2024-10-01 20:01     ` Bruce Richardson
2024-10-01 21:59       ` Isaac Boukris
2024-10-02  8:06         ` Bruce Richardson
2024-10-02 16:56 ` [PATCH v4 0/2] Improve TSC frequency accuracy Isaac Boukris
2024-10-02 16:56   ` [PATCH v4 1/2] timer: lower rounding of TSC estimation to 100KHz Isaac Boukris
2024-10-02 16:56   ` [PATCH v4 2/2] timer: allow platform to override cpu TSC frequency Isaac Boukris
2024-10-02 17:11     ` Bruce Richardson
2024-10-02 19:14       ` Isaac Boukris [this message]
2024-10-03  9:31         ` Bruce Richardson
2024-10-03 12:29           ` Isaac Boukris
2024-10-02 17:12   ` [PATCH v4 0/2] Improve TSC frequency accuracy Bruce Richardson
2024-10-03 12:26 ` [PATCH v5 " Isaac Boukris
2024-10-03 12:26   ` [PATCH v5 1/2] timer: lower rounding of TSC estimation to 100KHz Isaac Boukris
2024-10-03 14:05     ` Bruce Richardson
2024-10-03 15:13       ` Stephen Hemminger
2024-10-03 12:26   ` [PATCH v5 2/2] timer: allow platform to override cpu TSC frequency Isaac Boukris
2024-10-03 14:06     ` Bruce Richardson
2024-10-03 15:14       ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAC-fF8SVfaTdwmh4+YVPpvsmw6wjVAGaKrWqbQAif0JxaEptOQ@mail.gmail.com \
    --to=iboukris@gmail.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=roretzla@linux.microsoft.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).