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

[RFC] Reimplement tachanka_ranking_touch_all function #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PatKamin
Copy link
Collaborator

@PatKamin PatKamin commented Nov 30, 2021

Description

Types of changes

  • Bugfix (non-breaking change which fixes issue linked in Description above)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (correction or otherwise)
  • Cosmetics (whitespace, appearance)
  • Other

Checklist

  • Code compiles without errors
  • All tests pass locally with my changes (see TESTING section in CONTRIBUTING file)
  • Created tests which will fail without the change (if possible)
  • Extended the README/documentation (if necessary)
  • All newly added files have proprietary license (if necessary)
  • All newly added files are referenced in MANIFEST files (if necessary)

Further comments


This change is Reviewable

Reshape tests for this function and reimplement helper functions for
tests purposes.
@@ -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 {
Copy link
Collaborator

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?

critnib_iter(hash_to_type, 0, -1, *tachanka_ranking_touch_all_internal, &privdata);
}

struct frequencies {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

}

struct frequencies {
double *freq;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

static size_t i = 0;
*(((struct frequencies *)freqs)->freq + i) = ((struct ttype *)value)->f;
i++;
if (i == ((struct frequencies *)freqs)->size) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

// 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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).

};

static int tachanka_get_timestamp_state_internal(uintptr_t key, void *value, void *ts) {
static size_t i = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

// 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};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto - possible update of struct timestamps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants