sel4bench: add flog.h, a header for fast logging logging.h assumes it is post-processing the logs flog.h is for logging that takes place during the benchmark.
diff --git a/libsel4bench/Kconfig b/libsel4bench/Kconfig index 3a6bd53..46833ba 100644 --- a/libsel4bench/Kconfig +++ b/libsel4bench/Kconfig
@@ -8,7 +8,7 @@ # @TAG(NICTA_BSD) # -config LIB_SEL4_BENCH +menuconfig LIB_SEL4_BENCH bool "libsel4bench" default y depends on HAVE_LIB_SEL4 && HAVE_LIBC && HAVE_LIB_UTILS @@ -16,5 +16,12 @@ help Benchmarking library and functionality for various platforms +config FLOG + bool "Enable fast logging library?" + default n + depends on LIB_SEL4_BENCH + help + Provide flog.h functions. If this is false, flog.h functions will be #ifdef'd out. + config HAVE_LIB_SEL4_BENCH bool
diff --git a/libsel4bench/include/sel4bench/flog.h b/libsel4bench/include/sel4bench/flog.h new file mode 100644 index 0000000..bb51961 --- /dev/null +++ b/libsel4bench/include/sel4bench/flog.h
@@ -0,0 +1,62 @@ +/* + * Copyright 2016, NICTA + * + * This software may be distributed and modified according to the terms of + * the BSD 2-Clause license. Note that NO WARRANTY is provided. + * See "LICENSE_BSD2.txt" for details. + * + * @TAG(NICTA_BSD) + */ + +#pragma once + +#include <autoconf.h> +#include <sel4bench/sel4bench.h> +#include <stdlib.h> +#include <utils/util.h> + +typedef struct { + ccnt_t *results; + size_t length; + size_t next; + ccnt_t start; +} flog_t; + +#ifdef CONFIG_FLOG +static inline flog_t * +flog_init(ccnt_t *results, int length) +{ + flog_t *flog = calloc(1, sizeof(flog)); + if (unlikely(flog == NULL)) { + ZF_LOGE("Failed to allocate flog"); + return NULL; + } + + flog->results = results; + flog->length = length; + + return flog; +} + +static inline void +flog_end(flog_t *flog) { + ccnt_t end; + SEL4BENCH_READ_CCNT(end); + if (likely(flog->start != 0 && flog->next < flog->length)) { + flog->results[flog->next] = end - flog->start; + flog->next++; + } +} + +static inline void +flog_start(flog_t *flog) { + SEL4BENCH_READ_CCNT(flog->start); +} + +#else + +#define flog_init(r, l) +#define flog_end(f) +#define flog_start(f) + +#endif /* CONFIG_FLOG */