Using exit events with the new disk images in gem5 resources. #1540
Harshil2107
started this conversation in
gem5-dev
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What are Exit Events?
In gem5, exit events are a way to exit the simulation loop. Exit events can be used to perform operations outside the simulation when triggered, such as resetting stats, switching CPU types, dumping stats, taking checkpoints, etc. By default, the simulation will exit when an exit event is triggered, but we can modify this behavior by writing our own exit event handlers.
Writing Custom Exit Event Handlers
gem5 expects exit event handlers to be generators, and we can override them by passing our custom generator to the
simulator
object. Let’s say we have a resource that throws anm5 exit
at some point during execution. Instead of stopping and exiting the simulation, we want to switch processors (assuming we are using theSimpleSwitchableProcessor
). To do this, we would need to importExitEvent
fromgem5.simulate.exit_event
:Now, let's write our handler:
This handler will print a message and switch CPU types. We yield
False
because we want the simulation to continue.To add our handler to the
simulator
object, we do the following:NOTE: We pass a call to our handler (
exit_event_handler()
) and not the handler itself (exit_event_handler
) to the simulator.Exit Events Thrown by the New Disk Images
The new disk images on gem5 Resources generate various exit events, such as
m5 exit
,m5 workbegin
, andm5 workend
at different stages of the boot process. The generic Ubuntu disk images, like x86-ubuntu-22.04-img, arm-ubuntu-22.04-img, riscv-ubuntu-22.04-img, x86-ubuntu-24.04-img, arm-ubuntu-24.04-img, and riscv-ubuntu-24.04-img, trigger threem5 exit
events, which occur at the following points:sbin/init
is executed.after-boot.sh
script is executed. Theafter-boot.sh
script either runs a script passed viareadfile
or drops to an interactive shell if the kernel argumentinteractive=true
is set.after-boot.sh
script, after running thereadfile
script (if provided). If no script is provided, only the exit is triggered.All new disk images made after Ubuntu 22.04 on gem5 Resources will also throw these exit events. These disk images have corresponding boot workloads available on gem5 Resources.
In contrast, images like x86-ubuntu-24.04-npb-img and arm-ubuntu-24.04-npb-img generate the same three
m5 exit
events, but they also triggerm5 workbegin
andm5 workend
events at the start and end of the Region of Interest (ROI) in the benchmarks being run. The benchmark suites can be found on gem5 Resources at x86-ubuntu-24.04-npb-suite and arm-ubuntu-24.04-npb-suite.Handling Exit Events Thrown by the Disk Images
To fully boot the above disk images, we need to write an exit event handler to prevent the simulation from ending after the first exit (when the kernel is booted). An example exit event handler that we can use with these disk images would look like this:
Here, we yield
False
until thereadfile
script has run. We also switch processors (assuming we are using theSimpleSwitchableProcessor
) after the second exit event.If using the NPB disk images, we must also handle the
m5 workbegin
andm5 workend
exit events. A handler for those two events would look like this:These simple handlers reset stats on
workbegin
and dump stats onworkend
. To add all three handlers to thesimulator
, we can use the following:The above handlers provide examples of how to handle exit events, allowing the disk image to fully boot and run a
readfile
script.Beta Was this translation helpful? Give feedback.
All reactions