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 perf_event to cgroups v1 #166

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
youki

/tutorial
.idea/

**/target
.vagrant/
Expand Down
3 changes: 3 additions & 0 deletions src/cgroups/v1/controller_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub enum ControllerType {
Devices,
HugeTlb,
Pids,
PerfEvent,
Memory,
Blkio,
NetworkPriority,
Expand All @@ -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",
Expand All @@ -43,6 +45,7 @@ pub const CONTROLLERS: &[ControllerType] = &[
ControllerType::HugeTlb,
ControllerType::Memory,
ControllerType::Pids,
ControllerType::PerfEvent,
ControllerType::Blkio,
ControllerType::NetworkPriority,
ControllerType::NetworkClassifier,
Expand Down
7 changes: 5 additions & 2 deletions src/cgroups/v1/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)?,
Expand All @@ -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 => {
Expand Down
1 change: 1 addition & 0 deletions src/cgroups/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 40 additions & 0 deletions src/cgroups/v1/perf_event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::cgroups::v1::Controller;
use anyhow::Result;
use oci_spec::LinuxResources;
use std::path::Path;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
use anyhow::Result;

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");
}
}