diff options
author | David Brazdil <dbrazdil@google.com> | 2023-01-31 13:35:49 +0000 |
---|---|---|
committer | crosvm LUCI <crosvm-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-01-12 10:03:55 +0000 |
commit | ba2f66ae97c40a9cc67541cca1d64d033f665dc7 (patch) | |
tree | 57aa84053d52fcc2baf156ea70eab610c9e514d6 /aarch64 | |
parent | 4d5db1aec67544a5f1fa5be475324b0f0ce291d6 (diff) | |
download | crosvm-ba2f66ae97c40a9cc67541cca1d64d033f665dc7.tar.gz |
Clone host CPU capacity/clusters for --host-cpu-topology
When --host-cpu-topology flag is specified, crosvm will create 1:1
affinity masks between host CPUs and VM's vCPUs. Extend this mechanims
to also pass the cluster IDs and CPU capacity information to the guest.
Same as with --cpu-affinity, the client now cannot specify
--cpu-capacity and --cpu clusters together with --host-cpu-topology.
This only has an effect on DeviceTree-based platforms, same as the two
cmdline flags mentioned above.
Bug: 266664564
Test: ./tools/presubmit
Change-Id: I8f6d5cea7d8861e27f02ec55b50c0d12e1c2866b
Signed-off-by: David Dai <davidai@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4208668
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: David Brazdil <dbrazdil@google.com>
Diffstat (limited to 'aarch64')
-rw-r--r-- | aarch64/src/lib.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/aarch64/src/lib.rs b/aarch64/src/lib.rs index fbd3460f8..d5c476dae 100644 --- a/aarch64/src/lib.rs +++ b/aarch64/src/lib.rs @@ -13,6 +13,7 @@ use std::sync::mpsc; use std::sync::Arc; use arch::get_serial_cmdline; +use arch::CpuSet; use arch::DtbOverlay; use arch::GetSerialCmdlineError; use arch::RunnableLinuxVm; @@ -231,6 +232,8 @@ pub enum Error { Cmdline(kernel_cmdline::Error), #[error("failed to configure CPU Frequencies: {0}")] CpuFrequencies(base::Error), + #[error("failed to configure CPU topology: {0}")] + CpuTopology(base::Error), #[error("unable to create battery devices: {0}")] CreateBatDevices(arch::DeviceRegistrationError), #[error("unable to make an Event: {0}")] @@ -832,6 +835,33 @@ impl arch::LinuxArch for AArch64 { .collect(), ) } + + // Returns a (cpu_id -> value) map of the DMIPS/MHz capacities of logical cores + // in the host system. + fn get_host_cpu_capacity() -> std::result::Result<BTreeMap<usize, u32>, Self::Error> { + Ok(Self::collect_for_each_cpu(base::logical_core_capacity) + .map_err(Error::CpuTopology)? + .into_iter() + .enumerate() + .collect()) + } + + // Creates CPU cluster mask for each CPU in the host system. + fn get_host_cpu_clusters() -> std::result::Result<Vec<CpuSet>, Self::Error> { + let cluster_ids = Self::collect_for_each_cpu(base::logical_core_cluster_id) + .map_err(Error::CpuTopology)?; + Ok(cluster_ids + .iter() + .map(|&vcpu_cluster_id| { + cluster_ids + .iter() + .enumerate() + .filter(|(_, &cpu_cluster_id)| vcpu_cluster_id == cpu_cluster_id) + .map(|(cpu_id, _)| cpu_id) + .collect() + }) + .collect()) + } } #[cfg(feature = "gdb")] |