switcheroo.py (9521:1cd02decbfd3) switcheroo.py (9980:cc02ad629b36)
1# Copyright (c) 2012 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

--- 56 unchanged lines hidden (view full) ---

65
66 def next(self):
67 self.cur_cpu = (self.cur_cpu + 1) % len(self.cpus)
68 return self.cpus[self.cur_cpu]
69
70 def first(self):
71 return self.cpus[self.first_cpu]
72
1# Copyright (c) 2012 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

--- 56 unchanged lines hidden (view full) ---

65
66 def next(self):
67 self.cur_cpu = (self.cur_cpu + 1) % len(self.cpus)
68 return self.cpus[self.cur_cpu]
69
70 def first(self):
71 return self.cpus[self.first_cpu]
72
73def run_test(root, switcher=None, freq=1000):
73def run_test(root, switcher=None, freq=1000, verbose=False):
74 """Test runner for CPU switcheroo tests.
75
76 The switcheroo test runner is used to switch CPUs in a system that
77 has been prepared for CPU switching. Such systems should have
78 multiple CPUs when they are instantiated, but only one should be
79 switched in. Such configurations can be created using the
80 base_config.BaseFSSwitcheroo class.
81

--- 4 unchanged lines hidden (view full) ---

86 Unlike most other test runners, this one automatically configures
87 the memory mode of the system based on the first CPU the switcher
88 reports.
89
90 Keyword Arguments:
91 switcher -- CPU switcher implementation. See Sequential for
92 an example implementation.
93 period -- Switching frequency in Hz.
74 """Test runner for CPU switcheroo tests.
75
76 The switcheroo test runner is used to switch CPUs in a system that
77 has been prepared for CPU switching. Such systems should have
78 multiple CPUs when they are instantiated, but only one should be
79 switched in. Such configurations can be created using the
80 base_config.BaseFSSwitcheroo class.
81

--- 4 unchanged lines hidden (view full) ---

86 Unlike most other test runners, this one automatically configures
87 the memory mode of the system based on the first CPU the switcher
88 reports.
89
90 Keyword Arguments:
91 switcher -- CPU switcher implementation. See Sequential for
92 an example implementation.
93 period -- Switching frequency in Hz.
94 verbose -- Enable output at each switch (suppressed by default).
94 """
95
96 if switcher == None:
97 switcher = Sequential(root.system.cpu)
98
99 current_cpu = switcher.first()
100 system = root.system
101 system.mem_mode = type(current_cpu).memory_mode()
102
95 """
96
97 if switcher == None:
98 switcher = Sequential(root.system.cpu)
99
100 current_cpu = switcher.first()
101 system = root.system
102 system.mem_mode = type(current_cpu).memory_mode()
103
104 # Suppress "Entering event queue" messages since we get tons of them.
105 # Worse yet, they include the timestamp, which makes them highly
106 # variable and unsuitable for comparing as test outputs.
107 m5.internal.core.cvar.want_info = verbose
108
103 # instantiate configuration
104 m5.instantiate()
105
106 # Determine the switching period, this has to be done after
107 # instantiating the system since the time base must be fixed.
108 period = m5.ticks.fromSeconds(1.0 / freq)
109 while True:
110 exit_event = m5.simulate(period)
111 exit_cause = exit_event.getCause()
112
113 if exit_cause == "simulate() limit reached":
114 next_cpu = switcher.next()
115
109 # instantiate configuration
110 m5.instantiate()
111
112 # Determine the switching period, this has to be done after
113 # instantiating the system since the time base must be fixed.
114 period = m5.ticks.fromSeconds(1.0 / freq)
115 while True:
116 exit_event = m5.simulate(period)
117 exit_cause = exit_event.getCause()
118
119 if exit_cause == "simulate() limit reached":
120 next_cpu = switcher.next()
121
116 print "Switching CPUs..."
117 print "Next CPU: %s" % type(next_cpu)
122 if verbose:
123 print "Switching CPUs..."
124 print "Next CPU: %s" % type(next_cpu)
118 m5.drain(system)
119 if current_cpu != next_cpu:
120 m5.switchCpus(system, [ (current_cpu, next_cpu) ],
125 m5.drain(system)
126 if current_cpu != next_cpu:
127 m5.switchCpus(system, [ (current_cpu, next_cpu) ],
121 do_drain=False)
128 do_drain=False, verbose=verbose)
122 else:
123 print "Source CPU and destination CPU are the same, skipping..."
124 m5.resume(system)
125 current_cpu = next_cpu
126 elif exit_cause == "target called exit()" or \
127 exit_cause == "m5_exit instruction encountered":
128
129 sys.exit(0)
130 else:
131 print "Test failed: Unknown exit cause: %s" % exit_cause
132 sys.exit(1)
129 else:
130 print "Source CPU and destination CPU are the same, skipping..."
131 m5.resume(system)
132 current_cpu = next_cpu
133 elif exit_cause == "target called exit()" or \
134 exit_cause == "m5_exit instruction encountered":
135
136 sys.exit(0)
137 else:
138 print "Test failed: Unknown exit cause: %s" % exit_cause
139 sys.exit(1)