From f2713e69f63a0bc12582123ea7f57b9675f1546b 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: Fri, 14 Feb 2020 00:00:00 +0000 Subject: [PATCH] Don't pass dummy disk images to gem5 After https://gem5.atlassian.net/browse/GEM5-337: - gem5 baremetal can run without any disk images, just like QEMU - gem5 X86 can run with a single disk image and no horrendous dummy vmlinux and second disk image --- build-gem5 | 13 +------------ common.py | 5 ++--- run | 23 +++++++++++------------ 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/build-gem5 b/build-gem5 index 57e773a..a78c57e 100755 --- a/build-gem5 +++ b/build-gem5 @@ -61,18 +61,7 @@ https://github.com/cirosantilli/linux-kernel-module-cheat-regression#gem5-unit-t verbose = ['--verbose', LF] else: verbose = [] - if self.env['arch'] == 'x86_64': - dummy_img_path = os.path.join(disks_dir, 'linux-bigswap2.img') - with open(dummy_img_path, 'wb') as dummy_img_file: - zeroes = b'\x00' * (2 ** 16) - for i in range(2 ** 10): - dummy_img_file.write(zeroes) - self.sh.run_cmd(['mkswap', dummy_img_path, LF]) - with open(os.path.join(binaries_dir, 'x86_64-vmlinux-2.6.22.9'), 'w'): - # This file must always be present, despite --kernel overriding that default and selecting the kernel. - # I'm not even joking. No one has ever built x86 gem5 without the magic dist dir present. - pass - elif self.env['arch'] == 'arm' or self.env['arch'] == 'aarch64': + if self.env['is_arm']: gem5_system_source_dir = os.path.join(self.env['gem5_source_dir'], 'system') # dtb diff --git a/common.py b/common.py index 3f291c5..6edcc2f 100644 --- a/common.py +++ b/common.py @@ -844,7 +844,6 @@ Incompatible archs are skipped. # gem5 if not env['_args_given']['gem5_build_dir']: env['gem5_build_dir'] = join(env['gem5_out_dir'], env['gem5_build_id']) - env['gem5_fake_iso'] = join(env['gem5_out_dir'], 'fake.iso') env['gem5_m5term'] = join(env['gem5_build_dir'], 'm5term') env['gem5_build_build_dir'] = join(env['gem5_build_dir'], 'build') env['gem5_executable_dir'] = join(env['gem5_build_build_dir'], env['gem5_arch']) @@ -1065,7 +1064,7 @@ Incompatible archs are skipped. # Image if env['baremetal'] is not None: - env['disk_image'] = env['gem5_fake_iso'] + env['disk_image'] = None env['image'] = self.resolve_baremetal_executable(env['baremetal']) source_path_noext = os.path.splitext(join( env['root_dir'], @@ -1094,7 +1093,7 @@ Incompatible archs are skipped. if not env['_args_given']['linux_exec']: env['image'] = env['vmlinux'] if env['ramfs']: - env['disk_image'] = env['gem5_fake_iso'] + env['disk_image'] = None else: env['disk_image'] = env['rootfs_raw_file'] else: diff --git a/run b/run index e20d224..5b88ae4 100755 --- a/run +++ b/run @@ -471,11 +471,7 @@ Extra options to append at the end of the emulator command line. if self.env['emulator'] == 'gem5': if self.env['quiet']: show_stdout = False - if not self.env['baremetal'] is None: - if not os.path.exists(self.env['gem5_fake_iso']): - os.makedirs(os.path.dirname(self.env['gem5_fake_iso']), exist_ok=True) - self.sh.write_string_to_file(self.env['gem5_fake_iso'], 'a' * 512) - elif self.env['userland'] is None: + if self.env['baremetal'] is None and self.env['userland'] is None: if not os.path.exists(self.env['rootfs_raw_file']): if not os.path.exists(self.env['qcow2_file']): raise_rootfs_not_found() @@ -536,11 +532,12 @@ Extra options to append at the end of the emulator command line. extra_emulator_args.extend(['-r', str(cpt_dirs_sorted_by_tick.index(cpt_dir) + 1)]) cmd.extend([ self.env['gem5_fs_file'], LF, - '--disk-image', self.env['disk_image'], LF, '--kernel', self.env['image'], LF, '--num-cpus', str(self.env['cpus']), LF, '--script', self.env['gem5_readfile_file'], LF, ]) + if self.env['disk_image'] is not None: + cmd.extend(['--disk-image', self.env['disk_image'], LF]) if self.env['arch'] == 'x86_64': if self.env['kvm']: cmd.extend(['--cpu-type', 'X86KvmCPU', LF]) @@ -608,11 +605,12 @@ Extra options to append at the end of the emulator command line. '--bootscript', self.env['gem5_readfile_file'], LF, '--big-cpus', str((self.env['cpus'] + 1) // 2), LF, '--cpu-type', cpu_type, LF, - '--disk', self.env['disk_image'], LF, '--kernel', self.env['image'], LF, '--little-cpus', str(self.env['cpus'] // 2), LF, '--root', '/dev/vda', LF, ]) + if self.env['disk_image'] is not None: + cmd.extend(['--disk', self.env['disk_image'], LF]) if self.env['dtb']: cmd.extend([ '--dtb', @@ -749,6 +747,12 @@ Extra options to append at the end of the emulator command line. if not os.path.exists(self.env['rootfs_raw_file']): raise_rootfs_not_found() self.raw_to_qcow2(qemu_which=self.env['qemu_which']) + if rr: + extra_emulator_args.extend([ + '-drive', 'driver=blkreplay,if=none,image=img-direct,id=img-blkreplay', LF, + '-device', 'ide-hd,drive=img-blkreplay', LF, + ]) + if self.env['disk_image'] is not None: extra_emulator_args.extend([ '-drive', 'file={},format=qcow2,if={}{}{}'.format( @@ -759,11 +763,6 @@ Extra options to append at the end of the emulator command line. ), LF, ]) - if rr: - extra_emulator_args.extend([ - '-drive', 'driver=blkreplay,if=none,image=img-direct,id=img-blkreplay', LF, - '-device', 'ide-hd,drive=img-blkreplay', LF, - ]) if rr: extra_emulator_args.extend([ '-object', 'filter-replay,id=replay,netdev=net0', LF,