misc: Merge hotfix v20.0.0.2 into develop
[gem5.git] / configs / boot / hack_back_ckpt.rcS
1 #!/bin/sh
2
3 #
4 # This is a tricky script to understand. When run in M5, it creates
5 # a checkpoint after Linux boot up, but before any benchmarks have
6 # been run. By playing around with environment variables, we can
7 # detect whether the checkpoint has been taken.
8 # - If the checkpoint hasn't been taken, the script allows M5 to checkpoint the system,
9 # re-read this script into a new tmp file, and re-run it. On the
10 # second execution of this script (checkpoint has been taken), the
11 # environment variable is already set, so the script will exit the
12 # simulation
13 # - When we restore the simulation from a checkpoint, we can
14 # specify a new script for M5 to execute in the full-system simulation,
15 # and it will be executed as if a checkpoint had just been taken.
16 #
17 # Author:
18 # Joel Hestness, hestness@cs.utexas.edu
19 # while at AMD Research and Advanced Development Lab
20 # Date:
21 # 10/5/2010
22 #
23
24 # Test if the RUNSCRIPT_VAR environment variable is already set
25 if [ "${RUNSCRIPT_VAR+set}" != set ]
26 then
27 # Signal our future self that it's safe to continue
28 export RUNSCRIPT_VAR=1
29 else
30 # We've already executed once, so we should exit
31 /sbin/m5 exit
32 fi
33
34 # Checkpoint the first execution
35 echo "Checkpointing simulation..."
36 /sbin/m5 checkpoint
37
38 # Test if we previously okayed ourselves to run this script
39 if [ "$RUNSCRIPT_VAR" -eq 1 ]
40 then
41
42 # Signal our future self not to recurse infinitely
43 export RUNSCRIPT_VAR=2
44
45 # Read the script for the checkpoint restored execution
46 echo "Loading new script..."
47 /sbin/m5 readfile > /tmp/runscript
48 chmod 755 /tmp/runscript
49
50 # Execute the new runscript
51 if [ -s /tmp/runscript ]
52 then
53 exec /tmp/runscript
54 else
55 echo "Script not specified. Dropping into shell..."
56 /bin/bash
57 fi
58
59 fi
60
61 echo "Fell through script. Exiting..."
62 /sbin/m5 exit