diff --git a/README.adoc b/README.adoc index 1446fc3..f382778 100644 --- a/README.adoc +++ b/README.adoc @@ -202,6 +202,8 @@ The link:build[] script is just a lightweight wrapper that calls the smaller bui ./build --dry-run .... +see also: <>. + When you reach difficulties, QEMU makes it possible to easily GDB step debug the Linux kernel source code, see: xref:gdb[xrefstyle=full]. ===== Your first kernel module hack @@ -254,6 +256,8 @@ You can see that `./build` does that as well, by running: ./build --dry-run .... +See also: <>. + `--eval-after` is optional: you could just type `insmod hello.ko` in the terminal, but this makes it run automatically at the end of boot, and then drops you into a shell. If the guest and host are the same arch, typically x86_64, you can speed up boot further with <>: @@ -531,6 +535,7 @@ Read the following sections for further introductory material: * <> * <> +[[dry-run]] === Dry run to get commands for your project One of the major features of this repository is that we try to support the `--dry-run` option really well for all scripts. @@ -11879,7 +11884,6 @@ To use that file, first rebuild `m5ops.out` with the m5ops instructions enabled .... ./build-userland \ --arch aarch64 \ - --ccflags='-DLKMC_M5OPS_ENABLE=1' \ --force-rebuild \ userland/c/m5ops.c \ ; @@ -12180,7 +12184,19 @@ as explained in: gem5.opt --stats-help .... -TODO what is the advantage? The generated file for `--stats-file h5://stats.h5?desc=False` in LKMC f42c525d7973d70f4c836d2169cc2bd2893b4197 gem5 5af26353b532d7b5988cf0f6f3d0fbc5087dd1df was 946K, so much larger than the text version! +This is not exposed in LKMC f42c525d7973d70f4c836d2169cc2bd2893b4197 however, you just have to <>. + +TODO what is the advantage? The generated file for `--stats-file h5://stats.h5?desc=False` in LKMC f42c525d7973d70f4c836d2169cc2bd2893b4197 gem5 5af26353b532d7b5988cf0f6f3d0fbc5087dd1df for a single dump was 946K, so much larger than the text version seen at <> which was only 59KB max! + +We then try to see if it is any better when you have a bunch of dump events: + +.... +./run --arch aarch64 --emulator gem5 --userland userland/c/m5ops.c --userland-args 'd 1000' +.... + +and there yes, we see that the file size fell from 39MB on `stats.txt` to 3.2MB on `stats.m5`, so the increase observed previously was just due to some initial size overhead. + +We also note however that the stat dump made the such a simulation that just loops and dumps considerably slower, from 3s to 15s on <>. Fascinating, we are definitely not disk bound there. ===== gem5 only dump selected stats diff --git a/common.py b/common.py index 4542909..6cc6910 100644 --- a/common.py +++ b/common.py @@ -239,6 +239,8 @@ We aim display every command that modifies the filesystem state, and generate Bash equivalents even for actions taken directly in Python without shelling out. mkdir are generally omitted since those are obvious + +See also: https://cirosantilli.com/linux-kernel-module-cheat#dry-run ''' ) self.add_argument( diff --git a/path_properties.py b/path_properties.py index 0a4421a..e1897b0 100644 --- a/path_properties.py +++ b/path_properties.py @@ -649,6 +649,7 @@ path_properties_tuples = ( 'file_write_read.c': {'baremetal': False}, 'getchar.c': {'interactive': True}, 'malloc_max.c': {'disrupts_system': True}, + 'm5ops.c': {'allowed_emulators': {'gem5'}}, 'return1.c': {'exit_status': 1}, 'return2.c': {'exit_status': 2}, } @@ -669,6 +670,7 @@ path_properties_tuples = ( }, ), 'count.cpp': {'more_than_1s': True}, + 'm5ops.cpp': {'allowed_emulators': {'gem5'}}, 'parallel_sort.cpp': {'minimum_gcc_version': (9, 0, 0)}, 'sleep_for.cpp': { 'more_than_1s': True, diff --git a/userland/c/m5ops.c b/userland/c/m5ops.c index ee9af2a..117143c 100644 --- a/userland/c/m5ops.c +++ b/userland/c/m5ops.c @@ -1,34 +1,42 @@ /* https://cirosantilli.com/linux-kernel-module-cheat#m5ops-instructions */ -#include -#include #include +#define LKMC_M5OPS_ENABLE 1 #include int main(int argc, char **argv) { char action; + unsigned long long loops; + if (argc > 1) { action = argv[1][0]; } else { action = 'e'; } - switch (action) { - case 'c': - LKMC_M5OPS_CHECKPOINT; - break; - case 'd': - LKMC_M5OPS_DUMPSTATS; - break; - case 'e': - LKMC_M5OPS_EXIT; - break; - case 'f': - LKMC_M5OPS_FAIL_1; - break; - case 'r': - LKMC_M5OPS_RESETSTATS; - break; + if (argc > 2) { + loops = strtoull(argv[2], NULL, 0); + } else { + loops = 1; + } + for (unsigned long long i = 0; i < loops; i++) { + switch (action) { + case 'c': + LKMC_M5OPS_CHECKPOINT; + break; + case 'd': + LKMC_M5OPS_DUMPSTATS; + break; + case 'e': + LKMC_M5OPS_EXIT; + break; + case 'f': + LKMC_M5OPS_FAIL_1; + break; + case 'r': + LKMC_M5OPS_RESETSTATS; + break; + } } return EXIT_SUCCESS; } diff --git a/userland/cpp/m5ops.cpp b/userland/cpp/m5ops.cpp index b9b1c8b..938f9ab 100644 --- a/userland/cpp/m5ops.cpp +++ b/userland/cpp/m5ops.cpp @@ -1,5 +1,6 @@ /* https://cirosantilli.com/linux-kernel-module-cheat#m5ops-instructions */ +#define LKMC_M5OPS_ENABLE 1 #include int main(int argc, char **argv) {