source: mainline/uspace/app/hbench/hbench.h

Last change on this file was bdd9e92, checked in by Jiri Svoboda <jiri@…>, 15 months ago

Add random and sequential disk read benchmark

  • Property mode set to 100644
File size: 4.9 KB
RevLine 
[d230358]1/*
[bdd9e92]2 * Copyright (c) 2024 Jiri Svoboda
[d926f42]3 * Copyright (c) 2019 Vojtech Horky
[d230358]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
[fe656783]30/** @addtogroup hbench
[d230358]31 * @{
32 */
33/** @file
34 */
35
[fe656783]36#ifndef HBENCH_H_
37#define HBENCH_H_
[d230358]38
[d17cf8c]39#include <adt/hash_table.h>
[d926f42]40#include <errno.h>
[d230358]41#include <stdbool.h>
[3bd74758]42#include <perf.h>
[d230358]43
[871cff9a]44#define DEFAULT_RUN_COUNT 10
[68655bc2]45#define DEFAULT_MIN_RUN_DURATION_MSEC 1000
[871cff9a]46
[e7f9a09]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.
[94ebebf]53 *
[ebb0835]54 * Eventually, we could collection of hardware counters etc. without
55 * modifying signatures of any existing benchmark.
56 */
57typedef struct {
58 stopwatch_t stopwatch;
[9736c00]59 char *error_message;
60 size_t error_message_buffer_size;
[e7f9a09]61} bench_run_t;
62
[d17cf8c]63/** Benchmark environment configuration.
64 *
[871cff9a]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.
[d17cf8c]69 */
70typedef struct {
71 hash_table_t parameters;
[871cff9a]72 size_t run_count;
73 nsec_t minimal_run_duration_nanos;
[d17cf8c]74} bench_env_t;
75
[be30e74]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 */
[d17cf8c]82typedef bool (*benchmark_entry_t)(bench_env_t *, bench_run_t *, uint64_t);
[be30e74]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 */
[d17cf8c]90typedef bool (*benchmark_helper_t)(bench_env_t *, bench_run_t *);
91
92typedef 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
[94d52d5]100extern void bench_run_init(bench_run_t *, char *, size_t);
101extern bool bench_run_fail(bench_run_t *, const char *, ...);
[ebb0835]102
[2d81880]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
[e7f9a09]111static inline void bench_run_start(bench_run_t *run)
[ebb0835]112{
[e7f9a09]113 stopwatch_start(&run->stopwatch);
[ebb0835]114}
115
[e7f9a09]116static inline void bench_run_stop(bench_run_t *run)
[ebb0835]117{
[e7f9a09]118 stopwatch_stop(&run->stopwatch);
[ebb0835]119}
120
[d926f42]121extern errno_t csv_report_open(const char *);
[e7f9a09]122extern void csv_report_add_entry(bench_run_t *, int, benchmark_t *, uint64_t);
[d926f42]123extern void csv_report_close(void);
124
[d17cf8c]125extern errno_t bench_env_init(bench_env_t *);
126extern errno_t bench_env_param_set(bench_env_t *, const char *, const char *);
127extern const char *bench_env_param_get(bench_env_t *, const char *, const char *);
128extern void bench_env_cleanup(bench_env_t *);
[d926f42]129
[be30e74]130extern benchmark_t *benchmarks[];
131extern size_t benchmark_count;
132
[d926f42]133/* Put your benchmark descriptors here (and also to benchlist.c). */
[a787081]134extern benchmark_t benchmark_dir_read;
[c2db02a]135extern benchmark_t benchmark_fibril_mutex;
[a787081]136extern benchmark_t benchmark_file_read;
[bdd9e92]137extern benchmark_t benchmark_rand_read;
138extern benchmark_t benchmark_seq_read;
[a787081]139extern benchmark_t benchmark_malloc1;
140extern benchmark_t benchmark_malloc2;
141extern benchmark_t benchmark_ns_ping;
142extern benchmark_t benchmark_ping_pong;
[381c426]143extern benchmark_t benchmark_read1k;
[f393bc0]144extern benchmark_t benchmark_taskgetid;
[381c426]145extern benchmark_t benchmark_write1k;
[d926f42]146
[d230358]147#endif
148
149/** @}
150 */
Note: See TracBrowser for help on using the repository browser.