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

Add execCPUAffinity to the runtime process spec #174

Merged
merged 1 commit into from
Jul 2, 2024
Merged
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
33 changes: 33 additions & 0 deletions src/runtime/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ pub struct Process {
#[getset(get = "pub", set = "pub")]
/// Scheduler specifies the scheduling attributes for a process
scheduler: Option<Scheduler>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get = "pub", set = "pub")]
/// ExecCPUAffinity specifies the cpu affinity for a process
exec_cpu_affinity: Option<ExecCPUAffinity>,
}

// Default impl for processes in the container
Expand Down Expand Up @@ -152,6 +157,7 @@ impl Default for Process {
command_line: None,
// Empty IOPriority, no default iopriority
io_priority: Default::default(),
exec_cpu_affinity: Default::default(),
}
}
}
Expand Down Expand Up @@ -555,6 +561,33 @@ impl Default for LinuxSchedulerFlag {
}
}

#[derive(
Builder, Clone, Debug, Default, Deserialize, Getters, Setters, Eq, PartialEq, Serialize,
)]
#[builder(
default,
pattern = "owned",
setter(into, strip_option),
build_fn(error = "OciSpecError")
)]
#[getset(get = "pub", set = "pub")]
/// ExecCPUAffinity specifies CPU affinity used to execute the process.
/// This setting is not applicable to the container's init process.
pub struct ExecCPUAffinity {
#[serde(default, skip_serializing_if = "Option::is_none")]
/// cpu_affinity_initial is a list of CPUs a runtime parent process to be run on
/// initially, before the transition to container's cgroup.
/// This is a a comma-separated list, with dashes to represent ranges.
/// For example, `0-3,7` represents CPUs 0,1,2,3, and 7.
cpu_affinity_initial: Option<String>,

#[serde(default, skip_serializing_if = "Option::is_none")]
/// cpu_affinity_final is a list of CPUs the process will be run on after the transition
/// to container's cgroup. The format is the same as for `initial`. If omitted or empty,
/// the container's default CPU affinity, as defined by cpu.cpus property, is used.
cpu_affinity_final: Option<String>,
Comment on lines +574 to +588
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally fields in execCPUAffinity are initial and final.

https://github.com/opencontainers/runtime-spec/blob/701738418b9555d5213337a0991fd0ffd6c37808/config.md?plain=1#L343-L353

Since final is a reserved keyword in Rust, I added cpu_affinity_ as prefix.

}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading