configs: Generalize FileSystemConfig for non se.py
authorJason Lowe-Power <jason@lowepower.com>
Fri, 17 May 2019 02:09:56 +0000 (19:09 -0700)
committerJason Lowe-Power <jason@lowepower.com>
Fri, 17 May 2019 17:16:07 +0000 (17:16 +0000)
This patch updates the FileSystemConfig so it works with more kinds of
config scripts (e.g., the Learning gem5 scripts).

There are 4 main changes:
- Added system as a parameter to the config_filesystem function so the
function can search the system for the number of CPUs instead of relying
on options from Options.py
- Instead of calling redirect_paths everywhere config_filesystem is
used, now it is implicitly called.
- Cleaned up the Ruby scripts a bit to remove redundant calls to
config_filesystem
- Added a config_filesystem call to the Ruby Learning gem5 script
(currently the only Learning gem5 script that requires it).

In the future, I think it would be better to move the config_filesystem
call into simulate.py, probably into the instantiate function. I tried to
use the per-CPU configuration parameters instead of options from
Options.py, but that's not possible until after the SimObject params
have been finalized in instantiate.

Change-Id: Ie6501a7435cfb3ac9d2b45be3722388b34063b1e
Signed-off-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18848
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Tested-by: kokoro <noreply+kokoro@google.com>
configs/common/FileSystemConfig.py
configs/example/se.py
configs/learning_gem5/part3/simple_ruby.py
configs/ruby/GPU_VIPER.py
configs/ruby/MESI_Three_Level.py
configs/ruby/MOESI_AMD_Base.py
configs/ruby/MOESI_hammer.py
configs/ruby/Ruby.py

index e37fbd3a2b1f5add9b6402c7840ec1bff729ff0b..a9c7c92a5a0fb2105f0f49b29368cb51862584e0 100644 (file)
@@ -52,7 +52,24 @@ def replace_tree(path):
         rmtree(path)
     mkdir(path)
 
-def config_filesystem(options):
+def config_filesystem(system, options = None):
+    """ This function parses the system object to create the pseudo file system
+    @param system: The system to create the config for
+    @param options: An optional argument which contains an Options.py options
+           object. This is useful if when use se.py and will set the L2 cache
+           size and the clock in /proc/cpuinfo if provided.
+
+    First, this function walks the system object to find all CPUs.
+    Then, this function creates the following files with the CPU information
+      - /proc/cpuinfo which contains the clock  and the L2 size
+        (assumes all L2s private and the same size)
+      - /proc/stat simply lists all CPUs
+      - /sys/devices/system/cpu/online and /sys/devices/system/cpu/possible
+        These files list all of the CPUs in this system.
+      - /tmp
+
+    These files are created in the `fs` directory in the outdir path.
+    """
     fsdir = joinpath(m5.options.outdir, 'fs')
     replace_tree(fsdir)
 
@@ -60,50 +77,47 @@ def config_filesystem(options):
     procdir = joinpath(fsdir, 'proc')
     mkdir(procdir)
 
-    cpu_clock = '0'
+    cpus = [obj for obj in system.descendants() if isinstance(obj, BaseCPU)]
+
+    cpu_clock = 0
     if hasattr(options, 'cpu_clock'):
-        cpu_clock = options.cpu_clock
-    cpu_clock = toFrequency(cpu_clock)/mega
+        cpu_clock = toFrequency(options.cpu_clock) / mega
 
-    l2_size = '0'
+    l2_size = 0
     if hasattr(options, 'l2_size'):
-        l2_size = options.l2_size
-    l2_size = toMemorySize(l2_size)/kibi
-
-    cacheline_size = '0'
-    if hasattr(options, 'cacheline_size'):
-        cacheline_size = options.cacheline_size
+        l2_size = toMemorySize(options.l2_size) / kibi
 
-    for i in xrange(options.num_cpus):
-        one_cpu = 'processor       : %d\n' % (i)                  + \
+    for i,cpu in enumerate(cpus):
+        one_cpu = 'processor       : {proc}\n'                    + \
                   'vendor_id       : Generic\n'                   + \
                   'cpu family      : 0\n'                         + \
                   'model           : 0\n'                         + \
                   'model name      : Generic\n'                   + \
                   'stepping        : 0\n'                         + \
-                  'cpu MHz         : %0.3d\n'                       \
-                        % cpu_clock                               + \
-                  'cache size:     : %dK\n'                         \
-                        % l2_size                                 + \
+                  'cpu MHz         : {clock:0.3f}\n'              + \
+                  'cache size:     : {l2_size}K\n'                + \
                   'physical id     : 0\n'                         + \
-                  'siblings        : %s\n'                          \
-                        % options.num_cpus                        + \
-                  'core id         : %d\n'                          \
-                        % i                                       + \
-                  'cpu cores       : %d\n'                          \
-                        % options.num_cpus                        + \
+                  'siblings        : {num_cpus}\n'                + \
+                  'core id         : {proc}\n'                    + \
+                  'cpu cores       : {num_cpus}\n'                + \
                   'fpu             : yes\n'                       + \
                   'fpu exception   : yes\n'                       + \
                   'cpuid level     : 1\n'                         + \
                   'wp              : yes\n'                       + \
                   'flags           : fpu\n'                       + \
-                  'cache alignment : %d\n'                          \
-                        % cacheline_size                          + \
+                  'cache alignment : {cacheline_size}\n'          + \
                   '\n'
+        one_cpu = one_cpu.format(proc = i, num_cpus = len(cpus),
+                       # Note: it would be nice to use cpu.clock, but it hasn't
+                       # been finalized yet since m5.instantiate() isn't done.
+                       clock = cpu_clock,
+                       # Note: this assumes the L2 is private to each core
+                       l2_size = l2_size,
+                       cacheline_size=system.cache_line_size.getValue())
         file_append((procdir, 'cpuinfo'), one_cpu)
 
     file_append((procdir, 'stat'), 'cpu 0 0 0 0 0 0 0\n')
-    for i in xrange(options.num_cpus):
+    for i in xrange(len(cpus)):
         file_append((procdir, 'stat'), 'cpu%d 0 0 0 0 0 0 0\n' % i)
 
     # Set up /sys
@@ -114,13 +128,19 @@ def config_filesystem(options):
     cpudir = joinpath(sysdir, 'devices', 'system', 'cpu')
     makedirs(cpudir)
 
-    file_append((cpudir, 'online'), '0-%d' % (options.num_cpus-1))
-    file_append((cpudir, 'possible'), '0-%d' % (options.num_cpus-1))
+    file_append((cpudir, 'online'), '0-%d' % (len(cpus) - 1))
+    file_append((cpudir, 'possible'), '0-%d' % (len(cpus) - 1))
 
     # Set up /tmp
     tmpdir = joinpath(fsdir, 'tmp')
     replace_tree(tmpdir)
 
+    if options and hasattr(options, 'chroot'):
+        chroot = os.path.expanduser(options.chroot)
+    else:
+        chroot = '/'
+    system.redirect_paths = _redirect_paths(chroot)
+
 def register_node(cpu_list, mem, node_number):
     nodebasedir = joinpath(m5.options.outdir, 'fs', 'sys', 'devices',
                            'system', 'node')
@@ -176,7 +196,7 @@ def register_cache(level, idu_type, size, line_size, assoc, cpus):
         file_append((indexdir, 'physical_line_partition'), '1')
         file_append((indexdir, 'shared_cpu_map'), hex_mask(cpus))
 
-def redirect_paths(chroot):
+def _redirect_paths(chroot):
     # Redirect filesystem syscalls from src to the first matching dests
     redirect_paths = [RedirectPath(app_path = "/proc",
                           host_paths = ["%s/fs/proc" % m5.options.outdir]),
index cbebcea5eefada10480215e2e8f2a12e7a1be264..f43206ad2b4def123523134a0b9fb8ae80006ce3 100644 (file)
@@ -64,7 +64,7 @@ from common import CacheConfig
 from common import CpuConfig
 from common import BPConfig
 from common import MemConfig
-from common.FileSystemConfig import redirect_paths, config_filesystem
+from common.FileSystemConfig import config_filesystem
 from common.Caches import *
 from common.cpu2000 import *
 
@@ -246,9 +246,6 @@ for i in range(np):
 
     system.cpu[i].createThreads()
 
-system.redirect_paths = redirect_paths(os.path.expanduser(options.chroot))
-config_filesystem(options)
-
 if options.ruby:
     Ruby.create_system(options, False, system)
     assert(options.num_cpus == len(system.ruby._cpu_ports))
@@ -278,6 +275,7 @@ else:
     system.system_port = system.membus.slave
     CacheConfig.config_cache(options, system)
     MemConfig.config_mem(options, system)
+    config_filesystem(system, options)
 
 root = Root(full_system = False, system = system)
 Simulation.run(options, root, system, FutureClass)
index bcd5044a15e1f9ad5528cdfc09b7cba6891b2d15..0c622d070922d60d7bc36a87c7607fcbfc7ae00e 100644 (file)
@@ -45,6 +45,10 @@ import m5
 # import all of the SimObjects
 from m5.objects import *
 
+# Needed for running C++ threads
+m5.util.addToPath('../../')
+from common.FileSystemConfig import config_filesystem
+
 # You can import ruby_caches_MI_example to use the MI_example protocol instead
 # of the MSI protocol
 from msi_caches import MyCacheSystem
@@ -95,6 +99,9 @@ for cpu in system.cpu:
     cpu.workload = process
     cpu.createThreads()
 
+# Set up the pseudo file system for the threads function above
+config_filesystem(system)
+
 # set up the root SimObject and start the simulation
 root = Root(full_system = False, system = system)
 # instantiate all of the objects we've created above
index e8e781562444d4109788653d926d73178c81576d..52b6c28ab0c990147a0eaa448fd462aeb213fe84 100644 (file)
@@ -501,7 +501,6 @@ def create_system(options, full_system, system, dma_devices, bootmem,
 
     # Register CPUs and caches for each CorePair and directory (SE mode only)
     if not full_system:
-        FileSystemConfig.config_filesystem(options)
         for i in xrange((options.num_cpus + 1) // 2):
             FileSystemConfig.register_cpu(physical_package_id = 0,
                                           core_siblings = \
index 90e9190cb72889a171bb47eb4d8823c7d6d10026..20f48db32c023c72d49cb2d8e225af839e9ae68f 100644 (file)
@@ -263,8 +263,6 @@ def create_system(options, full_system, system, dma_ports, bootmem,
         all_cntrls = all_cntrls + [io_controller]
     # Register configuration with filesystem
     else:
-        FileSystemConfig.config_filesystem(options)
-
         for i in xrange(options.num_clusters):
             for j in xrange(num_cpus_per_cluster):
                 FileSystemConfig.register_cpu(physical_package_id = 0,
index a1faf1dfd89eae3238741896ba6f8c51b1b3fdea..0475dcb0c3b762fdc48abda5d8b275859a2b6cca 100644 (file)
@@ -328,7 +328,6 @@ def create_system(options, full_system, system, dma_devices, bootmem,
 
     # Register CPUs and caches for each CorePair and directory (SE mode only)
     if not full_system:
-        FileSystemConfig.config_filesystem(options)
         for i in xrange((options.num_cpus + 1) // 2):
             FileSystemConfig.register_cpu(physical_package_id = 0,
                                           core_siblings =
index 0b04980a3648c9401f9458a29f6cccc90abc502c..9ec7124df289476d9282a36b9811e5b81040540f 100644 (file)
@@ -258,8 +258,6 @@ def create_system(options, full_system, system, dma_ports, bootmem,
         all_cntrls = all_cntrls + [io_controller]
     # Register configuration with filesystem
     else:
-        FileSystemConfig.config_filesystem(options)
-
         for i in xrange(options.num_cpus):
             FileSystemConfig.register_cpu(physical_package_id = 0,
                                           core_siblings = [],
index 369a4e355800c32f071039275a4f02ebe6d67a57..2d69ac19a91ee45ab6e782263ccf2b6d956777ce 100644 (file)
@@ -156,7 +156,7 @@ def create_system(options, full_system, system, piobus = None, dma_ports = [],
     ruby = system.ruby
 
     # Generate pseudo filesystem
-    FileSystemConfig.config_filesystem(options)
+    FileSystemConfig.config_filesystem(system, options)
 
     # Create the network object
     (network, IntLinkClass, ExtLinkClass, RouterClass, InterfaceClass) = \