From 021b32acd3cec8e255dd47681939797ec64b8206 Mon Sep 17 00:00:00 2001 From: John Ogness Date: Tue, 20 Feb 2018 15:03:14 +0100 Subject: tools: rename 'rtex' tool to 'pgflt' The rtex tool only demonstrates prefaultingn to avoid runtime page faults. It makes more sense to call it pgflt. Signed-off-by: John Ogness --- schulung_tools/pgflt/func.c | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 schulung_tools/pgflt/func.c (limited to 'schulung_tools/pgflt/func.c') diff --git a/schulung_tools/pgflt/func.c b/schulung_tools/pgflt/func.c new file mode 100644 index 0000000..4b88166 --- /dev/null +++ b/schulung_tools/pgflt/func.c @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include +#include + +void timestamp(const char *msg, int val) +{ + static struct timespec tsl; + static long minfltl; + + struct timespec ts; + unsigned long diff; + struct rusage r; + long rdiff; + + clock_gettime(CLOCK_MONOTONIC, &ts); + getrusage(RUSAGE_SELF, &r); + + if (tsl.tv_sec != 0) { + diff = (ts.tv_sec - tsl.tv_sec) * 1000000000; + diff += ts.tv_nsec - tsl.tv_nsec; + + rdiff = r.ru_minflt - minfltl; + + printf("% 10d ns % 5ld faults : %s", diff, rdiff, msg); + if (val >= 0) + printf(" (%d)", val); + printf("\n"); + } + + tsl = ts; + minfltl = r.ru_minflt; +} + +/* 10 MiB */ +#define SIZE (10 * 1024 * 1024) + +void testfunc_malloc(void) +{ + char *p; + + p = malloc(SIZE); + if (!p) { + fprintf(stderr, "MALLOC FAILED: %s:%d\n", __FILE__, __LINE__); + return; + } + + memset(p, 42, SIZE); + + if (p[SIZE - 1] != 42) + fprintf(stderr, "MEMSET FAILED: %s:%d\n", __FILE__, __LINE__); + + free(p); +} + +void recursive_stack(int i) +{ + char buf[1024]; + if (i > 0) + recursive_stack(i - 1); +} + +void testfunc_deepstack(void) +{ + char buf[1024]; + recursive_stack(7 * 1024); +} -- cgit v1.2.3