Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VTune instrumentation #222

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ option(HAVE_RUST "build features written in rust" OFF)
option(RUST_USE_MUSL "build rust deps against musl" OFF)
option(BUILD_AND_INSTALL_CHECK "build our own version of check and link against it" OFF)
option(USE_PMEM "build persistent memory features" OFF)
option(HAVE_ITT_INSTRUMENTATION "Instrument code with ITT API" OFF)

option(COVERAGE "code coverage" OFF)

Expand Down Expand Up @@ -146,6 +147,13 @@ if (USE_PMEM)
link_directories(${LIBPMEM_LIBRARY_DIRS})
endif(USE_PMEM)

if (HAVE_ITT_INSTRUMENTATION)
pkg_check_modules(ITTNOTIFY REQUIRED ittnotify>=1.0)
include_directories(${ITTNOTIFY_INCLUDE_DIRS})
link_directories(${ITTNOTIFY_LIBRARY_DIRS})
link_libraries(${ITTNOTIFY_LIBRARIES})
endif(HAVE_ITT_INSTRUMENTATION)

find_package(Threads)

if(TARGET_CDB)
Expand All @@ -158,7 +166,8 @@ endif(TARGET_CDB)
include_directories(${include_directories}
"${PROJECT_BINARY_DIR}"
"${CCOMMON_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/src")
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/benchmarks")

# server & (cli) client
add_subdirectory(src)
Expand Down
29 changes: 22 additions & 7 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
add_executable(bench_micro bench_micro.c)
add_subdirectory(storage_cuckoo)
add_subdirectory(storage_slab)

target_include_directories(bench_micro PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/tests)
set(SOURCE bench_storage.c)

target_link_libraries(bench_micro cuckoo time)
target_link_libraries(bench_micro ccommon-static)
target_link_libraries(bench_micro pthread)
set(MODULES_SLAB
bench_storage_slab
slab
time)

set(MODULES_CUCKOO
bench_storage_cuckoo
cuckoo
time)

set(LIBS
ccommon-static
${CMAKE_THREAD_LIBS_INIT})

add_executable(bench_slab ${SOURCE})
target_link_libraries(bench_slab ${MODULES_SLAB} ${LIBS})

add_executable(bench_cuckoo ${SOURCE})
target_link_libraries(bench_cuckoo ${MODULES_CUCKOO} ${LIBS})
124 changes: 17 additions & 107 deletions benchmarks/bench_micro.c → benchmarks/bench_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include <errno.h>
#include <pthread.h>

#include <storage/cuckoo/item.h>
#include <storage/cuckoo/cuckoo.h>
#include <bench_storage.h>
#include <time/cc_timer.h>
#include <cc_debug.h>
#include <cc_mm.h>
Expand All @@ -33,23 +32,12 @@ static __thread unsigned int rseed = 1234; /* XXX: make this an option */

#define O(b, opt) option_uint(&(b->options.benchmark.opt))

typedef size_t benchmark_key_u;

struct benchmark_entry {
char *key;
benchmark_key_u key_size;

char *value;
size_t value_size;
};

struct benchmark_specific {
BENCHMARK_OPTION(OPTION_DECLARE);
BENCHMARK_OPTION(OPTION_DECLARE)
};

struct benchmark_options {
struct benchmark_specific benchmark;
cuckoo_options_st cuckoo;
};

struct benchmark {
Expand All @@ -64,9 +52,7 @@ benchmark_create(struct benchmark *b, const char *config)
b->entries = NULL;

struct benchmark_specific opts1 = { BENCHMARK_OPTION(OPTION_INIT) };
cuckoo_options_st opts2 = { CUCKOO_OPTION(OPTION_INIT) };
b->options.benchmark = opts1;
b->options.cuckoo = opts2;

size_t nopts = OPTION_CARDINALITY(struct benchmark_options);
option_load_default((struct option *)&b->options, nopts);
Expand Down Expand Up @@ -107,8 +93,8 @@ benchmark_entry_create(benchmark_key_u key, size_t size)
e.value = cc_alloc(e.value_size);
ASSERT(e.value != NULL);

memcpy(e.key, &key, e.key_size);
e.key[e.key_size - 1] = 0;
int ret = snprintf(e.key, e.key_size, "%zu", key);
ASSERT(ret > 0);

memset(e.value, 'a', e.value_size);
e.value[e.value_size - 1] = 0;
Expand Down Expand Up @@ -145,82 +131,6 @@ benchmark_entries_delete(struct benchmark *b)
cc_free(b->entries);
}

static int
benchmark_cuckoo_init(struct benchmark *b)
{
cuckoo_options_st *options = &b->options.cuckoo;
static cuckoo_metrics_st metrics = { CUCKOO_METRIC(METRIC_INIT) };
options->cuckoo_policy.val.vuint = CUCKOO_POLICY_EXPIRE;
options->cuckoo_item_size.val.vuint = O(b, entry_max_size) + ITEM_OVERHEAD;
options->cuckoo_nitem.val.vuint = O(b, nentries);

cuckoo_setup(options, &metrics);

return 0;
}

static rstatus_i
benchmark_cuckoo_deinit(struct benchmark *b)
{
cuckoo_teardown();
return CC_OK;
}

static rstatus_i
benchmark_cuckoo_put(struct benchmark *b, struct benchmark_entry *e)
{
struct bstring key;
struct val val;
val.type = VAL_TYPE_STR;
bstring_set_cstr(&val.vstr, e->value);
bstring_set_cstr(&key, e->key);

struct item *it = cuckoo_insert(&key, &val, INT32_MAX);

return it != NULL ? CC_OK : CC_ENOMEM;
}

static rstatus_i
benchmark_cuckoo_get(struct benchmark *b, struct benchmark_entry *e)
{
struct bstring key;
bstring_set_cstr(&key, e->key);
struct item *it = cuckoo_get(&key);

return it != NULL ? CC_OK : CC_EEMPTY;
}

static rstatus_i
benchmark_cuckoo_rem(struct benchmark *b, struct benchmark_entry *e)
{
struct bstring key;
bstring_set_cstr(&key, e->key);

return cuckoo_delete(&key) ? CC_OK : CC_EEMPTY;
}

enum benchmark_storage_engines {
BENCHMARK_CUCKOO,

MAX_BENCHMARK_STORAGE_ENGINES
};

static struct bench_engine_ops {
rstatus_i (*init)(struct benchmark *b);
rstatus_i (*deinit)(struct benchmark *b);
rstatus_i (*put)(struct benchmark *b, struct benchmark_entry *e);
rstatus_i (*get)(struct benchmark *b, struct benchmark_entry *e);
rstatus_i (*rem)(struct benchmark *b, struct benchmark_entry *e);
} bench_engines[MAX_BENCHMARK_STORAGE_ENGINES] = {
[BENCHMARK_CUCKOO] = {
.init = benchmark_cuckoo_init,
.deinit = benchmark_cuckoo_deinit,
.put = benchmark_cuckoo_put,
.get = benchmark_cuckoo_get,
.rem = benchmark_cuckoo_rem,
}
};

static void
benchmark_print_summary(struct benchmark *b, struct duration *d)
{
Expand All @@ -229,26 +139,26 @@ benchmark_print_summary(struct benchmark *b, struct duration *d)
}

static struct duration
benchmark_run(struct benchmark *b, struct bench_engine_ops *ops)
benchmark_run(struct benchmark *b)
{
ops->init(b);

struct array *in;
struct array *in2;

struct array *out;

size_t nentries = O(b, nentries);

bench_storage_init(O(b, entry_max_size), nentries);

array_create(&in, nentries, sizeof(struct benchmark_entry *));
array_create(&in2, nentries, sizeof(struct benchmark_entry *));
array_create(&out, nentries, sizeof(struct benchmark_entry *));

for (int i = 0; i < nentries; ++i) {
for (size_t i = 0; i < nentries; ++i) {
struct benchmark_entry **e = array_push(in);
*e = &b->entries[i];

ASSERT(ops->put(b, *e) == CC_OK);
ASSERT(bench_storage_put(*e) == CC_OK);
}

struct duration d;
Expand All @@ -260,14 +170,14 @@ benchmark_run(struct benchmark *b, struct bench_engine_ops *ops)
/* XXX: array_shuffle(in) */
}

int pct = RRAND(0, 100);
unsigned pct = RRAND(0, 100);

int pct_sum = 0;
unsigned pct_sum = 0;
if (pct_sum <= pct && pct < O(b, pct_get) + pct_sum) {
ASSERT(array_nelem(in) != 0);
struct benchmark_entry **e = array_pop(in);

if (ops->get(b, *e) != CC_OK) {
if (bench_storage_get(*e) != CC_OK) {
log_info("benchmark get() failed");
}

Expand All @@ -282,12 +192,12 @@ benchmark_run(struct benchmark *b, struct bench_engine_ops *ops)
} else {
ASSERT(array_nelem(in) != 0);
e = array_pop(in);
if (ops->rem(b, *e) != CC_OK) {
if (bench_storage_rem(*e) != CC_OK) {
log_info("benchmark rem() failed");
}
}

if (ops->put(b, *e) != CC_OK) {
if (bench_storage_put(*e) != CC_OK) {
log_info("benchmark put() failed");
}

Expand All @@ -299,7 +209,7 @@ benchmark_run(struct benchmark *b, struct bench_engine_ops *ops)
ASSERT(array_nelem(in) != 0);
struct benchmark_entry **e = array_pop(in);

if (ops->rem(b, *e) != CC_OK) {
if (bench_storage_rem(*e) != CC_OK) {
log_info("benchmark rem() failed");
}

Expand All @@ -310,7 +220,7 @@ benchmark_run(struct benchmark *b, struct bench_engine_ops *ops)

duration_stop(&d);

ops->deinit(b);
bench_storage_deinit();

return d;
}
Expand All @@ -326,7 +236,7 @@ main(int argc, char *argv[])

benchmark_entries_populate(&b);

struct duration d = benchmark_run(&b, &bench_engines[BENCHMARK_CUCKOO]);
struct duration d = benchmark_run(&b);

benchmark_print_summary(&b, &d);

Expand Down
19 changes: 19 additions & 0 deletions benchmarks/bench_storage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <cc_define.h>
#include <stddef.h>

typedef size_t benchmark_key_u;

struct benchmark_entry {
char *key;
benchmark_key_u key_size;
char *value;
size_t value_size;
};

rstatus_i bench_storage_init(size_t item_size, size_t nentries);
rstatus_i bench_storage_deinit(void);
rstatus_i bench_storage_put(struct benchmark_entry *e);
rstatus_i bench_storage_get(struct benchmark_entry *e);
rstatus_i bench_storage_rem(struct benchmark_entry *e);
3 changes: 3 additions & 0 deletions benchmarks/storage_cuckoo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_library(bench_storage_cuckoo storage_cuckoo.c)

target_link_libraries(bench_storage_cuckoo)
60 changes: 60 additions & 0 deletions benchmarks/storage_cuckoo/storage_cuckoo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <bench_storage.h>

#include <storage/cuckoo/item.h>
#include <storage/cuckoo/cuckoo.h>

static cuckoo_metrics_st metrics = { CUCKOO_METRIC(METRIC_INIT) };
static cuckoo_options_st options = { CUCKOO_OPTION(OPTION_INIT) };

rstatus_i
bench_storage_init(size_t item_size, size_t nentries)
{
option_load_default((struct option *)&options, OPTION_CARDINALITY(options));
options.cuckoo_policy.val.vuint = CUCKOO_POLICY_EXPIRE;
options.cuckoo_item_size.val.vuint = item_size + ITEM_OVERHEAD;
options.cuckoo_nitem.val.vuint = nentries;

cuckoo_setup(&options, &metrics);

return CC_OK;
}

rstatus_i
bench_storage_deinit(void)
{
cuckoo_teardown();
return CC_OK;
}

rstatus_i
bench_storage_put(struct benchmark_entry *e)
{
struct bstring key;
struct val val;
val.type = VAL_TYPE_STR;
bstring_set_cstr(&val.vstr, e->value);
bstring_set_cstr(&key, e->key);

struct item *it = cuckoo_insert(&key, &val, INT32_MAX);

return it != NULL ? CC_OK : CC_ENOMEM;
}

rstatus_i
bench_storage_get(struct benchmark_entry *e)
{
struct bstring key;
bstring_set_cstr(&key, e->key);
struct item *it = cuckoo_get(&key);

return it != NULL ? CC_OK : CC_EEMPTY;
}

rstatus_i
bench_storage_rem(struct benchmark_entry *e)
{
struct bstring key;
bstring_set_cstr(&key, e->key);

return cuckoo_delete(&key) ? CC_OK : CC_EEMPTY;
}
3 changes: 3 additions & 0 deletions benchmarks/storage_slab/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_library(bench_storage_slab storage_slab.c)

target_link_libraries(bench_storage_slab)
Loading