mirror of
https://github.com/andreas-abel/nanoBench.git
synced 2026-01-04 19:40:08 +01:00
NOP syntax
This commit is contained in:
10
README.md
10
README.md
@@ -129,10 +129,10 @@ Both `nanoBench.sh` and `kernel-nanoBench.sh` support the following command-line
|
|||||||
|
|
||||||
| Option | Description |
|
| Option | Description |
|
||||||
|------------------------------|-------------|
|
|------------------------------|-------------|
|
||||||
| `-asm <code>` | Assembler code sequence (in Intel syntax) containing the code to be benchmarked. |
|
| `-asm <code>` | Assembler code sequence (in Intel syntax<sup>[1](#syntax)</sup>) containing the code to be benchmarked. |
|
||||||
| `-asm_init <code>` | Assembler code sequence (in Intel syntax) that is executed once in the beginning of every benchmark run. |
|
| `-asm_init <code>` | Assembler code sequence (in Intel syntax<sup>[1](#syntax)</sup>) that is executed once in the beginning of every benchmark run. |
|
||||||
| `-asm_late_init <code>` | Assembler code sequence (in Intel syntax) that is executed once immediately before the code to be benchmarked. |
|
| `-asm_late_init <code>` | Assembler code sequence (in Intel syntax<sup>[1](#syntax)</sup>) that is executed once immediately before the code to be benchmarked. |
|
||||||
| `-asm_one_time_init <code>` | Assembler code sequence (in Intel syntax) that is executed once before the first benchmark run. |
|
| `-asm_one_time_init <code>` | Assembler code sequence (in Intel syntax<sup>[1](#syntax)</sup>) that is executed once before the first benchmark run. |
|
||||||
| `-code <filename>` | A binary file containing the code to be benchmarked as raw x86 machine code. *This option cannot be used together with `-asm`.* |
|
| `-code <filename>` | A binary file containing the code to be benchmarked as raw x86 machine code. *This option cannot be used together with `-asm`.* |
|
||||||
| `-code_init <filename>` | A binary file containing code to be executed once in the beginning of every benchmark run. *This option cannot be used together with `-asm_init`.* |
|
| `-code_init <filename>` | A binary file containing code to be executed once in the beginning of every benchmark run. *This option cannot be used together with `-asm_init`.* |
|
||||||
| `-code_late_init <filename>` | A binary file containing code to be executed once immediately before the code to be benchmarked. *This option cannot be used together with `-asm_late_init`.* |
|
| `-code_late_init <filename>` | A binary file containing code to be executed once immediately before the code to be benchmarked. *This option cannot be used together with `-asm_late_init`.* |
|
||||||
@@ -154,6 +154,8 @@ Both `nanoBench.sh` and `kernel-nanoBench.sh` support the following command-line
|
|||||||
| `-cpu <n>` | Pins the measurement thread to CPU n. `[Default: Pin the thread to the CPU it is currently running on.]` |
|
| `-cpu <n>` | Pins the measurement thread to CPU n. `[Default: Pin the thread to the CPU it is currently running on.]` |
|
||||||
| `-verbose` | Outputs the results of all performance counter readings. In the user-space version, the results are printed to stdout. The output of the kernel module can be accessed using `dmesg`. |
|
| `-verbose` | Outputs the results of all performance counter readings. In the user-space version, the results are printed to stdout. The output of the kernel module can be accessed using `dmesg`. |
|
||||||
|
|
||||||
|
<sup id="syntax">1</sup> As an extension, the tool also supports statements of the form `|n` (with 1≤n≤15) that are translated to n-byte NOPs.
|
||||||
|
|
||||||
The following parameters are only supported by `nanoBench.sh`.
|
The following parameters are only supported by `nanoBench.sh`.
|
||||||
|
|
||||||
| Option | Description |
|
| Option | Description |
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source utils.sh
|
||||||
|
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo "Error: nanoBench requires root privileges"
|
echo "Error: nanoBench requires root privileges"
|
||||||
echo "Try \"sudo ./kernel-nanoBench.sh ...\""
|
echo "Try \"sudo ./kernel-nanoBench.sh ...\""
|
||||||
@@ -18,36 +20,24 @@ taskset=""
|
|||||||
|
|
||||||
while [ "$1" ]; do
|
while [ "$1" ]; do
|
||||||
if [[ "$1" == -asm_i* ]]; then
|
if [[ "$1" == -asm_i* ]]; then
|
||||||
echo ".intel_syntax noprefix" > asm-init.s
|
assemble "$2" asm-init.bin
|
||||||
echo "$2" >> asm-init.s
|
echo -n "asm-init.bin" > /sys/nb/init
|
||||||
as asm-init.s -o asm-init.o
|
rm -f asm-init.bin
|
||||||
objcopy asm-init.o -O binary asm-init.o
|
|
||||||
echo -n "asm-init.o" > /sys/nb/init
|
|
||||||
rm -f asm-init.s asm-init.o
|
|
||||||
shift 2
|
shift 2
|
||||||
elif [[ "$1" == -asm_l* ]]; then
|
elif [[ "$1" == -asm_l* ]]; then
|
||||||
echo ".intel_syntax noprefix" > asm-late-init.s
|
assemble "$2" asm-late-init.bin
|
||||||
echo "$2" >> asm-late-init.s
|
echo -n "asm-late-init.bin" > /sys/nb/late_init
|
||||||
as asm-late-init.s -o asm-late-init.o
|
rm -f asm-late-init.bin
|
||||||
objcopy asm-late-init.o -O binary asm-late-init.o
|
|
||||||
echo -n "asm-late-init.o" > /sys/nb/late_init
|
|
||||||
rm -f asm-late-init.s asm-late-init.o
|
|
||||||
shift 2
|
shift 2
|
||||||
elif [[ "$1" == -asm_o* ]]; then
|
elif [[ "$1" == -asm_o* ]]; then
|
||||||
echo ".intel_syntax noprefix" > asm-one-time-init.s
|
assemble "$2" asm-one-time-init.bin
|
||||||
echo "$2" >> asm-one-time-init.s
|
echo -n "asm-one-time-init.bin" > /sys/nb/one_time_init
|
||||||
as asm-one-time-init.s -o asm-one-time-init.o
|
rm -f asm-one-time-init.bin
|
||||||
objcopy asm-one-time-init.o -O binary asm-one-time-init.o
|
|
||||||
echo -n "asm-one-time-init.o" > /sys/nb/one_time_init
|
|
||||||
rm -f asm-one-time-init.s asm-one-time-init.o
|
|
||||||
shift 2
|
shift 2
|
||||||
elif [[ "$1" == -as* ]]; then
|
elif [[ "$1" == -as* ]]; then
|
||||||
echo ".intel_syntax noprefix" > asm-code.s
|
assemble "$2" asm-code.bin
|
||||||
echo "$2" >> asm-code.s
|
echo -n "asm-code.bin" > /sys/nb/code
|
||||||
as asm-code.s -o asm-code.o
|
rm -f asm-code.bin
|
||||||
objcopy asm-code.o -O binary asm-code.o
|
|
||||||
echo -n "asm-code.o" > /sys/nb/code
|
|
||||||
rm -f asm-code.s asm-code.o
|
|
||||||
shift 2
|
shift 2
|
||||||
elif [[ "$1" == -code_i* ]]; then
|
elif [[ "$1" == -code_i* ]]; then
|
||||||
echo -n "$2" > /sys/nb/init
|
echo -n "$2" > /sys/nb/init
|
||||||
|
|||||||
27
nanoBench.sh
27
nanoBench.sh
@@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source utils.sh
|
||||||
|
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo "Error: nanoBench requires root privileges" 1>&2
|
echo "Error: nanoBench requires root privileges" 1>&2
|
||||||
echo "Try \"sudo ./nanoBench-asm.sh ...\"" 1>&2
|
echo "Try \"sudo ./nanoBench-asm.sh ...\"" 1>&2
|
||||||
@@ -22,31 +24,19 @@ done
|
|||||||
args=''
|
args=''
|
||||||
while [ "$2" ]; do
|
while [ "$2" ]; do
|
||||||
if [[ "$1" == -asm_i* ]]; then
|
if [[ "$1" == -asm_i* ]]; then
|
||||||
echo ".intel_syntax noprefix" > asm-init.s
|
assemble "$2" asm-init.bin
|
||||||
echo "$2" >> asm-init.s
|
|
||||||
as asm-init.s -o asm-init.o || exit
|
|
||||||
objcopy asm-init.o -O binary asm-init.bin
|
|
||||||
args="$args -code_init asm-init.bin"
|
args="$args -code_init asm-init.bin"
|
||||||
shift 2
|
shift 2
|
||||||
elif [[ "$1" == -asm_l* ]]; then
|
elif [[ "$1" == -asm_l* ]]; then
|
||||||
echo ".intel_syntax noprefix" > asm-late-init.s
|
assemble "$2" asm-late-init.bin
|
||||||
echo "$2" >> asm-late-init.s
|
|
||||||
as asm-late-init.s -o asm-late-init.o || exit
|
|
||||||
objcopy asm-late-init.o -O binary asm-late-init.bin
|
|
||||||
args="$args -code_late_init asm-late-init.bin"
|
args="$args -code_late_init asm-late-init.bin"
|
||||||
shift 2
|
shift 2
|
||||||
elif [[ "$1" == -asm_o* ]]; then
|
elif [[ "$1" == -asm_o* ]]; then
|
||||||
echo ".intel_syntax noprefix" > asm-one-time-init.s
|
assemble "$2" asm-one-time-init.bin
|
||||||
echo "$2" >> asm-one-time-init.s
|
|
||||||
as asm-one-time-init.s -o asm-one-time-init.o || exit
|
|
||||||
objcopy asm-one-time-init.o -O binary asm-one-time-init.bin
|
|
||||||
args="$args -code_one_time_init asm-one-time-init.bin"
|
args="$args -code_one_time_init asm-one-time-init.bin"
|
||||||
shift 2
|
shift 2
|
||||||
elif [[ "$1" == -as* ]]; then
|
elif [[ "$1" == -as* ]]; then
|
||||||
echo ".intel_syntax noprefix" > asm-code.s
|
assemble "$2" asm-code.bin
|
||||||
echo "$2" >> asm-code.s
|
|
||||||
as asm-code.s -o asm-code.o || exit
|
|
||||||
objcopy asm-code.o -O binary asm-code.bin
|
|
||||||
args="$args -code asm-code.bin"
|
args="$args -code asm-code.bin"
|
||||||
shift 2
|
shift 2
|
||||||
else
|
else
|
||||||
@@ -79,10 +69,7 @@ else
|
|||||||
user/nanoBench $@
|
user/nanoBench $@
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f asm-code.*
|
rm -f asm-*.bin
|
||||||
rm -f asm-init.*
|
|
||||||
rm -f asm-late-init.*
|
|
||||||
rm -f asm-one-time-init.*
|
|
||||||
|
|
||||||
echo $prev_rdpmc > /sys/bus/event_source/devices/cpu/rdpmc
|
echo $prev_rdpmc > /sys/bus/event_source/devices/cpu/rdpmc
|
||||||
echo $prev_nmi_watchdog > /proc/sys/kernel/nmi_watchdog
|
echo $prev_nmi_watchdog > /proc/sys/kernel/nmi_watchdog
|
||||||
|
|||||||
27
utils.sh
Normal file
27
utils.sh
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
assemble() {
|
||||||
|
asm=$1
|
||||||
|
filename=$2
|
||||||
|
echo ".intel_syntax noprefix" > asm-tmp.s
|
||||||
|
echo "$asm" >> asm-tmp.s
|
||||||
|
sed -i "
|
||||||
|
s/|15/.byte 0x66,0x66,0x66,0x66,0x66,0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00;/g
|
||||||
|
s/|14/.byte 0x66,0x66,0x66,0x66,0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00;/g
|
||||||
|
s/|13/.byte 0x66,0x66,0x66,0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00;/g
|
||||||
|
s/|12/.byte 0x66,0x66,0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00;/g
|
||||||
|
s/|11/.byte 0x66,0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00;/g
|
||||||
|
s/|10/.byte 0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00;/g
|
||||||
|
s/|9/.byte 0x66,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00;/g
|
||||||
|
s/|8/.byte 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00;/g
|
||||||
|
s/|7/.byte 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00;/g
|
||||||
|
s/|6/.byte 0x66,0x0f,0x1f,0x44,0x00,0x00;/g
|
||||||
|
s/|5/.byte 0x0f,0x1f,0x44,0x00,0x00;/g
|
||||||
|
s/|4/.byte 0x0f,0x1f,0x40,0x00;/g
|
||||||
|
s/|3/.byte 0x0f,0x1f,0x00;/g
|
||||||
|
s/|2/.byte 0x66,0x90;/g
|
||||||
|
s/|1/nop;/g
|
||||||
|
s/|//g
|
||||||
|
" asm-tmp.s
|
||||||
|
as asm-tmp.s -o asm-tmp.o || exit
|
||||||
|
objcopy asm-tmp.o -O binary "$filename"
|
||||||
|
rm asm-tmp.*
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user