HelenOS sources
This source file includes following definitions.
- runner
#include <block.h>
#include <loc.h>
#include <str_error.h>
#include <stdio.h>
#include <stdlib.h>
#include "../hbench.h"
static bool runner(bench_env_t *env, bench_run_t *run, uint64_t size)
{
const char *disk;
const char *nbstr;
service_id_t svcid;
size_t block_size;
aoff64_t dev_nblocks;
aoff64_t baddr;
bool block_inited = false;
char *buf = NULL;
uint64_t i;
errno_t rc;
int nitem;
unsigned nb;
disk = bench_env_param_get(env, "disk", NULL);
if (disk == NULL) {
bench_run_fail(run, "Yo must specify 'disk' parameter.");
goto error;
}
nbstr = bench_env_param_get(env, "nb", "1");
nitem = sscanf(nbstr, "%u", &nb);
if (nitem < 1) {
bench_run_fail(run, "'nb' must be an integer number of blocks.");
goto error;
}
rc = loc_service_get_id(disk, &svcid, 0);
if (rc != EOK) {
bench_run_fail(run, "failed resolving device '%s'", disk);
goto error;
}
rc = block_init(svcid);
if (rc != EOK) {
bench_run_fail(run, "failed opening block device '%s'",
disk);
}
block_inited = true;
rc = block_get_bsize(svcid, &block_size);
if (rc != EOK) {
bench_run_fail(run, "error determining device block size.");
goto error;
}
rc = block_get_nblocks(svcid, &dev_nblocks);
if (rc != EOK) {
bench_run_fail(run, "failed to obtain block device size.\n");
goto error;
}
if (dev_nblocks < nb) {
bench_run_fail(run, "device is smaller than %u blocks.\n",
nb);
goto error;
}
buf = malloc(block_size);
if (buf == NULL) {
bench_run_fail(run, "failed to allocate buffer (%zu bytes)",
block_size);
goto error;
}
bench_run_start(run);
for (i = 0; i < size; i++) {
baddr = i % (dev_nblocks - nb + 1);
rc = block_read_direct(svcid, baddr, 1, buf);
if (rc != EOK) {
bench_run_fail(run, "failed to read blocks %llu-%llu: "
"%s", (unsigned long long)baddr,
(unsigned long long)(baddr + nb - 1),
str_error(errno));
goto error;
}
}
bench_run_stop(run);
block_fini(svcid);
free(buf);
return true;
error:
if (buf != NULL)
free(buf);
if (block_inited)
block_fini(svcid);
return false;
}
benchmark_t benchmark_seq_read = {
.name = "seq_read",
.desc = "Sequential disk read (must set 'disk' parameter).",
.entry = &runner,
.setup = NULL,
.teardown = NULL
};
HelenOS homepage, sources at GitHub