mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-21 06:50:25 +00:00
kselftest: Extend vdso correctness test to clock_gettime64
With the release of Linux 5.1 has been added a new syscall, clock_gettime64, that provided a 64 bit time value for a specified clock_ID to make the kernel Y2038 safe on 32 bit architectures. Extend the vdso correctness test to cover the newly exposed vdso function. Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com> Acked-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
parent
c7e5789b24
commit
b2f1c3db28
2 changed files with 115 additions and 4 deletions
|
@ -66,12 +66,13 @@ static const char *versions[6] = {
|
||||||
"LINUX_4.15",
|
"LINUX_4.15",
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *names[2][5] = {
|
static const char *names[2][6] = {
|
||||||
{
|
{
|
||||||
"__kernel_gettimeofday",
|
"__kernel_gettimeofday",
|
||||||
"__kernel_clock_gettime",
|
"__kernel_clock_gettime",
|
||||||
"__kernel_time",
|
"__kernel_time",
|
||||||
"__kernel_clock_getres",
|
"__kernel_clock_getres",
|
||||||
|
"__kernel_getcpu",
|
||||||
#if defined(VDSO_32BIT)
|
#if defined(VDSO_32BIT)
|
||||||
"__kernel_clock_gettime64",
|
"__kernel_clock_gettime64",
|
||||||
#endif
|
#endif
|
||||||
|
@ -81,6 +82,7 @@ static const char *names[2][5] = {
|
||||||
"__vdso_clock_gettime",
|
"__vdso_clock_gettime",
|
||||||
"__vdso_time",
|
"__vdso_time",
|
||||||
"__vdso_clock_getres",
|
"__vdso_clock_getres",
|
||||||
|
"__vdso_getcpu",
|
||||||
#if defined(VDSO_32BIT)
|
#if defined(VDSO_32BIT)
|
||||||
"__vdso_clock_gettime64",
|
"__vdso_clock_gettime64",
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
#include "vdso_config.h"
|
||||||
|
|
||||||
|
static const char **name;
|
||||||
|
|
||||||
#ifndef SYS_getcpu
|
#ifndef SYS_getcpu
|
||||||
# ifdef __x86_64__
|
# ifdef __x86_64__
|
||||||
# define SYS_getcpu 309
|
# define SYS_getcpu 309
|
||||||
|
@ -27,6 +31,17 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __NR_clock_gettime64
|
||||||
|
#define __NR_clock_gettime64 403
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __kernel_timespec
|
||||||
|
struct __kernel_timespec {
|
||||||
|
long long tv_sec;
|
||||||
|
long long tv_nsec;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/* max length of lines in /proc/self/maps - anything longer is skipped here */
|
/* max length of lines in /proc/self/maps - anything longer is skipped here */
|
||||||
#define MAPS_LINE_LEN 128
|
#define MAPS_LINE_LEN 128
|
||||||
|
|
||||||
|
@ -36,6 +51,10 @@ typedef int (*vgettime_t)(clockid_t, struct timespec *);
|
||||||
|
|
||||||
vgettime_t vdso_clock_gettime;
|
vgettime_t vdso_clock_gettime;
|
||||||
|
|
||||||
|
typedef int (*vgettime64_t)(clockid_t, struct __kernel_timespec *);
|
||||||
|
|
||||||
|
vgettime64_t vdso_clock_gettime64;
|
||||||
|
|
||||||
typedef long (*vgtod_t)(struct timeval *tv, struct timezone *tz);
|
typedef long (*vgtod_t)(struct timeval *tv, struct timezone *tz);
|
||||||
|
|
||||||
vgtod_t vdso_gettimeofday;
|
vgtod_t vdso_gettimeofday;
|
||||||
|
@ -99,17 +118,23 @@ static void fill_function_pointers()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vdso_getcpu = (getcpu_t)dlsym(vdso, "__vdso_getcpu");
|
vdso_getcpu = (getcpu_t)dlsym(vdso, name[4]);
|
||||||
if (!vdso_getcpu)
|
if (!vdso_getcpu)
|
||||||
printf("Warning: failed to find getcpu in vDSO\n");
|
printf("Warning: failed to find getcpu in vDSO\n");
|
||||||
|
|
||||||
vgetcpu = (getcpu_t) vsyscall_getcpu();
|
vgetcpu = (getcpu_t) vsyscall_getcpu();
|
||||||
|
|
||||||
vdso_clock_gettime = (vgettime_t)dlsym(vdso, "__vdso_clock_gettime");
|
vdso_clock_gettime = (vgettime_t)dlsym(vdso, name[1]);
|
||||||
if (!vdso_clock_gettime)
|
if (!vdso_clock_gettime)
|
||||||
printf("Warning: failed to find clock_gettime in vDSO\n");
|
printf("Warning: failed to find clock_gettime in vDSO\n");
|
||||||
|
|
||||||
vdso_gettimeofday = (vgtod_t)dlsym(vdso, "__vdso_gettimeofday");
|
#if defined(VDSO_32BIT)
|
||||||
|
vdso_clock_gettime64 = (vgettime64_t)dlsym(vdso, name[5]);
|
||||||
|
if (!vdso_clock_gettime64)
|
||||||
|
printf("Warning: failed to find clock_gettime64 in vDSO\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vdso_gettimeofday = (vgtod_t)dlsym(vdso, name[0]);
|
||||||
if (!vdso_gettimeofday)
|
if (!vdso_gettimeofday)
|
||||||
printf("Warning: failed to find gettimeofday in vDSO\n");
|
printf("Warning: failed to find gettimeofday in vDSO\n");
|
||||||
|
|
||||||
|
@ -126,6 +151,11 @@ static inline int sys_clock_gettime(clockid_t id, struct timespec *ts)
|
||||||
return syscall(__NR_clock_gettime, id, ts);
|
return syscall(__NR_clock_gettime, id, ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int sys_clock_gettime64(clockid_t id, struct __kernel_timespec *ts)
|
||||||
|
{
|
||||||
|
return syscall(__NR_clock_gettime64, id, ts);
|
||||||
|
}
|
||||||
|
|
||||||
static inline int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
|
static inline int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||||
{
|
{
|
||||||
return syscall(__NR_gettimeofday, tv, tz);
|
return syscall(__NR_gettimeofday, tv, tz);
|
||||||
|
@ -191,6 +221,15 @@ static bool ts_leq(const struct timespec *a, const struct timespec *b)
|
||||||
return a->tv_nsec <= b->tv_nsec;
|
return a->tv_nsec <= b->tv_nsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ts64_leq(const struct __kernel_timespec *a,
|
||||||
|
const struct __kernel_timespec *b)
|
||||||
|
{
|
||||||
|
if (a->tv_sec != b->tv_sec)
|
||||||
|
return a->tv_sec < b->tv_sec;
|
||||||
|
else
|
||||||
|
return a->tv_nsec <= b->tv_nsec;
|
||||||
|
}
|
||||||
|
|
||||||
static bool tv_leq(const struct timeval *a, const struct timeval *b)
|
static bool tv_leq(const struct timeval *a, const struct timeval *b)
|
||||||
{
|
{
|
||||||
if (a->tv_sec != b->tv_sec)
|
if (a->tv_sec != b->tv_sec)
|
||||||
|
@ -254,7 +293,10 @@ static void test_one_clock_gettime(int clock, const char *name)
|
||||||
if (!ts_leq(&start, &vdso) || !ts_leq(&vdso, &end)) {
|
if (!ts_leq(&start, &vdso) || !ts_leq(&vdso, &end)) {
|
||||||
printf("[FAIL]\tTimes are out of sequence\n");
|
printf("[FAIL]\tTimes are out of sequence\n");
|
||||||
nerrs++;
|
nerrs++;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("[OK]\tTest Passed.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_clock_gettime(void)
|
static void test_clock_gettime(void)
|
||||||
|
@ -275,6 +317,70 @@ static void test_clock_gettime(void)
|
||||||
test_one_clock_gettime(INT_MAX, "invalid");
|
test_one_clock_gettime(INT_MAX, "invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_one_clock_gettime64(int clock, const char *name)
|
||||||
|
{
|
||||||
|
struct __kernel_timespec start, vdso, end;
|
||||||
|
int vdso_ret, end_ret;
|
||||||
|
|
||||||
|
printf("[RUN]\tTesting clock_gettime64 for clock %s (%d)...\n", name, clock);
|
||||||
|
|
||||||
|
if (sys_clock_gettime64(clock, &start) < 0) {
|
||||||
|
if (errno == EINVAL) {
|
||||||
|
vdso_ret = vdso_clock_gettime64(clock, &vdso);
|
||||||
|
if (vdso_ret == -EINVAL) {
|
||||||
|
printf("[OK]\tNo such clock.\n");
|
||||||
|
} else {
|
||||||
|
printf("[FAIL]\tNo such clock, but __vdso_clock_gettime64 returned %d\n", vdso_ret);
|
||||||
|
nerrs++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("[WARN]\t clock_gettime64(%d) syscall returned error %d\n", clock, errno);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vdso_ret = vdso_clock_gettime64(clock, &vdso);
|
||||||
|
end_ret = sys_clock_gettime64(clock, &end);
|
||||||
|
|
||||||
|
if (vdso_ret != 0 || end_ret != 0) {
|
||||||
|
printf("[FAIL]\tvDSO returned %d, syscall errno=%d\n",
|
||||||
|
vdso_ret, errno);
|
||||||
|
nerrs++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\t%llu.%09ld %llu.%09ld %llu.%09ld\n",
|
||||||
|
(unsigned long long)start.tv_sec, start.tv_nsec,
|
||||||
|
(unsigned long long)vdso.tv_sec, vdso.tv_nsec,
|
||||||
|
(unsigned long long)end.tv_sec, end.tv_nsec);
|
||||||
|
|
||||||
|
if (!ts64_leq(&start, &vdso) || !ts64_leq(&vdso, &end)) {
|
||||||
|
printf("[FAIL]\tTimes are out of sequence\n");
|
||||||
|
nerrs++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("[OK]\tTest Passed.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_clock_gettime64(void)
|
||||||
|
{
|
||||||
|
if (!vdso_clock_gettime64) {
|
||||||
|
printf("[SKIP]\tNo vDSO, so skipping clock_gettime64() tests\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int clock = 0; clock < sizeof(clocknames) / sizeof(clocknames[0]);
|
||||||
|
clock++) {
|
||||||
|
test_one_clock_gettime64(clock, clocknames[clock]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Also test some invalid clock ids */
|
||||||
|
test_one_clock_gettime64(-1, "invalid");
|
||||||
|
test_one_clock_gettime64(INT_MIN, "invalid");
|
||||||
|
test_one_clock_gettime64(INT_MAX, "invalid");
|
||||||
|
}
|
||||||
|
|
||||||
static void test_gettimeofday(void)
|
static void test_gettimeofday(void)
|
||||||
{
|
{
|
||||||
struct timeval start, vdso, end;
|
struct timeval start, vdso, end;
|
||||||
|
@ -327,9 +433,12 @@ static void test_gettimeofday(void)
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
name = (const char **)&names[VDSO_NAMES];
|
||||||
|
|
||||||
fill_function_pointers();
|
fill_function_pointers();
|
||||||
|
|
||||||
test_clock_gettime();
|
test_clock_gettime();
|
||||||
|
test_clock_gettime64();
|
||||||
test_gettimeofday();
|
test_gettimeofday();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Reference in a new issue