Skip to contentSkip to conversation

lib/tst_test: Use CLOCK_MONOTONIC for -I option.

RFC PATCH New Cyril Hrubis 4 participants 7 messages Jan 22, 2018 – Feb 7, 2018 Library code

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 lib/tst_test: Use CLOCK_MONOTONIC for -I option.

CLOCK_MONOTONIC has been added to linux in the 2.5 development branch so this syscall is available in all 2.6 kernels hence it's reasonable to be used it in the test library at this point it has been 15 years after all.

---
 lib/tst_test.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
lib/tst_test.c +6 -4
index 1df4b72df..2cf35ed66 100644
@@ -24,7 +24,6 @@
 #include <sys/mount.h>
 #include <sys/types.h>
 #include <sys/wait.h>
-#include <sys/time.h>
 
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
@@ -34,6 +33,8 @@
 #include "tst_ansi_color.h"
 #include "tst_safe_stdio.h"
 #include "tst_timer_test.h"
+#include "tst_clocks.h"
+#include "tst_timer.h"
 
 #include "old_resource.h"
 #include "old_device.h"
@@ -853,11 +854,12 @@ static void run_tests(void)
 
 static unsigned long long get_time_ms(void)
 {
-	struct timeval tv;
+	struct timespec ts;
 
-	gettimeofday(&tv, NULL);
+	if (tst_clock_gettime(CLOCK_MONOTONIC, &ts))
+		tst_brk(TBROK | TERRNO, "tst_clock_gettime()");
 
-	return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+	return tst_timespec_to_ms(ts);
 }
 
 static void add_paths(void)
Signature · 1 line
2.13.6
#1 lore raw

RFC PATCH 1/1 lib/tst_test: Use CLOCK_MONOTONIC for -I option.

----- Original Message -----

Quoted 4 lines

CLOCK_MONOTONIC has been added to linux in the 2.5 development branch so this syscall is available in all 2.6 kernels hence it's reasonable to be used it in the test library at this point it has been 15 years after all.

LGTM.
Compile tested on rhel59 rhel62 rhel69 rhel7 rhel6i386.

Regards,
Jan

#2 lore raw

RFC PATCH 1/1 lib/tst_test: Use CLOCK_MONOTONIC for -I option.

Hi!

Quoted 7 lines
Quoted 4 lines

CLOCK_MONOTONIC has been added to linux in the 2.5 development branch so this syscall is available in all 2.6 kernels hence it's reasonable to be used it in the test library at this point it has been 15 years after all.

LGTM.
Compile tested on rhel59 rhel62 rhel69 rhel7 rhel6i386.

After thinking about this yesterday I think that we should do the same for the old library just to keep testcase behavior consistent.

I will look into that and send follow up patch today.

Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

RFC PATCH 1/1 lib/tst_test: Use CLOCK_MONOTONIC for -I option.

In reply to Cyril Hrubis

lib/tst_test.c static void run_tests(void) · line 862

Quoted 5 lines · Cyril Hrubis

​...

lib/tst_test.c +1 -1
-       return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+       return tst_timespec_to_ms(ts);

​Both patches(include the old-lib one) looks good.

I just have a small question about function tst_timespec_to_ms(), why the t.tv_nsec plus 500000 when convert to msec?

static inline long long tst_timespec_to_ms(struct timespec t)

{
    return t.tv_sec * 1000 + (t.tv_nsec + 500000) / 1000000;
}

​

Signature · 5 lines
Li Wang
[email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20180125/3bbef9d1/attachment.html>
#5 lore raw

RFC PATCH 1/1 lib/tst_test: Use CLOCK_MONOTONIC for -I option.

Quoted 12 lines · Li Wang

On Mon, Jan 22, 2018 at 10:19 PM, Cyril Hrubis <[email protected] <mailto:[email protected]>> wrote:

​...

- return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ return tst_timespec_to_ms(ts);

Quoted 4 lines

​Both patches(include the old-lib one) looks good.

I just have a small question about function tst_timespec_to_ms(), why the t.tv_nsec plus 500000 when convert to msec?

Hi Li,

It seems to round up/down the decimal produced by converting nesc to msec. If the decimal is greater than 0.5, round up it. If not, round down it.

Thanks,
Xiao Yang

Quoted 14 lines

static inline long long tst_timespec_to_ms(struct timespec t)

{
    return t.tv_sec * 1000 + (t.tv_nsec + 500000) / 1000000;
}

​

Signature · 2 lines
Li Wang
[email protected] <mailto:[email protected]>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20180125/f9723f6c/attachment.html>

#6 lore raw

RFC PATCH 1/1 lib/tst_test: Use CLOCK_MONOTONIC for -I option.

Quoted 15 lines · Xiao Yang

On 2018/01/25 13:50, Li Wang wrote:

lib/tst_test.c static void run_tests(void) · line 862

Quoted 5 lines · Cyril Hrubis

​...

lib/tst_test.c +1 -1
-       return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+       return tst_timespec_to_ms(ts);

​Both patches(include the old-lib one) looks good.

Quoted 9 lines

I just have a small question about function tst_timespec_to_ms(), why the t.tv_nsec plus 500000 when convert to msec?

Hi Li,

It seems to round up/down the decimal produced by converting nesc to msec. If the decimal is greater than 0.5, round up it. If not, round down it.

​Ah, yes. Thanks so much!​

Signature · 5 lines
Li Wang
[email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20180125/b399ad79/attachment.html>