revamp linux testvector generation for refactoring checkpoint generation

This commit is contained in:
bbracker 2021-10-24 06:14:11 -07:00
parent 5d60a3a9df
commit d445095f1b
16 changed files with 256 additions and 115 deletions

View File

@ -1,25 +0,0 @@
#!/bin/bash
# Oftentimes this script runs so long you'll go to sleep.
# But you don't want the script to die when your computer goes to sleep.
# So consider invoking this with nohup (i.e. "nohup ./logAllBuildroot.sh")
# You can run "tail -f nohup.out" to see what would've
# outputted to the terminal if you didn't use nohup
# use on tera.
customQemu="/courses/e190ax/qemu_sim/rv64_initrd/qemu_experimental/qemu/build/qemu-system-riscv64"
# use on other systems
#customQemu="qemu-system-riscv64"
imageDir="../buildroot-image-output"
intermedDir="../linux-testvectors/intermediate-outputs"
outDir="../linux-testvectors"
# - Logs info needed by buildroot testbench
read -p "Warning: running this script will overwrite the contents of $outDir/all.txt.
Would you like to proceed? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
($customQemu -M virt -nographic -bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio -rtc clock=vm -icount shift=1 -d nochain,cpu,in_asm -serial /dev/null -singlestep -gdb tcp::1236 -S 2>&1 >/dev/null | ./parse_qemu.py | ./parseNew.py | ./remove_dup.awk > $outDir/all.txt) & riscv64-unknown-elf-gdb -x gdbinit_qemulog
fi

View File

@ -1,35 +0,0 @@
#!/bin/bash
# Oftentimes this script runs so long you'll go to sleep.
# But you don't want the script to die when your computer goes to sleep.
# So consider invoking this with nohup (i.e. "nohup ./logAllBuildroot.sh")
# You can run "tail -f nohup.out" to see what would've
# outputted to the terminal if you didn't use nohup
# use on tera.
customQemu="/courses/e190ax/qemu_sim/rv64_initrd/qemu_experimental/qemu/build/qemu-system-riscv64"
# use on other systems
#customQemu="qemu-system-riscv64"
instrs=50000000
imageDir="../buildroot-image-output"
outDir="../linux-testvectors/checkpoint$instrs"
intermedDir="$outDir/intermediate-outputs"
read -p "This scripts is going to create a checkpoint at $instrs instrs.
Is that what you wanted? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
mkdir -p $outDir
mkdir -p $intermedDir
# Simulate QEMU, parse QEMU trace, run GDB script which logs a bunch of data at the checkpoint
($customQemu -M virt -nographic -bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio -rtc clock=vm -icount shift=1 -d nochain,cpu,in_asm -serial /dev/null -singlestep -gdb tcp::1240 -S 2>&1 1>&2 | ./parse_qemu.py | ./parseNew.py | ./remove_dup.awk > $intermedDir/rawTrace.txt) & riscv64-unknown-elf-gdb -x ./checkpoint.gdb -ex "createCheckpoint $instrs \"$intermedDir\""
# Post-Process GDB outputs
./parseState.py "$outDir"
./fix_mem.py "$intermedDir/ramGDB.txt" "$outDir/ram.txt"
else
echo "You can change the number of instructions by editing the \"instrs\" variable in this script."
echo "Have a nice day!"
fi

View File

@ -1,4 +1,4 @@
define createCheckpoint
define genCheckpoint
# GDB config
set pagination off
set logging overwrite on
@ -11,24 +11,32 @@ define createCheckpoint
# QEMU Config
maintenance packet Qqemu.PhyMemMode:1
# Argument Parsing
set $statePath=$arg1
set $ramPath=$arg1
eval "set $statePath = \"%s/stateGDB.txt\"", $statePath
eval "set $ramPath = \"%s/ramGDB.txt\"", $ramPath
# Symbol file
file ../buildroot-image-output/vmlinux
# Argument Parsing
set $tcpPort=$arg0
set $instrCount=$arg1
set $statePath=$arg2
set $ramPath=$arg3
set $checkPC=$arg4
set $checkPCoccurences=$arg5
eval "set $statePath = \"%s/stateGDB.txt\"", $statePath
eval "set $ramPath = \"%s/ramGDB.txt\"", $ramPath
# Step over reset vector into actual code
stepi 1000
stepi 100
# Set breakpoint for where to stop
b do_idle
# Proceed to checkpoint
printf "GDB proceeding to checkpoint at %d instrs\n", $arg0
stepi $arg0-1000
printf "GDB proceeding to checkpoint at %d instrs\n", $instrCount
#stepi $instrCount-1000
b *$checkPC
ignore 2 $checkPCoccurences
c
printf "Reached checkpoint at %d instrs\n", $arg0
printf "Reached checkpoint at %d instrs\n", $instrCount
# Log all registers to a file
printf "GDB storing state to %s\n", $statePath

View File

@ -1,12 +1,18 @@
set pagination off
file ../buildroot-image-output/fw_jump.elf
file ../buildroot-image-output/vmlinux
target extended-remote :1237
b *0x80200040
c
file ../buildroot-image-output/vmlinux
#del 1
#stepi 500
#b irqchip_plic_warm_init
#c
#b plic_init
#c
b do_idle
c
#b do_idle
#c
#b *0xffffffff80202e58
#ignore 2 87
#c
#del 2

View File

@ -1,11 +0,0 @@
set pagination off
target extended-remote :1236
file ../buildroot-image-output/vmlinux
stepi 1000
b do_idle
ignore 1 2
c
# using 3 continues didn't work because the first breakpoint hit causes a pipe break error
set confirm off
kill
q

View File

@ -0,0 +1,56 @@
define genCheckpoint
# GDB config
set pagination off
set logging overwrite on
set logging redirect on
set confirm off
# Argument Parsing
set $tcpPort=$arg0
set $instrCount=$arg1
set $statePath=$arg2
set $ramPath=$arg3
set $checkPC=$arg4
set $checkPCoccurences=$arg5
eval "set $statePath = \"%s/stateGDB.txt\"", $statePath
eval "set $ramPath = \"%s/ramGDB.txt\"", $ramPath
# Connect to QEMU session
eval "target extended-remote :%d",$tcpPort
# QEMU Config
maintenance packet Qqemu.PhyMemMode:1
# Symbol file
file ../buildroot-image-output/vmlinux
# Step over reset vector into actual code
stepi 100
# Set breakpoint for where to stop
b do_idle
# Proceed to checkpoint
printf "GDB proceeding to checkpoint at %d instrs\n", $instrCount
#stepi $instrCount-1000
b *$checkPC
ignore 2 $checkPCoccurences
c
printf "Reached checkpoint at %d instrs\n", $instrCount
# Log all registers to a file
printf "GDB storing state to %s\n", $statePath
eval "set logging file %s", $statePath
set logging on
info all-registers
set logging off
# Log main memory to a file
printf "GDB storing RAM to %s\n", $ramPath
eval "set logging file %s", $ramPath
set logging on
x/134217728xb 0x80000000
set logging off
kill
q
end

View File

@ -0,0 +1,39 @@
#!/bin/bash
source genSettings.sh
tcpPort=1236
instrs=8500000
checkOutDir="$outDir/checkpoint$instrs"
checkIntermedDir="$checkOutDir/intermediate-outputs"
read -p "This scripts is going to create a checkpoint at $instrs instrs.
Is that what you wanted? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
mkdir -p $checkOutDir
mkdir -p $checkIntermedDir
instr=$(sed "${instrs}q;d" "../linux-testvectors/all.txt")
echo "Found ${instrs}th instr: ${instr}."
pc=$(echo $instr | cut -d " " -f1)
asm=$(echo $instr | cut -d " " -f2)
occurences=$(($(head -$instrs "../linux-testvectors/all.txt" | grep -c "${pc} ${asm}")-1))
echo "It occurs ${occurences} times before the ${instrs}th instr."
# Simulate QEMU, parse QEMU trace, run GDB script which logs a bunch of data at the checkpoint
($customQemu \
-M virt \
-nographic \
-bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio \
-singlestep -rtc clock=vm -icount shift=1,align=off,sleep=on,rr=replay,rrfile="$intermedDir/$recordFile" \
-gdb tcp::$tcpPort -S) \
& riscv64-unknown-elf-gdb -quiet -x genCheckpoint.gdb -ex "genCheckpoint $tcpPort $instrs \"$checkIntermedDir\" 0x$pc $occurences"
# Post-Process GDB outputs
./parseState.py "$checkOutDir"
./fix_mem.py "$intermedDir/ramGDB.txt" "$checkOutDir/ram.txt"
tail -n+$(($instrs-9)) "$outDir/$traceFile" > "$checkOutDir/$traceFile"
else
echo "You can change the number of instructions by editing the \"instrs\" variable in this script."
echo "Have a nice day!"
fi

View File

@ -0,0 +1,44 @@
define genInitMem
# GDB config
set pagination off
set logging overwrite on
set logging redirect on
set confirm off
# Argument Parsing
set $tcpPort=$arg0
set $bootmemPath=$arg1
set $untrimmedBootmemPath=$arg1
set $ramPath=$arg1
eval "set $bootmemPath = \"%s/bootmemGDB.txt\"", $bootmemPath
eval "set $untrimmedBootmemPath = \"%s/untrimmedBootmemGDB.txt\"", $untrimmedBootmemPath
eval "set $ramPath = \"%s/ramGDB.txt\"", $ramPath
# Connect to QEMU session
eval "target extended-remote :%d",$tcpPort
# QEMU Config
maintenance packet Qqemu.PhyMemMode:1
printf "Creating %s\n",$bootmemPath
eval "set logging file %s", $bootmemPath
set logging on
x/4096xb 0x1000
set logging off
printf "Creating %s\n",$untrimmedBootmemPath
printf "Warning - please verify that the second half of %s is all 0s\n",$untrimmedBootmemPath
eval "set logging file %s", $untrimmedBootmemPath
set logging on
x/8192xb 0x1000
set logging off
printf "Creating %s\n", $ramPath
eval "set logging file %s", $ramPath
set logging on
x/134217728xb 0x80000000
set logging off
kill
q
end

View File

@ -0,0 +1,27 @@
#!/bin/bash
source genSettings.sh
tcpPort=1235
read -p "Warning: running this script will overwrite the contents of memory dumps needed for simulation.
Would you like to proceed? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
($customQemu \
-M virt \
-nographic \
-bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio \
-gdb tcp::$tcpPort -S 2>/dev/null >/dev/null) \
& riscv64-unknown-elf-gdb -quiet -x genInitMem.gdb -ex "genInitMem $tcpPort \"$intermedDir\""
echo "Translating Mem from GDB to Questa format"
./fix_mem.py "$intermedDir/bootmemGDB.txt" "$outDir/bootmem.txt"
./fix_mem.py "$intermedDir/ramGDB.txt" "$outDir/ram.txt"
echo "Done"
echo "Creating debugging objdump of linux image"
riscv64-unknown-elf-objdump -D $imageDir/vmlinux > $outDir/vmlinux.objdump
extractFunctionRadix.sh $outDir/vmlinux.objdump
echo "Done"
fi

View File

@ -0,0 +1,11 @@
#!/bin/bash
# Warning! This is Tera-specific absolute path
# *** on the long term we'll want to include QEMU in the addins folder
export customQemu="/courses/e190ax/qemu_sim/rv64_initrd/qemu_experimental/qemu/build/qemu-system-riscv64"
export imageDir="../buildroot-image-output"
export outDir="../linux-testvectors-experimental"
export intermedDir="$outDir/intermediate-outputs"
export traceFile="all.txt"
export recordFile="all.qemu"
export tcpPort=1234

View File

@ -0,0 +1,24 @@
define genTrace
# Arguments
set $tcpPort=$arg0
# GDB config
set pagination off
set logging overwrite on
set logging redirect on
set confirm off
# Connect to QEMU session
eval "target extended-remote :%d",$tcpPort
# Symbol Files
file ../buildroot-image-output/vmlinux
# Run until Linux login prompt
b do_idle
ignore 1 2
c
kill
q
emd

View File

@ -0,0 +1,24 @@
#!/bin/bash
source genSettings.sh
tcpPort=1234
read -p "Warning: running this script will overwrite the contents of:
$outDir/$traceFile
$outDir/$recordFile
Would you like to proceed? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
mkdir -p $outDir
mkdir -p $intermedDir
($customQemu \
-M virt \
-nographic -serial /dev/null \
-bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio \
-singlestep -rtc clock=vm -icount shift=1,align=off,sleep=on,rr=record,rrfile="$intermedDir/$recordFile" \
-d nochain,cpu,in_asm \
-gdb tcp::$tcpPort -S \
2>&1 >/dev/null | ./parseQemuToGDB.py | ./parseGDBtoTrace.py | ./remove_dup.awk > "$outDir/$traceFile") \
& riscv64-unknown-elf-gdb -quiet -x genTrace.gdb -ex "genTrace $tcpPort"
fi

View File

@ -1,28 +0,0 @@
#!/bin/bash
# use on tera.
customQemu="/courses/e190ax/qemu_sim/rv64_initrd/qemu_experimental/qemu/build/qemu-system-riscv64"
# use on other systems
#customQemu="qemu-system-riscv64"
imageDir="../buildroot-image-output"
testVecDir="../linux-testvectors"
read -p "Warning: running this script will overwrite the contents of memory dumps needed for simulation.
Would you like to proceed? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
($customQemu -M virt -nographic -bios $imageDir/fw_jump.elf -kernel $imageDir/Image -append "root=/dev/vda ro" -initrd $imageDir/rootfs.cpio -d nochain,cpu,in_asm -serial /dev/null -singlestep -gdb tcp::1235 -S 2>/dev/null >/dev/null) &
riscv64-unknown-elf-gdb -x gdbinit_mem
echo "Translating Mem from GDB to Questa format"
./fix_mem.py "$testVecDir/intermediate-outputs/bootmemGDB.txt" "$testVecDir/bootmem.txt"
./fix_mem.py "$testVecDir/intermediate-outputs/ramGDB.txt" "$testVecDir/ram.txt"
echo "Done"
echo "Creating debugging objdump of linux image"
riscv64-unknown-elf-objdump -D $imageDir/vmlinux > $testVecDir/vmlinux.objdump
extractFunctionRadix.sh $testVecDir/vmlinux.objdump
echo "Done"
fi

View File

@ -110,6 +110,7 @@ def parseRegs(l):
# Main Code #
#############
for l in fileinput.input():
#sys.stderr.write(l)
if l.startswith('qemu-system-riscv64: QEMU: Terminated via GDBstub'):
break
elif l.startswith('IN:'):

View File

@ -34,7 +34,7 @@ stateGDBpath = outDir+'intermediate-outputs/stateGDB.txt'
if not os.path.exists(stateGDBpath):
sys.exit('Error input file '+stateGDBpath+'not found')
singleCSRs = ['mip','mie','mscratch','mcause','mepc','mtvec','medeleg','mideleg','sscratch','scause','sepc','stvec','sedeleg','sideleg','satp','mstatus']
singleCSRs = ['pc','mip','mie','mscratch','mcause','mepc','mtvec','medeleg','mideleg','sscratch','scause','sepc','stvec','sedeleg','sideleg','satp','mstatus']
thirtyTwoBitCSRs = ['mcounteren','scounteren']
listCSRs = ['hpmcounter','pmpaddr']
pmpcfg = ['pmpcfg']
@ -90,7 +90,7 @@ with open(stateGDBpath, 'r') as stateGDB:
outFileName = 'checkpoint-'+name.upper().strip('0123456789')
outFile = open(outDir+outFileName, 'a')
fourPmp = int(val,16)
for i in range(4):
for i in range(3,-1,-1):
byte = (fourPmp >> 4*i) & 0xf
outFile.write(hex(byte)[2:]+'\n')
outFile.close()