From dcf233230158d6d2bc96d73dfd3566d998cf92d1 Mon Sep 17 00:00:00 2001 From: Brad Campbell Date: Wed, 3 Jul 2024 15:26:37 -0400 Subject: [PATCH] store two most recent syscalls --- kernel/src/process_loading.rs | 2 +- kernel/src/process_standard.rs | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/kernel/src/process_loading.rs b/kernel/src/process_loading.rs index 54044eb493..705836cf68 100644 --- a/kernel/src/process_loading.rs +++ b/kernel/src/process_loading.rs @@ -375,7 +375,7 @@ fn load_process( // get a process and we didn't get a loading error (aka we got to // this point), then the app is a disabled process or just padding. let (process_option, unused_memory) = unsafe { - ProcessStandard::::create( + ProcessStandard::::create( kernel, chip, process_binary, diff --git a/kernel/src/process_standard.rs b/kernel/src/process_standard.rs index 3e62a4ad40..20b231f782 100644 --- a/kernel/src/process_standard.rs +++ b/kernel/src/process_standard.rs @@ -52,7 +52,7 @@ pub trait ProcessStandardDebug { fn set_new_app_stack_min_pointer(&self, ptr: *const u8); fn set_last_syscall(&self, syscall: Syscall); - fn get_last_syscall(&self) -> Option; + fn get_last_syscall(&self, index: usize) -> Option; fn reset_last_syscall(&self); fn increment_syscall_count(&self); @@ -104,6 +104,10 @@ struct ProcessStandardDebugFullInner { /// What was the most recent syscall. last_syscall: Option, + /// What was the previous most recent syscall. We store two syscalls because + /// often when debugging the most recent syscall is `Yield`. + penultimate_syscall: Option, + /// How many upcalls were dropped because the queue was insufficiently /// long. dropped_upcall_count: usize, @@ -159,13 +163,23 @@ impl ProcessStandardDebug for ProcessStandardDebugFull { } fn set_last_syscall(&self, syscall: Syscall) { - self.debug.map(|d| d.last_syscall = Some(syscall)); + self.debug.map(|d| { + d.penultimate_syscall = d.last_syscall; + d.last_syscall = Some(syscall); + }); } - fn get_last_syscall(&self) -> Option { - self.debug.map_or(None, |d| d.last_syscall) + fn get_last_syscall(&self, index: usize) -> Option { + self.debug.map_or(None, |d| match index { + 0 => d.last_syscall, + 1 => d.penultimate_syscall, + _ => None, + }) } fn reset_last_syscall(&self) { - self.debug.map(|d| d.last_syscall = None); + self.debug.map(|d| { + d.penultimate_syscall = None; + d.last_syscall = None; + }); } fn increment_syscall_count(&self) { @@ -210,6 +224,7 @@ impl Default for ProcessStandardDebugFull { app_stack_min_pointer: None, syscall_count: 0, last_syscall: None, + penultimate_syscall: None, dropped_upcall_count: 0, timeslice_expiration_count: 0, }), @@ -241,7 +256,7 @@ impl ProcessStandardDebug for () { fn set_new_app_stack_min_pointer(&self, _ptr: *const u8) {} fn set_last_syscall(&self, _syscall: Syscall) {} - fn get_last_syscall(&self) -> Option { + fn get_last_syscall(&self, _index: usize) -> Option { None } fn reset_last_syscall(&self) {} @@ -1318,7 +1333,7 @@ impl Process for ProcessSt } fn debug_syscall_last(&self) -> Option { - self.debug.get_last_syscall() + self.debug.get_last_syscall(0) } fn get_addresses(&self) -> ProcessAddresses {