Files
gem5/util/cpt_upgraders/mempool-sections.py
Gabe Black 61a6ec7b71 sim: Move serialization logic for MemPools out of System.
And move it into the MemPools class itself. The MemPools class should be
self contained, and be able to manage its own state. That should not be
the responsibility of another containing class.

Change-Id: Ib0bf70b57e92698f15bea0cc217dd98ee816d57b
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/50340
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Giacomo Travaglini <giacomo.travaglini@arm.com>
2021-09-29 12:17:35 +00:00

40 lines
1.5 KiB
Python

# This upgrader moves memory pool attributes from a vector of pointers to the
# next free page and a vector of the limit of each pool to sections which each
# represent one pool and which hold the page shift amount, the next free page,
# and the total pages in the pool.
def upgrader(cpt):
systems = {}
for sec in cpt.sections():
ptrs = cpt.get(sec, 'ptrs', fallback=None)
limits = cpt.get(sec, 'limits', fallback=None)
if ptrs and limits:
systems[sec] = ptrs, limits
for sec, (ptrs, limits) in systems.items():
ptrs = list(map(int, ptrs.split()))
limits = list(map(int, limits.split()))
if len(ptrs) != len(limits):
print(
f"'{sec}ptrs' and '{limits}limits' were not the same length!")
cpt.set(sec, 'num_mem_pools', str(len(ptrs)))
cpt.remove_option(sec, 'ptrs')
cpt.remove_option(sec, 'limits')
# Assume the page shift is 12, for a 4KiB page.
page_shift = 12
for idx, (ptr, limit) in enumerate(zip(ptrs, limits)):
new_sec = f'{sec}.memPool{idx}'
cpt.add_section(new_sec)
cpt.set(new_sec, 'page_shift', str(page_shift))
# Since there's no way to tell where the pool actually started,
# just assume it started wherever it is right now.
cpt.set(new_sec, 'start_page', str(ptr >> page_shift))
cpt.set(new_sec, 'free_page_num', str(ptr >> page_shift))
cpt.set(new_sec, 'total_pages', str((limit - ptr) >> page_shift))