source: mainline/uspace/app/hbench/hbench.h@ 2d81880

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2d81880 was 2d81880, checked in by Vojtech Horky <vojtech.horky@…>, 7 years ago

hbench: explain why we inline

  • Property mode set to 100644
File size: 4.5 KB
Line 
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/** Single run information.
45 *
46 * Used to store both performance information (now, only wall-clock
47 * time) as well as information about error.
48 *
49 * Use proper access functions when modifying data inside this structure.
50 *
51 * Eventually, we could collection of hardware counters etc. without
52 * modifying signatures of any existing benchmark.
53 */
54typedef struct {
55 stopwatch_t stopwatch;
56 char *error_message;
57 size_t error_message_buffer_size;
58} bench_run_t;
59
60/** Benchmark environment configuration.
61 *
62 * Use proper access functions when modifying data inside this structure.
63 */
64typedef struct {
65 hash_table_t parameters;
66} bench_env_t;
67
68/** Actual benchmark runner.
69 *
70 * The first argument describes the environment, second is used to store
71 * information about the run (performance data or error message) and
72 * third describes workload size (number of iterations).
73 */
74typedef bool (*benchmark_entry_t)(bench_env_t *, bench_run_t *, uint64_t);
75
76/** Setup and teardown callback type.
77 *
78 * Unlike in benchmark_entry_t, we do not need to pass in number of
79 * iterations to execute (note that we use bench_run_t only to simplify
80 * creation of error messages).
81 */
82typedef bool (*benchmark_helper_t)(bench_env_t *, bench_run_t *);
83
84typedef struct {
85 const char *name;
86 const char *desc;
87 benchmark_entry_t entry;
88 benchmark_helper_t setup;
89 benchmark_helper_t teardown;
90} benchmark_t;
91
92extern void bench_run_init(bench_run_t *, char *, size_t);
93extern bool bench_run_fail(bench_run_t *, const char *, ...);
94
95/*
96 * We keep the following two functions inline to ensure that we start
97 * measurement as close to the surrounding code as possible. Note that
98 * this inlining is done at least on the level of individual wrappers
99 * (this one and the one provided by stopwatch_t) to pass the control
100 * as fast as possible to the actual timer used.
101 */
102
103static inline void bench_run_start(bench_run_t *run)
104{
105 stopwatch_start(&run->stopwatch);
106}
107
108static inline void bench_run_stop(bench_run_t *run)
109{
110 stopwatch_stop(&run->stopwatch);
111}
112
113extern errno_t csv_report_open(const char *);
114extern void csv_report_add_entry(bench_run_t *, int, benchmark_t *, uint64_t);
115extern void csv_report_close(void);
116
117extern errno_t bench_env_init(bench_env_t *);
118extern errno_t bench_env_param_set(bench_env_t *, const char *, const char *);
119extern const char *bench_env_param_get(bench_env_t *, const char *, const char *);
120extern void bench_env_cleanup(bench_env_t *);
121
122extern benchmark_t *benchmarks[];
123extern size_t benchmark_count;
124
125/* Put your benchmark descriptors here (and also to benchlist.c). */
126extern benchmark_t benchmark_dir_read;
127extern benchmark_t benchmark_fibril_mutex;
128extern benchmark_t benchmark_file_read;
129extern benchmark_t benchmark_malloc1;
130extern benchmark_t benchmark_malloc2;
131extern benchmark_t benchmark_ns_ping;
132extern benchmark_t benchmark_ping_pong;
133
134#endif
135
136/** @}
137 */
Note: See TracBrowser for help on using the repository browser.