summaryrefslogtreecommitdiff
path: root/configs/boot/hack_back_ckpt.rcS
blob: 4c38a4d3252e4ffceaa5a49f4150663695b7484e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh

#
# This is a tricky script to understand. When run in M5, it creates
# a checkpoint after Linux boot up, but before any benchmarks have
# been run. By playing around with environment variables, we can
# detect whether the checkpoint has been taken.
#  - If the checkpoint hasn't been taken, the script allows M5 to checkpoint the system,
# re-read this script into a new tmp file, and re-run it. On the
# second execution of this script (checkpoint has been taken), the
# environment variable is already set, so the script will exit the
# simulation
#  - When we restore the simulation from a checkpoint, we can
# specify a new script for M5 to execute in the full-system simulation,
# and it will be executed as if a checkpoint had just been taken.
#
# Author:
#   Joel Hestness, hestness@cs.utexas.edu
#   while at AMD Research and Advanced Development Lab
# Date:
#   10/5/2010
#

# Test if the RUNSCRIPT_VAR environment variable is already set
if [ "${RUNSCRIPT_VAR+set}" != set ]
then
	# Signal our future self that it's safe to continue
	export RUNSCRIPT_VAR=1
else
	# We've already executed once, so we should exit
	/sbin/m5 exit
fi

# Checkpoint the first execution
echo "Checkpointing simulation..."
/sbin/m5 checkpoint

# Test if we previously okayed ourselves to run this script
if [ "$RUNSCRIPT_VAR" -eq 1 ]
then

	# Signal our future self not to recurse infinitely
	export RUNSCRIPT_VAR=2

	# Read the script for the checkpoint restored execution
	echo "Loading new script..."
	/sbin/m5 readfile > /tmp/runscript
	chmod 755 /tmp/runscript

	# Execute the new runscript
	if [ -s /tmp/runscript ]
	then
		exec /tmp/runscript
	else
		echo "Script not specified. Dropping into shell..."
		/bin/bash
	fi

fi

echo "Fell through script. Exiting..."
/sbin/m5 exit