Skip to content

Commit

Permalink
fix test (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
1a1a11a authored Dec 1, 2024
1 parent 9e7081e commit 2c22bcf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 67 deletions.
73 changes: 27 additions & 46 deletions libCacheSim/profiler/simulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ static void _simulate(gpointer data, gpointer user_data) {
int idx = GPOINTER_TO_UINT(data) - 1;
if (params->use_random_seed) {
set_rand_seed(rand());
} else {
set_rand_seed(1);
}

cache_stat_t *result = params->result;
reader_t *cloned_reader = clone_reader(params->reader);
request_t *req = new_request();
cache_t *local_cache = params->caches[idx];
strncpy(result[idx].cache_name, local_cache->cache_name,
CACHE_NAME_ARRAY_LEN);
strncpy(result[idx].cache_name, local_cache->cache_name, CACHE_NAME_ARRAY_LEN);

/* warm up using warmup_reader */
if (params->warmup_reader) {
Expand All @@ -62,8 +63,7 @@ static void _simulate(gpointer data, gpointer user_data) {
INFO("cache %s (size %" PRIu64
") finishes warm up using warmup reader "
"with %" PRIu64 " requests\n",
local_cache->cache_name, local_cache->cache_size,
result[idx].n_warmup_req);
local_cache->cache_name, local_cache->cache_size, result[idx].n_warmup_req);
}

read_one_req(cloned_reader, req);
Expand All @@ -72,8 +72,7 @@ static void _simulate(gpointer data, gpointer user_data) {
/* using warmup_frac or warmup_sec of requests from reader to warm up */
if (params->n_warmup_req > 0 || params->warmup_sec > 0) {
uint64_t n_warmup = 0;
while (req->valid && (n_warmup < params->n_warmup_req ||
req->clock_time - start_ts < params->warmup_sec)) {
while (req->valid && (n_warmup < params->n_warmup_req || req->clock_time - start_ts < params->warmup_sec)) {
req->clock_time -= start_ts;
local_cache->get(local_cache, req);
n_warmup += 1;
Expand All @@ -83,8 +82,7 @@ static void _simulate(gpointer data, gpointer user_data) {
INFO("cache %s (size %" PRIu64
") finishes warm up using "
"with %" PRIu64 " requests, %.2lf hour trace time\n",
local_cache->cache_name, local_cache->cache_size, n_warmup,
(double)(req->clock_time - start_ts) / 3600.0);
local_cache->cache_name, local_cache->cache_size, n_warmup, (double)(req->clock_time - start_ts) / 3600.0);
}

while (req->valid) {
Expand Down Expand Up @@ -123,8 +121,7 @@ static void _simulate(gpointer data, gpointer user_data) {
result[idx].curr_rtime = req->clock_time;
result[idx].n_obj = local_cache->n_obj;
result[idx].occupied_byte = local_cache->occupied_byte;
strncpy(result[idx].cache_name, local_cache->cache_name,
CACHE_NAME_ARRAY_LEN);
strncpy(result[idx].cache_name, local_cache->cache_name, CACHE_NAME_ARRAY_LEN);

// report progress
g_mutex_lock(&(params->mtx));
Expand All @@ -139,20 +136,18 @@ static void _simulate(gpointer data, gpointer user_data) {
close_reader(cloned_reader);
}

cache_stat_t *simulate_at_multi_sizes_with_step_size(
reader_t *const reader, const cache_t *cache, uint64_t step_size,
reader_t *warmup_reader, double warmup_frac, int warmup_sec,
int num_of_threads, bool use_random_seed) {
cache_stat_t *simulate_at_multi_sizes_with_step_size(reader_t *const reader, const cache_t *cache, uint64_t step_size,
reader_t *warmup_reader, double warmup_frac, int warmup_sec,
int num_of_threads, bool use_random_seed) {
int num_of_sizes = (int)ceil((double)cache->cache_size / (double)step_size);
get_num_of_req(reader);
uint64_t *cache_sizes = my_malloc_n(uint64_t, num_of_sizes);
for (int i = 0; i < num_of_sizes; i++) {
cache_sizes[i] = step_size * (i + 1);
}

cache_stat_t *res = simulate_at_multi_sizes(
reader, cache, num_of_sizes, cache_sizes, warmup_reader, warmup_frac,
warmup_sec, num_of_threads, use_random_seed);
cache_stat_t *res = simulate_at_multi_sizes(reader, cache, num_of_sizes, cache_sizes, warmup_reader, warmup_frac,
warmup_sec, num_of_threads, use_random_seed);
my_free(sizeof(uint64_t) * num_of_sizes, cache_sizes);
return res;
}
Expand All @@ -172,13 +167,9 @@ cache_stat_t *simulate_at_multi_sizes_with_step_size(
* note that warmup_reader, warmup_frac and warmup_sec are mutually exclusive
*
*/
cache_stat_t *simulate_at_multi_sizes(reader_t *reader, const cache_t *cache,
int num_of_sizes,
const uint64_t *cache_sizes,
reader_t *warmup_reader,
double warmup_frac, int warmup_sec,
int num_of_threads,
bool use_random_seed) {
cache_stat_t *simulate_at_multi_sizes(reader_t *reader, const cache_t *cache, int num_of_sizes,
const uint64_t *cache_sizes, reader_t *warmup_reader, double warmup_frac,
int warmup_sec, int num_of_threads, bool use_random_seed) {
int progress = 0;

cache_stat_t *result = my_malloc_n(cache_stat_t, num_of_sizes);
Expand All @@ -190,24 +181,21 @@ cache_stat_t *simulate_at_multi_sizes(reader_t *reader, const cache_t *cache,
params->warmup_reader = warmup_reader;
params->warmup_sec = warmup_sec;
params->n_caches = num_of_sizes;
params->n_warmup_req =
(uint64_t)((double)get_num_of_req(reader) * warmup_frac);
params->n_warmup_req = (uint64_t)((double)get_num_of_req(reader) * warmup_frac);
params->result = result;
params->free_cache_when_finish = true;
params->progress = &progress;
params->use_random_seed = use_random_seed;
g_mutex_init(&(params->mtx));

// build the thread pool
GThreadPool *gthread_pool = g_thread_pool_new(
(GFunc)_simulate, (gpointer)params, num_of_threads, TRUE, NULL);
GThreadPool *gthread_pool = g_thread_pool_new((GFunc)_simulate, (gpointer)params, num_of_threads, TRUE, NULL);
ASSERT_NOT_NULL(gthread_pool, "cannot create thread pool in simulator\n");

// start computation
params->caches = my_malloc_n(cache_t *, num_of_sizes);
for (int i = 1; i < num_of_sizes + 1; i++) {
params->caches[i - 1] =
create_cache_with_new_size(cache, cache_sizes[i - 1]);
params->caches[i - 1] = create_cache_with_new_size(cache, cache_sizes[i - 1]);
result[i - 1].cache_size = cache_sizes[i - 1];
ASSERT_TRUE(g_thread_pool_push(gthread_pool, GSIZE_TO_POINTER(i), NULL),
"cannot push data into thread_pool in get_miss_ratio\n");
Expand All @@ -220,8 +208,8 @@ cache_stat_t *simulate_at_multi_sizes(reader_t *reader, const cache_t *cache,
INFO(
"%s starts computation %s, num_warmup_req %lld, start cache size %s, "
"end cache size %s, %d sizes, %d threads, please wait\n",
__func__, cache->cache_name, (long long)(params->n_warmup_req),
start_cache_size, end_cache_size, num_of_sizes, num_of_threads);
__func__, cache->cache_name, (long long)(params->n_warmup_req), start_cache_size, end_cache_size, num_of_sizes,
num_of_threads);

// wait for all simulations to finish
while (progress < (uint64_t)num_of_sizes - 1) {
Expand Down Expand Up @@ -250,13 +238,9 @@ cache_stat_t *simulate_at_multi_sizes(reader_t *reader, const cache_t *cache,
* @param num_of_threads
* @return cache_stat_t*
*/
cache_stat_t *simulate_with_multi_caches(reader_t *reader, cache_t *caches[],
int num_of_caches,
reader_t *warmup_reader,
double warmup_frac, int warmup_sec,
int num_of_threads,
bool free_cache_when_finish,
bool use_random_seed) {
cache_stat_t *simulate_with_multi_caches(reader_t *reader, cache_t *caches[], int num_of_caches,
reader_t *warmup_reader, double warmup_frac, int warmup_sec,
int num_of_threads, bool free_cache_when_finish, bool use_random_seed) {
assert(num_of_caches > 0);
int i, progress = 0;

Expand All @@ -271,8 +255,7 @@ cache_stat_t *simulate_with_multi_caches(reader_t *reader, cache_t *caches[],
params->warmup_sec = warmup_sec;
params->use_random_seed = use_random_seed;
if (warmup_frac > 1e-6) {
params->n_warmup_req =
(uint64_t)((double)get_num_of_req(reader) * warmup_frac);
params->n_warmup_req = (uint64_t)((double)get_num_of_req(reader) * warmup_frac);
} else {
params->n_warmup_req = 0;
}
Expand All @@ -282,8 +265,7 @@ cache_stat_t *simulate_with_multi_caches(reader_t *reader, cache_t *caches[],
g_mutex_init(&(params->mtx));

// build the thread pool
GThreadPool *gthread_pool = g_thread_pool_new(
(GFunc)_simulate, (gpointer)params, num_of_threads, TRUE, NULL);
GThreadPool *gthread_pool = g_thread_pool_new((GFunc)_simulate, (gpointer)params, num_of_threads, TRUE, NULL);
ASSERT_NOT_NULL(gthread_pool, "cannot create thread pool in simulator\n");

// start computation
Expand All @@ -301,9 +283,8 @@ cache_stat_t *simulate_with_multi_caches(reader_t *reader, cache_t *caches[],
INFO(
"%s starts computation, num_warmup_req %lld, start cache %s size %s, "
"end cache %s size %s, %d caches, %d threads, please wait\n",
__func__, (long long)(params->n_warmup_req), caches[0]->cache_name,
start_cache_size, caches[num_of_caches - 1]->cache_name, end_cache_size,
num_of_caches, num_of_threads);
__func__, (long long)(params->n_warmup_req), caches[0]->cache_name, start_cache_size,
caches[num_of_caches - 1]->cache_name, end_cache_size, num_of_caches, num_of_threads);

// wait for all simulations to finish
while (progress < (uint64_t)num_of_caches - 1) {
Expand Down
36 changes: 15 additions & 21 deletions test/test_evictionAlgo.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ static void test_BeladySize(gconstpointer user_data) {
}

static void test_Random(gconstpointer user_data) {
uint64_t miss_cnt_true[] = {92525, 88564, 84428, 80194, 76149, 72098, 68188, 64226};
uint64_t miss_byte_true[] = {4172728832, 3974521344, 3759748608, 3536509952,
3323991552, 3112196096, 2914519040, 2723145216};
uint64_t miss_cnt_true[] = {92457, 88582, 84459, 80277, 76132, 72134, 68230, 64225};
uint64_t miss_byte_true[] = {4170166272, 3975292416, 3757524992, 3539850752,
3321110016, 3113551360, 2917275648, 2725705216};

reader_t *reader = (reader_t *)user_data;
common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 12, .default_ttl = DEFAULT_TTL};
Expand Down Expand Up @@ -203,9 +203,9 @@ static void test_GDSF(gconstpointer user_data) {
}

static void test_LHD(gconstpointer user_data) {
int64_t miss_cnt_true[] = {90483, 86854, 82396, 77280, 71365, 66809, 63819, 61148};
uint64_t miss_byte_true[] = {4208204288, 4057671680, 3835295232, 3596758016,
3325300736, 3115318272, 2956866560, 2808430592};
uint64_t miss_cnt_true[] = {90534, 86891, 82334, 77339, 71355, 66938, 63677, 61116};
uint64_t miss_byte_true[] = {4211037696, 4059153920, 3834546176, 3596945408,
3326034944, 3115964416, 2951718912, 2804600832};

reader_t *reader = (reader_t *)user_data;
common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL};
Expand All @@ -220,15 +220,9 @@ static void test_LHD(gconstpointer user_data) {
}

static void test_Hyperbolic(gconstpointer user_data) {
// uint64_t miss_cnt_true[] = {92922, 89464, 83434, 81218, 74543, 71236, 69365, 65355};
// uint64_t miss_byte_true[] = {4213470720, 4065431040, 3766589952, 3643898368,
// 3245191168, 3035883008, 2940686336, 2755298816};
uint64_t miss_cnt_true[] = {92922, 89464, 83434, 81226, 74543, 71236, 69365, 65355};
uint64_t miss_byte_true[] = {4213470720, 4065431040, 3766589952, 3644547072,
3245191168, 3035883008, 2940686336, 2755298816};
// uint64_t miss_cnt_true[] = {92922, 89478, 83434, 81226, 74543, 71236, 69365, 65355};
// uint64_t miss_byte_true[] = {4213470720, 4065774592, 3766589952, 3644547072,
// 3245191168, 3035883008, 2940686336, 2755298816};
uint64_t miss_cnt_true[] = {92924, 89470, 83452, 81234, 74544, 71234, 69356, 65338};
uint64_t miss_byte_true[] = {4213586432, 4064826368, 3766646272, 3644941824,
3245021184, 3035783168, 2939981312, 2754100224};

reader_t *reader = (reader_t *)user_data;
common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 18, .default_ttl = DEFAULT_TTL};
Expand All @@ -243,9 +237,9 @@ static void test_Hyperbolic(gconstpointer user_data) {
}

static void test_LeCaR(gconstpointer user_data) {
uint64_t miss_cnt_true[] = {93372, 89051, 79766, 81628, 72074, 67719, 65703, 66501};
uint64_t miss_byte_true[] = {4214290944, 4019908096, 3616905728, 3658493952,
3063654400, 2886511616, 2762634752, 2753583104};
uint64_t miss_cnt_true[] = {93374, 89067, 80230, 81526, 72159, 67712, 65206, 64541};
uint64_t miss_byte_true[] = {4214303232, 4021100032, 3593971712, 3652036096,
3075125760, 2886052864, 2735856128, 2698478080};

reader_t *reader = (reader_t *)user_data;
common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL};
Expand All @@ -260,9 +254,9 @@ static void test_LeCaR(gconstpointer user_data) {
}

static void test_Cacheus(gconstpointer user_data) {
uint64_t miss_cnt_true[] = {89868, 82069, 79774, 75123, 69478, 69513, 69101, 66009};
uint64_t miss_byte_true[] = {4044667904, 3688304128, 3537534976, 3260361216,
2995897856, 2965061120, 2925572096, 2785997824};
uint64_t miss_cnt_true[] = {89328, 82377, 80079, 77111, 69654, 69492, 69165, 66072};
uint64_t miss_byte_true[] = {4025448960, 3727429632, 3554795008, 3359375872,
3003613696, 2964137472, 2928446976, 2790086656};

reader_t *reader = (reader_t *)user_data;
common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL};
Expand Down

0 comments on commit 2c22bcf

Please sign in to comment.