Skip to content

Conversation

@nathanchance
Copy link
Member

See all of the individual commits for the details. I tested this with all architectures on x86_64 and 32-bit and 64-bit ARM and 32-bit and 64-bit x86 on aarch64.

Over the years, this script has gotten quite complex with the logic of
the QEMU options and user input. To make it easier to extend this in the
future, rewrite it in Python, which allows us to use much higher
built-in functions to parse input and make decisions based on that.

The performance difference between the shell and Python implementation
is not much. It is most noticeable when parsing the Linux kernel version
from an aarch64 kernel but the overall performance is still reasonable.

On an aarch64 host with a SoC with 16 Cortex-A72 cores:

  arm32_v7:

    Benchmark 1: boot-qemu.sh
    Time (mean ± σ):     14.265 s ±  0.021 s    [User: 15.572 s, System: 1.062 s]
    Range (min … max):   14.246 s … 14.305 s    10 runs

    Benchmark 2: boot-qemu.py
    Time (mean ± σ):     14.319 s ±  0.025 s    [User: 15.811 s, System: 0.925 s]
    Range (min … max):   14.282 s … 14.361 s    10 runs

    Summary
    'boot-qemu.sh' ran
        1.00 ± 0.00 times faster than 'boot-qemu.py'

  arm64:

    Benchmark 1: boot-qemu.sh
    Time (mean ± σ):      3.949 s ±  0.024 s    [User: 1.145 s, System: 1.165 s]
    Range (min … max):    3.916 s …  3.992 s    10 runs

    Benchmark 2: boot-qemu.py
    Time (mean ± σ):      4.009 s ±  0.032 s    [User: 1.426 s, System: 1.149 s]
    Range (min … max):    3.967 s …  4.049 s    10 runs

    Summary
    'boot-qemu.sh' ran
        1.02 ± 0.01 times faster than 'boot-qemu.py'

  arm64be:

    Benchmark 1: boot-qemu.sh
    Time (mean ± σ):      3.942 s ±  0.035 s    [User: 1.332 s, System: 1.114 s]
    Range (min … max):    3.910 s …  4.016 s    10 runs

    Benchmark 2: boot-qemu.py
    Time (mean ± σ):      3.985 s ±  0.028 s    [User: 1.196 s, System: 1.143 s]
    Range (min … max):    3.954 s …  4.034 s    10 runs

    Summary
    'boot-qemu.sh' ran
        1.01 ± 0.01 times faster than 'boot-qemu.py'

  x86:

    Benchmark 1: boot-qemu.sh
    Time (mean ± σ):     14.993 s ±  0.059 s    [User: 12.278 s, System: 1.094 s]
    Range (min … max):   14.926 s … 15.095 s    10 runs

    Benchmark 2: boot-qemu.py
    Time (mean ± σ):     14.985 s ±  0.045 s    [User: 12.455 s, System: 0.898 s]
    Range (min … max):   14.907 s … 15.039 s    10 runs

    Summary
    'boot-qemu.py' ran
        1.00 ± 0.00 times faster than 'boot-qemu.sh'

  x86_64:

    Benchmark 1: boot-qemu.sh
    Time (mean ± σ):     16.663 s ±  0.049 s    [User: 14.539 s, System: 0.544 s]
    Range (min … max):   16.601 s … 16.732 s    10 runs

    Benchmark 2: boot-qemu.py
    Time (mean ± σ):     16.692 s ±  0.059 s    [User: 14.044 s, System: 1.057 s]
    Range (min … max):   16.607 s … 16.819 s    10 runs

    Summary
    'boot-qemu.sh' ran
        1.00 ± 0.00 times faster than 'boot-qemu.py'

On an x86_64 host with an AMD Threadripper 3990X:

  arm32_v7:

    Benchmark 1: boot-qemu.sh
    Time (mean ± σ):      4.773 s ±  0.014 s    [User: 2.716 s, System: 0.065 s]
    Range (min … max):    4.750 s …  4.796 s    10 runs

    Benchmark 2: boot-qemu.py
    Time (mean ± σ):      4.807 s ±  0.021 s    [User: 2.749 s, System: 0.065 s]
    Range (min … max):    4.777 s …  4.841 s    10 runs

    Summary
    'boot-qemu.sh' ran
        1.01 ± 0.01 times faster than 'boot-qemu.py'

  arm64:

    Benchmark 1: boot-qemu.sh
    Time (mean ± σ):      5.089 s ±  0.022 s    [User: 3.196 s, System: 0.105 s]
    Range (min … max):    5.057 s …  5.122 s    10 runs

    Benchmark 2: boot-qemu.py
    Time (mean ± σ):      5.311 s ±  0.016 s    [User: 3.263 s, System: 0.141 s]
    Range (min … max):    5.297 s …  5.340 s    10 runs

    Summary
    'boot-qemu.sh' ran
        1.04 ± 0.01 times faster than 'boot-qemu.py'

  arm64be:

    Benchmark 1: boot-qemu.sh
    Time (mean ± σ):      5.011 s ±  0.021 s    [User: 3.124 s, System: 0.093 s]
    Range (min … max):    4.986 s …  5.049 s    10 runs

    Benchmark 2: boot-qemu.py
    Time (mean ± σ):      5.249 s ±  0.017 s    [User: 3.181 s, System: 0.155 s]
    Range (min … max):    5.223 s …  5.273 s    10 runs

    Summary
    'boot-qemu.sh' ran
        1.05 ± 0.01 times faster than 'boot-qemu.py'

  x86:

    Benchmark 1: boot-qemu.sh
    Time (mean ± σ):      2.869 s ±  0.022 s    [User: 0.532 s, System: 0.236 s]
    Range (min … max):    2.850 s …  2.906 s    10 runs

    Benchmark 2: boot-qemu.py
    Time (mean ± σ):      2.910 s ±  0.029 s    [User: 0.551 s, System: 0.236 s]
    Range (min … max):    2.856 s …  2.950 s    10 runs

    Summary
    'boot-qemu.sh' ran
        1.01 ± 0.01 times faster than 'boot-qemu.py'

  x86_64:

    Benchmark 1: boot-qemu.sh
    Time (mean ± σ):      3.242 s ±  0.043 s    [User: 1.390 s, System: 0.636 s]
    Range (min … max):    3.134 s …  3.277 s    10 runs

    Benchmark 2: boot-qemu.py
    Time (mean ± σ):      3.251 s ±  0.052 s    [User: 1.434 s, System: 0.602 s]
    Range (min … max):    3.130 s …  3.317 s    10 runs

    Summary
    'boot-qemu.sh' ran
        1.00 ± 0.02 times faster than 'boot-qemu.py'

This is designed to be a one-to-one rewrite, with the exception of
dropping support for '--debian' for simplicity's sake. It was always a
little janky at times and using other options such as libvirt is more
reliable. I may eventually contribute my other QEMU Python script to
this repository, which aims to drive full distributions.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Now that there is Python in this repository, we should make sure that it
stays consistently formatted like the shell scripts are.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Now that boot-qemu.sh has been rewritten in Python, this does not serve
any real purpose, as Python's argparse automatically shows the options
and help text.

Rewrite the README to give a brief overview of the repository.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Support for this was not forward ported during the Python rewrite, as it
did not always work that well. There are other alternatives such as
libvirt for running full distributions with QEMU. A future contribution
might add a Python script for roughly achieving what this set out to
accomplish.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool; this was overdue. Thanks for the rewrite. Untested on my end though. 🐗 🪵

Can you tell I use vim? :)

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
The version code is not printed anywhere so the function name is not as
accurate as it should be.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
This will be better in case we add anything after the 'gdb' if block.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
…_qemu()

It is not necessary.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
@nathanchance nathanchance merged commit 056d168 into ClangBuiltLinux:main Aug 2, 2022
@nathanchance
Copy link
Member Author

If there is any additional feedback from others, I am happy to address it in follow up pull requests.

@nathanchance nathanchance deleted the python-rewrite branch August 2, 2022 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants