-
Notifications
You must be signed in to change notification settings - Fork 64
Remove GLib dependency within bin/ #184
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
base: develop
Are you sure you want to change the base?
Changes from 13 commits
1155efd
bec3b4e
b8b2895
41662dc
f9d1c49
6177f2d
f7d58de
88b7048
2a9dde1
9cf2913
7e7c41d
af3ff57
61fb3cd
f360f63
5f292f4
5ebea84
805efbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,44 +20,54 @@ extern "C" { | |
uint64_t simulate_shards_mrc(struct PARAM *params); | ||
|
||
// Compute reuse distance for each request in fixed-rate mode. | ||
int64_t compute_distance_fixed_rate(struct PARAM *params, request_t *req, uint64_t timestamp) { | ||
int64_t compute_distance_fixed_rate(struct PARAM *params, request_t *req, | ||
uint64_t timestamp) { | ||
int64_t last_access = -1; | ||
int64_t distance = | ||
get_stack_dist_add_req(req, ¶ms->distance_tree, params->lookup_hash, (int64_t)timestamp, &last_access); | ||
get_stack_dist_add_req(req, ¶ms->distance_tree, params->lookup_hash, | ||
(int64_t)timestamp, &last_access); | ||
return distance; | ||
} | ||
|
||
// Compute reuse distance for each request in fixed-size mode. | ||
int64_t compute_distance_fixed_size(struct PARAM *params, request_t *req, uint64_t timestamp) { | ||
int64_t compute_distance_fixed_size(struct PARAM *params, request_t *req, | ||
uint64_t timestamp) { | ||
int64_t last_access = -1; | ||
int64_t distance = | ||
get_stack_dist_add_req(req, ¶ms->distance_tree, params->lookup_hash, (int64_t)timestamp, &last_access); | ||
get_stack_dist_add_req(req, ¶ms->distance_tree, params->lookup_hash, | ||
(int64_t)timestamp, &last_access); | ||
|
||
// If the object has not been accessed before, insert it into the priority tree. | ||
// If the object has not been accessed before, insert it into the priority | ||
// tree. | ||
if (distance == -1) { | ||
struct key *new_tuple = malloc(sizeof(struct key)); | ||
new_tuple->L = req->obj_id; | ||
new_tuple->Tmax = (req->hv) & ((1 << 24) - 1); | ||
params->prio_tree = insert_t(new_tuple, params->prio_tree); | ||
} | ||
|
||
// Update the priority tree and lookup hash when number of stored objects exceeds the threshold. | ||
while (params->prio_tree != NULL && params->prio_tree->value >= params->threshold) { | ||
|
||
// Update the priority tree and lookup hash when number of stored objects | ||
// exceeds the threshold. | ||
while (params->prio_tree != NULL && | ||
params->prio_tree->value >= params->threshold) { | ||
struct key *max = find_max_t(params->prio_tree)->key; | ||
uint64_t last_max = 0; | ||
params->rate = (double)max->Tmax / (double)(1 << 24); | ||
//printf("rate: %f\n", params->rate); | ||
// Update the sampler ratio when stored object overflows | ||
// printf("rate: %f\n", params->rate); | ||
// Update the sampler ratio when stored object overflows | ||
params->reader->sampler->sampling_ratio = params->rate; | ||
while ((last_max == max->Tmax) || (last_max == 0)) { | ||
obj_id_t id = max->L; | ||
if (id==req->obj_id) distance = -2; | ||
if (id == req->obj_id) distance = -2; | ||
last_max = max->Tmax; | ||
// Remove the key from prio_tree and update lookup and distance_tree. | ||
params->prio_tree = splay_delete_t(max, params->prio_tree); | ||
gpointer hash_value_inner = g_hash_table_lookup(params->lookup_hash, GSIZE_TO_POINTER((gsize)id)); | ||
g_hash_table_remove(params->lookup_hash, GSIZE_TO_POINTER((gsize)id)); | ||
params->distance_tree = splay_delete((long long)hash_value_inner, params->distance_tree); | ||
void *hash_value_inner = | ||
hashmap_get(params->lookup_hash, (const void *)id, sizeof(obj_id_t)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace the conversion with macro? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I shall define a new header file to accommodate these common GLib macros |
||
hashmap_remove(params->lookup_hash, (const void *)id, sizeof(obj_id_t)); | ||
|
||
params->distance_tree = | ||
splay_delete((long long)hash_value_inner, params->distance_tree); | ||
if (params->prio_tree) | ||
max = find_max_t(params->prio_tree)->key; | ||
else | ||
|
@@ -72,7 +82,7 @@ uint64_t simulate_shards_mrc(struct PARAM *params) { | |
reader_t *reader = params->reader; | ||
request_t *req = new_request(); | ||
uint64_t timestamp = 0; | ||
uint64_t n_req=0; | ||
uint64_t n_req = 0; | ||
read_one_req(reader, req); | ||
while (req->valid) { | ||
int64_t distance = params->compute_distance(params, req, timestamp); | ||
|
@@ -82,7 +92,7 @@ uint64_t simulate_shards_mrc(struct PARAM *params) { | |
n_req++; | ||
continue; | ||
} | ||
update_histogram(params->data, distance, params->rate); | ||
update_histogram(params->data, distance, params->rate); | ||
read_one_req(reader, req); | ||
timestamp++; | ||
n_req++; | ||
|
@@ -107,21 +117,27 @@ void generate_shards_mrc(struct PARAM *params, char *path) { | |
params->data = init_histogram(); | ||
params->prio_tree = NULL; | ||
params->distance_tree = NULL; | ||
params->lookup_hash = g_hash_table_new(g_direct_hash, g_direct_equal); | ||
hashmap_create_options_t lookup_hash_create_options = { | ||
.initial_capacity = 16, | ||
.comparer = obj_id_comparer, | ||
.hasher = obj_id_hasher}; | ||
params->lookup_hash = malloc(sizeof(hashmap_t)); | ||
hashmap_create_ex(lookup_hash_create_options, params->lookup_hash); | ||
|
||
// Start the simulation. | ||
uint64_t read_req=simulate_shards_mrc(params); | ||
uint64_t read_req = simulate_shards_mrc(params); | ||
|
||
// In fixed-size mode, perform additional post-processing. | ||
if (params->ver == true) { | ||
wrap_up_histogram(params->data, params->rate); | ||
} | ||
|
||
//SHARDS-adj | ||
// SHARDS-adj | ||
adjust_histogram(params->data, n_req, params->rate); | ||
|
||
export_histogram_to_csv(params->data, params->rate, path); | ||
g_hash_table_destroy(params->lookup_hash); | ||
hashmap_destroy(params->lookup_hash); | ||
free(params->lookup_hash); | ||
free_sTree_t(params->prio_tree); | ||
free_sTree(params->distance_tree); | ||
close_reader(params->reader); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some documentation on how to use the data structures in the repo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to add the documentation in |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
#include <assert.h> | ||
#include <string.h> | ||
|
||
#include "../include/libCacheSim/hashmap.h" | ||
#include "../include/libCacheSim/hashmap_defs.in" | ||
#include "../include/libCacheSim/reader.h" | ||
#include "../utils/include/mystr.h" | ||
|
||
|
@@ -242,7 +244,12 @@ void cal_working_set_size(reader_t *reader, int64_t *wss_obj, | |
int64_t *wss_byte) { | ||
reset_reader(reader); | ||
request_t *req = new_request(); | ||
GHashTable *obj_table = g_hash_table_new(g_direct_hash, g_direct_equal); | ||
hashmap_create_options_t obj_table_create_options = { | ||
.initial_capacity = 16, | ||
.comparer = obj_id_comparer, | ||
.hasher = obj_id_hasher}; | ||
struct hashmap_s new_obj_table; | ||
hashmap_create_ex(obj_table_create_options, &new_obj_table); | ||
*wss_obj = 0; | ||
*wss_byte = 0; | ||
|
||
|
@@ -267,11 +274,12 @@ void cal_working_set_size(reader_t *reader, int64_t *wss_obj, | |
continue; | ||
} | ||
|
||
if (g_hash_table_contains(obj_table, (gconstpointer)req->obj_id)) { | ||
if (hashmap_get(&new_obj_table, (const void *)(req->obj_id), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just use obj_id as the key? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is done as so. There is a custom hasher for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to previous issue, let's use a custom macro to wrap the conversion so that it would be easier to change if need to migrate and refactor later. |
||
sizeof(obj_id_t)) != NULL) { | ||
continue; | ||
} | ||
|
||
g_hash_table_add(obj_table, (gpointer)req->obj_id); | ||
hashmap_put(&new_obj_table, (void *)(req->obj_id), sizeof(obj_id_t), req); | ||
|
||
*wss_obj += 1; | ||
*wss_byte += req->obj_size; | ||
|
@@ -289,7 +297,7 @@ void cal_working_set_size(reader_t *reader, int64_t *wss_obj, | |
(long long)*wss_byte); | ||
} | ||
|
||
g_hash_table_destroy(obj_table); | ||
hashmap_destroy(&new_obj_table); | ||
free_request(req); | ||
reset_reader(reader); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debugging information?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 didn't quite get what you mean, do I need to add some
DEBUG()
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, when I read it yesterday, it was about some code that was commented out. Just want to remind you to remove unneeded code before merge. If some debugging-related code is needed and you want to keep the code, it is also ok as long as you add a comment stating why it is kept.