* [LTP] [RFC] [PATCH] sched: starvation: Autocallibrate the timeout
@ 2024-06-12 9:12 Cyril Hrubis
2024-06-12 10:29 ` Petr Vorel
0 siblings, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2024-06-12 9:12 UTC (permalink / raw)
To: ltp; +Cc: Steve
Instead of hardcoding the values we attempt to measure the CPU speed and
set the timeout accordingly. Given that the difference in the duration
of the test when the kernel is buggy is about 30x we do not have to have
a precise callibration, just very rough estimate if we are running on a
server or small ARM board would suffice.
So we attempt to measure how long does a bussy loop take and base the
default timeout on that. On x86_64 CPUs the resulting timeout is about
double of the value of the actual test runtime and works fine, but we
need to make sure that the coeficient we divide the result from
callibrate works for small boards too. So please run the test on as many
machines as you can and report if we need to make the dividor smaller or
not.
CC: Steve <xufeifei1@oppo.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
.../kernel/sched/cfs-scheduler/starvation.c | 40 +++++++++++++++++--
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/testcases/kernel/sched/cfs-scheduler/starvation.c b/testcases/kernel/sched/cfs-scheduler/starvation.c
index eb9fd6ff5..94175fdd1 100644
--- a/testcases/kernel/sched/cfs-scheduler/starvation.c
+++ b/testcases/kernel/sched/cfs-scheduler/starvation.c
@@ -21,11 +21,42 @@
#include <sched.h>
#include "tst_test.h"
+#include "tst_safe_clocks.h"
+#include "tst_timer.h"
static char *str_loop;
-static long loop = 2000000;
+static long loop = 1000000;
static char *str_timeout;
-static int timeout = 240;
+static int timeout;
+
+#define CALLIBRATE_LOOPS 100000000
+
+static int callibrate(void)
+{
+ volatile int counter;
+ struct timespec start, stop;
+ long long diff;
+
+ counter = CALLIBRATE_LOOPS;
+ do
+ counter--;
+ while (counter > 0);
+
+ SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC_RAW, &start);
+
+ counter = CALLIBRATE_LOOPS;
+ do
+ counter--;
+ while (counter > 0);
+
+ SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC_RAW, &stop);
+
+ diff = tst_timespec_diff_us(stop, start);
+
+ tst_res(TINFO, "CPU did %i loops in %llius", CALLIBRATE_LOOPS, diff);
+
+ return diff;
+}
static int wait_for_pid(pid_t pid)
{
@@ -59,8 +90,11 @@ static void setup(void)
if (tst_parse_long(str_loop, &loop, 1, LONG_MAX))
tst_brk(TBROK, "Invalid number of loop number '%s'", str_loop);
- if (tst_parse_int(str_timeout, &timeout, 1, INT_MAX))
+ if (tst_parse_int(str_timeout, &timeout, 1, INT_MAX)) {
tst_brk(TBROK, "Invalid number of timeout '%s'", str_timeout);
+ } else {
+ timeout = callibrate() / 1000;
+ }
tst_set_max_runtime(timeout);
}
--
2.44.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] [RFC] [PATCH] sched: starvation: Autocallibrate the timeout
2024-06-12 9:12 [LTP] [RFC] [PATCH] sched: starvation: Autocallibrate the timeout Cyril Hrubis
@ 2024-06-12 10:29 ` Petr Vorel
2024-06-12 10:57 ` Cyril Hrubis
0 siblings, 1 reply; 4+ messages in thread
From: Petr Vorel @ 2024-06-12 10:29 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: Steve, ltp
Hi all,
at least on ppc64le this results in TINFO: Updating max runtime to 0h 13m 17s
for test which runs 10 sec which is too much :(.
(aarch64, s390x have 3 min max runtime, x86_64 and i586 1 min)
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [RFC] [PATCH] sched: starvation: Autocallibrate the timeout
2024-06-12 10:29 ` Petr Vorel
@ 2024-06-12 10:57 ` Cyril Hrubis
2024-06-12 11:21 ` Cyril Hrubis
0 siblings, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2024-06-12 10:57 UTC (permalink / raw)
To: Petr Vorel; +Cc: Steve, ltp
Hi!
> at least on ppc64le this results in TINFO: Updating max runtime to 0h 13m 17s
> for test which runs 10 sec which is too much :(.
Too bad. I want to avoid writing a callibration loops in assembly or
have the coeficients per architecture but I guess that it will be
inevitable.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [RFC] [PATCH] sched: starvation: Autocallibrate the timeout
2024-06-12 10:57 ` Cyril Hrubis
@ 2024-06-12 11:21 ` Cyril Hrubis
0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2024-06-12 11:21 UTC (permalink / raw)
To: Petr Vorel; +Cc: Steve, ltp
Hi!
> > at least on ppc64le this results in TINFO: Updating max runtime to 0h 13m 17s
> > for test which runs 10 sec which is too much :(.
>
> Too bad. I want to avoid writing a callibration loops in assembly or
> have the coeficients per architecture but I guess that it will be
> inevitable.
Can you try with v2 I'm sending right away?
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-06-12 11:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-12 9:12 [LTP] [RFC] [PATCH] sched: starvation: Autocallibrate the timeout Cyril Hrubis
2024-06-12 10:29 ` Petr Vorel
2024-06-12 10:57 ` Cyril Hrubis
2024-06-12 11:21 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox