Skip to contentSkip to conversation

syscalls/timer_gettime: Add support for time64 tests

PATCH Superseded Viresh Kumar 3 participants 12 messages Apr 27, 2020 – Apr 28, 2020

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 syscalls/timer_gettime: Add support for time64 tests

This adds support for time64 tests to the existing timer_gettime() syscall tests.

---
 include/tst_timer.h                           |  40 +++++++
 .../syscalls/timer_gettime/timer_gettime01.c  | 112 +++++++++---------
 2 files changed, 98 insertions(+), 54 deletions(-)
include/tst_timer.h +40 -0
index 256e1d71e1bc..601f934da670 100644
@@ -15,6 +15,7 @@
 #include <sys/time.h>
 #include <time.h>
 #include "tst_test.h"
+#include "lapi/common_timers.h"
 #include "lapi/syscalls.h"
 
 /*
@@ -112,6 +113,11 @@ struct __kernel_timespec {
 	__kernel_time64_t       tv_sec;                 /* seconds */
 	long long               tv_nsec;                /* nanoseconds */
 };
+
+struct __kernel_itimerspec {
+	struct __kernel_timespec it_interval;    /* timer period */
+	struct __kernel_timespec it_value;       /* timer expiration */
+};
 #endif
 
 enum tst_ts_type {
@@ -129,6 +135,14 @@ struct tst_ts {
 	} ts;
 };
 
+struct tst_its {
+	enum tst_ts_type type;
+	union {
+		struct itimerspec libc_its;
+		struct __kernel_itimerspec kern_its;
+	} ts;
+};
+
 static inline void *tst_ts_get(struct tst_ts *t)
 {
 	if (!t)
@@ -147,6 +161,22 @@ static inline void *tst_ts_get(struct tst_ts *t)
 	}
 }
 
+static inline void *tst_its_get(struct tst_its *t)
+{
+	if (!t)
+		return NULL;
+
+	switch (t->type) {
+	case TST_LIBC_TIMESPEC:
+		return &t->ts.libc_its;
+	case TST_KERN_TIMESPEC:
+		return &t->ts.kern_its;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t->type);
+		return NULL;
+	}
+}
+
 static inline int libc_clock_getres(clockid_t clk_id, void *ts)
 {
 	return clock_getres(clk_id, ts);
@@ -212,6 +242,16 @@ static inline int sys_clock_nanosleep64(clockid_t clk_id, int flags,
 			   request, remain);
 }
 
+static inline int sys_timer_gettime(kernel_timer_t timerid, void *its)
+{
+	return tst_syscall(__NR_timer_gettime, timerid, its);
+}
+
+static inline int sys_timer_gettime64(kernel_timer_t timerid, void *its)
+{
+	return tst_syscall(__NR_timer_gettime64, timerid, its);
+}
+
 /*
  * Returns tst_ts seconds.
  */
testcases/kernel/syscalls/timer_gettime/timer_gettime01.c +58 -54

129 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#1 lore raw

PATCH 2/4 syscalls/timer_settime: Add support for time64 tests

This adds support for time64 tests to the existing timer_settime() syscall tests.

---
 include/tst_timer.h                           | 34 ++++++++++
 .../syscalls/timer_settime/timer_settime01.c  | 51 +++++++++++----
 .../syscalls/timer_settime/timer_settime02.c  | 65 ++++++++++++++-----
 3 files changed, 122 insertions(+), 28 deletions(-)
include/tst_timer.h +34 -0
index 601f934da670..94d03cecdabe 100644
@@ -252,6 +252,40 @@ static inline int sys_timer_gettime64(kernel_timer_t timerid, void *its)
 	return tst_syscall(__NR_timer_gettime64, timerid, its);
 }
 
+static inline int sys_timer_settime(kernel_timer_t timerid, int flags,
+				    void *its, void *old_its)
+{
+	return tst_syscall(__NR_timer_settime, timerid, flags, its, old_its);
+}
+
+static inline int sys_timer_settime64(kernel_timer_t timerid, int flags,
+				      void *its, void *old_its)
+{
+	return tst_syscall(__NR_timer_settime64, timerid, flags, its, old_its);
+}
+
+static inline void tst_its_set_time(struct tst_its *its, long long value_sec,
+				long long value_nsec, long long interval_sec,
+				long long interval_nsec)
+{
+	switch (its->type) {
+	case TST_LIBC_TIMESPEC:
+		its->ts.libc_its.it_value.tv_sec = value_sec;
+		its->ts.libc_its.it_value.tv_nsec = value_nsec;
+		its->ts.libc_its.it_interval.tv_sec = interval_sec;
+		its->ts.libc_its.it_interval.tv_nsec = interval_nsec;
+	break;
+	case TST_KERN_TIMESPEC:
+		its->ts.kern_its.it_value.tv_sec = value_sec;
+		its->ts.kern_its.it_value.tv_nsec = value_nsec;
+		its->ts.kern_its.it_interval.tv_sec = interval_sec;
+		its->ts.kern_its.it_interval.tv_nsec = interval_nsec;
+	break;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", its->type);
+	}
+}
+
 /*
  * Returns tst_ts seconds.
  */
testcases/kernel/syscalls/timer_settime/timer_settime01.c +39 -12

97 lines not on this page · raw message

testcases/kernel/syscalls/timer_settime/timer_settime02.c +49 -16

99 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#2 lore raw

PATCH 3/4 syscalls/timerfd: Add support for time64 tests

In reply to Viresh Kumar

This adds support for time64 tests to the existing timerfd_gettime() and timerfd_settime() syscall tests.

---
 include/tst_timer.h                           |  48 +++++++
 testcases/kernel/syscalls/timerfd/timerfd01.c |  58 ++++++--
 testcases/kernel/syscalls/timerfd/timerfd04.c |  56 ++++++--
 .../syscalls/timerfd/timerfd_gettime01.c      | 124 ++++++++---------
 .../syscalls/timerfd/timerfd_settime01.c      | 125 +++++++++---------
 .../syscalls/timerfd/timerfd_settime02.c      |  33 ++++-
 6 files changed, 301 insertions(+), 143 deletions(-)
include/tst_timer.h +48 -0
index 94d03cecdabe..a728d78d7def 100644
@@ -264,6 +264,54 @@ static inline int sys_timer_settime64(kernel_timer_t timerid, int flags,
 	return tst_syscall(__NR_timer_settime64, timerid, flags, its, old_its);
 }
 
+static inline int sys_timerfd_gettime(int fd, void *its)
+{
+	return tst_syscall(__NR_timerfd_gettime, fd, its);
+}
+
+static inline int sys_timerfd_gettime64(int fd, void *its)
+{
+	return tst_syscall(__NR_timerfd_gettime64, fd, its);
+}
+
+static inline int sys_timerfd_settime(int fd, int flags, void *its,
+				      void *old_its)
+{
+	return tst_syscall(__NR_timerfd_settime, fd, flags, its, old_its);
+}
+
+static inline int sys_timerfd_settime64(int fd, int flags, void *its,
+				      void *old_its)
+{
+	return tst_syscall(__NR_timerfd_settime64, fd, flags, its, old_its);
+}
+
+static inline long long tst_its_get_val_sec(struct tst_its its)
+{
+	switch (its.type) {
+	case TST_LIBC_TIMESPEC:
+		return its.ts.libc_its.it_value.tv_sec;
+	case TST_KERN_TIMESPEC:
+		return its.ts.kern_its.it_value.tv_sec;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", its.type);
+		return -1;
+	}
+}
+
+static inline long long tst_its_get_val_nsec(struct tst_its its)
+{
+	switch (its.type) {
+	case TST_LIBC_TIMESPEC:
+		return its.ts.libc_its.it_value.tv_nsec;
+	case TST_KERN_TIMESPEC:
+		return its.ts.kern_its.it_value.tv_nsec;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", its.type);
+		return -1;
+	}
+}
+
 static inline void tst_its_set_time(struct tst_its *its, long long value_sec,
 				long long value_nsec, long long interval_sec,
 				long long interval_nsec)
testcases/kernel/syscalls/timerfd/timerfd01.c +46 -12

108 lines not on this page · raw message

testcases/kernel/syscalls/timerfd/timerfd04.c +48 -8

97 lines not on this page · raw message

testcases/kernel/syscalls/timerfd/timerfd_gettime01.c +63 -61

162 lines not on this page · raw message

testcases/kernel/syscalls/timerfd/timerfd_settime01.c +66 -59

165 lines not on this page · raw message

testcases/kernel/syscalls/timerfd/timerfd_settime02.c +30 -3
index 0565802f4288..b6444a6db7ba 100644
@@ -15,8 +15,9 @@
  *  timerfd: Protect the might cancel mechanism proper
  */
 #include <unistd.h>
+#include "tst_timer.h"
+#include "lapi/abisize.h"
 #include "tst_safe_timerfd.h"
-#include "tst_test.h"
 #include "tst_fuzzy_sync.h"
 #include "tst_taint.h"
 
@@ -27,11 +28,34 @@
 #endif
 
 static int fd = -1;
-static struct itimerspec its;
+static struct tst_its its;
 static struct tst_fzsync_pair fzsync_pair;
 
+static struct test_variants {
+	int (*tfd_settime)(int fd, int flags, void *new_value, void *old_value);
+	enum tst_ts_type type;
+	char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+	{ .tfd_settime = sys_timerfd_settime, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+#endif
+
+#if defined(TST_ABI64)
+	{ .tfd_settime = sys_timerfd_settime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_timerfd_settime64 != __LTP__NR_INVALID_SYSCALL)
+	{ .tfd_settime = sys_timerfd_settime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"},
+#endif
+};
+
 static void setup(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+	its.type = tv->type;
+
 	tst_taint_init(TST_TAINT_W | TST_TAINT_D);
 	fd = SAFE_TIMERFD_CREATE(CLOCK_REALTIME, 0);
 
@@ -48,7 +72,9 @@ static void cleanup(void)
 
 static int punch_clock(int flags)
 {
-	return timerfd_settime(fd, flags, &its, NULL);
+	return variants[tst_variant].tfd_settime(fd, flags, tst_its_get(&its),
+						 NULL);
+
 }
 
 static void *thread_run(void *arg)
@@ -91,6 +117,7 @@ static void run(void)
 
 static struct tst_test test = {
 	.test_all = run,
+	.test_variants = ARRAY_SIZE(variants),
 	.setup = setup,
 	.cleanup = cleanup,
 	.min_kver = "2.6.25",
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#3 lore raw

PATCH 4/4 syscalls/sched_rr_get_interval: Add support for time64 tests

In reply to Viresh Kumar

This adds support for time64 tests to the existing sched_rr_get_interval() syscall tests.

---
 include/tst_timer.h                           |  16 +++
 .../sched_rr_get_interval01.c                 | 113 +++++++--------
 .../sched_rr_get_interval02.c                 | 119 ++++++++--------
 .../sched_rr_get_interval03.c                 | 133 +++++++++---------
 4 files changed, 192 insertions(+), 189 deletions(-)
include/tst_timer.h +16 -0
index a728d78d7def..a726298b407d 100644
@@ -12,6 +12,7 @@
 #ifndef TST_TIMER
 #define TST_TIMER
 
+#include <sched.h>
 #include <sys/time.h>
 #include <time.h>
 #include "tst_test.h"
@@ -242,6 +243,21 @@ static inline int sys_clock_nanosleep64(clockid_t clk_id, int flags,
 			   request, remain);
 }
 
+static inline int libc_sched_rr_get_interval(pid_t pid, void *ts)
+{
+	return sched_rr_get_interval(pid, ts);
+}
+
+static inline int sys_sched_rr_get_interval(pid_t pid, void *ts)
+{
+	return tst_syscall(__NR_sched_rr_get_interval, pid, ts);
+}
+
+static inline int sys_sched_rr_get_interval64(pid_t pid, void *ts)
+{
+	return tst_syscall(__NR_sched_rr_get_interval_time64, pid, ts);
+}
+
 static inline int sys_timer_gettime(kernel_timer_t timerid, void *its)
 {
 	return tst_syscall(__NR_timer_gettime, timerid, its);
testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval01.c +53 -60

132 lines not on this page · raw message

testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval02.c +56 -63

138 lines not on this page · raw message

testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c +67 -66

169 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#4 lore raw

PATCH 1/4 syscalls/timer_gettime: Add support for time64 tests

In reply to Viresh Kumar

Hi Viresh,

Quoted 14 lines

This adds support for time64 tests to the existing timer_gettime() syscall tests.

---
 include/tst_timer.h                           |  40 +++++++
 .../syscalls/timer_gettime/timer_gettime01.c  | 112 +++++++++---------
 2 files changed, 98 insertions(+), 54 deletions(-)
include/tst_timer.h +0 -0
index 256e1d71e1bc..601f934da670 100644

include/tst_timer.h line 18

Quoted 4 lines
include/tst_timer.h +1 -0
@@ -15,6 +15,7 @@
 #include <sys/time.h>
 #include <time.h>
 #include "tst_test.h"
+#include "lapi/common_timers.h"

Thanks for your patch. Unfortunately, the build got broken by this commit, I suspect this must be changed
https://travis-ci.org/github/pevik/ltp/builds/680061434

Kind regards,
Petr

#5 lore raw

PATCH 1/1 common_timers: staticize all definitions

Staticize all variable and function definitions to avoid build failures in the future if this gets included by multiple files.

---
 include/lapi/common_timers.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/lapi/common_timers.h +4 -4
index df4196eeb579..d2d0d0dab5fd 100644
@@ -15,7 +15,7 @@
 #define NSEC_PER_SEC (1000000000L)
 #endif
 
-clock_t clock_list[] = {
+static clock_t clock_list[] = {
 	CLOCK_REALTIME,
 	CLOCK_MONOTONIC,
 	CLOCK_PROCESS_CPUTIME_ID,
@@ -34,7 +34,7 @@ clock_t clock_list[] = {
 	case def_name:		\
 		return #def_name;
 
-const char *get_clock_str(const int clock_id)
+static inline const char *get_clock_str(const int clock_id)
 {
 	switch (clock_id) {
 	CLOCK_TO_STR(CLOCK_REALTIME);
@@ -50,7 +50,7 @@ const char *get_clock_str(const int clock_id)
 	}
 }
 
-int possibly_unsupported(clock_t clock)
+static inline int possibly_unsupported(clock_t clock)
 {
 	switch (clock) {
 	case CLOCK_BOOTTIME:
@@ -63,7 +63,7 @@ int possibly_unsupported(clock_t clock)
 	}
 }
 
-int have_cputime_timers(void)
+static inline int have_cputime_timers(void)
 {
 	return tst_kvercmp(2, 6, 12) >= 0;
 }
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#6 lore raw

PATCH 1/1 common_timers: staticize all definitions

Quoted 22 lines · Viresh Kumar

Staticize all variable and function definitions to avoid build failures in the future if this gets included by multiple files.

---
 include/lapi/common_timers.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/lapi/common_timers.h +1 -1
index df4196eeb579..d2d0d0dab5fd 100644
@@ -15,7 +15,7 @@
 #define NSEC_PER_SEC (1000000000L)
 #endif
 
-clock_t clock_list[] = {
+static clock_t clock_list[] = {
 	CLOCK_REALTIME,
 	CLOCK_MONOTONIC,
 	CLOCK_PROCESS_CPUTIME_ID,

include/lapi/common_timers.h clock_t clock_list[] = { · line 35

Quoted 2 lines
include/lapi/common_timers.h +0 -0
@@ -34,7 +34,7 @@ clock_t clock_list[] = {
 	case def_name:		\
 		return #def_name;

Unfortunately this still generates warning:

warning: ?clock_list? defined but not used

I missed seeing this earlier in the full build and saw it now while building a single test case.

I think we need to move this to some .c file and remove the "static" part. But I am not sure which one to. If we do that, then rest of the series will not be affected by it.

Or we can simply drop the "static" part and multiple copies of this will be present in different .c files. Which I don't really like to be honest.

Signature · 1 line
viresh
#7 lore raw

PATCH 1/1 common_timers: staticize all definitions

Quoted 29 lines · Viresh Kumar
Quoted 22 lines · Viresh Kumar

Staticize all variable and function definitions to avoid build failures in the future if this gets included by multiple files.

---
 include/lapi/common_timers.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/lapi/common_timers.h +1 -1
index df4196eeb579..d2d0d0dab5fd 100644
@@ -15,7 +15,7 @@
 #define NSEC_PER_SEC (1000000000L)
 #endif
 
-clock_t clock_list[] = {
+static clock_t clock_list[] = {
      CLOCK_REALTIME,
      CLOCK_MONOTONIC,
      CLOCK_PROCESS_CPUTIME_ID,

include/lapi/common_timers.h clock_t clock_list[] = { · line 35

Quoted 2 lines
include/lapi/common_timers.h +0 -0
@@ -34,7 +34,7 @@ clock_t clock_list[] = {
      case def_name:          \
              return #def_name;

Unfortunately this still generates warning:

Quoted 8 lines

warning: ?clock_list? defined but not used

I missed seeing this earlier in the full build and saw it now while building a single test case.

I think we need to move this to some .c file and remove the "static" part. But I am not sure which one to. If we do that, then rest of the series will not be affected by it.

That is probably the cleanest way, yes

Quoted 3 lines

Or we can simply drop the "static" part and multiple copies of this will be present in different .c files. Which I don't really like to be honest.

There is usually no warning about variables in header files that are marked 'static const' rather than just 'static', as that is a common way to do things in C++.

Quoted 3 lines

Or we can simply drop the "static" part and multiple copies of this will be present in different .c files. Which I don't really like to be honest.

With gcc-10 and clang-10 this will cause a link-time failure, because they now both default to "-fno-common" behavior.

Arnd

#8 lore raw

PATCH 1/1 common_timers: staticize all definitions

Hi,

...

Quoted 11 lines
Quoted 10 lines

include/lapi/common_timers.h clock_t clock_list[] = { · line 35

Quoted 8 lines
include/lapi/common_timers.h +1 -1
-clock_t clock_list[] = {
+static clock_t clock_list[] = {
      CLOCK_REALTIME,
      CLOCK_MONOTONIC,
      CLOCK_PROCESS_CPUTIME_ID,
@@ -34,7 +34,7 @@ clock_t clock_list[] = {
      case def_name:          \
              return #def_name;

Unfortunately this still generates warning:

Quoted 4 lines
Quoted 4 lines

warning: ?clock_list? defined but not used

I missed seeing this earlier in the full build and saw it now while building a single test case.

I overlooked that too, sorry.

Quoted 5 lines
Quoted 3 lines

I think we need to move this to some .c file and remove the "static" part. But I am not sure which one to. If we do that, then rest of the series will not be affected by it.

That is probably the cleanest way, yes

Yes, but it's a bit complicated, lapi headers were expected to be not part of the library. As you write, -fno-common make use variables in header files a bit complicated.

Quoted 7 lines
Quoted 3 lines

Or we can simply drop the "static" part and multiple copies of this will be present in different .c files. Which I don't really like to be honest.

There is usually no warning about variables in header files that are marked 'static const' rather than just 'static', as that is a common way to do things in C++.

Correct, static const clock_t clock_list[] would work. I'd be for this solution.

Quoted 6 lines
Quoted 3 lines

Or we can simply drop the "static" part and multiple copies of this will be present in different .c files. Which I don't really like to be honest.

With gcc-10 and clang-10 this will cause a link-time failure, because they now both default to "-fno-common" behavior.

True, we build in travis with -fno-common (fixed recently).

Quoted 1 line

Arnd

Kind regards,
Petr

#9 lore raw

PATCH 1/1 common_timers: staticize all definitions

Quoted 5 lines · Petr Vorel
Quoted 3 lines

There is usually no warning about variables in header files that are marked 'static const' rather than just 'static', as that is a common way to do things in C++.

Correct, static const clock_t clock_list[] would work. I'd be for this solution.

static const it is then :)

Signature · 1 line
viresh
#10 lore raw

PATCH 1/1 common_timers: staticize all definitions

In reply to Viresh Kumar

Hi Viresh,

Quoted 4 lines

Staticize all variable and function definitions to avoid build failures in the future if this gets included by multiple files.

Thanks for a quick fix.

BTW for library files we prefer to have in header include/tst_foo.h just function signatures and the implementations have in lib/tst_foo.c. Because also having implementations in include files sometimes bring problems. But for lapi files (which are included only for some tests) it's perfectly ok.

Kind regards,
Petr

#11 lore raw

PATCH 1/4 syscalls/timer_gettime: Add support for time64 tests

In reply to Petr Vorel
Quoted 11 lines · Petr Vorel

Hi Viresh,

Quoted 8 lines

This adds support for time64 tests to the existing timer_gettime() syscall tests.

---
 include/tst_timer.h                           |  40 +++++++
 .../syscalls/timer_gettime/timer_gettime01.c  | 112 +++++++++---------
 2 files changed, 98 insertions(+), 54 deletions(-)
Quoted 13 lines

include/tst_timer.h line 18

Quoted 9 lines
include/tst_timer.h +1 -0
index 256e1d71e1bc..601f934da670 100644
@@ -15,6 +15,7 @@
 #include <sys/time.h>
 #include <time.h>
 #include "tst_test.h"
+#include "lapi/common_timers.h"

Thanks for your patch. Unfortunately, the build got broken by this commit, I suspect this must be changed
https://travis-ci.org/github/pevik/ltp/builds/680061434

I have sent a patch to fix this and that patch should be applied before this series.

I didn't get this build error until the time I did a make clean, followed by a fresh build. And so never caught this :(

Signature · 1 line
viresh