在gem5中打印文件中的所有cache_blocks

Printing all cache_blocks in a file in gem5

本文关键字:cache blocks gem5 打印 文件      更新时间:2023-10-16

我需要在我定义的文本文件中,在每个预定的Tick(例如,每10000 Tick(打印所有cache_blocks及其关联集。有人知道我该怎么做吗?

关于经典的缓存模型,假设您的本地gem5副本与gem5-v19.0.0.0没有太大差异,您将不得不创建一个每X次发生的事件,并调用一个函数将您需要的内容打印到文件中。

您可能会使用BaseSetAssoc作为标记,但为了使其在下面的演练中具有通用性,我假设您已经实现了ExampleTags,这是一个继承自BaseTags的特殊标记类。

您必须将事件包装器添加到src/mem/cache/tags/example_tags.hh以及此包装器将调用的函数:

class ExampleTags : public BaseTags
{
protected:
EventFunctionWrapper snapshotEvent;
void takeSnapshot();
/** Whatever else is needed for this class. */
}

现在,转到src/mem/cache/tags/example_tags.cc。您的标签构造函数应该用它必须调用的函数初始化事件:

ExampleTags::ExampleTags(const Params *p)
: BaseTags(p),
/** ... Initialization of other members ... */
snapshotInterval(p->snapshot_interval),
snapshotEvent([this]{ takeSnapshot(); }, name())
{
// Constructor contents
}

然而,由于gem5初始化事物的方式,第一个事件不应该在构造函数中调度,而应该在startup((函数中调度,该函数必须从SimObject类重写。这是非常重要的,因为如果你是检查点,否则事情就会中断(curTick((在构造函数中有一个不正确的值(:

void
ExampleTags::startup()
{
BaseTags::startup();
// We can only store relevant block information after the blocks have
// been initialized
schedule(snapshotEvent, curTick() + snapshotInterval);
} 

最后,快照函数包含您在此间隔内想要做的任何事情:

void
ExampleTags::takeSnapshot()
{
// You can even use the tags' forEachBlk()
for (const auto& blk : blks) {
// Print what you need to the file. The blk.print() function
// can satisfy your needs
}
// Schedule next snapshot
schedule(snapshotEvent, curTick() + snapshotInterval);
}

snapshot_interval将在标签的等效python声明中声明,在src/mem/cache/tags/tags.py中:

class ExampleTags(BaseTags):
# ... Other parameters of these tags ...
snapshot_interval = Param.Unsigned(10000,
"Number of ticks between snapshots")