mirror of
https://github.com/containers/youki
synced 2024-11-22 17:02:00 +01:00
add perf_event to cgroups v1
This commit is contained in:
parent
b236cea615
commit
c66b2fa4d3
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
youki
|
||||
|
||||
/tutorial
|
||||
.idea/
|
||||
|
||||
**/target
|
||||
.vagrant/
|
||||
|
@ -8,6 +8,7 @@ pub enum ControllerType {
|
||||
Devices,
|
||||
HugeTlb,
|
||||
Pids,
|
||||
PerfEvent,
|
||||
Memory,
|
||||
Blkio,
|
||||
NetworkPriority,
|
||||
@ -24,6 +25,7 @@ impl Display for ControllerType {
|
||||
Self::Devices => "devices",
|
||||
Self::HugeTlb => "hugetlb",
|
||||
Self::Pids => "pids",
|
||||
Self::PerfEvent => "perf_event",
|
||||
Self::Memory => "memory",
|
||||
Self::Blkio => "blkio",
|
||||
Self::NetworkPriority => "net_prio",
|
||||
@ -43,6 +45,7 @@ pub const CONTROLLERS: &[ControllerType] = &[
|
||||
ControllerType::HugeTlb,
|
||||
ControllerType::Memory,
|
||||
ControllerType::Pids,
|
||||
ControllerType::PerfEvent,
|
||||
ControllerType::Blkio,
|
||||
ControllerType::NetworkPriority,
|
||||
ControllerType::NetworkClassifier,
|
||||
|
@ -12,8 +12,8 @@ use super::ControllerType as CtrlType;
|
||||
use super::{
|
||||
blkio::Blkio, controller_type::CONTROLLERS, cpu::Cpu, cpuacct::CpuAcct, cpuset::CpuSet,
|
||||
devices::Devices, freezer::Freezer, hugetlb::Hugetlb, memory::Memory,
|
||||
network_classifier::NetworkClassifier, network_priority::NetworkPriority, pids::Pids, util,
|
||||
Controller,
|
||||
network_classifier::NetworkClassifier, network_priority::NetworkPriority,
|
||||
perf_event::PerfEvent, pids::Pids, util, Controller,
|
||||
};
|
||||
|
||||
use crate::cgroups::common::CGROUP_PROCS;
|
||||
@ -75,6 +75,7 @@ impl Manager {
|
||||
CtrlType::HugeTlb => Hugetlb::needs_to_handle(linux_resources).is_some(),
|
||||
CtrlType::Memory => Memory::needs_to_handle(linux_resources).is_some(),
|
||||
CtrlType::Pids => Pids::needs_to_handle(linux_resources).is_some(),
|
||||
CtrlType::PerfEvent => PerfEvent::needs_to_handle(linux_resources).is_some(),
|
||||
CtrlType::Blkio => Blkio::needs_to_handle(linux_resources).is_some(),
|
||||
CtrlType::NetworkPriority => {
|
||||
NetworkPriority::needs_to_handle(linux_resources).is_some()
|
||||
@ -109,6 +110,7 @@ impl CgroupManager for Manager {
|
||||
CtrlType::HugeTlb => Hugetlb::add_task(pid, subsys.1)?,
|
||||
CtrlType::Memory => Memory::add_task(pid, subsys.1)?,
|
||||
CtrlType::Pids => Pids::add_task(pid, subsys.1)?,
|
||||
CtrlType::PerfEvent => PerfEvent::add_task(pid, subsys.1)?,
|
||||
CtrlType::Blkio => Blkio::add_task(pid, subsys.1)?,
|
||||
CtrlType::NetworkPriority => NetworkPriority::add_task(pid, subsys.1)?,
|
||||
CtrlType::NetworkClassifier => NetworkClassifier::add_task(pid, subsys.1)?,
|
||||
@ -129,6 +131,7 @@ impl CgroupManager for Manager {
|
||||
CtrlType::HugeTlb => Hugetlb::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::Memory => Memory::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::Pids => Pids::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::PerfEvent => PerfEvent::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::Blkio => Blkio::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::NetworkPriority => NetworkPriority::apply(linux_resources, &subsys.1)?,
|
||||
CtrlType::NetworkClassifier => {
|
||||
|
@ -11,6 +11,7 @@ pub mod manager;
|
||||
mod memory;
|
||||
mod network_classifier;
|
||||
mod network_priority;
|
||||
pub mod perf_event;
|
||||
mod pids;
|
||||
pub mod util;
|
||||
pub use controller::Controller;
|
||||
|
40
src/cgroups/v1/perf_event.rs
Normal file
40
src/cgroups/v1/perf_event.rs
Normal file
@ -0,0 +1,40 @@
|
||||
use crate::cgroups::v1::Controller;
|
||||
use anyhow::Result;
|
||||
use oci_spec::LinuxResources;
|
||||
use std::path::Path;
|
||||
|
||||
pub struct PerfEvent {}
|
||||
|
||||
impl Controller for PerfEvent {
|
||||
type Resource = ();
|
||||
|
||||
fn apply(_linux_resources: &LinuxResources, _cgroup_root: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
//no need to handle any case
|
||||
fn needs_to_handle(_linux_resources: &LinuxResources) -> Option<&Self::Resource> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs;
|
||||
|
||||
use nix::unistd::Pid;
|
||||
|
||||
use super::*;
|
||||
use crate::cgroups::{common::CGROUP_PROCS, test::setup};
|
||||
|
||||
#[test]
|
||||
fn test_add_task() {
|
||||
let (tmp, procs) = setup("test_perf_event_add_task", CGROUP_PROCS);
|
||||
let pid = Pid::from_raw(1000);
|
||||
|
||||
PerfEvent::add_task(pid, &tmp).expect("apply perf_event");
|
||||
|
||||
let content = fs::read_to_string(&procs)
|
||||
.unwrap_or_else(|_| panic!("read {} file content", CGROUP_PROCS));
|
||||
assert_eq!(content, "1000");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user