mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-01 05:04:26 +00:00
cgroups: fix the issue of getting wrong online cpus
It's better to get the online cpus from "/sys/devices/system/cpu/online" instead of from cpuset cgroup, cause there would be an latency between one cpu online and present in the root cpuset cgroup. Fixes: #1536 Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
This commit is contained in:
parent
5b5b5cc611
commit
3f46e6379d
@ -37,6 +37,8 @@ use std::collections::HashMap;
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
const GUEST_CPUS_PATH: &str = "/sys/devices/system/cpu/online";
|
||||||
|
|
||||||
// Convenience macro to obtain the scope logger
|
// Convenience macro to obtain the scope logger
|
||||||
macro_rules! sl {
|
macro_rules! sl {
|
||||||
() => {
|
() => {
|
||||||
@ -1027,23 +1029,10 @@ impl Manager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the guest's online cpus.
|
||||||
pub fn get_guest_cpuset() -> Result<String> {
|
pub fn get_guest_cpuset() -> Result<String> {
|
||||||
// for cgroup v2
|
let c = fs::read_to_string(GUEST_CPUS_PATH)?;
|
||||||
if cgroups::hierarchies::is_cgroup2_unified_mode() {
|
Ok(c.trim().to_string())
|
||||||
let c = fs::read_to_string("/sys/fs/cgroup/cpuset.cpus.effective")?;
|
|
||||||
return Ok(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// for cgroup v1
|
|
||||||
let m = get_mounts()?;
|
|
||||||
if m.get("cpuset").is_none() {
|
|
||||||
warn!(sl!(), "no cpuset cgroup!");
|
|
||||||
return Err(nix::Error::Sys(Errno::ENOENT).into());
|
|
||||||
}
|
|
||||||
|
|
||||||
let p = format!("{}/cpuset.cpus", m.get("cpuset").unwrap());
|
|
||||||
let c = fs::read_to_string(p.as_str())?;
|
|
||||||
Ok(c)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since the OCI spec is designed for cgroup v1, in some cases
|
// Since the OCI spec is designed for cgroup v1, in some cases
|
||||||
|
Loading…
Reference in New Issue
Block a user