Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset ebb0835 in mainline


Ignore:
Timestamp:
2019-01-07T12:56:22Z (2 years ago)
Author:
Vojtech Horky <vojtech.horky@…>
Branches:
lfn, master
Children:
c2db02a
Parents:
a787081
Message:

hbench: add tiny wrapper around stopwatch_t

This prepares the harness for future extensions when more than wallclock
time would be prepared. The data would be stored inside the new
structure and the actual benchmarks would not need to be modified at all
(they really should not care which metrics are collected).

Location:
uspace/app/hbench
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/hbench/csv.c

    ra787081 rebb0835  
    6767 * @param workload_size Workload size.
    6868 */
    69 void csv_report_add_entry(stopwatch_t *stopwatch, int run_index,
     69void csv_report_add_entry(benchmeter_t *meter, int run_index,
    7070    benchmark_t *bench, uint64_t workload_size)
    7171{
     
    7676        fprintf(csv_output, "%s,%d,%" PRIu64 ",%lld\n",
    7777            bench->name, run_index, workload_size,
    78             (long long) stopwatch_get_nanos(stopwatch));
     78            (long long) stopwatch_get_nanos(&meter->stopwatch));
    7979}
    8080
  • uspace/app/hbench/doc/doxygroups.h

    ra787081 rebb0835  
    1919 * benchmark function to the benchmark_t.
    2020 *
    21  * The benchmarking function has to accept for arguments:
    22  *  @li stopwatch_t: store the measured data there
     21 * The benchmarking function has to accept four arguments:
     22 *  @li benchmeter_t: call benchmeter_start and benchmeter_stop around the
     23 *      actual benchmarking code
    2324 *  @li uint64_t: size of the workload - typically number of inner loops in
    2425 *      your benchmark (used to self-calibrate benchmark size)
     
    2829 * Typically, the structure of the function is following:
    2930 * @code{c}
    30  * static bool runner(stopwatch_t *stopwatch, uint64_t size,
     31 * static bool runner(benchmeter_t *meter, uint64_t size,
    3132 *     char *error, size_t error_size)
    3233 * {
    33  *      stopwatch_start(stopwatch);
     34 *      benchmeter_start(meter);
    3435 *      for (uint64_t i = 0; i < size; i++) {
    3536 *              // measured action
    3637 *      }
    37  *      stopwatch_stop(stopwatch);
     38 *      benchmeter_stop(meter);
    3839 *
    3940 *      return true;
  • uspace/app/hbench/fs/dirread.c

    ra787081 rebb0835  
    4343 * that the corresponding blocks would be cached after first run.
    4444 */
    45 static bool runner(stopwatch_t *stopwatch, uint64_t size,
     45static bool runner(benchmeter_t *meter, uint64_t size,
    4646    char *error, size_t error_size)
    4747{
    4848        const char *path = bench_param_get("dirname", "/");
    4949
    50         stopwatch_start(stopwatch);
     50        benchmeter_start(meter);
    5151        for (uint64_t i = 0; i < size; i++) {
    5252                DIR *dir = opendir(path);
     
    6464                closedir(dir);
    6565        }
    66         stopwatch_stop(stopwatch);
     66        benchmeter_stop(meter);
    6767
    6868        return true;
  • uspace/app/hbench/fs/fileread.c

    ra787081 rebb0835  
    4444 * corresponding blocks would be cached after first run.
    4545 */
    46 static bool runner(stopwatch_t *stopwatch, uint64_t size,
     46static bool runner(benchmeter_t *meter, uint64_t size,
    4747    char *error, size_t error_size)
    4848{
     
    6565        }
    6666
    67         stopwatch_start(stopwatch);
     67        benchmeter_start(meter);
    6868        for (uint64_t i = 0; i < size; i++) {
    6969                int rc = fseek(file, 0, SEEK_SET);
     
    8484                }
    8585        }
    86         stopwatch_stop(stopwatch);
     86        benchmeter_stop(meter);
    8787
    8888leave_close:
  • uspace/app/hbench/hbench.h

    ra787081 rebb0835  
    4141#include <perf.h>
    4242
    43 typedef bool (*benchmark_entry_t)(stopwatch_t *, uint64_t,
     43/*
     44 * So far, a simple wrapper around system stopwatch.
     45 * Eventually, we could collection of hardware counters etc. without
     46 * modifying signatures of any existing benchmark.
     47 */
     48typedef struct {
     49        stopwatch_t stopwatch;
     50} benchmeter_t;
     51
     52static inline void benchmeter_init(benchmeter_t *meter)
     53{
     54        stopwatch_init(&meter->stopwatch);
     55}
     56
     57static inline void benchmeter_start(benchmeter_t *meter)
     58{
     59        stopwatch_start(&meter->stopwatch);
     60}
     61
     62static inline void benchmeter_stop(benchmeter_t *meter)
     63{
     64        stopwatch_stop(&meter->stopwatch);
     65}
     66
     67typedef bool (*benchmark_entry_t)(benchmeter_t *, uint64_t,
    4468    char *, size_t);
    4569typedef bool (*benchmark_helper_t)(char *, size_t);
     
    5781
    5882extern errno_t csv_report_open(const char *);
    59 extern void csv_report_add_entry(stopwatch_t *, int, benchmark_t *, uint64_t);
     83extern void csv_report_add_entry(benchmeter_t *, int, benchmark_t *, uint64_t);
    6084extern void csv_report_close(void);
    6185
  • uspace/app/hbench/ipc/ns_ping.c

    ra787081 rebb0835  
    3838#include "../hbench.h"
    3939
    40 static bool runner(stopwatch_t *stopwatch, uint64_t niter,
     40static bool runner(benchmeter_t *meter, uint64_t niter,
    4141    char *error, size_t error_size)
    4242{
    43         stopwatch_start(stopwatch);
     43        benchmeter_start(meter);
    4444
    4545        for (uint64_t count = 0; count < niter; count++) {
     
    5454        }
    5555
    56         stopwatch_stop(stopwatch);
     56        benchmeter_stop(meter);
    5757
    5858        return true;
  • uspace/app/hbench/ipc/ping_pong.c

    ra787081 rebb0835  
    5959}
    6060
    61 static bool runner(stopwatch_t *stopwatch, uint64_t niter,
     61static bool runner(benchmeter_t *meter, uint64_t niter,
    6262    char *error, size_t error_size)
    6363{
    64         stopwatch_start(stopwatch);
     64        benchmeter_start(meter);
    6565
    6666        for (uint64_t count = 0; count < niter; count++) {
     
    7575        }
    7676
    77         stopwatch_stop(stopwatch);
     77        benchmeter_stop(meter);
    7878
    7979        return true;
  • uspace/app/hbench/main.c

    ra787081 rebb0835  
    5353#define MAX_ERROR_STR_LENGTH 1024
    5454
    55 static void short_report(stopwatch_t *stopwatch, int run_index,
     55static void short_report(benchmeter_t *meter, int run_index,
    5656    benchmark_t *bench, uint64_t workload_size)
    5757{
    58         csv_report_add_entry(stopwatch, run_index, bench, workload_size);
    59 
    60         usec_t duration_usec = NSEC2USEC(stopwatch_get_nanos(stopwatch));
     58        csv_report_add_entry(meter, run_index, bench, workload_size);
     59
     60        usec_t duration_usec = NSEC2USEC(stopwatch_get_nanos(&meter->stopwatch));
    6161
    6262        printf("Completed %" PRIu64 " operations in %llu us",
    6363            workload_size, duration_usec);
    6464        if (duration_usec > 0) {
    65                 double nanos = stopwatch_get_nanos(stopwatch);
     65                double nanos = stopwatch_get_nanos(&meter->stopwatch);
    6666                double thruput = (double) workload_size / (nanos / 1000000000.0l);
    6767                printf(", %.0f ops/s.\n", thruput);
     
    106106 *
    107107 */
    108 static void compute_stats(stopwatch_t *stopwatch, size_t stopwatch_count,
     108static void compute_stats(benchmeter_t *meter, size_t stopwatch_count,
    109109    uint64_t workload_size, double precision, double *out_duration_avg,
    110110    double *out_duration_sigma, double *out_thruput_avg)
     
    115115
    116116        for (size_t i = 0; i < stopwatch_count; i++) {
    117                 double nanos = stopwatch_get_nanos(&stopwatch[i]);
     117                double nanos = stopwatch_get_nanos(&meter[i].stopwatch);
    118118                double thruput = (double) workload_size / nanos;
    119119
     
    130130}
    131131
    132 static void summary_stats(stopwatch_t *stopwatch, size_t stopwatch_count,
     132static void summary_stats(benchmeter_t *meter, size_t meter_count,
    133133    benchmark_t *bench, uint64_t workload_size)
    134134{
    135135        double duration_avg, duration_sigma, thruput_avg;
    136         compute_stats(stopwatch, stopwatch_count, workload_size, 0.001,
     136        compute_stats(meter, meter_count, workload_size, 0.001,
    137137            &duration_avg, &duration_sigma, &thruput_avg);
    138138
     
    140140            "%.0f ops/s; Samples: %zu\n",
    141141            workload_size, duration_avg / 1000.0, duration_sigma / 1000.0,
    142             thruput_avg * 1000000000.0, stopwatch_count);
     142            thruput_avg * 1000000000.0, meter_count);
    143143}
    144144
     
    175175                workload_size = ((uint64_t) 1) << bits;
    176176
    177                 stopwatch_t stopwatch = STOPWATCH_INITIALIZE_STATIC;
    178 
    179                 bool ok = bench->entry(&stopwatch, workload_size,
     177                benchmeter_t meter;
     178                benchmeter_init(&meter);
     179
     180                bool ok = bench->entry(&meter, workload_size,
    180181                    error_msg, MAX_ERROR_STR_LENGTH);
    181182                if (!ok) {
    182183                        goto leave_error;
    183184                }
    184                 short_report(&stopwatch, -1, bench, workload_size);
    185 
    186                 nsec_t duration = stopwatch_get_nanos(&stopwatch);
     185                short_report(&meter, -1, bench, workload_size);
     186
     187                nsec_t duration = stopwatch_get_nanos(&meter.stopwatch);
    187188                if (duration > SEC2NSEC(MIN_DURATION_SECS)) {
    188189                        break;
     
    192193        printf("Workload size set to %" PRIu64 ", measuring %d samples.\n", workload_size, NUM_SAMPLES);
    193194
    194         stopwatch_t *stopwatch = calloc(NUM_SAMPLES, sizeof(stopwatch_t));
    195         if (stopwatch == NULL) {
     195        benchmeter_t *meter = calloc(NUM_SAMPLES, sizeof(benchmeter_t));
     196        if (meter == NULL) {
    196197                snprintf(error_msg, MAX_ERROR_STR_LENGTH, "failed allocating memory");
    197198                goto leave_error;
    198199        }
    199200        for (int i = 0; i < NUM_SAMPLES; i++) {
    200                 stopwatch_init(&stopwatch[i]);
    201 
    202                 bool ok = bench->entry(&stopwatch[i], workload_size,
     201                benchmeter_init(&meter[i]);
     202
     203                bool ok = bench->entry(&meter[i], workload_size,
    203204                    error_msg, MAX_ERROR_STR_LENGTH);
    204205                if (!ok) {
    205                         free(stopwatch);
     206                        free(meter);
    206207                        goto leave_error;
    207208                }
    208                 short_report(&stopwatch[i], i, bench, workload_size);
    209         }
    210 
    211         summary_stats(stopwatch, NUM_SAMPLES, bench, workload_size);
     209                short_report(&meter[i], i, bench, workload_size);
     210        }
     211
     212        summary_stats(meter, NUM_SAMPLES, bench, workload_size);
    212213        printf("\nBenchmark completed\n");
    213214
    214         free(stopwatch);
     215        free(meter);
    215216
    216217        goto leave;
  • uspace/app/hbench/malloc/malloc1.c

    ra787081 rebb0835  
    3636#include "../hbench.h"
    3737
    38 static bool runner(stopwatch_t *stopwatch, uint64_t size,
     38static bool runner(benchmeter_t *meter, uint64_t size,
    3939    char *error, size_t error_size)
    4040{
    41         stopwatch_start(stopwatch);
     41        benchmeter_start(meter);
    4242        for (uint64_t i = 0; i < size; i++) {
    4343                void *p = malloc(1);
     
    5050                free(p);
    5151        }
    52         stopwatch_stop(stopwatch);
     52        benchmeter_stop(meter);
    5353
    5454        return true;
  • uspace/app/hbench/malloc/malloc2.c

    ra787081 rebb0835  
    3535#include "../hbench.h"
    3636
    37 static bool runner(stopwatch_t *stopwatch, uint64_t niter,
     37static bool runner(benchmeter_t *meter, uint64_t niter,
    3838    char *error, size_t error_size)
    3939{
    40         stopwatch_start(stopwatch);
     40        benchmeter_start(meter);
    4141
    4242        void **p = malloc(niter * sizeof(void *));
     
    6767        free(p);
    6868
    69         stopwatch_stop(stopwatch);
     69        benchmeter_stop(meter);
    7070
    7171        return true;
Note: See TracChangeset for help on using the changeset viewer.