* [LTP] [PATCH 0/2] Fix timestamp tests in SysV IPC tests
@ 2020-12-03 15:28 Cyril Hrubis
2020-12-03 15:28 ` [LTP] [PATCH 1/2] libnewipc: Add get_ipc_timestamp() Cyril Hrubis
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Cyril Hrubis @ 2020-12-03 15:28 UTC (permalink / raw)
To: ltp
Cyril Hrubis (2):
libnewipc: Add get_ipc_timestamp()
syscalls/ipc: Make use of get_ipc_timestamp()
include/libnewipc.h | 3 +++
libs/libltpnewipc/libnewipc.c | 13 +++++++++++++
testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c | 4 ++--
testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c | 4 ++--
testcases/kernel/syscalls/ipc/shmctl/Makefile | 2 +-
testcases/kernel/syscalls/ipc/shmctl/shmctl01.c | 4 ++--
6 files changed, 23 insertions(+), 7 deletions(-)
--
2.26.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH 1/2] libnewipc: Add get_ipc_timestamp()
2020-12-03 15:28 [LTP] [PATCH 0/2] Fix timestamp tests in SysV IPC tests Cyril Hrubis
@ 2020-12-03 15:28 ` Cyril Hrubis
2020-12-04 3:21 ` Li Wang
2020-12-03 15:28 ` [LTP] [PATCH 2/2] syscalls/ipc: Make use of get_ipc_timestamp() Cyril Hrubis
2020-12-04 9:22 ` [LTP] [PATCH 0/2] Fix timestamp tests in SysV IPC tests Jan Stancek
2 siblings, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2020-12-03 15:28 UTC (permalink / raw)
To: ltp
That returns timestamps that should return values comparable to the
stime/rtime/ctime.
From Thomas Gleixner:
> Due to the internal implementation of ktime_get_real_seconds(), which is
> a 2038 safe replacement for the former get_seconds() function, this
> accumulation issue can be observed. (time(2) via syscall and newer
> versions of VDSO use the same mechanism).
>
> clock_gettime(CLOCK_REALTIME, &ts);
> sec = time();
> assert(sec >= ts.tv_sec);
>
> That assert can trigger for two reasons:
>
> 1) Clock was set between the clock_gettime() and time().
>
> 2) The clock has advanced far enough that:
>
> timekeeper.tv_nsec + (clock_now_ns() - last_update_ns) > NSEC_PER_SEC
> The same problem exists for CLOCK_XXX vs. CLOCK_XXX_COARSE
>
> clock_gettime(CLOCK_XXX, &ts);
> clock_gettime(CLOCK_XXX_COARSE, &tc);
> assert(tc.tv_sec >= ts.tv_sec);
>
> The _COARSE variants return their associated timekeeper.tv_sec,tv_nsec
> pair without reading the clock. Same as #2 above just extended to clock
> MONOTONIC.
Which means the timestamps in the structure we get from msg* calls can
be 1 second smaller that timestamps returned from realtime timers.
However it also means that the _COARSE timers should be the same as the
SysV timestamps and could be used for these tests instead. Also these
timers should be available since 2.6.32 which is old enough to assume
that they are present.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
include/libnewipc.h | 3 +++
libs/libltpnewipc/libnewipc.c | 13 +++++++++++++
2 files changed, 16 insertions(+)
diff --git a/include/libnewipc.h b/include/libnewipc.h
index 30288cd68..075364f85 100644
--- a/include/libnewipc.h
+++ b/include/libnewipc.h
@@ -22,6 +22,7 @@
#ifndef __LIBNEWIPC_H
#define __LIBNEWIPC_H 1
+#include <time.h>
#include <sys/types.h>
#define MSG_RD 0400
@@ -56,4 +57,6 @@ void *probe_free_addr(const char *file, const int lineno);
#define PROBE_FREE_ADDR() \
probe_free_addr(__FILE__, __LINE__)
+time_t get_ipc_timestamp(void);
+
#endif /* newlibipc.h */
diff --git a/libs/libltpnewipc/libnewipc.c b/libs/libltpnewipc/libnewipc.c
index 3734040b7..d0974bbe0 100644
--- a/libs/libltpnewipc/libnewipc.c
+++ b/libs/libltpnewipc/libnewipc.c
@@ -23,6 +23,7 @@
#include "libnewipc.h"
#include "tst_safe_stdio.h"
#include "tst_safe_sysv_ipc.h"
+#include "tst_clocks.h"
#define BUFSIZE 1024
@@ -86,3 +87,15 @@ void *probe_free_addr(const char *file, const int lineno)
return addr;
}
+
+time_t get_ipc_timestamp(void)
+{
+ struct timespec ts;
+ int ret;
+
+ ret = tst_clock_gettime(CLOCK_REALTIME_COARSE, &ts);
+ if (ret < 0)
+ tst_brk(TBROK | TERRNO, "clock_gettime(CLOCK_REALTIME_COARSE)");
+
+ return ts.tv_sec;
+}
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 2/2] syscalls/ipc: Make use of get_ipc_timestamp()
2020-12-03 15:28 [LTP] [PATCH 0/2] Fix timestamp tests in SysV IPC tests Cyril Hrubis
2020-12-03 15:28 ` [LTP] [PATCH 1/2] libnewipc: Add get_ipc_timestamp() Cyril Hrubis
@ 2020-12-03 15:28 ` Cyril Hrubis
2020-12-04 9:22 ` [LTP] [PATCH 0/2] Fix timestamp tests in SysV IPC tests Jan Stancek
2 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2020-12-03 15:28 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c | 4 ++--
testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c | 4 ++--
testcases/kernel/syscalls/ipc/shmctl/Makefile | 2 +-
testcases/kernel/syscalls/ipc/shmctl/shmctl01.c | 4 ++--
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c
index 5c1e317e9..afe552c4f 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c
@@ -25,13 +25,13 @@ static void verify_msgrcv(void)
SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
- time(&before_rcv);
+ before_rcv = get_ipc_timestamp();
TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0));
if (TST_RET == -1) {
tst_res(TFAIL | TTERRNO, "msgrcv failed");
return;
}
- time(&after_rcv);
+ after_rcv = get_ipc_timestamp();
if (strcmp(rcv_buf.mtext, snd_buf.mtext) == 0)
tst_res(TPASS, "message received(%s) = message sent(%s)",
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
index 5f5da52d2..432b03def 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
@@ -29,13 +29,13 @@ static void verify_msgsnd(void)
struct msqid_ds qs_buf;
time_t before_snd, after_snd;
- time(&before_snd);
+ before_snd = get_ipc_timestamp();
TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, 0));
if (TST_RET == -1) {
tst_res(TFAIL | TTERRNO, "msgsnd() failed");
return;
}
- time(&after_snd);
+ after_snd = get_ipc_timestamp();
SAFE_MSGCTL(queue_id, IPC_STAT, &qs_buf);
diff --git a/testcases/kernel/syscalls/ipc/shmctl/Makefile b/testcases/kernel/syscalls/ipc/shmctl/Makefile
index 106b73697..06d72d968 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/Makefile
+++ b/testcases/kernel/syscalls/ipc/shmctl/Makefile
@@ -10,6 +10,6 @@ shmctl05: LDLIBS += -lrt
include $(top_srcdir)/include/mk/testcases.mk
-shmctl02 shmctl04 shmctl06: LTPLDLIBS = -lltpnewipc
+shmctl01 shmctl02 shmctl04 shmctl06: LTPLDLIBS = -lltpnewipc
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
index 3a39a4d74..eb5307d1e 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
@@ -240,9 +240,9 @@ static int get_shm_idx_from_id(int shm_id)
static void setup(void)
{
- ctime_min = time(NULL);
+ ctime_min = get_ipc_timestamp();
shm_id = SAFE_SHMGET(IPC_PRIVATE, SHM_SIZE, IPC_CREAT | SHM_RW);
- ctime_max = time(NULL);
+ ctime_max = get_ipc_timestamp();
shm_idx = get_shm_idx_from_id(shm_id);
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 1/2] libnewipc: Add get_ipc_timestamp()
2020-12-03 15:28 ` [LTP] [PATCH 1/2] libnewipc: Add get_ipc_timestamp() Cyril Hrubis
@ 2020-12-04 3:21 ` Li Wang
0 siblings, 0 replies; 6+ messages in thread
From: Li Wang @ 2020-12-04 3:21 UTC (permalink / raw)
To: ltp
Hi Cyril,
On Thu, Dec 3, 2020 at 11:27 PM Cyril Hrubis <chrubis@suse.cz> wrote:
> That returns timestamps that should return values comparable to the
> stime/rtime/ctime.
>
> From Thomas Gleixner:
>
> > Due to the internal implementation of ktime_get_real_seconds(), which is
> > a 2038 safe replacement for the former get_seconds() function, this
> > accumulation issue can be observed. (time(2) via syscall and newer
> > versions of VDSO use the same mechanism).
> >
> > clock_gettime(CLOCK_REALTIME, &ts);
> > sec = time();
> > assert(sec >= ts.tv_sec);
> >
> > That assert can trigger for two reasons:
> >
> > 1) Clock was set between the clock_gettime() and time().
> >
> > 2) The clock has advanced far enough that:
> >
> > timekeeper.tv_nsec + (clock_now_ns() - last_update_ns) > NSEC_PER_SEC
> > The same problem exists for CLOCK_XXX vs. CLOCK_XXX_COARSE
> >
> > clock_gettime(CLOCK_XXX, &ts);
> > clock_gettime(CLOCK_XXX_COARSE, &tc);
> > assert(tc.tv_sec >= ts.tv_sec);
> >
> > The _COARSE variants return their associated timekeeper.tv_sec,tv_nsec
> > pair without reading the clock. Same as #2 above just extended to clock
> > MONOTONIC.
>
> Which means the timestamps in the structure we get from msg* calls can
> be 1 second smaller that timestamps returned from realtime timers.
>
> However it also means that the _COARSE timers should be the same as the
> SysV timestamps and could be used for these tests instead. Also these
> timers should be available since 2.6.32 which is old enough to assume
> that they are present.
>
Sounds reasonable. From Thomas's analysis, it seems the *_COARSE
can work for us, so I'm OK to go with this way to fix.
For series:
Acked-by: Li Wang <liwang@redhat.com>
--
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20201204/2ce56e3c/attachment.htm>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH 0/2] Fix timestamp tests in SysV IPC tests
2020-12-03 15:28 [LTP] [PATCH 0/2] Fix timestamp tests in SysV IPC tests Cyril Hrubis
2020-12-03 15:28 ` [LTP] [PATCH 1/2] libnewipc: Add get_ipc_timestamp() Cyril Hrubis
2020-12-03 15:28 ` [LTP] [PATCH 2/2] syscalls/ipc: Make use of get_ipc_timestamp() Cyril Hrubis
@ 2020-12-04 9:22 ` Jan Stancek
2020-12-04 10:14 ` Cyril Hrubis
2 siblings, 1 reply; 6+ messages in thread
From: Jan Stancek @ 2020-12-04 9:22 UTC (permalink / raw)
To: ltp
----- Original Message -----
> Cyril Hrubis (2):
> libnewipc: Add get_ipc_timestamp()
> syscalls/ipc: Make use of get_ipc_timestamp()
>
> include/libnewipc.h | 3 +++
> libs/libltpnewipc/libnewipc.c | 13 +++++++++++++
> testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c | 4 ++--
> testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c | 4 ++--
> testcases/kernel/syscalls/ipc/shmctl/Makefile | 2 +-
> testcases/kernel/syscalls/ipc/shmctl/shmctl01.c | 4 ++--
> 6 files changed, 23 insertions(+), 7 deletions(-)
>
Acked-by: Jan Stancek <jstancek@redhat.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH 0/2] Fix timestamp tests in SysV IPC tests
2020-12-04 9:22 ` [LTP] [PATCH 0/2] Fix timestamp tests in SysV IPC tests Jan Stancek
@ 2020-12-04 10:14 ` Cyril Hrubis
0 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2020-12-04 10:14 UTC (permalink / raw)
To: ltp
Hi!
Pushed, thanks Li and Jan for the review.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-12-04 10:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-03 15:28 [LTP] [PATCH 0/2] Fix timestamp tests in SysV IPC tests Cyril Hrubis
2020-12-03 15:28 ` [LTP] [PATCH 1/2] libnewipc: Add get_ipc_timestamp() Cyril Hrubis
2020-12-04 3:21 ` Li Wang
2020-12-03 15:28 ` [LTP] [PATCH 2/2] syscalls/ipc: Make use of get_ipc_timestamp() Cyril Hrubis
2020-12-04 9:22 ` [LTP] [PATCH 0/2] Fix timestamp tests in SysV IPC tests Jan Stancek
2020-12-04 10:14 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox