Skip to content

Commit

Permalink
add the handle yield
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhiyuanSue committed Dec 11, 2024
1 parent 96a47a8 commit b824697
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion kernel/src/syscall/invocation/invoke_tcb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn invoke_tcb_write_registers(

if resumeTarget != 0 {
// cancel_ipc(dest);
if dest.is_stopped(){
if dest.is_stopped() {
dest.cancel_ipc();
}
dest.restart();
Expand Down
16 changes: 12 additions & 4 deletions kernel/src/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use sel4_common::arch::ArchReg;
use sel4_common::arch::ArchReg::*;
#[cfg(not(feature = "KERNEL_MCS"))]
use sel4_common::sel4_config::tcbCaller;
use sel4_task::sched_context::sched_context_t;

pub const SysCall: isize = -1;
pub const SYSCALL_MAX: isize = SysCall;
Expand Down Expand Up @@ -72,8 +73,8 @@ use sel4_ipc::{endpoint_func, notification_func, Transfer};
#[cfg(feature = "KERNEL_MCS")]
use sel4_task::mcs_preemption_point;
use sel4_task::{
activateThread, get_currenct_thread, rescheduleRequired, schedule, set_thread_state, tcb_t,
ThreadState,
activateThread, chargeBudget, get_currenct_thread, ksConsumed, ksCurSC, rescheduleRequired,
schedule, set_thread_state, tcb_t, ThreadState,
};
pub use utils::*;

Expand Down Expand Up @@ -536,8 +537,15 @@ fn handle_recv(block: bool) {
fn handle_yield() {
#[cfg(feature = "KERNEL_MCS")]
{
sel4_common::println!("todo: mcs handle yield");
// TODO: MCS
unsafe {
let consumed =
convert_to_mut_type_ref::<sched_context_t>(ksCurSC).scConsumed + ksConsumed;
chargeBudget(
(*convert_to_mut_type_ref::<sched_context_t>(ksCurSC).refill_head()).rAmount,
false,
);
convert_to_mut_type_ref::<sched_context_t>(ksCurSC).scConsumed = consumed;
}
}
#[cfg(not(feature = "KERNEL_MCS"))]
{
Expand Down
4 changes: 1 addition & 3 deletions sel4_ipc/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ impl endpoint_func for endpoint {
can_grant_reply: bool,
canDonate: bool,
) {
use sel4_common::{
structures_gen::seL4_Fault_tag, types_gen::seL4_Fault_tag::seL4_Fault_NullFault,
};
use sel4_common::structures_gen::seL4_Fault_tag;
use sel4_task::{ksCurSC, reply::reply_t, sched_context::sched_context_t};

match self.get_ep_state() {
Expand Down
24 changes: 14 additions & 10 deletions sel4_task/src/tcb.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#[cfg(feature = "KERNEL_MCS")]
use crate::ksCurSC;
use crate::prio_t;
use crate::tcb_queue::tcb_queue_t;
#[cfg(feature = "KERNEL_MCS")]
use crate::{ksReleaseHead, sched_context::sched_context_t};
use core::intrinsics::{likely, unlikely};
use sel4_common::arch::{
msgRegisterNum, n_exceptionMessage, n_syscallMessage, vm_rights_t, ArchReg, ArchTCB,
};
use sel4_common::fault::*;
use sel4_common::message_info::seL4_MessageInfo_func;
use sel4_common::sel4_config::*;
use sel4_common::shared_types_bf_gen::seL4_MessageInfo;
use sel4_common::structures::{exception_t, seL4_IPCBuffer};
use sel4_common::structures_gen::{
cap, cap_reply_cap, cap_tag, lookup_fault, lookup_fault_Splayed, mdb_node, seL4_Fault,
seL4_Fault_CapFault, seL4_Fault_tag, thread_state,
Expand All @@ -24,12 +30,6 @@ use sel4_vspace::{
setCurrentUserVSpaceRoot, ttbr_new,
};
use sel4_vspace::{pptr_t, set_vm_root};
#[cfg(feature="KERNEL_MCS")]
use crate::ksCurSC;
use crate::prio_t;
use crate::tcb_queue::tcb_queue_t;
use sel4_common::sel4_config::*;
use sel4_common::structures::{exception_t, seL4_IPCBuffer};

use super::scheduler::{
addToBitmap, get_currenct_thread, possible_switch_to, ready_queues_index, removeFromBitmap,
Expand Down Expand Up @@ -542,11 +542,15 @@ impl tcb_t {
{
// MCS
set_thread_state(self, ThreadState::ThreadStateRestart);
if convert_to_mut_type_ref::<sched_context_t>(self.tcbSchedContext).sc_sporadic() && self.tcbSchedContext != unsafe{ksCurSC}{
convert_to_mut_type_ref::<sched_context_t>(self.tcbSchedContext).refill_unblock_check();
if convert_to_mut_type_ref::<sched_context_t>(self.tcbSchedContext).sc_sporadic()
&& self.tcbSchedContext != unsafe { ksCurSC }
{
convert_to_mut_type_ref::<sched_context_t>(self.tcbSchedContext)
.refill_unblock_check();
}
convert_to_mut_type_ref::<sched_context_t>(self.tcbSchedContext).schedContext_resume();
if self.is_schedulable(){
convert_to_mut_type_ref::<sched_context_t>(self.tcbSchedContext)
.schedContext_resume();
if self.is_schedulable() {
possible_switch_to(self);
}
}
Expand Down

0 comments on commit b824697

Please sign in to comment.