From e8f049ed11355bb2e9564430ac8357a311226870 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: Sat, 13 Oct 2018 00:00:00 +0000 Subject: [PATCH] gem5: default build id to worktree --- README.adoc | 40 +++++++++++++++++++--------------------- common.py | 11 +++++++---- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/README.adoc b/README.adoc index fc7ecae..839a567 100644 --- a/README.adoc +++ b/README.adoc @@ -10714,7 +10714,7 @@ Like <>, you will need to pass the `-n` option to anything tha ./run-gdb --run-id 1 .... -To run multiple gem5 checkouts, see: <>. +To run multiple gem5 checkouts, see: <>. Implementation note: we create multiple namespaces for two things: @@ -10808,11 +10808,9 @@ git -C "$(./getvar gem5_src_dir)" checkout some-branch Don't forget however that gem5 has Python scripts in its source code tree, and that those must match the source code of a given build. -Therefore, you can't forget to checkout to the sources to that of the corresponding build before running, unless you explicitly tell gem5 to use a non-default source tree with `--gem5-worktree`. +Therefore, you can't forget to checkout to the sources to that of the corresponding build before running, unless you explicitly tell gem5 to use a non-default source tree with <>. This becomes inevitable when you want to launch multiple simultaneous runs at different checkouts. -This becomes inevitable when you want to launch <>. - -===== gem5 simultaneous runs with build variants +===== gem5 worktree In order to checkout multiple gem5 builds and run them simultaneously, you also need to use the `--gem5-worktree` flag: @@ -10822,7 +10820,7 @@ In order to checkout multiple gem5 builds and run them simultaneously, you also # Build another branch. git -C "$(./getvar linux_src_dir)" checkout some-branch -./build-gem5 --gem5-build-id some-branch --gem5-worktree some-branch +./build-gem5 --gem5-worktree some-branch # Restore master. git -C "$(./getvar linux_src_dir)" checkout - @@ -10832,31 +10830,31 @@ git -C "$(./getvar linux_src_dir)" checkout - # Run another branch using the worktree for the scripts, # without the need to check out anything. -./run --gem5 --gem5-build-id some-branch --gem5-worktree some-branch --run-id 1 &>/dev/null & +./run --gem5 --gem5-worktree some-branch --run-id 1 &>/dev/null & .... +This automatically creates a link:https://git-scm.com/docs/git-worktree[Git worktree] of gem5 if one didn't exit yet. Therefore, if you want to edit the code used by `--gem5-worktree-id`, you must edit it on the worktree: + +.... +cd data/gem5/some-branch +vim create-bugs +git checkout was-working-i-think +.... + +We promise that the scripts sill never touch that worktree again once it has been created: it is now up to you to manage the code manually. + When `--gem5-worktree` is not given, the default source tree under `submodules/gem5` is used. -The `--gem5-worktree ` determines the location of the gem5 tree to be used for both: +The `--gem5-worktree ` command determines the location of the gem5 tree to be used for both: * the input C files of the build at build time * the Python scripts to be used at runtime The difference between `--gem5-build-id` and `--gem5-worktree` is that `--gem5-build-id` specifies the gem5 build output directory, while `--gem5-worktree` specifies the source input directory. -If `--gem5-worktree ` is given, the directory used is `data/gem5/`, and: +`--gem5-worktree` also sets `--gem5-build-id` by default, so that different worktrees lead to different builds by default. -* if that directory does not exist, create a `git worktree` at a branch `wt/` on current commit of `submodules/gem5` there. -+ -The `wt/` branch name prefix stands for `WorkTree`, and is done to allow us to checkout to a test `some-branch` branch under `submodules/gem5` and still use `--gem5-worktree some-branch`, without conflict for the worktree branch, which can only be checked out once. -* otherwise, leave that worktree untouched, without updating it - -Therefore, future builds for `worktree-id` will not automatically modify the revision of the worktree, and to do that you must manually check it out: - -.... -git -C data/gem5/some-branch checkout some-branch-v2 -./build-buildroot --gem5 --gem5-build-id some-branch --gem5-worktree some-branch -.... +Each Git worktree needs a branch name, and we append the `wt/` prefix to the `--gem5-worktree` value, where `wt` stands for `WorkTree`. This is done to allow us to checkout to a test `some-branch` branch under `submodules/gem5` and still use `--gem5-worktree some-branch`, without conflict for the worktree branch, which can only be checked out once. `--gem5-worktree` is only required if you have multiple gem5 checkouts, e.g. it would not be required for multiple builds of the same tree, e.g. a <> and a non-debug one. @@ -10895,7 +10893,7 @@ With this setup, both your private gem5 source and build are safely kept outside ===== gem5 debug build -The `gem5.debug` has optimizations turned off unlike the default `gem5.opt`, and provides a much better <>: +The `gem5.debug` executable has optimizations turned off unlike the default `gem5.opt`, and provides a much better <>: .... ./build-gem5 --arch aarch64 --gem5-build-type debug diff --git a/common.py b/common.py index 64b166e..d44bf0f 100644 --- a/common.py +++ b/common.py @@ -43,6 +43,7 @@ extract_vmlinux = os.path.join(linux_src_dir, 'scripts', 'extract-vmlinux') qemu_src_dir = os.path.join(submodules_dir, 'qemu') parsec_benchmark_src_dir = os.path.join(submodules_dir, 'parsec-benchmark') ccache_dir = os.path.join('/usr', 'lib', 'ccache') +default_build_id = 'default' arch_map = { 'a': 'arm', 'A': 'aarch64', @@ -115,7 +116,6 @@ def get_argparse(default_args=None, argparse_args=None): for key in this.arch_map: arch_choices.append(key) arch_choices.append(this.arch_map[key]) - default_build_id = 'default' parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter, **argparse_args @@ -172,9 +172,8 @@ See the documentation for other values known to work. parser.add_argument( '-N', '--gem5-worktree', help='''\ -gem5 git worktree to use for build and Python scripts at runtime. Automatically -create a new git worktree with the given id if one does not exist. If not -given, just use the submodule source. +Create and use a git worktree of the gem5 submodule. +See: https://github.com/cirosantilli/linux-kernel-module-cheat#gem5-worktree ''' ) parser.add_argument( @@ -526,6 +525,10 @@ def setup(parser): args = parser.parse_args() if args.arch in this.arch_map: args.arch = this.arch_map[args.arch] + # Because argparse sucks: + # https://stackoverflow.com/questions/30487767/check-if-argparse-optional-argument-is-set-or-not + if args.gem5_worktree is not None and args.gem5_build_id == default_build_id: + args.gem5_build_id = args.gem5_worktree this.machine = args.machine if args.arch == 'arm': this.armv = 7