Skip to content

Commit 1954875

Browse files
vCPUs default to same core as PD managing them
I think this makes more sense, if a PD that is acting as a VMM is on core 2 and it only has one vCPU, that vCPU should probably run on core 2 as well. In the case of a single vCPU, I don't think it really makes sense for it to not run on the same core as the VMM. Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
1 parent cbc4c9d commit 1954875

3 files changed

Lines changed: 24 additions & 16 deletions

File tree

docs/manual.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,8 @@ Additionally, it supports the following child elements:
10971097
The `vcpu` element has the following attributes:
10981098

10991099
* `id`: The vCPU identifier. Must be at least 0 and less than 62.
1100+
* `cpu`: (optional) set the physical CPU core that the vCPU will run on. Defaults to the same CPU
1101+
core of the PD that the virtual machine belongs to.
11001102
* `setvar_id`: (optional) Specifies a symbol in the program image. This symbol will be rewritten with the vCPU identifier.
11011103

11021104
The `map` element has the same attributes as the protection domain with the exception of `setvar_vaddr`.

tool/microkit/src/capdl/builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,12 +936,14 @@ pub fn build_capdl_spec(
936936
capdl_util_make_vcpu_cap(vm_vcpu_obj_id),
937937
));
938938

939+
// vCPU should default to CPU that the PD runs if not explicitly specified.
940+
let vcpu_affinity = vcpu.cpu.unwrap_or(pd.cpu);
939941
// Finally create TCB, unlike PDs, VMs are suspended by default until resume'd by their parent.
940942
let vm_vcpu_tcb_inner_obj = object::Tcb {
941943
slots: caps_to_bind_to_vm_tcbs,
942944
extra: Box::new(object::TcbExtraInfo {
943945
ipc_buffer_addr: Word(0),
944-
affinity: Word(vcpu.cpu.0.into()),
946+
affinity: Word(vcpu_affinity.0.into()),
945947
prio: virtual_machine.priority,
946948
max_prio: virtual_machine.priority,
947949
// Given the use cases of VMs, for now we always give them FPU access.

tool/microkit/src/sdf.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub struct VirtualMachine {
295295
pub struct VirtualCpu {
296296
pub id: u64,
297297
pub setvar_id: Option<String>,
298-
pub cpu: CpuCore,
298+
pub cpu: Option<CpuCore>,
299299
}
300300

301301
/// To avoid code duplication for handling protection domains
@@ -1186,22 +1186,26 @@ impl VirtualMachine {
11861186

11871187
let setvar_id = node.attribute("setvar_id").map(ToOwned::to_owned);
11881188

1189-
let cpu = CpuCore(
1190-
sdf_parse_number(child.attribute("cpu").unwrap_or("0"), node)?
1189+
let cpu = if let Some(cpu) = child.attribute("cpu") {
1190+
let cpu_value: u8 = sdf_parse_number(cpu, node)?
11911191
.try_into()
1192-
.expect("cpu # fits in u8"),
1193-
);
1192+
.expect("cpu # fits in u8");
11941193

1195-
if cpu.0 >= config.num_cores {
1196-
return Err(value_error(
1197-
xml_sdf,
1198-
&child,
1199-
format!(
1200-
"cpu core must be less than {}, got {}",
1201-
config.num_cores, cpu
1202-
),
1203-
));
1204-
}
1194+
if cpu_value >= config.num_cores {
1195+
return Err(value_error(
1196+
xml_sdf,
1197+
&child,
1198+
format!(
1199+
"cpu core must be less than {}, got {}",
1200+
config.num_cores, cpu_value
1201+
),
1202+
));
1203+
}
1204+
1205+
Some(CpuCore(cpu_value))
1206+
} else {
1207+
None
1208+
};
12051209

12061210
vcpus.push(VirtualCpu { id, setvar_id, cpu });
12071211
}

0 commit comments

Comments
 (0)