* [LTP] [RFC] [PATCH] lib/tst_test: Use CLOCK_MONOTONIC for -I option.
@ 2018-01-22 14:19 Cyril Hrubis
2018-01-23 8:31 ` Jan Stancek
2018-01-25 5:50 ` Li Wang
0 siblings, 2 replies; 7+ messages in thread
From: Cyril Hrubis @ 2018-01-22 14:19 UTC (permalink / raw)
To: ltp
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.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
lib/tst_test.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 1df4b72df..2cf35ed66 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -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)
--
2.13.6
^ permalink raw reply related [flat|nested] 7+ messages in thread* [LTP] [RFC] [PATCH] lib/tst_test: Use CLOCK_MONOTONIC for -I option.
2018-01-22 14:19 [LTP] [RFC] [PATCH] lib/tst_test: Use CLOCK_MONOTONIC for -I option Cyril Hrubis
@ 2018-01-23 8:31 ` Jan Stancek
2018-01-23 8:47 ` Cyril Hrubis
2018-02-07 15:15 ` Cyril Hrubis
2018-01-25 5:50 ` Li Wang
1 sibling, 2 replies; 7+ messages in thread
From: Jan Stancek @ 2018-01-23 8:31 UTC (permalink / raw)
To: ltp
----- Original Message -----
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [LTP] [RFC] [PATCH] lib/tst_test: Use CLOCK_MONOTONIC for -I option.
2018-01-22 14:19 [LTP] [RFC] [PATCH] lib/tst_test: Use CLOCK_MONOTONIC for -I option Cyril Hrubis
2018-01-23 8:31 ` Jan Stancek
@ 2018-01-25 5:50 ` Li Wang
2018-01-25 6:59 ` Xiao Yang
1 sibling, 1 reply; 7+ messages in thread
From: Li Wang @ 2018-01-25 5:50 UTC (permalink / raw)
To: ltp
On Mon, Jan 22, 2018 at 10:19 PM, Cyril Hrubis <chrubis@suse.cz> wrote:
> ...
>
> - 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;
}
--
Li Wang
liwang@redhat.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20180125/3bbef9d1/attachment.html>
^ permalink raw reply [flat|nested] 7+ messages in thread* [LTP] [RFC] [PATCH] lib/tst_test: Use CLOCK_MONOTONIC for -I option.
2018-01-25 5:50 ` Li Wang
@ 2018-01-25 6:59 ` Xiao Yang
2018-01-25 7:51 ` Li Wang
0 siblings, 1 reply; 7+ messages in thread
From: Xiao Yang @ 2018-01-25 6:59 UTC (permalink / raw)
To: ltp
On 2018/01/25 13:50, Li Wang wrote:
>
>
> On Mon, Jan 22, 2018 at 10:19 PM, Cyril Hrubis <chrubis@suse.cz
> <mailto:chrubis@suse.cz>> wrote:
>
> ...
>
> - 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?
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
>
> static inline long long tst_timespec_to_ms(struct timespec t)
> {
> return t.tv_sec * 1000 + (t.tv_nsec + 500000) / 1000000;
> }
>
>
>
> --
> Li Wang
> liwang@redhat.com <mailto:liwang@redhat.com>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20180125/f9723f6c/attachment.html>
^ permalink raw reply [flat|nested] 7+ messages in thread* [LTP] [RFC] [PATCH] lib/tst_test: Use CLOCK_MONOTONIC for -I option.
2018-01-25 6:59 ` Xiao Yang
@ 2018-01-25 7:51 ` Li Wang
0 siblings, 0 replies; 7+ messages in thread
From: Li Wang @ 2018-01-25 7:51 UTC (permalink / raw)
To: ltp
On Thu, Jan 25, 2018 at 2:59 PM, Xiao Yang <yangx.jy@cn.fujitsu.com> wrote:
> On 2018/01/25 13:50, Li Wang wrote:
>
>
>
> On Mon, Jan 22, 2018 at 10:19 PM, Cyril Hrubis <chrubis@suse.cz> wrote:
>
>> ...
>>
>> - 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?
>
> 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!
--
Li Wang
liwang@redhat.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20180125/b399ad79/attachment.html>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-02-07 15:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-22 14:19 [LTP] [RFC] [PATCH] lib/tst_test: Use CLOCK_MONOTONIC for -I option Cyril Hrubis
2018-01-23 8:31 ` Jan Stancek
2018-01-23 8:47 ` Cyril Hrubis
2018-02-07 15:15 ` Cyril Hrubis
2018-01-25 5:50 ` Li Wang
2018-01-25 6:59 ` Xiao Yang
2018-01-25 7:51 ` 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.