-
Notifications
You must be signed in to change notification settings - Fork 4
[RFC] Reimplement tachanka_ranking_touch_all function #33
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: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -579,26 +579,64 @@ MEMKIND_EXPORT bool tachanka_ranking_event_pop(EventEntry_t *event) | |
| return ranking_event_pop(&ranking_event_buff, event); | ||
| } | ||
|
|
||
| struct touch_data { | ||
| __u64 timestamp; | ||
| double add_hotness; | ||
| }; | ||
|
|
||
| static int tachanka_ranking_touch_all_internal(uintptr_t key, void *value, void *privdata) { | ||
| uint64_t timestamp = ((struct touch_data *)privdata)->timestamp; | ||
| double add_hotness = ((struct touch_data *)privdata)->add_hotness; | ||
| ranking_touch(ranking, (struct ttype *)value, timestamp, add_hotness); | ||
| return 0; | ||
| } | ||
|
|
||
| MEMKIND_EXPORT void tachanka_ranking_touch_all(__u64 timestamp, double add_hotness) | ||
| { | ||
| // TODO re-implement this function | ||
| // add API for getting specific element from slab_allocator | ||
| // and re-implement it | ||
| // for (int i = 0; i < ntypes; ++i) { | ||
| // ranking_touch(ranking, &ttypes[i], timestamp, add_hotness); | ||
| // } | ||
| struct touch_data privdata = {timestamp, add_hotness}; | ||
| critnib_iter(hash_to_type, 0, -1, *tachanka_ranking_touch_all_internal, &privdata); | ||
| } | ||
|
|
||
| struct frequencies { | ||
|
Collaborator
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. Ditto |
||
| double *freq; | ||
|
Collaborator
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. I think it would be clearer to use hotness instead of freq - frequency is there for historic reasons, currently hotness is not a direct measure of frequency. |
||
| size_t size; | ||
| }; | ||
|
|
||
| static int tachanka_get_frequency_internal(uintptr_t key, void *value, void *freqs) { | ||
| static size_t i = 0; | ||
| *(((struct frequencies *)freqs)->freq + i) = ((struct ttype *)value)->f; | ||
| i++; | ||
| if (i == ((struct frequencies *)freqs)->size) { | ||
|
Collaborator
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. If there are less ttypes than size, how do we know which entries are set and valid? Maybe we should store i as a field of struct frequencies - set it to zero before iterating over critnib and then iterate the way we do, without static variables? Another cool feature would be to know if overflow occurred - maybe we can store two counters, one absolute (not reset to 0 on overflow) and the other one that actually handles indices - reset to zero on overflow? This structure is not copied and only one instance is created per function call (stored on stack), additional counters have minimal overhead. In my mind, the code would also be more readable than with static int. |
||
| i = 0; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| // Getter used in the tachanka_check_ranking_touch_all test | ||
| MEMKIND_EXPORT double tachanka_get_frequency(size_t index) { | ||
| // TODO: re-implement (add API in slab_allocator first!) | ||
| // return ttypes[index].f; | ||
| MEMKIND_EXPORT void *tachanka_get_frequency(double *freqs, size_t size) { | ||
| struct frequencies frequencies = {freqs, size}; | ||
| critnib_iter(hash_to_type, 0, -1, *tachanka_get_frequency_internal, &frequencies); | ||
|
Collaborator
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. Please check previous comment - it applies to this place as well (extension of struct frequencies). |
||
| return 0; | ||
| } | ||
|
|
||
| struct timestamps { | ||
| TimestampState_t *timestamp; | ||
| size_t size; | ||
| }; | ||
|
|
||
| static int tachanka_get_timestamp_state_internal(uintptr_t key, void *value, void *ts) { | ||
| static size_t i = 0; | ||
|
Collaborator
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. The remark is exactly the same as the one for tachanka_get_frequency_internal |
||
| *(((struct timestamps *)ts)->timestamp + i) = ((struct ttype *)value)->timestamp_state; | ||
| i++; | ||
| if (i == ((struct timestamps *)ts)->size) { | ||
| i = 0; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| // Getter used in the tachanka_check_ranking_touch_all test | ||
| MEMKIND_EXPORT TimestampState_t tachanka_get_timestamp_state(size_t index) { | ||
| // TODO: re-implement (add API in slab_allocator first!) | ||
| // return ttypes[index].timestamp_state; | ||
| MEMKIND_EXPORT void *tachanka_get_timestamp_state(TimestampState_t *timestamps, size_t size) { | ||
| struct timestamps ts = {timestamps, size}; | ||
|
Collaborator
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. Ditto - possible update of struct timestamps |
||
| critnib_iter(hash_to_type, 0, -1, *tachanka_get_timestamp_state_internal, &ts); | ||
| return 0; | ||
| } | ||
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.
Why is this structure declared here, not at the top?