Skip to content
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
3 changes: 3 additions & 0 deletions zircon-loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ fn spawn(thread: Arc<Thread>) {
let mut cx = thread.wait_for_run().await;
trace!("go to user: {:#x?}", cx);
debug!("switch to {}|{}", thread.proc().name(), thread.name());
let tmp_time = kernel_hal::timer_now().as_nanos();
kernel_hal::context_run(&mut cx);
let time = kernel_hal::timer_now().as_nanos() - tmp_time;
thread.time_add(time);
trace!("back from user: {:#x?}", cx);
EXCEPTIONS_USER.add(1);
let mut exit = false;
Expand Down
10 changes: 10 additions & 0 deletions zircon-object/src/task/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ struct ThreadInner {
/// NOTE: This variable will never be `Suspended`. On suspended, the
/// `suspend_count` is non-zero, and this represents the state before suspended.
state: ThreadState,
/// The time this thread has run on cpu
time: u128,
}

impl Thread {
Expand Down Expand Up @@ -345,6 +347,14 @@ impl Thread {
pub fn get_exceptionate(&self) -> Arc<Exceptionate> {
self.exceptionate.clone()
}

pub fn time_add(&self, time: u128) {
self.inner.lock().time += time;
}

pub fn get_time(&self) -> u64 {
self.inner.lock().time as u64
}
}

pub trait IntoResult<T> {
Expand Down
5 changes: 4 additions & 1 deletion zircon-syscall/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ impl Syscall<'_> {
time.write(timer_now().as_nanos() as u64 + UTC_OFFSET.load(Ordering::Relaxed))?;
Ok(())
}
ZX_CLOCK_THREAD => unimplemented!(),
ZX_CLOCK_THREAD => {
time.write(self.thread.get_time())?;
Ok(())
}
_ => Err(ZxError::NOT_SUPPORTED),
}
}
Expand Down