#include <cassert>
#include <cerrno>
#include <unistd.h>
#include "benchmark.hpp"
#include "libpmemobj.h"
extern "C" {
#include "lane.h"
}
#define OPERATION_REPEAT_COUNT 10000
struct prog_args {
char *lane_section_name;
};
struct obj_bench {
PMEMobjpool *pop;
struct prog_args *pa;
enum lane_section_type lane_type;
};
static enum lane_section_type
parse_lane_section(const char *arg)
{
if (strcmp(arg, "allocator") == 0)
return LANE_SECTION_ALLOCATOR;
else if (strcmp(arg, "list") == 0)
return LANE_SECTION_LIST;
else if (strcmp(arg, "transaction") == 0)
return LANE_SECTION_TRANSACTION;
else
return MAX_LANE_SECTION;
}
static int
lanes_init(struct benchmark *bench, struct benchmark_args *args)
{
assert(bench != NULL);
assert(args != NULL);
assert(args->opts != NULL);
struct obj_bench *ob =
(struct obj_bench *)malloc(sizeof(struct obj_bench));
if (ob == NULL) {
perror("malloc");
return -1;
}
pmembench_set_priv(bench, ob);
ob->pa = (struct prog_args *)args->opts;
size_t psize = args->is_poolset ? 0 : PMEMOBJ_MIN_POOL;
ob->pop = pmemobj_create(args->fname, "obj_lanes", psize, args->fmode);
if (ob->pop == NULL) {
fprintf(stderr, "%s\n", pmemobj_errormsg());
goto err;
}
ob->lane_type = parse_lane_section(ob->pa->lane_section_name);
if (ob->lane_type == MAX_LANE_SECTION) {
fprintf(stderr, "wrong lane type\n");
goto err;
}
return 0;
err:
free(ob);
return -1;
}
static int
lanes_exit(struct benchmark *bench, struct benchmark_args *args)
{
struct obj_bench *ob = (struct obj_bench *)pmembench_get_priv(bench);
pmemobj_close(ob->pop);
free(ob);
return 0;
}
static int
lanes_op(struct benchmark *bench, struct operation_info *info)
{
struct obj_bench *ob = (struct obj_bench *)pmembench_get_priv(bench);
struct lane_section *section;
for (int i = 0; i < OPERATION_REPEAT_COUNT; i++) {
lane_hold(ob->pop, §ion, ob->lane_type);
lane_release(ob->pop);
}
return 0;
}
static struct benchmark_clo lanes_clo[1];
static struct benchmark_info lanes_info;
CONSTRUCTOR(obj_lines_costructor)
void
obj_lines_costructor(void)
{
lanes_clo[0].opt_short = 's';
lanes_clo[0].opt_long = "lane_section";
lanes_clo[0].descr = "The lane section type: allocator,"
" list or transaction";
lanes_clo[0].type = CLO_TYPE_STR;
lanes_clo[0].off =
clo_field_offset(struct prog_args, lane_section_name);
lanes_clo[0].def = "allocator";
lanes_info.name = "obj_lanes";
lanes_info.brief = "Benchmark for internal lanes "
"operation";
lanes_info.init = lanes_init;
lanes_info.exit = lanes_exit;
lanes_info.multithread = true;
lanes_info.multiops = true;
lanes_info.operation = lanes_op;
lanes_info.measure_time = true;
lanes_info.clos = lanes_clo;
lanes_info.nclos = ARRAY_SIZE(lanes_clo);
lanes_info.opts_size = sizeof(struct prog_args);
lanes_info.rm_file = true;
lanes_info.allow_poolset = true;
REGISTER_BENCHMARK(lanes_info);
}