| 1 | /*
|
|---|
| 2 | * Copyright (c) 2018 Jiri Svoboda
|
|---|
| 3 | * Copyright (c) 2019 Vojtech Horky
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | *
|
|---|
| 10 | * - Redistributions of source code must retain the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | * documentation and/or other materials provided with the distribution.
|
|---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | * derived from this software without specific prior written permission.
|
|---|
| 17 | *
|
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | /** @addtogroup hbench
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /** @file
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #ifndef HBENCH_H_
|
|---|
| 37 | #define HBENCH_H_
|
|---|
| 38 |
|
|---|
| 39 | #include <adt/hash_table.h>
|
|---|
| 40 | #include <errno.h>
|
|---|
| 41 | #include <stdbool.h>
|
|---|
| 42 | #include <perf.h>
|
|---|
| 43 |
|
|---|
| 44 | #define DEFAULT_RUN_COUNT 10
|
|---|
| 45 | #define DEFAULT_MIN_RUN_DURATION_SEC 10
|
|---|
| 46 |
|
|---|
| 47 | /** Single run information.
|
|---|
| 48 | *
|
|---|
| 49 | * Used to store both performance information (now, only wall-clock
|
|---|
| 50 | * time) as well as information about error.
|
|---|
| 51 | *
|
|---|
| 52 | * Use proper access functions when modifying data inside this structure.
|
|---|
| 53 | *
|
|---|
| 54 | * Eventually, we could collection of hardware counters etc. without
|
|---|
| 55 | * modifying signatures of any existing benchmark.
|
|---|
| 56 | */
|
|---|
| 57 | typedef struct {
|
|---|
| 58 | stopwatch_t stopwatch;
|
|---|
| 59 | char *error_message;
|
|---|
| 60 | size_t error_message_buffer_size;
|
|---|
| 61 | } bench_run_t;
|
|---|
| 62 |
|
|---|
| 63 | /** Benchmark environment configuration.
|
|---|
| 64 | *
|
|---|
| 65 | * Benchmarking code (runners) should use access functions to read
|
|---|
| 66 | * data from this structure (now only bench_env_param_get).
|
|---|
| 67 | *
|
|---|
| 68 | * Harness can access it directly.
|
|---|
| 69 | */
|
|---|
| 70 | typedef struct {
|
|---|
| 71 | hash_table_t parameters;
|
|---|
| 72 | size_t run_count;
|
|---|
| 73 | nsec_t minimal_run_duration_nanos;
|
|---|
| 74 | } bench_env_t;
|
|---|
| 75 |
|
|---|
| 76 | /** Actual benchmark runner.
|
|---|
| 77 | *
|
|---|
| 78 | * The first argument describes the environment, second is used to store
|
|---|
| 79 | * information about the run (performance data or error message) and
|
|---|
| 80 | * third describes workload size (number of iterations).
|
|---|
| 81 | */
|
|---|
| 82 | typedef bool (*benchmark_entry_t)(bench_env_t *, bench_run_t *, uint64_t);
|
|---|
| 83 |
|
|---|
| 84 | /** Setup and teardown callback type.
|
|---|
| 85 | *
|
|---|
| 86 | * Unlike in benchmark_entry_t, we do not need to pass in number of
|
|---|
| 87 | * iterations to execute (note that we use bench_run_t only to simplify
|
|---|
| 88 | * creation of error messages).
|
|---|
| 89 | */
|
|---|
| 90 | typedef bool (*benchmark_helper_t)(bench_env_t *, bench_run_t *);
|
|---|
| 91 |
|
|---|
| 92 | typedef struct {
|
|---|
| 93 | const char *name;
|
|---|
| 94 | const char *desc;
|
|---|
| 95 | benchmark_entry_t entry;
|
|---|
| 96 | benchmark_helper_t setup;
|
|---|
| 97 | benchmark_helper_t teardown;
|
|---|
| 98 | } benchmark_t;
|
|---|
| 99 |
|
|---|
| 100 | extern void bench_run_init(bench_run_t *, char *, size_t);
|
|---|
| 101 | extern bool bench_run_fail(bench_run_t *, const char *, ...);
|
|---|
| 102 |
|
|---|
| 103 | /*
|
|---|
| 104 | * We keep the following two functions inline to ensure that we start
|
|---|
| 105 | * measurement as close to the surrounding code as possible. Note that
|
|---|
| 106 | * this inlining is done at least on the level of individual wrappers
|
|---|
| 107 | * (this one and the one provided by stopwatch_t) to pass the control
|
|---|
| 108 | * as fast as possible to the actual timer used.
|
|---|
| 109 | */
|
|---|
| 110 |
|
|---|
| 111 | static inline void bench_run_start(bench_run_t *run)
|
|---|
| 112 | {
|
|---|
| 113 | stopwatch_start(&run->stopwatch);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | static inline void bench_run_stop(bench_run_t *run)
|
|---|
| 117 | {
|
|---|
| 118 | stopwatch_stop(&run->stopwatch);
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | extern errno_t csv_report_open(const char *);
|
|---|
| 122 | extern void csv_report_add_entry(bench_run_t *, int, benchmark_t *, uint64_t);
|
|---|
| 123 | extern void csv_report_close(void);
|
|---|
| 124 |
|
|---|
| 125 | extern errno_t bench_env_init(bench_env_t *);
|
|---|
| 126 | extern errno_t bench_env_param_set(bench_env_t *, const char *, const char *);
|
|---|
| 127 | extern const char *bench_env_param_get(bench_env_t *, const char *, const char *);
|
|---|
| 128 | extern void bench_env_cleanup(bench_env_t *);
|
|---|
| 129 |
|
|---|
| 130 | extern benchmark_t *benchmarks[];
|
|---|
| 131 | extern size_t benchmark_count;
|
|---|
| 132 |
|
|---|
| 133 | /* Put your benchmark descriptors here (and also to benchlist.c). */
|
|---|
| 134 | extern benchmark_t benchmark_dir_read;
|
|---|
| 135 | extern benchmark_t benchmark_fibril_mutex;
|
|---|
| 136 | extern benchmark_t benchmark_file_read;
|
|---|
| 137 | extern benchmark_t benchmark_malloc1;
|
|---|
| 138 | extern benchmark_t benchmark_malloc2;
|
|---|
| 139 | extern benchmark_t benchmark_ns_ping;
|
|---|
| 140 | extern benchmark_t benchmark_ping_pong;
|
|---|
| 141 |
|
|---|
| 142 | #endif
|
|---|
| 143 |
|
|---|
| 144 | /** @}
|
|---|
| 145 | */
|
|---|