All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/timer_settime03: Scale interval with clock precision
@ 2022-05-25 11:31 Cyril Hrubis
  2022-05-26 10:26 ` Li Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2022-05-25 11:31 UTC (permalink / raw)
  To: ltp

What the test does is to:

- set initial expiration in the past
- set very small interval value
- expect the timer to overrun immediatelly many times
  to trigger timer overrun counter overflow

However the test has harcoded expectation that the kernel timers have
1ns resolution. And while that is true for many modern hardware high
resolution timers are generally not always present.

The test tried to cope with that by adding kernel requirement for
CONFIG_HIGH_RES_TIMERS=y however that does not necessarily mean that the
high resolution hardware is present or that the drivers are loaded.
This only means that the support has been compiled in the kernel.

So instead of disabling the test when kernel timers have lower precision
we scale the timer interval so that the inverval length divided by the
timer precision is constant i.e. handler_delay.

Fixes #925

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 .../syscalls/timer_settime/timer_settime03.c      | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/testcases/kernel/syscalls/timer_settime/timer_settime03.c b/testcases/kernel/syscalls/timer_settime/timer_settime03.c
index 4597bf74e..a828f63d3 100644
--- a/testcases/kernel/syscalls/timer_settime/timer_settime03.c
+++ b/testcases/kernel/syscalls/timer_settime/timer_settime03.c
@@ -32,6 +32,8 @@
 static timer_t timer;
 static volatile int handler_called, overrun, saved_errno;
 
+static struct timespec realtime_resolution;
+
 static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
 {
 	struct itimerspec spec;
@@ -61,6 +63,11 @@ static void setup(void)
 
 	SAFE_SIGNAL(SIGUSR1, sighandler);
 	SAFE_TIMER_CREATE(CLOCK_REALTIME, &sev, &timer);
+
+	SAFE_CLOCK_GETRES(CLOCK_REALTIME, &realtime_resolution);
+
+	tst_res(TINFO, "CLOCK_REALTIME resolution %lins",
+	        (long)realtime_resolution.tv_nsec);
 }
 
 static void run(void)
@@ -81,9 +88,9 @@ static void run(void)
 
 	/* spec.it_value = now - 1.4 * max overrun value */
 	/* IOW, overflow will land right in the middle of negative range */
-	spec.it_value.tv_sec -= handler_delay / 100000000;
+	spec.it_value.tv_sec -= (handler_delay / 100000000) * realtime_resolution.tv_nsec;
 	spec.it_value.tv_nsec -= nsec;
-	spec.it_interval.tv_nsec = 1;
+	spec.it_interval.tv_nsec = realtime_resolution.tv_nsec;
 
 	SAFE_TIMER_SETTIME(timer, TIMER_ABSTIME, &spec, NULL);
 	while (!handler_called);
@@ -115,10 +122,6 @@ static struct tst_test test = {
 	.test_all = run,
 	.setup = setup,
 	.cleanup = cleanup,
-	.needs_kconfigs = (const char *[]) {
-		"CONFIG_HIGH_RES_TIMERS=y",
-		NULL
-	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "78c9c4dfbf8c"},
 		{"CVE", "2018-12896"},
-- 
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] syscalls/timer_settime03: Scale interval with clock precision
  2022-05-25 11:31 [LTP] [PATCH] syscalls/timer_settime03: Scale interval with clock precision Cyril Hrubis
@ 2022-05-26 10:26 ` Li Wang
  2022-05-26 13:21   ` Petr Vorel
  0 siblings, 1 reply; 5+ messages in thread
From: Li Wang @ 2022-05-26 10:26 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: LTP List


[-- Attachment #1.1: Type: text/plain, Size: 1090 bytes --]

On Wed, May 25, 2022 at 7:29 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> What the test does is to:
>
> - set initial expiration in the past
> - set very small interval value
> - expect the timer to overrun immediatelly many times
>   to trigger timer overrun counter overflow
>
> However the test has harcoded expectation that the kernel timers have
> 1ns resolution. And while that is true for many modern hardware high
> resolution timers are generally not always present.
>
> The test tried to cope with that by adding kernel requirement for
> CONFIG_HIGH_RES_TIMERS=y however that does not necessarily mean that the
> high resolution hardware is present or that the drivers are loaded.
> This only means that the support has been compiled in the kernel.
>
> So instead of disabling the test when kernel timers have lower precision
> we scale the timer interval so that the inverval length divided by the
> timer precision is constant i.e. handler_delay.
>
> Fixes #925
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
>

Reviewed-by: Li Wang <liwang@redhat.com>


-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 1866 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] syscalls/timer_settime03: Scale interval with clock precision
  2022-05-26 10:26 ` Li Wang
@ 2022-05-26 13:21   ` Petr Vorel
  2022-05-26 15:15     ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Petr Vorel @ 2022-05-26 13:21 UTC (permalink / raw)
  To: Li Wang; +Cc: LTP List

Hi Cyril, Li,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Could we merge this before release?
Do we need more testing? (some testing already done on by reported on
https://github.com/linux-test-project/ltp/issues/925)

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] syscalls/timer_settime03: Scale interval with clock precision
  2022-05-26 13:21   ` Petr Vorel
@ 2022-05-26 15:15     ` Cyril Hrubis
  2022-05-27  1:35       ` Li Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2022-05-26 15:15 UTC (permalink / raw)
  To: Petr Vorel; +Cc: LTP List

Hi!
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> 
> Could we merge this before release?

I guess that this is pretty safe, it does not change the test behavior
on high resolution timers and fixes false possitive without them. So I
would vote for merging it now.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] syscalls/timer_settime03: Scale interval with clock precision
  2022-05-26 15:15     ` Cyril Hrubis
@ 2022-05-27  1:35       ` Li Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Li Wang @ 2022-05-27  1:35 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: LTP List


[-- Attachment #1.1: Type: text/plain, Size: 298 bytes --]

> > Could we merge this before release?
>
> I guess that this is pretty safe, it does not change the test behavior
> on high resolution timers and fixes false possitive without them. So I
> would vote for merging it now.
>

Yes, tested also good from my side.
Pushed, thanks!

-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 753 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-27  1:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-25 11:31 [LTP] [PATCH] syscalls/timer_settime03: Scale interval with clock precision Cyril Hrubis
2022-05-26 10:26 ` Li Wang
2022-05-26 13:21   ` Petr Vorel
2022-05-26 15:15     ` Cyril Hrubis
2022-05-27  1:35       ` Li Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.