summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@mit.edu>2011-07-28 22:54:10 -0400
committerAndy Lutomirski <luto@mit.edu>2011-07-28 22:54:10 -0400
commitbdc5ae11deb1f59ffc115c79624f7b14f7ad2709 (patch)
tree8b0d6f4fb061dd484e4427c228c368d19d12a601
parent20eea16dfe46b7fc1025ffcea5402c717ef1662d (diff)
downloadmisc-tests-bdc5ae11deb1f59ffc115c79624f7b14f7ad2709.tar.gz
test_vsyscall: Add CLOCK_MONOTONIC
-rw-r--r--test_vsyscall.cc38
1 files changed, 29 insertions, 9 deletions
diff --git a/test_vsyscall.cc b/test_vsyscall.cc
index cbb1fe7..afeeb90 100644
--- a/test_vsyscall.cc
+++ b/test_vsyscall.cc
@@ -27,6 +27,9 @@ typedef long (*gtod_t)(struct timeval *tv, struct timezone *tz);
const gtod_t vgtod = (gtod_t)0xffffffffff600000;
gtod_t vdso_gtod;
+typedef int (*vgettime_t)(clockid_t, timespec *);
+vgettime_t vdso_gettime;
+
typedef long (*time_func_t)(time_t *t);
const time_func_t vtime = (time_func_t)0xffffffffff600400;
time_func_t vdso_time;
@@ -47,6 +50,10 @@ void init_vdso()
if (!vdso_gtod)
printf("Warning: failed to find gettimeofday in vDSO\n");
+ vdso_gettime = (vgettime_t)dlsym(vdso, "clock_gettime");
+ if (!vdso_gtod)
+ printf("Warning: failed to find clock_gettime in vDSO\n");
+
vdso_time = (time_func_t)dlsym(vdso, "time");
if (!vdso_time)
printf("Warning: failed to find time in vDSO\n");
@@ -62,6 +69,11 @@ static inline long sys_gtod(struct timeval *tv, struct timezone *tz)
return syscall(__NR_gettimeofday, tv, tz);
}
+static inline int sys_clock_gettime(clockid_t id, struct timespec *ts)
+{
+ return syscall(__NR_clock_gettime, id, ts);
+}
+
static inline long sys_time(time_t *t)
{
return syscall(__NR_time, t);
@@ -202,24 +214,32 @@ int bench(int argc, char **argv)
{
struct timeval tv;
struct timezone tz;
- benchmark(" syscall gettimeofday", [&]{sys_gtod(&tv, &tz);});
- benchmark(" vdso gettimeofday", [&]{vdso_gtod(&tv, &tz);});
- benchmark("vsyscall gettimeofday", [&]{vgtod(&tv, &tz);});
+ struct timespec ts;
+
+ benchmark(" syscall gettimeofday ", [&]{sys_gtod(&tv, &tz);});
+ benchmark(" vdso gettimeofday ", [&]{vdso_gtod(&tv, &tz);});
+ benchmark("vsyscall gettimeofday ", [&]{vgtod(&tv, &tz);});
+
+ printf("\n");
+ benchmark(" syscall CLOCK_MONOTONIC ", [&]{
+ sys_clock_gettime(CLOCK_MONOTONIC, &ts);
+ });
+ benchmark(" vdso CLOCK_MONOTONIC ", [&]{vdso_gettime(CLOCK_MONOTONIC, &ts);});
printf("\n");
time_t t;
- benchmark(" syscall time ", [&]{sys_time(&t);});
+ benchmark(" syscall time ", [&]{sys_time(&t);});
if (vdso_time)
- benchmark(" vdso time ", [&]{vdso_time(&t);});
- benchmark("vsyscall time ", [&]{vtime(&t);});
+ benchmark(" vdso time ", [&]{vdso_time(&t);});
+ benchmark("vsyscall time ", [&]{vtime(&t);});
printf("\n");
unsigned cpu, node;
- benchmark(" vdso getcpu ", [&]{vdso_getcpu(&cpu, &node, 0);});
- benchmark("vsyscall getcpu ", [&]{vgetcpu(&cpu, &node, 0);});
+ benchmark(" vdso getcpu ", [&]{vdso_getcpu(&cpu, &node, 0);});
+ benchmark("vsyscall getcpu ", [&]{vgetcpu(&cpu, &node, 0);});
printf("\n");
- benchmark("dummy syscall ", [&]{syscall(0xffffffff);});
+ benchmark("dummy syscall ", [&]{syscall(0xffffffff);});
return 0;
}