mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-06 18:38:01 +00:00
crosvm: use vcpu cgorups for plugin
BUG=b:228634930 TEST=presubmit --quick Change-Id: I92f0a025280fca0cdfdf6b2420cbfd213ec0bc08 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3696460 Tested-by: kokoro <noreply+kokoro@google.com> Auto-Submit: Anton Romanov <romanton@google.com> Commit-Queue: Dmitry Torokhov <dtor@chromium.org> Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
This commit is contained in:
parent
2ada57d26e
commit
ded868a59f
1 changed files with 20 additions and 1 deletions
|
@ -6,8 +6,8 @@ mod process;
|
||||||
mod vcpu;
|
mod vcpu;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
use std::io::{self, Write};
|
||||||
use std::os::unix::net::UnixDatagram;
|
use std::os::unix::net::UnixDatagram;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
@ -279,6 +279,7 @@ pub fn run_vcpus(
|
||||||
kill_signaled: &Arc<AtomicBool>,
|
kill_signaled: &Arc<AtomicBool>,
|
||||||
exit_evt: &Event,
|
exit_evt: &Event,
|
||||||
vcpu_handles: &mut Vec<thread::JoinHandle<()>>,
|
vcpu_handles: &mut Vec<thread::JoinHandle<()>>,
|
||||||
|
vcpu_cgroup_tasks_file: Option<File>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let vcpu_thread_barrier = Arc::new(Barrier::new((vcpu_count) as usize));
|
let vcpu_thread_barrier = Arc::new(Barrier::new((vcpu_count) as usize));
|
||||||
let use_kvm_signals = !kvm.check_extension(Cap::ImmediateExit);
|
let use_kvm_signals = !kvm.check_extension(Cap::ImmediateExit);
|
||||||
|
@ -325,6 +326,9 @@ pub fn run_vcpus(
|
||||||
let vcpu_exit_evt = exit_evt.try_clone().context("failed to clone event")?;
|
let vcpu_exit_evt = exit_evt.try_clone().context("failed to clone event")?;
|
||||||
let vcpu_plugin = plugin.create_vcpu(cpu_id)?;
|
let vcpu_plugin = plugin.create_vcpu(cpu_id)?;
|
||||||
let vcpu = Vcpu::new(cpu_id as c_ulong, kvm, vm).context("error creating vcpu")?;
|
let vcpu = Vcpu::new(cpu_id as c_ulong, kvm, vm).context("error creating vcpu")?;
|
||||||
|
let vcpu_cgroup_tasks_file = vcpu_cgroup_tasks_file
|
||||||
|
.as_ref()
|
||||||
|
.map(|f| f.try_clone().unwrap());
|
||||||
|
|
||||||
vcpu_handles.push(
|
vcpu_handles.push(
|
||||||
thread::Builder::new()
|
thread::Builder::new()
|
||||||
|
@ -336,6 +340,10 @@ pub fn run_vcpus(
|
||||||
vcpu.set_signal_mask(&[])
|
vcpu.set_signal_mask(&[])
|
||||||
.expect("failed to set up KVM VCPU signal mask");
|
.expect("failed to set up KVM VCPU signal mask");
|
||||||
}
|
}
|
||||||
|
// Move vcpu thread to cgroup
|
||||||
|
if let Some(mut f) = vcpu_cgroup_tasks_file {
|
||||||
|
f.write_all(base::gettid().to_string().as_bytes()).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
if let Err(e) = enable_core_scheduling() {
|
if let Err(e) = enable_core_scheduling() {
|
||||||
error!("Failed to enable core scheduling: {}", e);
|
error!("Failed to enable core scheduling: {}", e);
|
||||||
|
@ -808,6 +816,16 @@ pub fn run_config(cfg: Config) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if vcpu_handles.is_empty() && dying_instant.is_none() && plugin.is_started() {
|
if vcpu_handles.is_empty() && dying_instant.is_none() && plugin.is_started() {
|
||||||
|
let vcpu_cgroup_tasks_file = match &cfg.vcpu_cgroup_path {
|
||||||
|
None => None,
|
||||||
|
Some(cgroup_path) => {
|
||||||
|
// Move main process to cgroup_path
|
||||||
|
let mut f = File::create(&cgroup_path.join("tasks"))?;
|
||||||
|
f.write_all(std::process::id().to_string().as_bytes())?;
|
||||||
|
Some(f)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let res = run_vcpus(
|
let res = run_vcpus(
|
||||||
&kvm,
|
&kvm,
|
||||||
&vm,
|
&vm,
|
||||||
|
@ -816,6 +834,7 @@ pub fn run_config(cfg: Config) -> Result<()> {
|
||||||
&kill_signaled,
|
&kill_signaled,
|
||||||
&exit_evt,
|
&exit_evt,
|
||||||
&mut vcpu_handles,
|
&mut vcpu_handles,
|
||||||
|
vcpu_cgroup_tasks_file,
|
||||||
);
|
);
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
dying_instant.get_or_insert(Instant::now());
|
dying_instant.get_or_insert(Instant::now());
|
||||||
|
|
Loading…
Reference in a new issue