Skip to content

Commit

Permalink
i#6893: Delete unused cacheline snoop objects. (#6906)
Browse files Browse the repository at this point in the history
The snoop cache tracks sharing for each cacheline accessed. The prior
code never deleted these tracking structures once they were allocated,
causing the tracking data to grow with every new cacheline touched. This
change deletes cacheline trackers once the cacheline is no longer
present in any tracked cache. It also changes the container used for
tracking from a vector of bools to a set of cache IDs, to simplify
snooped cache lookup and iteration.

Fixes: #6893
  • Loading branch information
brettcoon committed Aug 2, 2024
1 parent 7d39db4 commit b3348cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
36 changes: 18 additions & 18 deletions clients/drcachesim/simulator/snoop_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ void
snoop_filter_t::snoop(addr_t tag, int id, bool is_write)
{
coherence_table_entry_t *coherence_entry = &coherence_table_[tag];
// Initialize new snoop filter entry.
if (coherence_entry->sharers.empty()) {
coherence_entry->sharers.resize(num_snooped_caches_, false);
coherence_entry->dirty = false;
}

auto num_sharers = std::count(coherence_entry->sharers.begin(),
coherence_entry->sharers.end(), true);
size_t num_sharers = coherence_entry->sharers.size();

// Check that cache id is valid.
assert(id >= 0 && id < num_snooped_caches_);
Expand All @@ -91,7 +85,8 @@ snoop_filter_t::snoop(addr_t tag, int id, bool is_write)
assert(!coherence_entry->dirty || num_sharers == 1);

// Check if this request causes a writeback.
if (!coherence_entry->sharers[id] && coherence_entry->dirty) {
if (coherence_entry->sharers.find(id) == coherence_entry->sharers.end() &&
coherence_entry->dirty) {
num_writebacks_++;
coherence_entry->dirty = false;
}
Expand All @@ -101,16 +96,18 @@ snoop_filter_t::snoop(addr_t tag, int id, bool is_write)
coherence_entry->dirty = true;
if (num_sharers > 0) {
// Writes will invalidate other caches_.
for (int i = 0; i < num_snooped_caches_; i++) {
if (coherence_entry->sharers[i] && id != i) {
caches_[i]->invalidate(tag, INVALIDATION_COHERENCE);
num_invalidates_++;
coherence_entry->sharers[i] = false;
}
auto it = coherence_entry->sharers.begin();
while (it != coherence_entry->sharers.end()) {
int i = *it++;
if (i == id)
continue;
caches_[i]->invalidate(tag, INVALIDATION_COHERENCE);
num_invalidates_++;
coherence_entry->sharers.erase(i);
}
}
}
coherence_entry->sharers[id] = true;
coherence_entry->sharers.insert(id);
}

/* This function is called whenever a coherent cache evicts a line. */
Expand All @@ -120,20 +117,23 @@ snoop_filter_t::snoop_eviction(addr_t tag, int id)
coherence_table_entry_t *coherence_entry = &coherence_table_[tag];

// Check if sharer list is initialized.
assert(coherence_entry->sharers.size() == (uint64_t)num_snooped_caches_);
assert(!coherence_entry->sharers.empty());
// Check that cache id is valid.
assert(id >= 0 && id < num_snooped_caches_);
// Check that tag is valid.
assert(tag != TAG_INVALID);
// Check that we currently have this cache marked as a sharer.
assert(coherence_entry->sharers[id]);
assert(coherence_entry->sharers.find(id) != coherence_entry->sharers.end());

if (coherence_entry->dirty) {
num_writebacks_++;
coherence_entry->dirty = false;
}

coherence_entry->sharers[id] = false;
coherence_entry->sharers.erase(id);
if (coherence_entry->sharers.empty()) {
coherence_table_.erase(tag);
}
}

void
Expand Down
5 changes: 3 additions & 2 deletions clients/drcachesim/simulator/snoop_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <stdint.h>

#include <unordered_map>
#include <unordered_set>
#include <vector>

#include "cache.h"
Expand All @@ -45,8 +46,8 @@ namespace dynamorio {
namespace drmemtrace {

struct coherence_table_entry_t {
std::vector<bool> sharers;
bool dirty;
std::unordered_set<int> sharers; // IDs of caches sharing this line.
bool dirty = false;
};

class snoop_filter_t {
Expand Down

0 comments on commit b3348cc

Please sign in to comment.