gem5: make serial port configurable
authorSimon Gerber <simon.gerber@inf.ethz.ch>
Wed, 19 Aug 2015 11:26:29 +0000 (13:26 +0200)
committerSimon Gerber <simon.gerber@inf.ethz.ch>
Wed, 19 Aug 2015 11:26:33 +0000 (13:26 +0200)
Signed-off-by: Simon Gerber <simon.gerber@inf.ethz.ch>

tools/arm_gem5/gem5script.py
tools/harness/machines/gem5.py

index a67390f..f9c5871 100644 (file)
@@ -92,7 +92,9 @@ parser.add_option("--l2_assoc", type="int", default=8)
 parser.add_option("--l3_assoc", type="int", default=16)
 parser.add_option("--cacheline_size", type="int", default=64)
 parser.add_option("--loglevel", type="int", default=4)
+parser.add_option("--console-port", type="int", default=3456)
 (options, args) = parser.parse_args()
+print options
     
 #######################################################################
 #
@@ -146,7 +148,7 @@ system.boot_osflags = boot_flags
 system.realview.attachOnChipIO(system.membus, system.bridge)
 system.realview.attachIO(system.iobus)
 system.intrctrl = IntrControl()
-system.terminal = Terminal()
+system.terminal = Terminal(port=options.console_port)
 system.vncserver = VncServer()
 
 system.physmem.port = system.membus.master
index 7f66eb5..d065a6e 100644 (file)
@@ -106,7 +106,7 @@ class Gem5MachineBase(Machine):
         env = dict(os.environ)
         if 'LD_LIBRARY_PATH' in env:
             del env['LD_LIBRARY_PATH']
-        self.child = subprocess.Popen(cmd, stderr=devnull, env=env)
+        self.child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=devnull, env=env)
         time.sleep(GEM5_START_TIMEOUT)
 
     def shutdown(self):
@@ -136,7 +136,7 @@ class Gem5MachineBase(Machine):
         self.telnet_connected = False
         while not self.telnet_connected:
             try:
-                self.telnet = telnetlib.Telnet("localhost", 3456)
+                self.telnet = telnetlib.Telnet("localhost", self.telnet_port)
                 self.telnet_connected = True
                 self.output = self.telnet.get_socket().makefile()
             except IOError, e:
@@ -187,13 +187,23 @@ class Gem5MachineARMMultiCore(Gem5MachineARM):
     def get_cores_per_socket(self):
         return 1
 
+    def get_free_port(self):
+        import socket
+        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        s.bind(('', 0))
+        # extract port from addrinfo
+        self.telnet_port = s.getsockname()[1]
+        s.close()
+
     def _get_cmdline(self):
+        self.get_free_port()
         script_path = os.path.join(self.options.sourcedir, 'tools/arm_gem5', 'gem5script.py')
         return ([GEM5_PATH + 'gem5.fast', script_path, \
                  '--kernel=%s'%self.kernel_img, \
                  '--caches', \
                  '--l2cache', \
-                 '--n=%s' % self.get_ncores()]
+                 '--n=%s' % self.get_ncores(), \
+                 '--console-port=%s' % self.telnet_port]
                 + GEM5_CACHES_ENABLE)
 
 # SK: this will not work, since gem5 uses the menu.lst specified in the arm_gem5_image