Skip to content

Commit

Permalink
Merge pull request tock#4267 from GabrielPavaloiu/grant-remove-upcalls
Browse files Browse the repository at this point in the history
grant: added remove_pending_upcalls function
  • Loading branch information
alevy authored Dec 17, 2024
2 parents 5b3c55d + c057fe3 commit 7c88a62
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
23 changes: 23 additions & 0 deletions kernel/src/grant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,29 @@ impl<'a> GrantKernelData<'a> {
)
}

/// Search the work queue for the first pending operation with the given
/// `subscribe_num` and if one exists remove it from the task queue.
///
/// Returns the associated [`Task`] if one was found, otherwise returns
/// [`None`].
pub fn remove_upcall(&self, subscribe_num: usize) -> Option<crate::process::Task> {
self.process.remove_upcall(UpcallId {
subscribe_num,
driver_num: self.driver_num,
})
}

/// Remove all scheduled upcalls with the given `subscribe_num` from the
/// task queue.
///
/// Returns the number of removed upcalls.
pub fn remove_pending_upcalls(&self, subscribe_num: usize) -> usize {
self.process.remove_pending_upcalls(UpcallId {
subscribe_num,
driver_num: self.driver_num,
})
}

/// Returns a lifetime limited reference to the requested
/// [`ReadOnlyProcessBuffer`].
///
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ impl Kernel {
// that there are no pending upcalls with the same
// identifier but with the old function pointer, we
// clear them now.
process.remove_pending_upcalls(upcall_id);
let _ =process.remove_pending_upcalls(upcall_id);
}

if config::CONFIG.trace_syscalls {
Expand Down
4 changes: 3 additions & 1 deletion kernel/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ pub trait Process {

/// Remove all scheduled upcalls with the given `upcall_id` from the task
/// queue.
fn remove_pending_upcalls(&self, upcall_id: UpcallId);
///
/// Returns the number of removed upcalls.
fn remove_pending_upcalls(&self, upcall_id: UpcallId) -> usize;

/// Returns the current state the process is in.
fn get_state(&self) -> State;
Expand Down
9 changes: 5 additions & 4 deletions kernel/src/process_standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ impl<C: Chip, D: 'static + ProcessStandardDebug> Process for ProcessStandard<'_,
|| self.state.get() == State::Running
}

fn remove_pending_upcalls(&self, upcall_id: UpcallId) {
self.tasks.map(|tasks| {
fn remove_pending_upcalls(&self, upcall_id: UpcallId) -> usize {
self.tasks.map_or(0, |tasks| {
let count_before = tasks.len();
tasks.retain(|task| match task {
// Remove only tasks that are function calls with an id equal
Expand All @@ -564,8 +564,8 @@ impl<C: Chip, D: 'static + ProcessStandardDebug> Process for ProcessStandard<'_,
},
_ => true,
});
let count_after = tasks.len();
if config::CONFIG.trace_syscalls {
let count_after = tasks.len();
debug!(
"[{:?}] remove_pending_upcalls[{:#x}:{}] = {} upcall(s) removed",
self.processid(),
Expand All @@ -574,7 +574,8 @@ impl<C: Chip, D: 'static + ProcessStandardDebug> Process for ProcessStandard<'_,
count_before - count_after,
);
}
});
count_after - count_before
})
}

fn is_running(&self) -> bool {
Expand Down

0 comments on commit 7c88a62

Please sign in to comment.