Message ID | 1589818051-20549-7-git-send-email-pmorel@linux.ibm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | s390x: Testing the Channel Subsystem I/O | expand |
On 18/05/2020 18.07, Pierre Morel wrote: > use get_clock_ms() to calculate a delay in ms > > Signed-off-by: Pierre Morel <pmorel@linux.ibm.com> > --- > lib/s390x/asm/time.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/lib/s390x/asm/time.h b/lib/s390x/asm/time.h > index 25c7a3c..931a119 100644 > --- a/lib/s390x/asm/time.h > +++ b/lib/s390x/asm/time.h > @@ -23,4 +23,14 @@ static inline uint64_t get_clock_ms(void) > return (clk >> (63 - 51)) / 1000; > } > > +static inline void mdelay(unsigned long ms) > +{ > + unsigned long startclk; > + > + startclk = get_clock_ms(); > + for (;;) > + if (get_clock_ms() - startclk > ms) > + break; Maybe rather: for (;get_clock_ms() - startclk <= ms;) ; ? Or: while (get_clock_ms() - startclk <= ms) ; ? Thomas
On 2020-05-26 20:16, Thomas Huth wrote: > On 18/05/2020 18.07, Pierre Morel wrote: >> use get_clock_ms() to calculate a delay in ms >> >> Signed-off-by: Pierre Morel <pmorel@linux.ibm.com> >> --- >> lib/s390x/asm/time.h | 10 ++++++++++ >> 1 file changed, 10 insertions(+) >> >> diff --git a/lib/s390x/asm/time.h b/lib/s390x/asm/time.h >> index 25c7a3c..931a119 100644 >> --- a/lib/s390x/asm/time.h >> +++ b/lib/s390x/asm/time.h >> @@ -23,4 +23,14 @@ static inline uint64_t get_clock_ms(void) >> return (clk >> (63 - 51)) / 1000; >> } >> >> +static inline void mdelay(unsigned long ms) >> +{ >> + unsigned long startclk; >> + >> + startclk = get_clock_ms(); >> + for (;;) >> + if (get_clock_ms() - startclk > ms) >> + break; > > Maybe rather: > > for (;get_clock_ms() - startclk <= ms;) > ; > > ? > Or: > > while (get_clock_ms() - startclk <= ms) > ; > ? > > Thomas > Hi, your comment made me realize I did not take care on the wrapping. I will rework this. Thanks, Pierre
diff --git a/lib/s390x/asm/time.h b/lib/s390x/asm/time.h index 25c7a3c..931a119 100644 --- a/lib/s390x/asm/time.h +++ b/lib/s390x/asm/time.h @@ -23,4 +23,14 @@ static inline uint64_t get_clock_ms(void) return (clk >> (63 - 51)) / 1000; } +static inline void mdelay(unsigned long ms) +{ + unsigned long startclk; + + startclk = get_clock_ms(); + for (;;) + if (get_clock_ms() - startclk > ms) + break; +} + #endif
use get_clock_ms() to calculate a delay in ms Signed-off-by: Pierre Morel <pmorel@linux.ibm.com> --- lib/s390x/asm/time.h | 10 ++++++++++ 1 file changed, 10 insertions(+)