mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-22 16:16:16 +04:00
modify select implementation
This commit is contained in:
parent
0aa995d98c
commit
ba09ab92a8
@ -1,3 +1,2 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
sleep 10 && sudo ifconfig tap0 10.0.0.1 &
|
|
||||||
make run net=on arch=x86_64 mode=release
|
make run net=on arch=x86_64 mode=release
|
||||||
|
@ -7,6 +7,7 @@ use crate::syscall::{SysError, SysResult};
|
|||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use rcore_fs::vfs::PollStatus;
|
use rcore_fs::vfs::PollStatus;
|
||||||
use crate::sync::Condvar;
|
use crate::sync::Condvar;
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
// TODO: merge FileLike to FileHandle ?
|
// TODO: merge FileLike to FileHandle ?
|
||||||
// TODO: fix dup and remove Clone
|
// TODO: fix dup and remove Clone
|
||||||
@ -58,12 +59,15 @@ impl FileLike {
|
|||||||
Ok(status)
|
Ok(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn poll_condvar(&self) -> Option<&Condvar> {
|
pub fn poll_condvar(&self, condvars: &mut Vec<&Condvar>) {
|
||||||
let condvar = match self {
|
let condvar = match self {
|
||||||
FileLike::File(file) => file.poll_condvar()?,
|
FileLike::File(file) => {
|
||||||
FileLike::Socket(socket) => socket.poll_condvar()?
|
condvars.push(&crate::fs::STDIN.pushed);
|
||||||
|
},
|
||||||
|
FileLike::Socket(socket) => {
|
||||||
|
condvars.push(&(*crate::drivers::SOCKET_ACTIVITY));
|
||||||
|
},
|
||||||
};
|
};
|
||||||
Ok(status)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fcntl(&mut self, cmd: usize, arg: usize) -> SysResult {
|
pub fn fcntl(&mut self, cmd: usize, arg: usize) -> SysResult {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
//! Syscalls for file system
|
//! Syscalls for file system
|
||||||
|
|
||||||
use core::cell::UnsafeCell;
|
use core::cell::UnsafeCell;
|
||||||
use core::cmp::min;
|
use core::cmp::min;
|
||||||
use core::mem::size_of;
|
use core::mem::size_of;
|
||||||
@ -102,6 +101,8 @@ impl Syscall<'_> {
|
|||||||
// check whether the fds is valid and is owned by this process
|
// check whether the fds is valid and is owned by this process
|
||||||
let mut condvars = Vec::new();
|
let mut condvars = Vec::new();
|
||||||
condvars.push(&(*TICK_ACTIVITY));
|
condvars.push(&(*TICK_ACTIVITY));
|
||||||
|
condvars.push(&STDIN.pushed);
|
||||||
|
condvars.push(&(*SOCKET_ACTIVITY));
|
||||||
|
|
||||||
let polls = unsafe { self.vm().check_write_array(ufds, nfds)? };
|
let polls = unsafe { self.vm().check_write_array(ufds, nfds)? };
|
||||||
for poll in polls.iter() {
|
for poll in polls.iter() {
|
||||||
@ -110,22 +111,16 @@ impl Syscall<'_> {
|
|||||||
return Err(SysError::EINVAL);
|
return Err(SysError::EINVAL);
|
||||||
},
|
},
|
||||||
Some(file_like) => {
|
Some(file_like) => {
|
||||||
if let Some(condvar) = file_like.poll_condvar(){
|
// file_like.poll_condvar(&mut condvars);
|
||||||
condvars.push(condvar);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
condvars =
|
|
||||||
drop(proc);
|
drop(proc);
|
||||||
|
|
||||||
let begin_time_ms = crate::trap::uptime_msec();
|
let begin_time_ms = crate::trap::uptime_msec();
|
||||||
|
//&[&STDIN.pushed, &(*SOCKET_ACTIVITY)] condvars.as_slice()
|
||||||
|
// println!("poll called {:?}", condvars.len());
|
||||||
// condvars.push(&STDIN.pushed);
|
Condvar::wait_events(condvars.as_slice(), move || {
|
||||||
// condvars.push(&(*SOCKET_ACTIVITY));
|
|
||||||
|
|
||||||
Condvar::wait_events(&condvars., move || {
|
|
||||||
use PollEvents as PE;
|
use PollEvents as PE;
|
||||||
let proc = self.process();
|
let proc = self.process();
|
||||||
let mut events = 0;
|
let mut events = 0;
|
||||||
@ -210,6 +205,12 @@ impl Syscall<'_> {
|
|||||||
1 << 31
|
1 << 31
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut condvars = Vec::new();
|
||||||
|
condvars.push(&(*TICK_ACTIVITY));
|
||||||
|
condvars.push(&STDIN.pushed);
|
||||||
|
condvars.push(&(*SOCKET_ACTIVITY));
|
||||||
|
println!("select used");
|
||||||
|
|
||||||
// for debugging
|
// for debugging
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
debug!("files before select {:#?}", proc.files);
|
debug!("files before select {:#?}", proc.files);
|
||||||
@ -217,13 +218,13 @@ impl Syscall<'_> {
|
|||||||
drop(proc);
|
drop(proc);
|
||||||
|
|
||||||
let begin_time_ms = crate::trap::uptime_msec();
|
let begin_time_ms = crate::trap::uptime_msec();
|
||||||
Condvar::wait_events(&[&STDIN.pushed, &(*SOCKET_ACTIVITY)], move || {
|
Condvar::wait_events(condvars.as_slice(), move || {
|
||||||
let proc = self.process();
|
let proc = self.process();
|
||||||
let mut events = 0;
|
let mut events = 0;
|
||||||
for (&fd, file_like) in proc.files.iter() {
|
for (&fd, file_like) in proc.files.iter() {
|
||||||
if fd >= nfds {
|
// if fd >= nfds {
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
if !err_fds.contains(fd) && !read_fds.contains(fd) && !write_fds.contains(fd) {
|
if !err_fds.contains(fd) && !read_fds.contains(fd) && !write_fds.contains(fd) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -266,6 +267,59 @@ impl Syscall<'_> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sys_epoll_create(
|
||||||
|
&mut self,
|
||||||
|
size: usize,
|
||||||
|
) -> SysResult {
|
||||||
|
info!("epoll_create: size: {:?}", size);
|
||||||
|
|
||||||
|
return Ok(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sys_epoll_create1(
|
||||||
|
&mut self,
|
||||||
|
flags: usize,
|
||||||
|
) -> SysResult {
|
||||||
|
info!("epoll_create1: flags: {:?}", flags);
|
||||||
|
|
||||||
|
return Ok(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sys_epoll_ctl(
|
||||||
|
&mut self,
|
||||||
|
epfd: usize,
|
||||||
|
op: usize,
|
||||||
|
fd: usize,
|
||||||
|
event: *mut PollEvents,
|
||||||
|
) -> SysResult {
|
||||||
|
return Ok(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sys_epoll_wait(
|
||||||
|
&mut self,
|
||||||
|
epfd: usize,
|
||||||
|
events: *mut EpollEvent,
|
||||||
|
maxevents: usize,
|
||||||
|
timeout: usize,
|
||||||
|
) -> SysResult {
|
||||||
|
return Ok(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sys_epoll_pwait(
|
||||||
|
&mut self,
|
||||||
|
epfd: usize,
|
||||||
|
events: *mut EpollEvent,
|
||||||
|
maxevents: usize,
|
||||||
|
timeout: usize,
|
||||||
|
sigset_t: *mut SigSet_t,
|
||||||
|
) -> SysResult {
|
||||||
|
return Ok(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
pub fn sys_readv(&mut self, fd: usize, iov_ptr: *const IoVec, iov_count: usize) -> SysResult {
|
pub fn sys_readv(&mut self, fd: usize, iov_ptr: *const IoVec, iov_count: usize) -> SysResult {
|
||||||
info!(
|
info!(
|
||||||
"readv: fd: {}, iov: {:?}, count: {}",
|
"readv: fd: {}, iov: {:?}, count: {}",
|
||||||
@ -591,7 +645,6 @@ impl Syscall<'_> {
|
|||||||
|
|
||||||
// BUGFIX: '..' and '.'
|
// BUGFIX: '..' and '.'
|
||||||
if path.len() > 0 {
|
if path.len() > 0 {
|
||||||
|
|
||||||
let cwd = match path.as_bytes()[0] {
|
let cwd = match path.as_bytes()[0] {
|
||||||
b'/' => String::from("/"),
|
b'/' => String::from("/"),
|
||||||
_ => proc.cwd.clone(),
|
_ => proc.cwd.clone(),
|
||||||
@ -1557,5 +1610,22 @@ impl FdSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct SigSet_t {
|
||||||
|
__val: [u64; 1024 / 8 / 8],
|
||||||
|
}
|
||||||
|
|
||||||
|
union epoll_data_t {
|
||||||
|
ptr: u64,
|
||||||
|
fd: i32,
|
||||||
|
v32: u32,
|
||||||
|
v64: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct EpollEvent {
|
||||||
|
events: u32, /* Epoll events */
|
||||||
|
data: epoll_data_t, /* User data variable */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Pathname is interpreted relative to the current working directory(CWD)
|
/// Pathname is interpreted relative to the current working directory(CWD)
|
||||||
const AT_FDCWD: usize = -100isize as usize;
|
const AT_FDCWD: usize = -100isize as usize;
|
||||||
|
@ -165,7 +165,9 @@ impl Syscall<'_> {
|
|||||||
SYS_PPOLL => {
|
SYS_PPOLL => {
|
||||||
self.sys_ppoll(args[0] as *mut PollFd, args[1], args[2] as *const TimeSpec)
|
self.sys_ppoll(args[0] as *mut PollFd, args[1], args[2] as *const TimeSpec)
|
||||||
} // ignore sigmask
|
} // ignore sigmask
|
||||||
SYS_EPOLL_CREATE1 => self.unimplemented("epoll_create1", Err(SysError::ENOSYS)),
|
SYS_EPOLL_CREATE1 => self.sys_epoll_create1(args[0]),
|
||||||
|
SYS_EPOLL_PWAIT => self.sys_epoll_pwait(args[0], args[1] as *mut EpollEvent,
|
||||||
|
args[2], args[3], args[4] as *mut SigSet_t),
|
||||||
|
|
||||||
// file system
|
// file system
|
||||||
SYS_STATFS => self.unimplemented("statfs", Err(SysError::EACCES)),
|
SYS_STATFS => self.unimplemented("statfs", Err(SysError::EACCES)),
|
||||||
@ -458,6 +460,7 @@ impl Syscall<'_> {
|
|||||||
SYS_ARCH_PRCTL => self.sys_arch_prctl(args[0] as i32, args[1]),
|
SYS_ARCH_PRCTL => self.sys_arch_prctl(args[0] as i32, args[1]),
|
||||||
SYS_TIME => self.sys_time(args[0] as *mut u64),
|
SYS_TIME => self.sys_time(args[0] as *mut u64),
|
||||||
SYS_EPOLL_CREATE => self.unimplemented("epoll_create", Err(SysError::ENOSYS)),
|
SYS_EPOLL_CREATE => self.unimplemented("epoll_create", Err(SysError::ENOSYS)),
|
||||||
|
// SYS_EPOLL_WAIT =>self.sys_epoll_wait(args[0], args[1] as *mut EpollEvent, args[2], args[3]),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
Some(ret)
|
Some(ret)
|
||||||
|
Loading…
Reference in New Issue
Block a user