[U-Boot] [PATCH v6 1/2] x86: Add TSC-specific timer functions

Ivan Gorinov ivan.gorinov at intel.com
Fri Apr 20 18:00:47 UTC 2018


On Fri, Apr 20, 2018 at 06:25:08AM -0600, Andy Shevchenko wrote:
> > Coreboot timestamp functions and Quark memory reference code use
> > get_tbclk() to get TSC frequency. This will not work if another
> > early timer is selected.
> > 
> > Add tsc_rate_mhz() function and use it in the code that specifically
> > needs to get TSC rate regardless of currently selected early timer.
> 
> 
> >  void delay_n(uint32_t ns)
> >  {
> >  	/* 1000 MHz clock has 1ns period --> no conversion required
> > */
> > -	uint64_t final_tsc = rdtsc();
> > +	uint64_t start_tsc = rdtsc();
> > +	uint64_t ticks;
> >  
> > -	final_tsc += ((get_tbclk_mhz() * ns) / 1000);
> > -
> > -	while (rdtsc() < final_tsc)
> > -		;
> > +	ticks = (tsc_rate_mhz() * ns) / 1000;
> 
> > +	while (rdtsc() - start_tsc < ticks);
> 
> I would rather preserve existing style.

OK. Existing style does not correctly handle overflow,
but for a 64-bit counter it's a very unlikely event.


More information about the U-Boot mailing list