如何访问 gem5 线程统计信息?

How can I access gem5 thread stats?

我希望在我的一些工作中使用 gem5,并且有一个关于它的功能的非常普遍的问题。

我的问题是,使用 gem5,我能否在 SE 或 FS 模式下获得有关单个线程的行为/系统资源使用情况的统计信息。例如,如果我的应用程序中有 2 个线程 运行,我可以看到线程 1 在 CPU 1 上使用 X 周期,在 CPU 2 上使用 Y 周期等,而线程 2 使用 Z CPU 3 等循环。如果可能,它是否也扩展到缓存使用、内存使用等?

我看到了以下问题:Accessing logical (software) thread ID in gem5,但我认为仅使用硬件线程统计信息就可以满足我们的用例。

我看到 src/cpu/thread_state.hh 中的 ThreadState class 具有以下字段:

/** Number of instructions committed. */
Counter numInst;
/** Stat for number instructions committed. */
Stats::Scalar numInsts;
/** Number of ops (including micro ops) committed. */
Counter numOp;
/** Stat for number ops (including micro ops) committed. */
Stats::Scalar numOps;
/** Stat for number of memory references. */
Stats::Scalar numMemRefs;

这看起来像是我可以使用的东西。有谁知道这些统计信息是否可以很容易地在统计文件中按线程输出?

谢谢!

我自己没有做过,但我会做出以下有根据的猜测:

  • se.py:SE 有一个限制,它只能 运行 每个核心一个线程,所以我怀疑这会直接显示在每个核心统计数据上

  • fs.py: 线程的定义是 OS 依赖的,所以你需要某种来宾支持。

    例如,在 ARM Linux 内核跟踪的上下文中,CONFIG_PID_IN_CONTEXTIDR 在日志中显示:How to access logical software user thread ID of a Linux process in gem5? 但不确定获取统计信息的难易程度

很可能 se.py 会是更简单的方法。

--enable-context-switch-stats-dump

我刚刚在阅读一些资料时遇到了这个选项:

        parser.add_option("--enable-context-switch-stats-dump", \
                action="store_true", help="Enable stats dump at context "\
                "switches and dump tasks file (required for Streamline)")

它似乎挂钩然后 PC 命中 __switch_to 内核符号地址:

void
FsLinux::startup()
{
    FsWorkload::startup();

    if (enableContextSwitchStatsDump) {
        if (getArch() == Loader::Arm64)
            dumpStats = addKernelFuncEvent<DumpStats64>("__switch_to");
        else
            dumpStats = addKernelFuncEvent<DumpStats>("__switch_to");

所以这应该为每个上下文切换转储每个线程!

不过我还没有测试过,我想知道将哪个线程关联起来有多容易。