Skip to content

Commit

Permalink
Mcs support (#22)
Browse files Browse the repository at this point in the history
* start add some of the mcs features

* add lot's of mcs todo codes and add the new pbf of aarch64

* add the no mcs case framework

* pass the rel4_complier

* put in all the symbols

* update the fastpath_reply_recv

* try to add the riscv pbf support

* fill in the real riscv pbf

* adjust the archtecture of the timer

* add the time functions for the qemu-arm-virt and spike

* add some timer functions

* add the framework of the sched_context

* update some of the mcs functions

* continue add the sched_context part

* fix previous bugs

* try to add some code but have bugs

* fill in some of the code again

* add some boot code,but have some panics

* add the alloc root task sched context part

* update the schedule and fix the previous bug

* finish the boot part code, start debug

* update the syscall num

* add some necessery mcs codes

* continue add mcs code

* add some thing about the interrupt entry

* fix one assert

* use is_schedulable to replace the is_runable

* try to fix the handle_fault on mcs and no mcs

* fix sysgetclock bug

* successfully go into the tests

* add the framework of handle syscall

* complete the handlesyscall

* add the reply

* finish the functions of reply

* add the do reply part

* update the ci

* add the some functions

* finish fill in sched control code

* add some of the mcs feature in the handlesyscall

* pass the tcb set space function

* finish the TCBSetTimeoutEndpoint part

* update the decode sched context invocation

* try to add the decodeSchedContext_Bind code

* fix bugs

* update the rece code

* add restart part

* add the handle yield

* fix some bugs

* fix the cnode bug

* try to fix more bugs of convert

* fix bugs

* fix some bugs

* fix another bug

* add the invoke sc unbind and pass all bind tests
  • Loading branch information
ZhiyuanSue authored Dec 14, 2024
1 parent 33d8cca commit e52020a
Show file tree
Hide file tree
Showing 37 changed files with 1,741 additions and 308 deletions.
57 changes: 54 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
strategy:
matrix:
platform: [spike, qemu-arm-virt]
mcs: [off, on]
include:
- platform: qemu-arm-virt
arch: aarch64
Expand Down Expand Up @@ -78,11 +77,63 @@ jobs:
env:
ARCH: ${{ matrix.arch }}
PLATFORM: ${{ matrix.platform }}
MCS: ${{ matrix.mcs }}
run: |
echo $ARCH
echo $PLATFORM
cd rel4_kernel && ./build.py -p $PLATFORM -m $MCS
cd rel4_kernel && ./build.py -p $PLATFORM -m off
- name: simulate
env:
ARCH: ${{ matrix.arch }}
PLATFORM: ${{ matrix.platform }}
run: cd rel4_kernel/build && ./simulate > 1.log
timeout-minutes: 2
continue-on-error: true
- run: cat rel4_kernel/build/1.log
- name: Check Result
run: rel4_kernel/.github/workflows/parse.py rel4_kernel/build/1.log
sel4-test-mcs:
# if: ${{ contains(github.event.head_commit.message, 'git subrepo')}}
runs-on: ubuntu-latest
strategy:
matrix:
platform: [spike, qemu-arm-virt]
include:
- platform: qemu-arm-virt
arch: aarch64
- platform: spike
arch: riscv64
container:
image: yfblock/rel4-dev:1.2
options: --user=root
defaults:
run:
working-directory: ./sel4-test
steps:
- run: mkdir sel4-test
working-directory: .
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2024-02-01
components: rust-src rustfmt
rustflags:
target: riscv64imac-unknown-none-elf aarch64-unknown-none-softfloat
- name: Install qemu
run: apt update && apt -y install qemu-system-misc qemu-system-aarch64
- name: Clone Menifest && Sync repositories
run: |
repo init -u https://github.com/rel4team/sel4test-manifest.git -b ci-test
sed -i "19c\ \t<project name=\"mi-dev-integral-rel4.git\" path=\"rel4_kernel\" revision=\"${{ github.sha }}\" remote=\"seL4_kernel\" upstream=\"mi_dev\" dest-branch=\"mi_dev\"/>" .repo/manifests/default.xml
repo sync
- run: cd kernel && git checkout mi_dev
# - run: cd rel4_kernel && git checkout mi_dev
- name: Build
env:
ARCH: ${{ matrix.arch }}
PLATFORM: ${{ matrix.platform }}
run: |
echo $ARCH
echo $PLATFORM
cd rel4_kernel && ./build.py -p $PLATFORM -m on
- name: simulate
env:
ARCH: ${{ matrix.arch }}
Expand Down
1 change: 1 addition & 0 deletions kernel/src/arch/aarch64/c_traps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub fn c_handle_syscall(_cptr: usize, _msgInfo: usize, syscall: usize) {
// if hart_id() == 0 {
// debug!("c_handle_syscall: syscall: {},", syscall as isize);
// }
// sel4_common::println!("c handle syscall");
slowpath(syscall);
// debug!("c_handle_syscall complete");
}
Expand Down
3 changes: 2 additions & 1 deletion kernel/src/arch/aarch64/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::arch::aarch64::consts::ARMDataAbort;
use crate::arch::aarch64::consts::ARMPrefetchAbort;
use crate::compatibility::lookupIPCBuffer;
use crate::halt;
use crate::kernel::boot::current_fault;
use crate::object::lookupCapAndSlot;
use crate::strnlen;
use crate::syscall::handle_fault;
Expand All @@ -15,6 +14,7 @@ use aarch64_cpu::registers::Readable;
use aarch64_cpu::registers::TTBR0_EL1;
use log::debug;
use sel4_common::arch::ArchReg::*;
use sel4_common::ffi::current_fault;
use sel4_common::platform::timer;
use sel4_common::platform::Timer_func;
use sel4_common::print;
Expand Down Expand Up @@ -116,6 +116,7 @@ pub fn handleVMFaultEvent(vm_faultType: usize) -> exception_t {
if status != exception_t::EXCEPTION_NONE {
handle_fault(get_currenct_thread());
}
// sel4_common::println!("handle vm fault event");
schedule();
activateThread();
exception_t::EXCEPTION_NONE
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/arch/riscv/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::read_stval;
use crate::compatibility::lookupIPCBuffer;
use crate::config::*;
use crate::halt;
use crate::kernel::boot::current_fault;
use crate::object::lookupCapAndSlot;
use crate::strnlen;
use crate::syscall::handle_fault;
Expand All @@ -12,6 +11,7 @@ use crate::syscall::{
};
use log::debug;
use sel4_common::arch::ArchReg::*;
use sel4_common::ffi::current_fault;
use sel4_common::platform::read_time;
use sel4_common::print;
use sel4_common::sel4_config::seL4_MsgMaxLength;
Expand Down
14 changes: 14 additions & 0 deletions kernel/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,25 @@ pub const RISCVLoadPageFault: usize = 13;
pub const RISCVStorePageFault: usize = 15;
pub const RISCVSupervisorTimer: usize = 9223372036854775813;

pub const thread_control_caps_update_ipc_buffer: usize = 0x1;
pub const thread_control_caps_update_space: usize = 0x2;
pub const thread_control_caps_update_fault: usize = 0x4;
pub const thread_control_caps_update_timeout: usize = 0x8;

pub const thread_control_sched_update_priority: usize = 0x1;
pub const thread_control_sched_update_mcp: usize = 0x2;
pub const thread_control_sched_update_sc: usize = 0x4;
pub const thread_control_sched_update_fault: usize = 0x8;

pub const thread_control_update_priority: usize = 0x1;
pub const thread_control_update_ipc_buffer: usize = 0x2;
pub const thread_control_update_space: usize = 0x4;
pub const thread_control_update_mcp: usize = 0x8;

pub const thread_control_update_sc: usize = 0x10;
pub const thread_control_update_fault: usize = 0x20;
pub const thread_control_update_timeout: usize = 0x40;

pub const seL4_WordBits: usize = 64;

pub const seL4_UserTop: usize = 0x00007fffffffffff;
Expand Down
53 changes: 50 additions & 3 deletions kernel/src/interfaces_impl/cspace.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::usize;

use crate::config::CONFIG_MAX_NUM_WORK_UNITS_PER_PREEMPTION;
// use crate::ffi::tcbDebugRemove;
use crate::interrupt::{deletingIRQHandler, isIRQPending, setIRQState, IRQState};
Expand All @@ -6,12 +8,16 @@ use crate::syscall::safe_unbind_notification;
use sel4_common::sel4_config::{tcbCNodeEntries, tcbCTable, tcbVTable};
use sel4_common::structures::exception_t;
use sel4_common::structures_gen::{cap, cap_null_cap, cap_tag, endpoint, notification};
use sel4_common::utils::convert_to_mut_type_ref;
use sel4_common::utils::{
convert_to_mut_type_ref, convert_to_option_mut_type_ref, convert_to_option_type_ref,
};
use sel4_cspace::capability::cap_func;
use sel4_cspace::compatibility::{ZombieType_ZombieTCB, Zombie_new};
use sel4_cspace::interface::finaliseCap_ret;
use sel4_ipc::{endpoint_func, notification_func, Transfer};
use sel4_task::{get_currenct_thread, ksWorkUnitsCompleted, tcb_t};
use sel4_task::{get_currenct_thread, ksWorkUnitsCompleted, tcb_t, ThreadState};
#[cfg(feature = "KERNEL_MCS")]
use sel4_task::{reply::reply_t, sched_context::sched_context_t};
#[cfg(target_arch = "riscv64")]
use sel4_vspace::find_vspace_for_asid;
#[cfg(target_arch = "aarch64")]
Expand Down Expand Up @@ -190,14 +196,45 @@ pub fn finaliseCap(capability: &cap, _final: bool, _exposed: bool) -> finaliseCa
let ntfn = convert_to_mut_type_ref::<notification>(
cap::cap_notification_cap(capability).get_capNtfnPtr() as usize,
);
#[cfg(feature = "KERNEL_MCS")]
if let Some(sc) = convert_to_option_mut_type_ref::<sched_context_t>(
ntfn.get_ntfnSchedContext() as usize,
) {
sc.schedContext_unbindNtfn();
}
ntfn.safe_unbind_tcb();
ntfn.cacncel_all_signal();
}
fc_ret.remainder = cap_null_cap::new().unsplay();
fc_ret.cleanupInfo = cap_null_cap::new().unsplay();
return fc_ret;
}
cap_tag::cap_reply_cap | cap_tag::cap_null_cap | cap_tag::cap_domain_cap => {
cap_tag::cap_reply_cap => {
#[cfg(feature = "KERNEL_MCS")]
if _final {
if let Some(reply) = convert_to_option_mut_type_ref::<reply_t>(
cap::cap_reply_cap(capability).get_capReplyPtr() as usize,
) {
if reply.replyTCB != 0 {
match convert_to_mut_type_ref::<tcb_t>(reply.replyTCB).get_state() {
ThreadState::ThreadStateBlockedOnReply => {
reply.remove(convert_to_mut_type_ref::<tcb_t>(reply.replyTCB));
}
ThreadState::ThreadStateBlockedOnReceive => {
convert_to_mut_type_ref::<tcb_t>(reply.replyTCB).cancel_ipc();
}
_ => {
panic!("invalid tcb state");
}
}
}
}
}
fc_ret.remainder = cap_null_cap::new().unsplay();
fc_ret.cleanupInfo = cap_null_cap::new().unsplay();
return fc_ret;
}
cap_tag::cap_null_cap | cap_tag::cap_domain_cap => {
fc_ret.remainder = cap_null_cap::new().unsplay();
fc_ret.cleanupInfo = cap_null_cap::new().unsplay();
return fc_ret;
Expand Down Expand Up @@ -236,6 +273,16 @@ pub fn finaliseCap(capability: &cap, _final: bool, _exposed: bool) -> finaliseCa
};
let cte_ptr = tcb.get_cspace_mut_ref(tcbCTable);
safe_unbind_notification(tcb);
#[cfg(feature = "KERNEL_MCS")]
if let Some(sc) =
convert_to_option_mut_type_ref::<sched_context_t>(tcb.tcbSchedContext)
{
sc.schedContext_unbindTCB(tcb);
if sc.scYieldFrom != 0 {
convert_to_mut_type_ref::<tcb_t>(sc.scYieldFrom)
.schedContext_completeYieldTo();
}
}
tcb.cancel_ipc();
tcb.suspend();
// #[cfg(feature="DEBUG_BUILD")]
Expand Down
6 changes: 0 additions & 6 deletions kernel/src/kernel/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ use crate::structures::{extra_caps_t, syscall_error_t};
// #[link_section = ".boot.bss"]
pub static mut current_lookup_fault: lookup_fault = lookup_fault(Bitfield { arr: [0; 2] });

#[no_mangle]
// #[link_section = ".boot.bss"]
pub static mut current_fault: seL4_Fault = seL4_Fault {
0: Bitfield { arr: [0; 2usize] },
};

#[no_mangle]
// #[link_section = ".boot.bss"]
pub static mut current_syscall_error: syscall_error_t = syscall_error_t {
Expand Down
Loading

0 comments on commit e52020a

Please sign in to comment.