clock_gettime04: set threshold based on the clock tick rate
PATCH 1/1 clock_gettime04: set threshold based on the clock tick rate
This is to get rid of the intermittent failures in clock_gettime04, which are likely caused by different clock tick rates on platforms. Here set the threshold no less than each clock tick in millisecond:
delta = 1000(ms)/ticks_number_per_sec + 5;
Error log:
clock_gettime04.c:163: TFAIL: CLOCK_REALTIME_COARSE(syscall with old kernel spec):
Difference between successive readings greater than 5 ms (1): 10
clock_gettime04.c:163: TFAIL: CLOCK_MONOTONIC_COARSE(vDSO with old kernel spec):
Difference between successive readings greater than 5 ms (2): 10
From Waiman Long:
That failure happens for CLOCK_REALTIME_COARSE which is a faster but less precise version of CLOCK_REALTIME. The time resolution is actually a clock tick. Since arm64 has a HZ rate of 100. That means each tick is 10ms. So a CLOCK_REALTIME_COARSE threshold of 5ms is probably not enough. I would say in the case of CLOCK_REALTIME_COARSE, we have to increase the threshold based on the clock tick rate of the system. This is more a test failure than is an inherent problem in the kernel.
Fixes #898
--- testcases/kernel/syscalls/clock_gettime/clock_gettime04.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c +2 -1
@@ -35,7 +35,7 @@ clockid_t clks[] = { };static gettime_t ptr_vdso_gettime, ptr_vdso_gettime64; -static long long delta =5 ; +static long long delta;static inline int do_vdso_gettime (gettime_t vdso,clockid_t clk_id,void *ts) {
@@ -92,6 +92,7 @@ static struct time64_variants variants[] = {static void setup (void ) { + delta =1000 /sysconf (_SC_CLK_TCK) +5 ;if (tst_is_virt (VIRT_ANY )) {tst_res (TINFO ,"Running in a virtual machine, multiply the delta by 10." ); delta *=10 ;
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 45 lines · Li Wang
This is to get rid of the intermittent failures in
clock_gettime04, which are likely caused by different clock tick rates on platforms. Here set the threshold no less than each clock tick in millisecond:delta = 1000(ms)/ticks_number_per_sec + 5;Error log:
clock_gettime04.c:163: TFAIL:CLOCK_REALTIME_COARSE(syscall with old kernel spec):
Difference between successive readings greater than 5 ms (1): 10
clock_gettime04.c:163: TFAIL:CLOCK_MONOTONIC_COARSE(vDSO with old kernel spec):
Difference between successive readings greater than 5 ms (2): 10From Waiman Long:
That failure happens forCLOCK_REALTIME_COARSEwhich is a faster but less precise version ofCLOCK_REALTIME. The time resolution is actually a clock tick. Since arm64 has a HZ rate of 100. That means each tick is 10ms. So aCLOCK_REALTIME_COARSEthreshold of 5ms is probably not enough. I would say in the case ofCLOCK_REALTIME_COARSE, we have to increase the threshold based on the clock tick rate of the system. This is more a test failure than is an inherent problem in the kernel.Fixes #898
Reported-by Eirik Fuller <[email protected]>Signed-off-by Li Wang <[email protected]>Cc Waiman Long <[email protected]>Cc Viresh Kumar <[email protected]>--- testcases/kernel/syscalls/clock_gettime/clock_gettime04.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)testcases/kernel/syscalls/clock_gettime/clock_gettime04.c +1
-1@@ -35,7 +35,7 @@ clockid_t clks[] = { };static gettime_t ptr_vdso_gettime, ptr_vdso_gettime64; -static long long delta =5 ; +static long long delta;static inline int do_vdso_gettime (gettime_t vdso,clockid_t clk_id,void *ts) {
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c static struct time64_variants variants[] = { · line 95
Quoted 4 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c +1
-0@@ -92,6 +92,7 @@ static struct time64_variants variants[] = {static void setup (void ) { + delta =1000 /sysconf (_SC_CLK_TCK) +5 ;
This does not look correct to me. The sysconf(_SC_CLK_TCK) returns 100 on systems where the test was working fine with 5 second delta. I think that the difference is that _SC_CLK_TCK returns how fast are the jiffies incremented which does not really matter for most of the modern hardware that uses high resolution harware for timers.
I think that we should really use whatever is returned by the clock_getres(CLOCK_REALTIME_COARSE, &res), as long as high resolution timers are not available this call will return resolution in miliseconds and with high resolution timers available the reported resolution will be in nanosecond range, so it should probably be something as:
clock_getres(CLOCK_REALTIME_COARSE, &res); delta = 5 + (res.tv_nsec / 1000000) * 5;
Quoted 9 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c +0
-0if (tst_is_virt (VIRT_ANY )) {tst_res (TINFO ,"Running in a virtual machine, multiply the delta by 10." ); delta *=10 ;Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 14 lines · Cyril Hrubis
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c clockid_t clks[] = { · line 40
Quoted 10 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c +1
-1@@ -35,7 +35,7 @@ clockid_t clks[] = { };static gettime_t ptr_vdso_gettime, ptr_vdso_gettime64; -static long long delta =5 ; +static long long delta; static inline int do_vdso_gettime(gettime_t vdso, clockid_t clk_id,void *ts)
Quoted 3 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c +0
-0{@@ -92,6 +92,7 @@ static struct time64_variants variants[] = {
Quoted 10 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c static struct time64_variants variants[] = { · line 95
Quoted 3 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c +1
-0static void setup (void ) { + delta =1000 /sysconf (_SC_CLK_TCK) +5 ;This does not look correct to me. The
sysconf(_SC_CLK_TCK)returns 100 on systems where the test was working fine with 5 second delta. I think that the difference is that_SC_CLK_TCKreturns how fast are the jiffies incremented which does not really matter for most of the modern hardware that uses high resolution harware for timers.
You're right, I checked some documents and confirmed this. There I used the system tick rate (in the worst situations) that seemed a bit loose to other clockids.
Quoted 10 lines
I think that we should really use whatever is returned by the
clock_getres(CLOCK_REALTIME_COARSE, &res), as long as high resolution timers are not available this call will return resolution in miliseconds and with high resolution timers available the reported resolution will be in nanosecond range, so it should probably be something as:clock_getres(CLOCK_REALTIME_COARSE, &res); delta = 5 + (res.tv_nsec / 1000000) * 5;
Sounds reasonable.
But I don't understand why you multiply 5 for the resolution (in milliseconds) here. Or, a wiser choice is to get the real resolution for each clockid? i.e.
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c +0 -3
@@ -92,23 +92,27 @@ static struct time64_variants variants[] = {static void setup (void ) { - delta =1000 /sysconf (_SC_CLK_TCK) +5 ; -if (tst_is_virt (VIRT_ANY )) { - tst_res(TINFO, "Running in a virtual machine, multiply the
delta by 10.");
- delta *= 10;
- }
-
find_clock_gettime_vdso(&ptr_vdso_gettime, &ptr_vdso_gettime64);
}
static void run(unsigned int i)
{
struct tst_ts ts;
+ struct timespec res;
long long start, end = 0, diff, slack;
struct time64_variants *tv;
int count = 10000, ret;
unsigned int j;+ clock_getres(clks[i], &res);
+ tst_res(TINFO, "%s: resolution is %ldns", tst_clock_name(clks[i]),
res.tv_nsec);
+
+ delta = 5 + res.tv_nsec/1000000;
+ if (tst_is_virt(VIRT_ANY)) {
+ delta *= 10;
+ tst_res(TINFO, "Multiply the delta by 10 in virtual
machine: %lld", delta);
+ }
+
do {
for (j = 0; j < ARRAY_SIZE(variants); j++) {
/* Refresh time in start */Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 10 lines
Quoted 4 lines
clock_getres(CLOCK_REALTIME_COARSE, &res); delta = 5 + (res.tv_nsec / 1000000) * 5;Sounds reasonable.
But I don't understand why you multiply 5 for the resolution (in milliseconds) here. Or, a wiser choice is to get the real resolution for each clockid? i.e.
I did multiply it with 5 just to add some error margin. I guess that we can as well multiply it with 2 if that works well enough.
I do not think that we should get resolution for each clock, the COARSE clock should have the worst resolution of all clocks.
Quoted 43 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c +10
-6@@ -92,23 +92,27 @@ static struct time64_variants variants[] = {static void setup (void ) { - delta =1000 /sysconf (_SC_CLK_TCK) +5 ; -if (tst_is_virt (VIRT_ANY )) { - tst_res(TINFO, "Running in a virtual machine, multiply the delta by 10."); - delta *= 10; - } -find_clock_gettime_vdso (&ptr_vdso_gettime, &ptr_vdso_gettime64); }static void run (unsigned int i) {struct tst_ts ts; +struct timespec res;long long start, end =0 , diff, slack;struct time64_variants *tv;int count =10000 , ret;unsigned int j; +clock_getres (clks[i], &res); +tst_res (TINFO ,"%s: resolution is %ldns" ,tst_clock_name (clks[i]), res.tv_nsec); + + delta =5 + res.tv_nsec/1000000 ; +if (tst_is_virt (VIRT_ANY )) { + delta *=10 ; +tst_res (TINFO ,"Multiply the delta by 10 in virtual machine: %lld", delta); + } +do { for (j = 0; j < ARRAY_SIZE(variants); j++) { /* Refresh time in start */Signature · 2 lines
Regards, Li Wang
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 6 lines · Cyril Hrubis
Hi!
Quoted 5 lines
Quoted 4 lines
clock_getres(CLOCK_REALTIME_COARSE, &res); delta = 5 + (res.tv_nsec / 1000000) * 5;
Quoted 9 lines
Quoted 5 lines
Sounds reasonable.
But I don't understand why you multiply 5 for the resolution (in milliseconds) here. Or, a wiser choice is to get the real resolution for each clockid? i.e.
I did multiply it with 5 just to add some error margin. I guess that we can as well multiply it with 2 if that works well enough.
Ok, I'd like to multiply 5 in case VM needs more.
Quoted 3 lines
I do not think that we should get resolution for each clock, the COARSE clock should have the worst resolution of all clocks.
Yes, quite enough for the rest.
For precise clock, the second part will be zero since divided by 1000000.
delta = 5 + (res.tv_nsec / 1000000) * 5;
Test data from aarch4 (kernel-5.14) FYI:
===================
clock_gettime04.c:108: TINFO: CLOCK_REALTIME: resolution is 1ns
...
clock_gettime04.c:108: TINFO: CLOCK_REALTIME_COARSE: resolution is 10000000ns
clock_gettime04.c:108: TINFO: CLOCK_MONOTONIC: resolution is 1ns clock_gettime04.c:108: TINFO: CLOCK_MONOTONIC_COARSE: resolution is 10000000ns
clock_gettime04.c:108: TINFO: CLOCK_MONOTONIC_RAW: resolution is 1ns clock_gettime04.c:108: TINFO: CLOCK_BOOTTIME: resolution is 1ns
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril,
Sorry, I didn't complete my input but sent the email by touch key combination... Comments in below.
Quoted 8 lines · Li Wang
Quoted 4 lines
I did multiply it with 5 just to add some error margin. I guess that we can as well multiply it with 2 if that works well enough.
Ok, I'd like to multiply 5 in case VM needs more.
Quoted 9 lines
Quoted 3 lines
I do not think that we should get resolution for each clock, the COARSE clock should have the worst resolution of all clocks.
Yes, quite enough for the rest.
For precise clock, the second part will be zero since divided by 1000000.delta = 5 + (res.tv_nsec / 1000000) * 5;
My concern here is that seems a bit looser to the rest clocks. Because "10ms" as delta is a big value to the precise clock since the resolution of some is only 1ns.
(The delta will be "10ms" on x86_64 and "15ms" on aarch64.)
In my path V2, we can make the second part _zero_ by dividing 1000000. Then we can keep using the proper delta for each clock.
Test data from x86_64:
========
clock_gettime04.c:108: TINFO: CLOCK_REALTIME: resolution is 1ns clock_gettime04.c:112: TINFO: delta = : 5
...
clock_gettime04.c:108: TINFO: CLOCK_REALTIME_COARSE: resolution is 1000000ns clock_gettime04.c:112: TINFO: delta = : 10 clock_gettime04.c:108: TINFO: CLOCK_MONOTONIC: resolution is 1ns clock_gettime04.c:112: TINFO: delta = : 5
clock_gettime04.c:108: TINFO: CLOCK_MONOTONIC_COARSE: resolution is 1000000ns
clock_gettime04.c:112: TINFO: delta = : 10 clock_gettime04.c:108: TINFO: CLOCK_MONOTONIC_RAW: resolution is 1ns clock_gettime04.c:112: TINFO: delta = : 5
clock_gettime04.c:108: TINFO: CLOCK_BOOTTIME: resolution is 1ns clock_gettime04.c:112: TINFO: delta = : 5
Quoted 19 lines
Test data from aarch4 (kernel-5.14) FYI:
===================
clock_gettime04.c:108: TINFO:CLOCK_REALTIME: resolution is 1ns
...
clock_gettime04.c:108: TINFO:CLOCK_REALTIME_COARSE: resolution is 10000000ns
clock_gettime04.c:108: TINFO:CLOCK_MONOTONIC: resolution is 1ns clock_gettime04.c:108: TINFO:CLOCK_MONOTONIC_COARSE: resolution is 10000000ns
clock_gettime04.c:108: TINFO:CLOCK_MONOTONIC_RAW: resolution is 1ns clock_gettime04.c:108: TINFO:CLOCK_BOOTTIME: resolution is 1ns--
Regards,
Li Wang
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 5 lines
My concern here is that seems a bit looser to the rest clocks. Because "10ms" as delta is a big value to the precise clock since the resolution of some is only 1ns.
(The delta will be "10ms" onx86_64and "15ms" on aarch64.)
delta will be 55ms (not 15ms) on aarch64, this is too big ^
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Thinking of it again I think that:
- the COARSE clocks runs on jiffies, the rest of the clocks may use high resolution if available
- we need two deltas, one for the coarse clocks and one for the rest
- the delta should generally be clock resolution + epsion (5ms)
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 45 lines · Li Wang
This is to get rid of the intermittent failures in
clock_gettime04, which are likely caused by different clock tick rates on platforms. Here set the threshold no less than each clock tick in millisecond:delta = 1000(ms)/ticks_number_per_sec + 5;Error log:
clock_gettime04.c:163: TFAIL:CLOCK_REALTIME_COARSE(syscall with old kernel spec):
Difference between successive readings greater than 5 ms (1): 10
clock_gettime04.c:163: TFAIL:CLOCK_MONOTONIC_COARSE(vDSO with old kernel spec):
Difference between successive readings greater than 5 ms (2): 10From Waiman Long:
That failure happens forCLOCK_REALTIME_COARSEwhich is a faster but less precise version ofCLOCK_REALTIME. The time resolution is actually a clock tick. Since arm64 has a HZ rate of 100. That means each tick is 10ms. So aCLOCK_REALTIME_COARSEthreshold of 5ms is probably not enough. I would say in the case ofCLOCK_REALTIME_COARSE, we have to increase the threshold based on the clock tick rate of the system. This is more a test failure than is an inherent problem in the kernel.Fixes #898
Reported-by Eirik Fuller <[email protected]>Signed-off-by Li Wang <[email protected]>Cc Waiman Long <[email protected]>Cc Viresh Kumar <[email protected]>--- testcases/kernel/syscalls/clock_gettime/clock_gettime04.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)testcases/kernel/syscalls/clock_gettime/clock_gettime04.c +1
-1@@ -35,7 +35,7 @@ clockid_t clks[] = { };static gettime_t ptr_vdso_gettime, ptr_vdso_gettime64; -static long long delta =5 ; +static long long delta;static inline int do_vdso_gettime (gettime_t vdso,clockid_t clk_id,void *ts) {
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c static struct time64_variants variants[] = { · line 98
Quoted 7 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c +1
-0@@ -92,6 +92,7 @@ static struct time64_variants variants[] = {static void setup (void ) { + delta =1000 /sysconf (_SC_CLK_TCK) +5 ;if (tst_is_virt (VIRT_ANY )) {tst_res (TINFO ,"Running in a virtual machine, multiply the delta by 10." ); delta *=10 ;
Actually, only CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE use clock tick for its time measurement. The rests use a higher resolution internal timer. Perhaps, we could have a separate coarse_delta for these two cases and use delta for the rest.
Cheers,
Longman
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 5 lines · Waiman Long
Quoted 5 lines
static void setup(void)
{
+ delta = 1000/sysconf(_SC_CLK_TCK) + 5;
if (tst_is_virt(VIRT_ANY)) {
tst_res(TINFO, "Running in a virtual machine, multiply the
Quoted 8 lines
delta by 10.");
Quoted 1 line
delta *= 10;Actually, only
CLOCK_REALTIME_COARSEandCLOCK_MONOTONIC_COARSEuse clock tick for its time measurement. The rests use a higher resolution internal timer. Perhaps, we could have a separatecoarse_deltafor these two cases and use delta for the rest.
Good point, at least for aarch64 the CLOCK*_COARSE makes use of the clock tick is 10ms.
However, as many architectures have varying tick rates and use dynamically timer, maybe a further method is to get it via clock_getres() just like Cyril mentioned in another email.
(I draft patch V2 in that email, feel free to review)
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp