Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance usability of CPU template helper tool #4492

Merged
merged 12 commits into from
Mar 15, 2024

Conversation

zulinx86
Copy link
Contributor

@zulinx86 zulinx86 commented Mar 8, 2024

Reasons

This PR mainly aims to enhance the usability of the CPU template helper tool.

The most inconvenient thing is that users need to prepare kernel, rootfs and Firecracker config to run the tool, although it doesn't actually start the microVM and those resources don't lead to meaningful changes to guest CPU config. But unfortunately, it cannot run without those resources because the CPU template helper tool should use the Firecracker's microVM initialization process (build_microvm_for_boot() of vmm crate) which requires such resources.

Changes

The main change is: CPU template helper tool prepares some required resources (kernel, rootfs and Firecracker config) on the behalf of users if --config parameter is not provided.

There are some refactoring commits in the first 6 commits.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • [ ] If a specific issue led to this PR, this PR closes the issue.
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this
    PR.
  • [ ] API changes follow the Runbook for Firecracker API changes.
  • User-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.
  • New TODOs link to an issue.
  • Commits meet
    contribution quality standards.

  • This functionality cannot be added in rust-vmm.

@zulinx86 zulinx86 force-pushed the improve_helper branch 3 times, most recently from fbb59af to b7f39dd Compare March 8, 2024 19:52
@zulinx86 zulinx86 self-assigned this Mar 8, 2024
@zulinx86 zulinx86 added rust Pull requests that update Rust code python Pull requests that update Python code Type: Enhancement Indicates new feature requests labels Mar 8, 2024
Copy link

codecov bot commented Mar 8, 2024

Codecov Report

Attention: Patch coverage is 96.49123% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 81.56%. Comparing base (a35412b) to head (e370111).

Files Patch % Lines
src/cpu-template-helper/src/main.rs 93.33% 1 Missing ⚠️
src/cpu-template-helper/src/utils/mod.rs 97.43% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4492      +/-   ##
==========================================
+ Coverage   81.52%   81.56%   +0.04%     
==========================================
  Files         243      243              
  Lines       29848    29875      +27     
==========================================
+ Hits        24334    24368      +34     
+ Misses       5514     5507       -7     
Flag Coverage Δ
4.14-c5n.metal 78.89% <96.29%> (?)
4.14-c7g.metal ?
4.14-m5d.metal ?
4.14-m5n.metal 78.88% <96.29%> (?)
4.14-m6a.metal 78.02% <96.29%> (+0.03%) ⬆️
4.14-m6g.metal 76.97% <96.49%> (+0.02%) ⬆️
4.14-m6i.metal 78.88% <96.29%> (+0.03%) ⬆️
4.14-m7g.metal 76.97% <96.49%> (?)
5.10-c5n.metal 81.54% <96.29%> (?)
5.10-c7g.metal ?
5.10-m5d.metal ?
5.10-m5n.metal 81.53% <96.29%> (?)
5.10-m6a.metal 80.76% <96.29%> (+0.03%) ⬆️
5.10-m6g.metal 79.84% <96.49%> (+0.02%) ⬆️
5.10-m6i.metal 81.52% <96.29%> (+0.02%) ⬆️
5.10-m7g.metal 79.84% <96.49%> (?)
6.1-c5n.metal 81.54% <96.29%> (?)
6.1-c7g.metal ?
6.1-m5d.metal ?
6.1-m5n.metal 81.53% <96.29%> (?)
6.1-m6a.metal 80.76% <96.29%> (+0.03%) ⬆️
6.1-m6g.metal 79.84% <96.49%> (+0.02%) ⬆️
6.1-m6i.metal 81.52% <96.29%> (+0.02%) ⬆️
6.1-m7g.metal 79.84% <96.49%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zulinx86 zulinx86 marked this pull request as draft March 10, 2024 15:54
@zulinx86 zulinx86 force-pushed the improve_helper branch 2 times, most recently from baa2784 to cda58bd Compare March 11, 2024 08:55
Copy link
Contributor

@pb8o pb8o left a comment

Choose a reason for hiding this comment

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

  • chore(cpu-template-helper): Add mock kernels
    • Could we keep the sources in the repo? Looks like a simple .c and Makefile can create those kernel files?

@zulinx86
Copy link
Contributor Author

zulinx86 commented Mar 11, 2024

  • chore(cpu-template-helper): Add mock kernels

    • Could we keep the sources in the repo? Looks like a simple .c and Makefile can create those kernel files?

Yes, we can keep the source. I'm still trying to find a way to create a PE binary instead of copying it from linux-loader binary in order to make it under our control.

@zulinx86 zulinx86 force-pushed the improve_helper branch 8 times, most recently from be59e62 to 93de09b Compare March 11, 2024 21:00
@zulinx86 zulinx86 marked this pull request as ready for review March 12, 2024 09:12
@zulinx86 zulinx86 requested a review from pb8o March 12, 2024 15:43
@zulinx86 zulinx86 added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Mar 12, 2024
pb8o
pb8o previously approved these changes Mar 15, 2024
src/cpu-template-helper/src/utils/mock_kernel/Makefile Outdated Show resolved Hide resolved
src/cpu-template-helper/src/utils/mock_kernel/Makefile Outdated Show resolved Hide resolved
src/cpu-template-helper/src/utils/mod.rs Show resolved Hide resolved
src/vmm/src/arch/aarch64/regs.rs Outdated Show resolved Hide resolved
src/vmm/src/vstate/vcpu/aarch64.rs Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
The `--config` parameter of the fingerprint dump command is used to pass
a Firecracker config file (not a fingerprint file).

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Imports the template module directly from vmm-sys-util instead of
firecracker's utils library, because it is just re-published from
vmm-sys-utils by firecracker's utils library. Thanks to this, we can
avoid module name collision between firecracker and cpu-template-helper.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
These type annotations are not needed thanks for Rust's type inference.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
The KVM register ID for PC (program counter) was calculated at runtime.
Make it constant value like other registers.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Align the register name to Linux kernel.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
On kernel 6.5, a new timer register SYS_CNTPCT_EL0 becomes available and
it was added to an exception list in integration tests. But from users'
perspective, it is quite harmful for users to need to filter it out on
their side because it isn't useful in CPU template lifecycle and it is
ignoreable. So it should be excluded on the tool side.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Currently cpu-template-helper requires some resources (kernel, rootfs
and Firecracker config files) to dump a guest CPU config or a
fingerprint or verify a CPU template, although they don't affect the
output essentially. This is because it utilizes
`build_microvm_for_boot()` function imported from vmm crate that
requires those resources. Adding mock kernels is preliminary task to
remove the requirement.

`build_microvm_for_boot()` requires a valid ELF file for x86_64 and a
file containing a valid kernel header for aarch64. So we use a minimal C
program for x86_64 and just write a kernel header to a file for aarch64.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
The added utility function prepares all the required resources
temporarily and removes them after use to help users not to need to do
that.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Now users no longer need to prepare kernel image file, rootfs file and
Firecracker config file that don't affect the output essentially. If
`--config` is not provided, the CPU template helper tool does the
preparation instead. The parameter itself is preserved for backward
compatibility and special usecases (like changing the number of vCPUs).
In addition, it becomes able to simplify tests a lot.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
The previous commit made `--config` optional, but it is used to specify
a CPU template to verify. To allow users to verify a CPU template
without passing a Firecracker config file, adds `--template` to the
command.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Now that there is no need to specify `--config` to
`cpu-template-helper`, removes `--config` from integration tests and
simplifies them. Also regathers fingerprint files. All the fingerprint
changes are caused by the difference of the number of vCPUs: the
Firecracker's default value is 1 vCPU but the test config value is 2
vCPUs.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Previously, only consecutive guest CPU configs were verified.
A fingerprint contains not only guest CPU config but also host
configuration.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
@zulinx86 zulinx86 merged commit 6fc6f48 into firecracker-microvm:main Mar 15, 2024
6 of 7 checks passed
@zulinx86 zulinx86 deleted the improve_helper branch March 15, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests that update Python code rust Pull requests that update Rust code Status: Awaiting review Indicates that a pull request is ready to be reviewed Type: Enhancement Indicates new feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants