[COMMIT osv master] tests: add misc-vdso-perf.c to measure performance of VDSO

5 views
Skip to first unread message

Commit Bot

unread,
Oct 15, 2023, 1:04:15 PM10/15/23
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

tests: add misc-vdso-perf.c to measure performance of VDSO

This patch adds a simple test program intended to measure performance of VDSO
based functions like clock_gettime(), gettimeofday() and time().
It will be useful to evaluate overhead of future changes to support
running statically linked executables on OSv.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/modules/tests/Makefile b/modules/tests/Makefile
--- a/modules/tests/Makefile
+++ b/modules/tests/Makefile
@@ -139,7 +139,8 @@ tests := tst-pthread.so misc-ramdisk.so tst-vblk.so tst-bsd-evh.so \
libtls.so libtls_gold.so tst-tls.so tst-tls-gold.so tst-tls-pie.so \
tst-sigaction.so tst-syscall.so tst-ifaddrs.so tst-getdents.so \
tst-netlink.so misc-zfs-io.so misc-zfs-arc.so tst-pthread-create.so \
- misc-futex-perf.so misc-syscall-perf.so tst-brk.so tst-reloc.so
+ misc-futex-perf.so misc-syscall-perf.so tst-brk.so tst-reloc.so \
+ misc-vdso-perf.so
# libstatic-thread-variable.so tst-static-thread-variable.so \
# tst-f128.so \

diff --git a/tests/misc-vdso-perf.c b/tests/misc-vdso-perf.c
--- a/tests/misc-vdso-perf.c
+++ b/tests/misc-vdso-perf.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2023 Waldemar Kozaczuk
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level directory.
+ */
+
+/* Simple test program intended to measure performance of VDSO
+ based functions like clock_gettime(), gettimeofday() and time().
+ It will be useful to evaluate overhead of future changes to support
+ running statically linked executables on OSv.
+
+ - build as static executable:
+ gcc -o misc-vdso-perf-static tests/misc-vdso-perf.c -static
+
+ - build as static PIE:
+ gcc -o misc-vdso-perf-static-pie tests/misc-vdso-perf.c -pie -static-pie
+*/
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <syscall.h>
+#include <assert.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <time.h>
+
+uint64_t nstime()
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ uint64_t mul = 1000000000, mul2 = 1000;
+ return tv.tv_sec * mul + tv.tv_usec * mul2;
+}
+
+int main(int argc, char **argv)
+{
+ long count = 50000000;
+ long loop = count;
+ uint64_t start = nstime();
+
+ struct timespec ts1;
+ while (loop--) {
+ assert(0 == clock_gettime(CLOCK_MONOTONIC, &ts1));
+ }
+
+ uint64_t end = nstime();
+
+ long average_syscall_duration = (end - start) / count;
+ printf("%lu ns (elapsed %.2f sec) %s\n", average_syscall_duration, (end - start) / 1000000000.0, ": average clock_gettime duration");
+}
+
Reply all
Reply to author
Forward
0 new messages