From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Shevchenko Date: Fri, 20 Apr 2018 15:25:08 +0300 Subject: [U-Boot] [PATCH v6 1/2] x86: Add TSC-specific timer functions In-Reply-To: <269698c303c3da454b34f149d4a3562fc57091f2.1523570597.git.ivan.gorinov@intel.com> References: <269698c303c3da454b34f149d4a3562fc57091f2.1523570597.git.ivan.gorinov@intel.com> Message-ID: <1524227108.21176.462.camel@linux.intel.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Thu, 2018-04-12 at 15:12 -0700, Ivan Gorinov 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. > } > /* Delay number of microseconds */ > -void delay_u(uint32_t ms) > +void delay_u(uint32_t us) > { > /* 64-bit math is not an option, just use loops */ > - while (ms--) > + while (us--) > delay_n(1000); > } This is a separate change. -- Andy Shevchenko Intel Finland Oy