From a8377340fd829e70a92fe6060da35f81c0c4a62d Mon Sep 17 00:00:00 2001 From: GabrielPavaloiu Date: Tue, 10 Dec 2024 15:40:57 +0200 Subject: [PATCH 1/2] grant: added remove_pending_upcalls function Added a method to GrantKernelData that removes all pending upcalls of the current driver with the given subscriber_num from the process's upcall queue. --- kernel/src/grant.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/src/grant.rs b/kernel/src/grant.rs index d8522d9b5c..a101f19cab 100644 --- a/kernel/src/grant.rs +++ b/kernel/src/grant.rs @@ -619,6 +619,15 @@ impl<'a> GrantKernelData<'a> { ) } + /// Remove all scheduled upcalls with the given `subscribe_num` from the + /// task queue. + pub fn remove_pending_upcalls(&self, subscribe_num: usize) { + self.process.remove_pending_upcalls(UpcallId { + subscribe_num, + driver_num: self.driver_num, + }); + } + /// Returns a lifetime limited reference to the requested /// [`ReadOnlyProcessBuffer`]. /// From c057fe3438d71537e35728ad476c89c9a928d967 Mon Sep 17 00:00:00 2001 From: GabrielPavaloiu Date: Thu, 12 Dec 2024 13:22:40 +0200 Subject: [PATCH 2/2] {grant, process}: updated remove pending upcalls api Changed remove_pending_upcalls to return the number of tasks removed. Added an API to call remove_upcall from GrantKernelData. --- kernel/src/grant.rs | 18 ++++++++++++++++-- kernel/src/kernel.rs | 2 +- kernel/src/process.rs | 4 +++- kernel/src/process_standard.rs | 9 +++++---- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/kernel/src/grant.rs b/kernel/src/grant.rs index a101f19cab..ecf2080d8d 100644 --- a/kernel/src/grant.rs +++ b/kernel/src/grant.rs @@ -619,13 +619,27 @@ 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 { + 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. - pub fn remove_pending_upcalls(&self, subscribe_num: usize) { + /// + /// 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 diff --git a/kernel/src/kernel.rs b/kernel/src/kernel.rs index b408f0631a..1880d52f01 100644 --- a/kernel/src/kernel.rs +++ b/kernel/src/kernel.rs @@ -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 { diff --git a/kernel/src/process.rs b/kernel/src/process.rs index 3509fa7946..a4b461bff3 100644 --- a/kernel/src/process.rs +++ b/kernel/src/process.rs @@ -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; diff --git a/kernel/src/process_standard.rs b/kernel/src/process_standard.rs index 5d4dc5592a..87ed46f9e9 100644 --- a/kernel/src/process_standard.rs +++ b/kernel/src/process_standard.rs @@ -552,8 +552,8 @@ impl 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 @@ -564,8 +564,8 @@ impl 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(), @@ -574,7 +574,8 @@ impl Process for ProcessStandard<'_, count_before - count_after, ); } - }); + count_after - count_before + }) } fn is_running(&self) -> bool {