可参考前两篇:

Gem5运行时更改缓存替换算法的传参方法

Gem5运行时更改预取的传参方法

1.在common/Caches.py中,添加:

class L3Cache(Cache):
    assoc = 8
    tag_latency = 30
    data_latency = 30
    response_latency = 30
    mshrs = 20
    tgts_per_mshr = 12
    write_buffers = 8

2.在common/CacheConfig.py中,修改两处:

if options.l2cache:
        # Provide a clock for the L2 and the L1-to-L2 bus here as they
        # are not connected using addTwoLevelCacheHierarchy. Use the
        # same clock as the CPUs.
        system.l2 = l2_cache_class(
            clk_domain=system.cpu_clk_domain, **_get_cache_opts("l2", options)
        )

        system.tol2bus = L2XBar(clk_domain=system.cpu_clk_domain)
        system.l2.cpu_side = system.tol2bus.mem_side_ports
        
        if options.l3cache:
            system.l3 = L3Cache(
                clk_domain=system.cpu_clk_domain, **_get_cache_opts("l3", options)
            )

            system.tol3bus = L2XBar(clk_domain=system.cpu_clk_domain)  # 连接 L2 和 L3
            system.l3.cpu_side = system.tol3bus.mem_side_ports
            system.l3.mem_side = system.membus.cpu_side_ports  # L3 连接到内存总线

            # 让 L2 连接到 L3,而不是直接连接到 membus
            system.l2.mem_side = system.tol3bus.cpu_side_ports
        else:
            system.l2.mem_side = system.membus.cpu_side_ports

        if options.l2cache:
            if options.l3cache:
                system.cpu[i].connectAllPorts(
                    system.tol2bus.cpu_side_ports,
                    system.tol3bus.cpu_side_ports,  # 连接到 L3
                    system.membus.mem_side_ports,
                )
            else:
                system.cpu[i].connectAllPorts(
                    system.tol2bus.cpu_side_ports,
                    system.membus.cpu_side_ports,  # 没有 L3 时直接连到 membus
                    system.membus.mem_side_ports,
                )

3.在se.py中,添加:

parser.add_argument("--l3cache", action="store_true", help="Enable L3 cache")

parser.add_argument(
    "--l3_replacement_policy",
    choices=["LRU", "Random", "BRRIP", "TreePLRU", "DRRIP"],
 #   choices=["LRU", "Random", "BRRIP", "TreePLRU", "DRRIP", "ARRIP", "TUBINS", "EQPCN"],
    help="Replacement policy for L3 cache."
)

Options.l3_replacement_policy = args.l3_replacement_policy

4.在运行脚本中,添加:

--l3cache --num-l3caches=1 --l3_size=1MB --l3_assoc=4  --l3_replacement_policy=LRU \

5.在运行结果stat/config.json中,可以看到是否添加成功:

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐