Explorar o código

chore: change some typo and format

greatbridf hai 6 meses
pai
achega
c5b5572fc6

+ 5 - 5
Cargo.toml

@@ -50,19 +50,19 @@ debug = true
 panic = "abort"
 
 [profile.dev.package.eonix_preempt]
-opt-level = "s"
+opt-level = 2
 
 [profile.dev.package.eonix_runtime]
-opt-level = "s"
+opt-level = 2
 
 [profile.dev.package.eonix_sync]
-opt-level = "s"
+opt-level = 2
 
 [profile.dev.package.intrusive_list]
-opt-level = "s"
+opt-level = 2
 
 [profile.dev.package.eonix_hal]
-opt-level = "s"
+opt-level = 2
 
 [profile.dev.package."*"]
 opt-level = "s"

+ 3 - 4
crates/eonix_runtime/src/scheduler.rs

@@ -9,7 +9,7 @@ use alloc::sync::Arc;
 use core::{
     mem::forget,
     ptr::NonNull,
-    sync::atomic::{compiler_fence, AtomicUsize, Ordering},
+    sync::atomic::{compiler_fence, Ordering},
     task::Waker,
 };
 use eonix_hal::processor::halt;
@@ -136,9 +136,8 @@ impl Scheduler {
         unsafe { TASKS.lock().cursor_mut_from_ptr(task as *const _).remove() };
     }
 
-    fn select_cpu_for_task(&self, _task: &Task) -> usize {
-        static NEXT_CPU: AtomicUsize = AtomicUsize::new(0);
-        NEXT_CPU.fetch_add(1, Ordering::Relaxed) % 4
+    fn select_cpu_for_task(&self, task: &Task) -> usize {
+        task.cpu.load(Ordering::Relaxed) as _
     }
 
     pub fn activate(&self, task: &Arc<Task>) {

+ 1 - 1
crates/slab_allocator/src/slab_cache.rs

@@ -89,7 +89,7 @@ where
     Allocator: PageAlloc<RawPage = Raw>,
 {
     pub(crate) const fn new_in(object_size: u32) -> Self {
-        // avoid uncessary branch in alloc and dealloc
+        // avoid unnecessary branch in alloc and dealloc
         assert!(object_size <= PAGE_SIZE as u32 / 2);
 
         Self {

+ 3 - 3
src/io.rs

@@ -3,7 +3,7 @@ use crate::prelude::*;
 use core::{cmp, mem::MaybeUninit};
 
 #[must_use]
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[derive(Debug)]
 pub enum FillResult {
     Done(usize),
     Partial(usize),
@@ -64,7 +64,7 @@ pub trait StreamRead {
     fn read_till_end(
         &mut self,
         buffer: &mut [u8],
-        func: impl FnMut(&mut [u8]) -> KResult<()>,
+        func: impl Fn(&mut [u8]) -> KResult<()>,
     ) -> KResult<usize>;
 
     fn ignore_all(&mut self) -> KResult<usize>;
@@ -77,7 +77,7 @@ where
     fn read_till_end(
         &mut self,
         buffer: &mut [u8],
-        mut func: impl FnMut(&mut [u8]) -> KResult<()>,
+        func: impl Fn(&mut [u8]) -> KResult<()>,
     ) -> KResult<usize> {
         let mut total = 0;
         while let Some(data) = self.poll_data(buffer)? {

+ 2 - 1
src/kernel/mem/mm_list.rs

@@ -753,7 +753,8 @@ impl PageTableExt for KernelPageTable<'_> {
         let from_iter = from.iter_user(range);
 
         for (to, from) in to_iter.zip(from_iter) {
-            *to = *from;
+            let (pfn, attr) = from.get();
+            to.set(pfn, attr);
         }
     }
 }

+ 3 - 13
src/kernel/mem/page_cache.rs

@@ -7,7 +7,6 @@ use crate::{
 };
 use align_ext::AlignExt;
 use alloc::{collections::btree_map::BTreeMap, sync::Weak};
-use core::sync::atomic::{AtomicUsize, Ordering};
 use eonix_mm::paging::{PageAlloc, RawPage, PAGE_SIZE, PAGE_SIZE_BITS};
 use eonix_sync::Mutex;
 
@@ -78,14 +77,12 @@ impl CachePage {
 
     pub fn all(&self) -> &[u8] {
         unsafe {
-            // SAFETY: The page is exclusively owned by us, so we can safely access its data.
             self.0.as_memblk().as_bytes()
         }
     }
 
     pub fn all_mut(&mut self) -> &mut [u8] {
         unsafe {
-            // SAFETY: The page is exclusively owned by us, so we can safely access its data.
             self.0.as_memblk().as_bytes_mut()
         }
     }
@@ -118,8 +115,6 @@ impl PageCache {
     pub async fn read(&self, buffer: &mut dyn Buffer, mut offset: usize) -> KResult<usize> {
         let mut pages = self.pages.lock().await;
 
-        // println_debug!("before pagecache read, {}", buffer.available());
-
         loop {
             let page_id = offset >> PAGE_SIZE_BITS;
             let page = pages.get(&page_id);
@@ -127,12 +122,9 @@ impl PageCache {
             match page {
                 Some(page) => {
                     let inner_offset = offset % PAGE_SIZE;
-                    // println_debug!(
-                    //     "pagecache try fill data {}",
-                    //     page.valid_data()[inner_offset..].len()
-                    // );
 
-                    // Todo: still cause uncessary IO if valid_size < PAGESIZE and fill result is Done
+                    // TODO: still cause unnecessary IO if valid_size < PAGESIZE
+                    //       and fill result is Done
                     if page.valid_size() == 0
                         || buffer
                             .fill(&page.valid_data()[inner_offset..])?
@@ -146,7 +138,6 @@ impl PageCache {
                 }
                 None => {
                     let mut new_page = CachePage::new();
-                    // println_debug!("page cache try get {}", offset.align_down(PAGE_SIZE));
                     self.backend
                         .upgrade()
                         .unwrap()
@@ -155,7 +146,6 @@ impl PageCache {
                 }
             }
         }
-        // println_debug!("after page cache read{}", buffer.available());
 
         Ok(buffer.wrote())
     }
@@ -285,7 +275,7 @@ impl PageCache {
 // with this trait, "page cache" and "block cache" are unified,
 // for fs, offset is file offset (floor algin to PAGE_SIZE)
 // for blkdev, offset is block idx (floor align to PAGE_SIZE / BLK_SIZE)
-// Oh no, this would make uncessary cache
+// Oh no, this would make unnecessary cache
 pub trait PageCacheBackend {
     fn read_page(&self, page: &mut CachePage, offset: usize) -> KResult<usize>;
 

+ 3 - 13
src/kernel/syscall/file_rw.rs

@@ -532,16 +532,6 @@ fn ppoll(
     do_poll(thread, fds, nfds, 0)
 }
 
-fn do_pselect(
-    nfds: u32,
-    readfds: *mut FDSet,
-    writefds: *mut FDSet,
-    exceptfds: *mut FDSet,
-    timeout: *const TimeSpec,
-    sigmask: *const SigSet,
-) {
-}
-
 #[eonix_macros::define_syscall(SYS_PSELECT6)]
 fn pselect6(
     nfds: u32,
@@ -560,7 +550,9 @@ fn pselect6(
     }
 
     let timeout = UserPointerMut::new(timeout)?;
-    let timeout_value = timeout.read()?;
+    
+    // Read here to check for invalid pointers.
+    let _timeout_value = timeout.read()?;
 
     Task::block_on(sleep(Duration::from_millis(10)));
 
@@ -569,8 +561,6 @@ fn pselect6(
         tv_nsec: 0,
     })?;
 
-    // println_debug!("slept for {timeout_value:?}");
-
     Ok(0)
 }
 

+ 4 - 18
src/kernel/syscall/procops.rs

@@ -434,28 +434,14 @@ fn getgid() -> KResult<u32> {
     Ok(0)
 }
 
-#[eonix_macros::define_syscall(SYS_GETEGID)]
-fn getegid() -> KResult<u32> {
-    // All users are root for now.
-    Ok(0)
-}
-
-#[eonix_macros::define_syscall(SYS_GETRANDOM)]
-fn getrandom() -> KResult<u32> {
-    // All users are root for now.
-    Ok(0)
-}
-
 #[eonix_macros::define_syscall(SYS_SYNC)]
-fn sync() -> KResult<u32> {
-    // All users are root for now.
-    Ok(0)
+fn sync() -> KResult<()> {
+    Ok(())
 }
 
 #[eonix_macros::define_syscall(SYS_FSYNC)]
-fn fsync() -> KResult<u32> {
-    // All users are root for now.
-    Ok(0)
+fn fsync() -> KResult<()> {
+    Ok(())
 }
 
 #[cfg(target_arch = "x86_64")]