Changeset d17cf8c in mainline
- Timestamp:
- 2019-01-21T13:39:37Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 94d52d5
- Parents:
- e7f9a09
- Location:
- uspace/app/hbench
- Files:
-
- 11 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/hbench/Makefile
re7f9a09 rd17cf8c 36 36 benchlist.c \ 37 37 csv.c \ 38 env.c \ 38 39 main.c \ 39 params.c \40 40 fs/dirread.c \ 41 41 fs/fileread.c \ -
uspace/app/hbench/doc/doxygroups.h
re7f9a09 rd17cf8c 19 19 * benchmark function to the benchmark_t. 20 20 * 21 * The benchmarking function has to accept two arguments: 21 * The benchmarking function has to accept trhee arguments: 22 * @li bench_env_t: benchmark environment configuration 22 23 * @li bench_run_t: call bench_run_start and bench_run_stop around the 23 24 * actual benchmarking code … … 27 28 * Typically, the structure of the function is following: 28 29 * @code{c} 29 * static bool runner (bench_run_t *run, uint64_t size)30 * static bool runnerconst bench_env_t const *envbench_run_t *run, uint64_t size) 30 31 * { 31 32 * bench_run_start(run); -
uspace/app/hbench/env.c
re7f9a09 rd17cf8c 34 34 */ 35 35 36 #include <adt/hash_table.h>37 36 #include <stdlib.h> 38 37 #include <stdio.h> … … 90 89 }; 91 90 92 /** Table of extra parameters (of param_t). */ 93 static hash_table_t param_hash_table; 94 95 extern errno_t bench_param_init(void) 91 extern errno_t bench_env_init(bench_env_t *env) 96 92 { 97 bool ok = hash_table_create(& param_hash_table, 0, 0, ¶m_hash_table_ops);93 bool ok = hash_table_create(&env->parameters, 0, 0, ¶m_hash_table_ops); 98 94 if (!ok) { 99 95 return ENOMEM; … … 103 99 } 104 100 105 extern void bench_ param_cleanup(void)101 extern void bench_env_cleanup(bench_env_t *env) 106 102 { 107 hash_table_destroy(& param_hash_table);103 hash_table_destroy(&env->parameters); 108 104 } 109 105 110 errno_t bench_ param_set(const char *key, const char *value)106 errno_t bench_env_param_set(bench_env_t *env, const char *key, const char *value) 111 107 { 112 108 param_t *param = malloc(sizeof(param_t)); … … 126 122 } 127 123 128 hash_table_insert(& param_hash_table, ¶m->link);124 hash_table_insert(&env->parameters, ¶m->link); 129 125 130 126 return EOK; 131 127 } 132 128 133 const char *bench_ param_get(const char *key, const char *default_value)129 const char *bench_env_param_get(bench_env_t *env, const char *key, const char *default_value) 134 130 { 135 ht_link_t *item = hash_table_find(& param_hash_table, (char *) key);131 ht_link_t *item = hash_table_find(&env->parameters, (char *) key); 136 132 137 133 if (item == NULL) { -
uspace/app/hbench/fs/dirread.c
re7f9a09 rd17cf8c 44 44 * that the corresponding blocks would be cached after first run. 45 45 */ 46 static bool runner(bench_ run_t *run, uint64_t size)46 static bool runner(bench_env_t *env, bench_run_t *run, uint64_t size) 47 47 { 48 const char *path = bench_ param_get("dirname", "/");48 const char *path = bench_env_param_get(env, "dirname", "/"); 49 49 50 50 bench_run_start(run); -
uspace/app/hbench/fs/fileread.c
re7f9a09 rd17cf8c 45 45 * corresponding blocks would be cached after first run. 46 46 */ 47 static bool runner(bench_ run_t *run, uint64_t size)47 static bool runner(bench_env_t *env, bench_run_t *run, uint64_t size) 48 48 { 49 const char *path = bench_ param_get("filename", "/data/web/helenos.png");49 const char *path = bench_env_param_get(env, "filename", "/data/web/helenos.png"); 50 50 51 51 char *buf = malloc(BUFFER_SIZE); -
uspace/app/hbench/hbench.h
re7f9a09 rd17cf8c 37 37 #define HBENCH_H_ 38 38 39 #include <adt/hash_table.h> 39 40 #include <errno.h> 40 41 #include <stdarg.h> … … 58 59 size_t error_buffer_size; 59 60 } bench_run_t; 61 62 /** Benchmark environment configuration. 63 * 64 * Use proper access functions when modifying data inside this structure. 65 */ 66 typedef struct { 67 hash_table_t parameters; 68 } bench_env_t; 69 70 typedef bool (*benchmark_entry_t)(bench_env_t *, bench_run_t *, uint64_t); 71 typedef bool (*benchmark_helper_t)(bench_env_t *, bench_run_t *); 72 73 typedef struct { 74 const char *name; 75 const char *desc; 76 benchmark_entry_t entry; 77 benchmark_helper_t setup; 78 benchmark_helper_t teardown; 79 } benchmark_t; 60 80 61 81 static inline void bench_run_init(bench_run_t *run, char *error_buffer, … … 87 107 } 88 108 89 typedef bool (*benchmark_entry_t)(bench_run_t *, uint64_t);90 typedef bool (*benchmark_helper_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 109 extern benchmark_t *benchmarks[]; 101 110 extern size_t benchmark_count; … … 105 114 extern void csv_report_close(void); 106 115 107 extern errno_t bench_ param_init(void);108 extern errno_t bench_ param_set(const char *, const char *);109 extern const char *bench_ param_get(const char *, const char *);110 extern void bench_ param_cleanup(void);116 extern errno_t bench_env_init(bench_env_t *); 117 extern errno_t bench_env_param_set(bench_env_t *, const char *, const char *); 118 extern const char *bench_env_param_get(bench_env_t *, const char *, const char *); 119 extern void bench_env_cleanup(bench_env_t *); 111 120 112 121 /* Put your benchmark descriptors here (and also to benchlist.c). */ -
uspace/app/hbench/ipc/ns_ping.c
re7f9a09 rd17cf8c 38 38 #include "../hbench.h" 39 39 40 static bool runner(bench_ run_t *run, uint64_t niter)40 static bool runner(bench_env_t *env, bench_run_t *run, uint64_t niter) 41 41 { 42 42 bench_run_start(run); -
uspace/app/hbench/ipc/ping_pong.c
re7f9a09 rd17cf8c 40 40 static ipc_test_t *test = NULL; 41 41 42 static bool setup(bench_ run_t *run)42 static bool setup(bench_env_t *env, bench_run_t *run) 43 43 { 44 44 errno_t rc = ipc_test_create(&test); … … 52 52 } 53 53 54 static bool teardown(bench_ run_t *run)54 static bool teardown(bench_env_t *env, bench_run_t *run) 55 55 { 56 56 ipc_test_destroy(test); … … 58 58 } 59 59 60 static bool runner(bench_ run_t *run, uint64_t niter)60 static bool runner(bench_env_t *env, bench_run_t *run, uint64_t niter) 61 61 { 62 62 bench_run_start(run); -
uspace/app/hbench/main.c
re7f9a09 rd17cf8c 148 148 } 149 149 150 static bool run_benchmark(bench mark_t *bench)150 static bool run_benchmark(bench_env_t *env, benchmark_t *bench) 151 151 { 152 152 printf("Warm up and determine workload size...\n"); … … 169 169 170 170 if (bench->setup != NULL) { 171 ret = bench->setup( &helper_run);171 ret = bench->setup(env, &helper_run); 172 172 if (!ret) { 173 173 goto leave_error; … … 190 190 bench_run_init(&run, error_msg, MAX_ERROR_STR_LENGTH); 191 191 192 bool ok = bench->entry( &run, workload_size);192 bool ok = bench->entry(env, &run, workload_size); 193 193 if (!ok) { 194 194 goto leave_error; … … 212 212 bench_run_init(&runs[i], error_msg, MAX_ERROR_STR_LENGTH); 213 213 214 bool ok = bench->entry( &runs[i], workload_size);214 bool ok = bench->entry(env, &runs[i], workload_size); 215 215 if (!ok) { 216 216 free(runs); … … 233 233 leave: 234 234 if (bench->teardown != NULL) { 235 bool ok = bench->teardown( &helper_run);235 bool ok = bench->teardown(env, &helper_run); 236 236 if (!ok) { 237 237 printf("Error: %s\n", error_msg); … … 245 245 } 246 246 247 static int run_benchmarks( void)247 static int run_benchmarks(bench_env_t *env) 248 248 { 249 249 unsigned int count_ok = 0; … … 256 256 for (size_t it = 0; it < benchmark_count; it++) { 257 257 printf("%s (%s)\n", benchmarks[it]->name, benchmarks[it]->desc); 258 if (run_benchmark( benchmarks[it])) {258 if (run_benchmark(env, benchmarks[it])) { 259 259 count_ok++; 260 260 continue; … … 314 314 } 315 315 316 static void handle_param_arg( char *arg)316 static void handle_param_arg(bench_env_t *env, char *arg) 317 317 { 318 318 char *value = NULL; 319 319 char *key = str_tok(arg, "=", &value); 320 bench_ param_set(key, value);320 bench_env_param_set(env, key, value); 321 321 } 322 322 323 323 int main(int argc, char *argv[]) 324 324 { 325 errno_t rc = bench_param_init(); 325 bench_env_t bench_env; 326 errno_t rc = bench_env_init(&bench_env); 326 327 if (rc != EOK) { 327 328 fprintf(stderr, "Failed to initialize internal params structure: %s\n", … … 350 351 break; 351 352 case 'p': 352 handle_param_arg( optarg);353 handle_param_arg(&bench_env, optarg); 353 354 break; 354 355 case -1: … … 378 379 379 380 if (str_cmp(benchmark, "*") == 0) { 380 exit_code = run_benchmarks( );381 exit_code = run_benchmarks(&bench_env); 381 382 } else { 382 383 bool benchmark_exists = false; … … 384 385 if (str_cmp(benchmark, benchmarks[i]->name) == 0) { 385 386 benchmark_exists = true; 386 exit_code = run_benchmark( benchmarks[i]) ? 0 : -1;387 exit_code = run_benchmark(&bench_env, benchmarks[i]) ? 0 : -1; 387 388 break; 388 389 } … … 395 396 396 397 csv_report_close(); 397 bench_ param_cleanup();398 bench_env_cleanup(&bench_env); 398 399 399 400 return exit_code; -
uspace/app/hbench/malloc/malloc1.c
re7f9a09 rd17cf8c 36 36 #include "../hbench.h" 37 37 38 static bool runner(bench_ run_t *run, uint64_t size)38 static bool runner(bench_env_t *env, bench_run_t *run, uint64_t size) 39 39 { 40 40 bench_run_start(run); -
uspace/app/hbench/malloc/malloc2.c
re7f9a09 rd17cf8c 35 35 #include "../hbench.h" 36 36 37 static bool runner(bench_ run_t *run, uint64_t niter)37 static bool runner(bench_env_t *env, bench_run_t *run, uint64_t niter) 38 38 { 39 39 bench_run_start(run); -
uspace/app/hbench/synch/fibril_mutex.c
re7f9a09 rd17cf8c 65 65 } 66 66 67 static bool runner(bench_ run_t *run, uint64_t size)67 static bool runner(bench_env_t *env, bench_run_t *run, uint64_t size) 68 68 { 69 69 shared_t shared;
Note:
See TracChangeset
for help on using the changeset viewer.