LAB/GEM5

GEM5에 L3 Cache 추가

RyoTTa 2021. 3. 13. 16:06
반응형

1. configs/common/Options.py 파일에 l3 cache option 추가

parser.add_option("--l3cache", action="store_true")

 

2. configs/common/Caches.py 파일에 l3 cache class 추가

class L3Cache(Cache):
    assoc = 16
    tag_latency = 32
    data_latency = 32
    response_latency = 32
    mshrs = 32
    tgts_per_mshr = 24
    write_buffers = 16

 

3. src/mem/XBar.py 파일에 L3XBar class 추가

class L3XBar(CoherentXBar):
    width = 32
    frontend_latency = 1
    forward_latency = 0
    response_latency = 1
    snoop_response_latency = 1
    snoop_filter = SnoopFilter(lookup_latency = 0)
    point_of_unification = True

 

4. src/cpu/BaseCPU.py 파일에 L3XBar import

from XBar import L3XBar

 

5. src/cpu/BaseCPU.py 파일에 addThreeLevelCacheHierarchy() 함수 정의

def addThreeLevelCacheHierarchy(self, ic, dc, l2c, iwc = None, dwc = None):
    self.addPrivateSplitL2Caches(ic, dc, iwc, dwc)
    self.toL3Bus = L3XBar()
    self.connectCachedPorts(self.toL3Bus)
    self.l3cache = l3c
    self.toL3Bus.master = self.l3cache.cpu_side
    self._cached_ports = ['l3cache.mem_side']

 

6. configs/common/CacheConfig.py 에 L3Cache 및 l3_cache_class 정의

    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,
                                   size=options.l2_size,
                                   assoc=options.l2_assoc)

        system.tol2bus = L2XBar(clk_domain = system.cpu_clk_domain)
        system.l2.cpu_side = system.tol2bus.master
        system.l2.mem_side = system.membus.slave
        if options.l2_hwp_type:
            hwpClass = ObjectList.hwp_list.get(options.l2_hwp_type)
            if system.l2.prefetcher != "Null":
                print("Warning: l2-hwp-type is set (", hwpClass, "), but",
                      "the current l2 has a default Hardware Prefetcher",
                      "of type", type(system.l2.prefetcher), ", using the",
                      "specified by the flag option.")
            system.l2.prefetcher = hwpClass()

위와 같은 부분을 아래와 같이 수정한다.

    if options.l2cache and options.l3cache :
        # 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,
                                   size=options.l2_size,
                                   assoc=options.l2_assoc)
        system.l3 = l3_cache_class(clk_domain=system.cpu_clk_domain,
                                    size=options.l3_size,
                                    assoc=options.l3_assoc)

        system.tol2bus = L2XBar(clk_domain = system.cpu_clk_domain)
        system.tol3bus = L3XBar(clk_domain = system.cpu_clk_domain)
        system.l2.cpu_side = system.tol2bus.master
        system.l2.mem_side = system.tol3bus.slave
        system.l3.cpu_side = system.tol3bus.master
        system.l3.mem_side = system.membus.slave
        if options.l2_hwp_type:
            hwpClass = ObjectList.hwp_list.get(options.l2_hwp_type)
            if system.l2.prefetcher != "Null":
                print("Warning: l2-hwp-type is set (", hwpClass, "), but",
                      "the current l2 has a default Hardware Prefetcher",
                      "of type", type(system.l2.prefetcher), ", using the",
                      "specified by the flag option.")
            system.l2.prefetcher = hwpClass()
            
    elif 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,
                                   size=options.l2_size,
                                   assoc=options.l2_assoc)

        system.tol2bus = L2XBar(clk_domain = system.cpu_clk_domain)
        system.l2.cpu_side = system.tol2bus.master
        system.l2.mem_side = system.membus.slave
        if options.l2_hwp_type:
            hwpClass = ObjectList.hwp_list.get(options.l2_hwp_type)
            if system.l2.prefetcher != "Null":
                print("Warning: l2-hwp-type is set (", hwpClass, "), but",
                      "the current l2 has a default Hardware Prefetcher",
                      "of type", type(system.l2.prefetcher), ", using the",
                      "specified by the flag option.")
            system.l2.prefetcher = hwpClass()

 

또한 "if options.cpu_type == " 부분에서 원하는 ISA에서 l3cache를 추가해야한다,

X86 ISA를 사용하길 원하므로, 마지막 else 문을 아래와 같이 수정한다.

    else:
        dcache_class, icache_class, l2_cache_class, walk_cache_class = \
            L1_DCache, L1_ICache, L2Cache, None

        if buildEnv['TARGET_ISA'] in ['x86', 'riscv']:
            walk_cache_class = PageTableWalkerCache

위와 같은 부분을 아래와 같이 수정한다.

 

    else:
        dcache_class, icache_class, l2_cache_class, l3_cache_class, walk_cache_class = \
            L1_DCache, L1_ICache, L2Cache, L3Cache, None

        if buildEnv['TARGET_ISA'] in ['x86', 'riscv']:
            walk_cache_class = PageTableWalkerCache

 

7. Build

scons ./build/X86/gem5.opt

최종적으로 빌드 후 실행하면 아래와 같은 .dot file을 확인할 수 있다,

반응형

'LAB > GEM5' 카테고리의 다른 글

GEM5, NVMain에 L3 Cache 추가  (0) 2021.03.17
GEM5, NVMain 설치  (0) 2021.03.16
GEM5 Tutorial 6 - 간단한 SimObject 제작  (0) 2021.03.09
GEM5 Tutorial 5 - se.py 및 fs.py 구성  (0) 2021.03.05
GEM5 Tutorial 4 - 제공되는 Default Config  (0) 2021.03.04