On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <pal...@dabbelt.com> wrote: > diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile > new file mode 100644 > index 000000000000..f644e582f4b8 > --- /dev/null > +++ b/arch/riscv/lib/Makefile
> + > +void __delay(unsigned long cycles) > +{ > + u64 t0 = get_cycles(); > + > + while ((unsigned long)(get_cycles() - t0) < cycles) > + cpu_relax(); > +} > + > +void udelay(unsigned long usecs) > +{ > + u64 ucycles = (u64)usecs * timebase; > + do_div(ucycles, 1000000U); > + __delay((unsigned long)ucycles); > +} > +EXPORT_SYMBOL(udelay); > + > +void ndelay(unsigned long nsecs) > +{ > + u64 ncycles = (u64)nsecs * timebase; > + do_div(ncycles, 1000000000U); > + __delay((unsigned long)ncycles); > +} I'd be slightly worried about a global 'timebase' identifier that might conflict with a variable in some random driver. Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case). Arnd