Skip to content

Commit

Permalink
add scheduler to runtime spec
Browse files Browse the repository at this point in the history
Signed-off-by: lengrongfu <1275177125@qq.com>
  • Loading branch information
lengrongfu committed Jul 9, 2023
1 parent 6de5737 commit 3dec094
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions src/runtime/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ pub struct Process {
/// SelinuxLabel specifies the selinux context that the container
/// process is run as.
selinux_label: Option<String>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get = "pub", set = "pub")]
/// Scheduler specifies the scheduling attributes for a process
scheduler: Option<Scheduler>,
}

// Default impl for processes in the container
Expand Down Expand Up @@ -115,6 +120,8 @@ impl Default for Process {
apparmor_profile: Default::default(),
// Empty String, no default selinux
selinux_label: Default::default(),
// Empty String, no default scheduler
scheduler: Default::default(),
// See impl Default for LinuxCapabilities
capabilities: Some(Default::default()),
// Sets the default maximum of 1024 files the process can open
Expand Down Expand Up @@ -345,3 +352,113 @@ impl Default for LinuxCapabilities {
}
}
}

#[derive(Builder, Clone, Debug, Deserialize, Getters, Setters, Eq, PartialEq, Serialize)]
#[builder(
default,
pattern = "owned",
setter(into, strip_option),
build_fn(error = "OciSpecError")
)]
#[getset(get = "pub", set = "pub")]
/// Scheduler represents the scheduling attributes for a process. It is based on
/// the Linux sched_setattr(2) syscall.
pub struct Scheduler {
/// Policy represents the scheduling policy (e.g., SCHED_FIFO, SCHED_RR, SCHED_OTHER).
policy: LinuxSchedulerPolicy,

#[serde(default, skip_serializing_if = "Option::is_none")]
/// Nice is the nice value for the process, which affects its priority.
nice: Option<i32>,

#[serde(default, skip_serializing_if = "Option::is_none")]
/// Priority represents the static priority of the process.
priority: Option<i32>,

#[serde(default, skip_serializing_if = "Option::is_none")]
/// Flags is an array of scheduling flags.
flags: Option<Vec<LinuxSchedulerFlag>>,

// The following ones are used by the DEADLINE scheduler.
#[serde(default, skip_serializing_if = "Option::is_none")]
/// Runtime is the amount of time in nanoseconds during which the process
/// is allowed to run in a given period.
runtime: Option<u64>,

#[serde(default, skip_serializing_if = "Option::is_none")]
/// Deadline is the absolute deadline for the process to complete its execution.
deadline: Option<u64>,

#[serde(default, skip_serializing_if = "Option::is_none")]
/// Period is the length of the period in nanoseconds used for determining the process runtime.
period: Option<u64>,
}

/// Default scheduler is SCHED_OTHER with no priority.
impl Default for Scheduler {
fn default() -> Self {
Self {
policy: LinuxSchedulerPolicy::default(),
nice: None,
priority: None,
flags: None,
runtime: None,
deadline: None,
period: None,
}
}
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// LinuxSchedulerPolicy represents different scheduling policies used with the Linux Scheduler
pub enum LinuxSchedulerPolicy {
/// SchedOther is the default scheduling policy
SchedOther,
/// SchedFIFO is the First-In-First-Out scheduling policy
SchedFifo,
/// SchedRR is the Round-Robin scheduling policy
SchedRr,
/// SchedBatch is the Batch scheduling policy
SchedBatch,
/// SchedISO is the Isolation scheduling policy
SchedIso,
/// SchedIdle is the Idle scheduling policy
SchedIdle,
/// SchedDeadline is the Deadline scheduling policy
SchedDeadline,
}

/// Default LinuxSchedulerPolicy is SchedOther
impl Default for LinuxSchedulerPolicy {
fn default() -> Self {
LinuxSchedulerPolicy::SchedOther
}
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// LinuxSchedulerFlag represents the flags used by the Linux Scheduler.
pub enum LinuxSchedulerFlag {
/// SchedFlagResetOnFork represents the reset on fork scheduling flag
SchedResetOnFork,
/// SchedFlagReclaim represents the reclaim scheduling flag
SchedFlagReclaim,
/// SchedFlagDLOverrun represents the deadline overrun scheduling flag
SchedFlagDLOverrun,
/// SchedFlagKeepPolicy represents the keep policy scheduling flag
SchedFlagKeepPolicy,
/// SchedFlagKeepParams represents the keep parameters scheduling flag
SchedFlagKeepParams,
/// SchedFlagUtilClampMin represents the utilization clamp minimum scheduling flag
SchedFlagUtilClampMin,
/// SchedFlagUtilClampMin represents the utilization clamp maximum scheduling flag
SchedFlagUtilClampMax,
}

/// Default LinuxSchedulerFlag is SchedResetOnFork
impl Default for LinuxSchedulerFlag {
fn default() -> Self {
LinuxSchedulerFlag::SchedResetOnFork
}
}

0 comments on commit 3dec094

Please sign in to comment.