Keep track of ticks each context uses

This commit is contained in:
Jeremy Soller
2020-02-18 21:16:53 -07:00
parent d4d14c78c3
commit b616fdb067
3 changed files with 22 additions and 3 deletions

View File

@@ -122,6 +122,8 @@ pub struct Context {
pub running: bool,
/// CPU ID, if locked
pub cpu_id: Option<usize>,
/// Number of timer ticks executed
pub ticks: u64,
/// Current system call
pub syscall: Option<(usize, usize, usize, usize, usize, usize)>,
/// Head buffer to use when system call buffers are not page aligned
@@ -197,6 +199,7 @@ impl Context {
status: Status::Blocked,
running: false,
cpu_id: None,
ticks: 0,
syscall: None,
syscall_head,
syscall_tail,

View File

@@ -67,7 +67,7 @@ pub unsafe fn switch() -> bool {
use core::ops::DerefMut;
//set PIT Interrupt counter to 0, giving each process same amount of PIT ticks
PIT_TICKS.store(0, Ordering::SeqCst);
let ticks = PIT_TICKS.swap(0, Ordering::SeqCst);
// Set the global lock to avoid the unsafe operations below from causing issues
while arch::CONTEXT_SWITCH_LOCK.compare_and_swap(false, true, Ordering::SeqCst) {
@@ -86,6 +86,7 @@ pub unsafe fn switch() -> bool {
.current()
.expect("context::switch: not inside of context");
let mut context = context_lock.write();
context.ticks += ticks as u64 + 1; // Always round ticks up
from_ptr = context.deref_mut() as *mut Context;
}

View File

@@ -6,7 +6,7 @@ use crate::context;
use crate::syscall::error::Result;
pub fn resource() -> Result<Vec<u8>> {
let mut string = format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{}\n",
let mut string = format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{:<8}{}\n",
"PID",
"PGID",
"PPID",
@@ -18,6 +18,7 @@ pub fn resource() -> Result<Vec<u8>> {
"ENS",
"STAT",
"CPU",
"TICKS",
"MEM",
"NAME");
{
@@ -57,6 +58,19 @@ pub fn resource() -> Result<Vec<u8>> {
format!("?")
};
let ticks = context.ticks;
let ticks_string = if ticks >= 1000 * 1000 * 1000 * 1000 {
format!("{} T", ticks / 1000 / 1000 / 1000 / 1000)
} else if ticks >= 1000 * 1000 * 1000 {
format!("{} G", ticks / 1000 / 1000 / 1000)
} else if ticks >= 1000 * 1000 {
format!("{} M", ticks / 1000 / 1000)
} else if ticks >= 1000 {
format!("{} K", ticks / 1000)
} else {
format!("{}", ticks)
};
let mut memory = 0;
if let Some(ref kfx) = context.kstack {
memory += kfx.len();
@@ -96,7 +110,7 @@ pub fn resource() -> Result<Vec<u8>> {
let name_bytes = context.name.lock();
let name = str::from_utf8(&name_bytes).unwrap_or("");
string.push_str(&format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{}\n",
string.push_str(&format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{:<8}{}\n",
context.id.into(),
context.pgid.into(),
context.ppid.into(),
@@ -108,6 +122,7 @@ pub fn resource() -> Result<Vec<u8>> {
context.ens.into(),
stat_string,
cpu_string,
ticks_string,
memory_string,
name));
}