diff mbox series

[kvm-unit-tests,v7,06/12] s390x: use get_clock_ms() to calculate a delay in ms

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

Commit Message

Pierre Morel May 18, 2020, 4:07 p.m. UTC
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(+)

Comments

Thomas Huth May 26, 2020, 6:16 p.m. UTC | #1
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
Pierre Morel June 4, 2020, 7:21 a.m. UTC | #2
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 mbox series

Patch

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