diff mbox series

timer_getoverrun/2-3: increase tolerance for overshoot

Message ID 81c89bbde27ede0ef4291df60186bdcd293a3db5.1571219422.git.jstancek@redhat.com
State Accepted, archived
Headers show
Series timer_getoverrun/2-3: increase tolerance for overshoot | expand

Commit Message

Jan Stancek Oct. 16, 2019, 9:51 a.m. UTC
Joerg reports that test fails on systems with low timer precision (qemu-arm64,
4ms timer precision) due to way we calculate maximum number of overruns.
If the expected overruns is less than 200, there is no tollerance.

Allow up to ~50ms of extra overruns.

Reported-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>
Acked-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>
Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 .../conformance/interfaces/timer_getoverrun/2-3.c             | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Cyril Hrubis Oct. 17, 2019, 12:54 p.m. UTC | #1
Hi!
> Joerg reports that test fails on systems with low timer precision (qemu-arm64,
> 4ms timer precision) due to way we calculate maximum number of overruns.
> If the expected overruns is less than 200, there is no tollerance.
> 
> Allow up to ~50ms of extra overruns.
> 
> Reported-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>
> Acked-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> ---
>  .../conformance/interfaces/timer_getoverrun/2-3.c             | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_getoverrun/2-3.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_getoverrun/2-3.c
> index 96b7d01e6ffe..66f8b583a5a6 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_getoverrun/2-3.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_getoverrun/2-3.c
> @@ -94,11 +94,17 @@ int main(void)
>  
>  	valuensec = tsres.tv_nsec;
>  	intervalnsec = 2 * valuensec;
> -	//expectedoverruns = (1000000000 - valuensec) / intervalnsec;
>  	expectedoverruns = 1000000000 / intervalnsec - 1;
>  
> +	/*
> +	 * waking up from sleep isn't instant, we can overshoot.
> +	 * Allow up to ~50ms worth of extra overruns.
> +	 */
> +	fudge = 50000000 / intervalnsec + 1;

I wonder if we can measure the sleep with monotonic clock, then we can
be more precise, since we would know how much we overshoot. But it's
probably not worth of complicating the code.

Either way I'm fine with this version as well, acked.

>  	printf("value = %d sec, interval = %d nsec, "
> -	       "expected overruns = %d\n", 1, intervalnsec, expectedoverruns);
> +	       "expected overruns = %d, fudge = %d\n", 1,
> +	       intervalnsec, expectedoverruns, fudge);
>  
>  	its.it_interval.tv_sec = 0;
>  	its.it_interval.tv_nsec = intervalnsec;
> @@ -146,7 +152,6 @@ int main(void)
>  	 * extra expiries after the nanosleep completes so do
>  	 * a range check.
>  	 */
> -	fudge = expectedoverruns / 100;
>  	if (overruns >= expectedoverruns && overruns < expectedoverruns + fudge) {
>  		printf("Test PASSED\n");
>  		return PTS_PASS;
> -- 
> 1.8.3.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp
Jan Stancek Oct. 18, 2019, 7:58 a.m. UTC | #2
----- Original Message -----
> Hi!
> I wonder if we can measure the sleep with monotonic clock, then we can
> be more precise, since we would know how much we overshoot. But it's
> probably not worth of complicating the code.
> 
> Either way I'm fine with this version as well, acked.

I pushed current patch. If we find it's still causing issues
I'll look into the idea with monotonic clock.

Thanks,
Jan
Joerg Vehlow Oct. 18, 2019, 8:02 a.m. UTC | #3
Hi,

Am 18.10.2019 um 09:58 schrieb Jan Stancek:
> ----- Original Message -----
>> Hi!
>> I wonder if we can measure the sleep with monotonic clock, then we can
>> be more precise, since we would know how much we overshoot. But it's
>> probably not worth of complicating the code.
>>
>> Either way I'm fine with this version as well, acked.
> I pushed current patch. If we find it's still causing issues
> I'll look into the idea with monotonic clock.
>
Thanks for fixing this. I'd like to mention, that CLOCK_MONOTONIC is an
optionalfeature in posix. I do not know if there are systems missing it,
that might run these test.

Jörg
diff mbox series

Patch

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_getoverrun/2-3.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_getoverrun/2-3.c
index 96b7d01e6ffe..66f8b583a5a6 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/timer_getoverrun/2-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_getoverrun/2-3.c
@@ -94,11 +94,17 @@  int main(void)
 
 	valuensec = tsres.tv_nsec;
 	intervalnsec = 2 * valuensec;
-	//expectedoverruns = (1000000000 - valuensec) / intervalnsec;
 	expectedoverruns = 1000000000 / intervalnsec - 1;
 
+	/*
+	 * waking up from sleep isn't instant, we can overshoot.
+	 * Allow up to ~50ms worth of extra overruns.
+	 */
+	fudge = 50000000 / intervalnsec + 1;
+
 	printf("value = %d sec, interval = %d nsec, "
-	       "expected overruns = %d\n", 1, intervalnsec, expectedoverruns);
+	       "expected overruns = %d, fudge = %d\n", 1,
+	       intervalnsec, expectedoverruns, fudge);
 
 	its.it_interval.tv_sec = 0;
 	its.it_interval.tv_nsec = intervalnsec;
@@ -146,7 +152,6 @@  int main(void)
 	 * extra expiries after the nanosleep completes so do
 	 * a range check.
 	 */
-	fudge = expectedoverruns / 100;
 	if (overruns >= expectedoverruns && overruns < expectedoverruns + fudge) {
 		printf("Test PASSED\n");
 		return PTS_PASS;