mem-cache: Simplify generation of stride prefetcher table
Some compilers (gcc version 12.3.0) will start complaining when perfect forwarding the StrideEntry argument constructed with an extra parameter (see later patches). Using a pointer seems to fix the gcc bug. The commit is also changing the signature of findTable and allocateContext so that a reference rather than a pointer is return. In this way we don't deal with the hack of returning a raw ptr from a unique_ptr Change-Id: Idd451208aae80bbfae76110c859e93084bcb2635 Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
This commit is contained in:
37
src/mem/cache/prefetch/stride.cc
vendored
37
src/mem/cache/prefetch/stride.cc
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2012-2013, 2015, 2022-2023 Arm Limited
|
||||
* Copyright (c) 2012-2013, 2015, 2022-2024 Arm Limited
|
||||
* All rights reserved
|
||||
*
|
||||
* The license below extends only to copyright in the software and shall
|
||||
@@ -91,36 +91,35 @@ Stride::Stride(const StridePrefetcherParams &p)
|
||||
{
|
||||
}
|
||||
|
||||
Stride::PCTable*
|
||||
Stride::PCTable&
|
||||
Stride::findTable(int context)
|
||||
{
|
||||
// Check if table for given context exists
|
||||
auto it = pcTables.find(context);
|
||||
if (it != pcTables.end())
|
||||
return &it->second;
|
||||
return *(it->second);
|
||||
|
||||
// If table does not exist yet, create one
|
||||
return allocateNewContext(context);
|
||||
}
|
||||
|
||||
Stride::PCTable*
|
||||
Stride::PCTable&
|
||||
Stride::allocateNewContext(int context)
|
||||
{
|
||||
std::string table_name = name() + ".PCTable" + std::to_string(context);
|
||||
// Create new table
|
||||
auto ins_result = pcTables.emplace(std::piecewise_construct,
|
||||
std::forward_as_tuple(context),
|
||||
std::forward_as_tuple(table_name.c_str(),
|
||||
pcTableInfo.numEntries,
|
||||
pcTableInfo.assoc,
|
||||
pcTableInfo.replacementPolicy,
|
||||
pcTableInfo.indexingPolicy,
|
||||
StrideEntry(initConfidence)));
|
||||
pcTables[context].reset(new PCTable(
|
||||
table_name.c_str(),
|
||||
pcTableInfo.numEntries,
|
||||
pcTableInfo.assoc,
|
||||
pcTableInfo.replacementPolicy,
|
||||
pcTableInfo.indexingPolicy,
|
||||
StrideEntry(initConfidence)));
|
||||
|
||||
DPRINTF(HWPrefetch, "Adding context %i with stride entries\n", context);
|
||||
|
||||
// Get iterator to new pc table, and then return a pointer to the new table
|
||||
return &(ins_result.first->second);
|
||||
// return a reference to the new table
|
||||
return *(pcTables[context]);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -141,13 +140,13 @@ Stride::calculatePrefetch(const PrefetchInfo &pfi,
|
||||
RequestorID requestor_id = useRequestorId ? pfi.getRequestorId() : 0;
|
||||
|
||||
// Get corresponding pc table
|
||||
PCTable* pcTable = findTable(requestor_id);
|
||||
PCTable& pc_table = findTable(requestor_id);
|
||||
|
||||
// Search for entry in the pc table
|
||||
StrideEntry *entry = pcTable->findEntry(pc, is_secure);
|
||||
StrideEntry *entry = pc_table.findEntry(pc, is_secure);
|
||||
|
||||
if (entry != nullptr) {
|
||||
pcTable->accessEntry(entry);
|
||||
pc_table.accessEntry(entry);
|
||||
|
||||
// Hit in table
|
||||
int new_stride = pf_addr - entry->lastAddr;
|
||||
@@ -198,11 +197,11 @@ Stride::calculatePrefetch(const PrefetchInfo &pfi,
|
||||
DPRINTF(HWPrefetch, "Miss: PC %x pkt_addr %x (%s)\n", pc, pf_addr,
|
||||
is_secure ? "s" : "ns");
|
||||
|
||||
StrideEntry* entry = pcTable->findVictim(pc);
|
||||
StrideEntry* entry = pc_table.findVictim(pc);
|
||||
|
||||
// Insert new entry's data
|
||||
entry->lastAddr = pf_addr;
|
||||
pcTable->insertEntry(pc, is_secure, entry);
|
||||
pc_table.insertEntry(pc, is_secure, entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
8
src/mem/cache/prefetch/stride.hh
vendored
8
src/mem/cache/prefetch/stride.hh
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Inria
|
||||
* Copyright (c) 2012-2013, 2015, 2022 Arm Limited
|
||||
* Copyright (c) 2012-2013, 2015, 2022, 2024 Arm Limited
|
||||
* All rights reserved
|
||||
*
|
||||
* The license below extends only to copyright in the software and shall
|
||||
@@ -145,7 +145,7 @@ class Stride : public Queued
|
||||
SatCounter8 confidence;
|
||||
};
|
||||
typedef AssociativeSet<StrideEntry> PCTable;
|
||||
std::unordered_map<int, PCTable> pcTables;
|
||||
std::unordered_map<int, std::unique_ptr<PCTable>> pcTables;
|
||||
|
||||
/**
|
||||
* If this parameter is set to true, then the prefetcher will operate at
|
||||
@@ -161,7 +161,7 @@ class Stride : public Queued
|
||||
* @param context The context to be searched for.
|
||||
* @return The table corresponding to the given context.
|
||||
*/
|
||||
PCTable* findTable(int context);
|
||||
PCTable& findTable(int context);
|
||||
|
||||
/**
|
||||
* Create a PC table for the given context.
|
||||
@@ -169,7 +169,7 @@ class Stride : public Queued
|
||||
* @param context The context of the new PC table.
|
||||
* @return The new PC table
|
||||
*/
|
||||
PCTable* allocateNewContext(int context);
|
||||
PCTable& allocateNewContext(int context);
|
||||
|
||||
public:
|
||||
Stride(const StridePrefetcherParams &p);
|
||||
|
||||
Reference in New Issue
Block a user