On Sat, 2019-03-16 at 14:42 +0000, Wiles, Keith wrote:
> > On Mar 16, 2019, at 2:03 AM, Pavan Nikhilesh Bhagavatula <
> > pbhagavat...@marvell.com> wrote:
> > 
> > From: Pavan Nikhilesh <pbhagavat...@marvell.com>
> > 
> > When estimating tsc frequency using sleep/gettime round it up to
> > the
> > nearest multiple of 10Mhz for more accuracy.
> > 
> > Signed-off-by: Pavan Nikhilesh <pbhagavat...@marvell.com>
> > ---
> > Useful in case of ARM64 if we enable RTE_ARM_EAL_RDTSC_USE_PMU,
> > get_tsc_freq_arch() will return 0 as there is no instruction to
> > determine
> > the clk of PMU and eal falls back to sleep(1).
> > 
> > lib/librte_eal/common/eal_common_timer.c | 4 ++--
> > lib/librte_eal/linuxapp/eal/eal_timer.c  | 2 +-
> > 2 files changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/lib/librte_eal/common/eal_common_timer.c
> > b/lib/librte_eal/common/eal_common_timer.c
> > index dcf26bfea..1358bbed0 100644
> > --- a/lib/librte_eal/common/eal_common_timer.c
> > +++ b/lib/librte_eal/common/eal_common_timer.c
> > @@ -69,7 +69,7 @@ estimate_tsc_freq(void)
> >     /* assume that the sleep(1) will sleep for 1 second */
> >     uint64_t start = rte_rdtsc();
> >     sleep(1);
> > -   return rte_rdtsc() - start;
> > +   return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, 1E7);
> > }
> > 
> > void
> > @@ -83,7 +83,7 @@ set_tsc_freq(void)
> >     if (!freq)
> >             freq = estimate_tsc_freq();
> > 
> > -   RTE_LOG(DEBUG, EAL, "TSC frequency is ~%" PRIu64 " KHz\n", freq
> > / 1000);
> > +   RTE_LOG(INFO, EAL, "TSC frequency is ~%" PRIu64 " Hz\n", freq);
> >     eal_tsc_resolution_hz = freq;

I missed this log will remove it in the next version.

> > }
> > 
> > diff --git a/lib/librte_eal/linuxapp/eal/eal_timer.c
> > b/lib/librte_eal/linuxapp/eal/eal_timer.c
> > index bc8f05199..864d6ef29 100644
> > --- a/lib/librte_eal/linuxapp/eal/eal_timer.c
> > +++ b/lib/librte_eal/linuxapp/eal/eal_timer.c
> > @@ -248,7 +248,7 @@ get_tsc_freq(void)
> > 
> >             double secs = (double)ns/NS_PER_SEC;
> >             tsc_hz = (uint64_t)((end - start)/secs);
> > -           return tsc_hz;
> > +           return RTE_ALIGN_MUL_NEAR(tsc_hz, 1E7);
> 
> Maybe I missed an email about this, but why would I want the TSC hz
> rounded here? I do not mind the macro just the fact that we are
> changing TSC hz value. If the TSC value is wrong then we need to fix
> the value, but I do not see it being wrong here.

Since in this function nanosleep might not be cycle accurate we need to
round it up.

Please note that estimation only applies when  get_tsc_freq_arch()
fails. i.e there is no CPU instruction that specifies the cyc/sec.

As I mentioned in the patch notes
"Useful in case of ARM64 if we enable RTE_ARM_EAL_RDTSC_USE_PMU,
get_tsc_freq_arch() will return 0 as there is no instruction to
determine the clock of PMU and eal falls back to sleep(1)/nanosleep." 

> >     }
> > #endif
> >     return 0;
> > --
> > 2.21.0
> > 
> 
> Regards,
> Keith
> 

Reply via email to