问题描述
在调试--debug-flag Cache
的问题时,我注意到此printf:
bool
MSHR::handleSnoop(PacketPtr pkt,Counter _order)
{
DPRINTF(Cache,"%s for %s\n",__func__,pkt->print());
打印为:
7306617000: Cache: global: handleSnoop for WriteReq [80a70800:80a70803] UC D=110e0000
这有点令人困惑,因为大多数DPRINTF
行都具有simobject的完整路径,如system.cpu5.dcache
中的
7306617000: Cache: system.cpu5.dcache: sendWriteQueuePacket: write WriteReq [80a70800:80a70803] UC D=110e0000
global
是什么意思?
在gem5 3ca404da175a66e0b958165ad75eb5f54cb5e772中进行了测试。
解决方法
global只是意味着DPRINTF
既不是从SimObject调用的,也不是从实现name()
方法的类中调用的。
通过扩展DPRINTF
的定义,我们看到它调用name()
:
#define DPRINTF(x,...) do { \
using namespace Debug; \
if (DTRACE(x)) { \
Trace::getDebugLogger()->dprintf_flag( \
curTick(),name(),#x,__VA_ARGS__); \
} \
} while (0)
和name()
在SimObject
基类上定义:
virtual const std::string name() const { return params()->name; }
但是,如果一个类不是从SimObject
派生出来的,也不是实现自定义name()
的,那么它只能解析为name()
中声明的全局src/base/trace.hh
:
// Return the global context name "global". This function gets called when
// the DPRINTF macros are used in a context without a visible name() function
const std::string &name();
实现为:
const std::string &name()
{
static const std::string default_name("global");
return default_name;
}
因此在上面的示例中,MSHR
不是SimObject
,而是Cache
。