cgroups_rs/systemd/
cpu.rs1use crate::systemd::error::{Error, Result};
7use crate::systemd::{
8 CPU_QUOTA_PERIOD_US, CPU_QUOTA_PER_SEC_US, CPU_SHARES, CPU_SYSTEMD_VERSION, CPU_WEIGHT,
9};
10
11pub fn shares(shares: u64, v2: bool) -> Result<(&'static str, u64)> {
18 let id = if v2 { CPU_WEIGHT } else { CPU_SHARES };
19
20 Ok((id, shares))
21}
22
23pub fn period(period: u64, systemd_version: usize) -> Result<(&'static str, u64)> {
25 if systemd_version < CPU_SYSTEMD_VERSION {
26 return Err(Error::ObsoleteSystemd);
27 }
28
29 Ok((CPU_QUOTA_PERIOD_US, period))
30}
31
32pub fn quota(quota: u64) -> Result<(&'static str, u64)> {
34 Ok((CPU_QUOTA_PER_SEC_US, quota))
35}