Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions docs/cpu_profile_generation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# CPU Profile Generation

## Generating a CPU profile for a new target

To generate a new CPU profile you start by executing the following command

```shell
$ cargo run --release -p arch --bin generate-cpu-profile --features="cpu_profile_generation" "<Your chosen name for the CPU profile>"

```
on the machine you want to create a CPU profile for. This creates four new files in the `arch/src/x86_64/cpu_profiles` directory:
- `<your chosen name in lower case with spaces replaced by underscore (_)>.cpuid.json`
- `<your chosen name in lower case with spaces replaced by underscore (_)>.msr.json`
- one license file for each of the two files listed above

check them in to git and then extend the `arch::x86_64::CpuProfile` enum with a new variant for your freshly generated profile.

The final step is then to adapt `arch::x86_64::CpuProfile::cpuid_data` and `arch::x86_64::CpuProfile::msr_data` mutatis mutandis
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it is just me but I had to google the meaning of mutatis mutandis

Copy link
Copy Markdown
Author

@olivereanderson olivereanderson Mar 23, 2026

Choose a reason for hiding this comment

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

I will try to find a simpler formulation. As always there is no need to be unnecessarily fancy. I just don't know of any other concise way to say exactly that, but it doesn't hurt to spend a few more words here anyway 🙂

to load the cpuid and msr JSON files we created above.

## Can existing CPU profiles be updated?

More recent KVM versions may introduce more support for already existing hardware features. When this happens it is of course
tempting to run the CPU profile generation tool again with the new KVM version as we then get a profile supporting more CPU
functionality. Doing this without giving the CPU profile a new name is however a breaking change and thus not permitted.
Such PRs will **not be accepted**. Instead we encourage you add a `V2` (or higher number if `V<i>` already exists) suffix
when generating the profile.

## Outlook
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see your idea and the writeup is valuabe! I think however this belongs to an issue. Outlook section may link to an issue, tho.


We intend to improve both CPU profile support in Cloud hypervisor as well as the CPU profile generation tool. Here is a
list of ideas that we want to consider.

### Buildscript: Full automation and (de-) compression

We will include a build script that automatically extends the `CpuProfile` enum and updates the `cpuid_data` and `msr_data`
methods accordingly.

While we are at it we can also make the build script compress the JSON files and place those bytes into the binary instead
of the full JSON files as we currently do.

### CPU Profile upload endpoint

It would not be much effort to adapt CHV to permit end users to specify their own JSON files instead of those associated
with a profile name.

This way users can run the CPU profile generation tool on their own hardware and use the resulting CPU profile without
involving upstream.

Advanced users also get a lot of control to adjust CPU profiles to satisfy their needs as they can now manipulate several
CPUID and/or MSR-based features themselves.

Before we go ahead with this however, we need to clearly document which changes Cloud hypervisor makes itself regardless
of the selected CPU profile.
Loading