From c2983e0e1f43399b96b63d03b88a9891a44e2308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Tue, 22 Jan 2019 00:00:00 +0000 Subject: [PATCH] bench-boot: start convert to cli function --- bench-boot | 202 +++++++++++++++++++++++++++--------------------- build | 3 +- cli_function.py | 2 + common.py | 2 + 4 files changed, 121 insertions(+), 88 deletions(-) diff --git a/bench-boot b/bench-boot index 02888ac..d592dcc 100755 --- a/bench-boot +++ b/bench-boot @@ -1,95 +1,125 @@ -#!/usr/bin/env bash -set -eu -root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" -test_size=1 -while [ $# -gt 0 ]; do - case "$1" in - --size) - # 1: a few seconds and important - # 2: < 5 minutes and important or a few seconds and not too important - # 3: all - test_size="$2" - shift 2 - ;; - esac -done +#!/usr/bin/env python3 -if [ $# -gt 1 ]; then - extra_args=" $*" -else - extra_args= -fi -getvar="${root_dir}/getvar" -common_bench_boot="$("$getvar" bench_boot)" -caches='--caches --l2cache --l1d_size=1024kB --l1i_size=1024kB --l2_size=1024kB --l3_size=1024kB' +import common +from shell_helpers import LF -bench() ( - "${root_dir}/bench-cmd" "./run --arch ${1}${extra_args}" "$common_bench_boot" -) +class Main(common.LkmcCliFunction): + def __init__(self): + super().__init__( + defaults={ + 'print_time': False, + }, + description='''\ +Run Linux kernel boot tests and benchmarks. +''' + ) + self.add_argument( + '--size', + default=1, + type=int, + help='''\ +Size of the tests to run. Scale: -newline() ( - echo >> "$common_bench_boot" -) +* 1: a few seconds and important +* 2: < 5 minutes and important or a few seconds and not too important +* 3: all +''' + ) -gem5_insts() ( - printf "instructions $(./gem5-stat --arch "$1" sim_insts)\n" >> "$common_bench_boot" - newline -) + def _bench(self, **kwargs): + self.run(**kwargs) -qemu_insts() ( - common_arch="$1" - ./qemu-trace2txt --arch "$common_arch" - common_qemu_trace_txt_file="$("$getvar" --arch "$common_arch" qemu_trace_txt_file)" - printf "instructions $(wc -l "${common_qemu_trace_txt_file}" | cut -d' ' -f1)\n" >> "$common_bench_boot" - newline -) + def timed_main(self): + #bench() ( + # "${root_dir}/bench-cmd" "./run --arch ${1}${extra_args}" "$self.env['bench_boot']" + #) + # + #newline() ( + # echo >> "$self.env['bench_boot']" + #) + # + #gem5_insts() ( + # printf "instructions $(./gem5-stat --arch "$1" sim_insts)\n" >> "$self.env['bench_boot']" + # newline + #) + # + #qemu_insts() ( + # common_arch="$1" + # ./qemu-trace2txt --arch "$common_arch" + # common_qemu_trace_txt_file="$("$getvar" --arch "$common_arch" qemu_trace_txt_file)" + # printf "instructions $(wc -l "${common_qemu_trace_txt_file}" | cut -d' ' -f1)\n" >> "$self.env['bench_boot']" + # newline + #) + # + #rm -f "${self.env['bench_boot']}" -rm -f "${common_bench_boot}" + self.run = self.import_path_main('run') + run_args = self.get_common_args() + if self.env['emulator'] == 'gem5': + run_args['eval'] = 'm5 exit' + elif self.env['emulator'] == 'qemu': + run_args['eval'] = '/poweroff.out' + if (self.env['emulator'] == 'qemu' or + (self.env['emulator'] == 'gem5' and self.env['size'] >= 2)): + self._bench(**run_args) + if self.env['host_arch'] == self.env['arch']: + # TODO: find out why it fails. + if self.env['emulator'] != 'gem5': + self._bench(kvm=True, **run_args) + # newline + if self.env['emulator'] == 'qemu' and self.env['size'] >= 2: + self._bench(trace='exec_tb', **run_args) + # qemu_insts "$arch" + if self.env['emulator'] == 'gem5' and self.env['size'] >= 3: + self._bench( + extra_emulator_args=[ + '--cpu-type', + 'DerivO3CPU', + '--caches', + '--l2cache', + '--l1d_size=1024kB', + '--l1i_size=1024kB', + '--l2_size=1024kB', + '--l3_size=1024kB', + ], + **run_args + ) + # gem5_insts "$arch" -arch=x86_64 -bench "${arch} --eval '/poweroff.out'" -newline -bench "${arch} --eval '/poweroff.out' --kvm" -newline -if [ "$test_size" -ge 2 ]; then - bench "${arch} --eval '/poweroff.out' --trace exec_tb" - qemu_insts "$arch" - bench "$arch --eval 'm5 exit' --emulator gem5" - gem5_insts "$arch" -fi -#bench "$arch --eval 'm5 exit' --emulator gem5 -- --cpu-type=DerivO3CPU ${caches}" -#gem5_insts "$arch" + #arch=arm + #bench "$arch --eval '/poweroff.out'" + #newline + #if [ self.env['size'] -ge 2 ]; then + # bench "$arch --eval '/poweroff.out' --trace exec_tb" + # qemu_insts "$arch" + # bench "$arch --eval 'm5 exit' --emulator gem5" + # gem5_insts "$arch" + #fi + #if [ self.env['size'] -ge 3 ]; then + # bench "$arch --eval 'm5 exit' --emulator gem5 -- --cpu-type=HPI ${caches}" + # gem5_insts "$arch" + #fi -arch=arm -bench "$arch --eval '/poweroff.out'" -newline -if [ "$test_size" -ge 2 ]; then - bench "$arch --eval '/poweroff.out' --trace exec_tb" - qemu_insts "$arch" - bench "$arch --eval 'm5 exit' --emulator gem5" - gem5_insts "$arch" -fi -if [ "$test_size" -ge 3 ]; then - bench "$arch --eval 'm5 exit' --emulator gem5 -- --cpu-type=HPI ${caches}" - gem5_insts "$arch" -fi + #arch=aarch64 + #bench "$arch --eval '/poweroff.out'" + #newline + #if [ self.env['size'] -ge 2 ]; then + # bench "$arch --eval '/poweroff.out' --trace exec_tb" + # qemu_insts "$arch" + # bench "$arch --eval 'm5 exit' --emulator gem5" + # gem5_insts "$arch" + #fi + #if [ self.env['size'] -ge 3 ]; then + # bench "$arch --eval 'm5 exit' --emulator gem5 -- --cpu-type=HPI ${caches}" + # gem5_insts "$arch" + # #bench "$arch --eval 'm5 exit' --emulator gem5 --gem5-script biglittle" + # #gem5_insts "$arch" + # bench "$arch --eval 'm5 exit' --emulator gem5 --gem5-build-type fast" + # gem5_insts "$arch" + # bench "$arch --eval 'm5 exit' --emulator gem5 --gem5-build-type debug" + # gem5_insts "$arch" + #fi + +if __name__ == '__main__': + Main().cli_exit() -arch=aarch64 -bench "$arch --eval '/poweroff.out'" -newline -if [ "$test_size" -ge 2 ]; then - bench "$arch --eval '/poweroff.out' --trace exec_tb" - qemu_insts "$arch" - bench "$arch --eval 'm5 exit' --emulator gem5" - gem5_insts "$arch" -fi -if [ "$test_size" -ge 3 ]; then - bench "$arch --eval 'm5 exit' --emulator gem5 -- --cpu-type=HPI ${caches}" - gem5_insts "$arch" - #bench "$arch --eval 'm5 exit' --emulator gem5 --gem5-script biglittle" - #gem5_insts "$arch" - bench "$arch --eval 'm5 exit' --emulator gem5 --gem5-build-type fast" - gem5_insts "$arch" - bench "$arch --eval 'm5 exit' --emulator gem5 --gem5-build-type debug" - gem5_insts "$arch" -fi diff --git a/build b/build index b311b59..268a831 100755 --- a/build +++ b/build @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -import platform import re import os @@ -368,7 +367,7 @@ Which components to build. Default: qemu-buildroot } # E.g. on an ARM host, the package gcc-arm-linux-gnueabihf # is called just gcc. - processor = platform.processor() + processor = self.env['host_arch'] if processor != 'arm': apt_get_pkgs.update({ 'gcc-arm-linux-gnueabihf', diff --git a/cli_function.py b/cli_function.py index 911eee9..b343c8c 100755 --- a/cli_function.py +++ b/cli_function.py @@ -431,6 +431,8 @@ amazing function! assert one_cli_function.get_cli(pos_mandatory=1, bool=False) == [('--bool',), ('--bool-cli',), ('1',)] assert one_cli_function.get_cli(pos_mandatory=1, pos_optional=2, args_star=['3', '4']) == [('--bool-cli',), ('1',), ('2',), ('3',), ('4',)] assert one_cli_function.get_cli(pos_mandatory=1, append=['2', '3']) == [('--append', '2'), ('--append', '3',), ('--bool-cli',), ('1',)] + print(one_cli_function.get_cli(pos_mandatory=1, args_star=['asdf', 'qwer'])) + assert one_cli_function.get_cli(pos_mandatory=1, args_star=['asdf', 'qwer']) == [('--bool-cli',), ('1',), ('asdf',), ('qwer',),] if len(sys.argv) > 1: # CLI call with argv command line arguments. diff --git a/common.py b/common.py index 9f666ee..975427a 100644 --- a/common.py +++ b/common.py @@ -12,6 +12,7 @@ import json import math import multiprocessing import os +import platform import re import shutil import signal @@ -105,6 +106,7 @@ consts['emulator_choices'] = set() for key in consts['emulator_short_to_long_dict']: consts['emulator_choices'].add(key) consts['emulator_choices'].add(consts['emulator_short_to_long_dict'][key]) +consts['host_arch'] = platform.processor() class LkmcCliFunction(cli_function.CliFunction): '''