forked from koniifer/ableos
speed up cpu + ipc
This commit is contained in:
parent
3f4c9fdb5a
commit
dc83d8e175
|
@ -70,8 +70,8 @@ extern "x86-interrupt" fn double_fault_handler(
|
||||||
#[naked]
|
#[naked]
|
||||||
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||||
use super::task_switcher;
|
use super::task_switcher;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
// print!(".");
|
||||||
asm!(
|
asm!(
|
||||||
// Kernel tick
|
// Kernel tick
|
||||||
"call {tick}",
|
"call {tick}",
|
||||||
|
@ -121,10 +121,17 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
|
||||||
print!("{chr}");
|
print!("{chr}");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DecodedKey::RawKey(key) => match KeyCode::from(key) {
|
DecodedKey::RawKey(key) => {
|
||||||
KeyCode::AltLeft | KeyCode::AltRight => (),
|
use KeyCode::*;
|
||||||
kc => print!("{kc:?}"),
|
match KeyCode::from(key) {
|
||||||
},
|
AltLeft | AltRight => (),
|
||||||
|
ArrowDown | ArrowRight | ArrowLeft | ArrowUp => {
|
||||||
|
warn!("ArrowKeys are unsupported currently");
|
||||||
|
}
|
||||||
|
|
||||||
|
kc => print!("{kc:?}"),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +150,17 @@ pub fn init_idt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_pit_frequency(pit: u16, freq: u32) {
|
pub fn set_pit_frequency(pit: u16, freq: u32) {
|
||||||
let divisor: u16 = (1193180 / freq).try_into().unwrap();
|
let ret = (1193180 / freq).try_into();
|
||||||
|
|
||||||
|
let divisor: u16 = match ret {
|
||||||
|
Ok(div) => div,
|
||||||
|
Err(err) => {
|
||||||
|
error!("{}", err);
|
||||||
|
|
||||||
|
warn!("Defaulting to 1000 on PIT{}", pit);
|
||||||
|
1000
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
outb(0x36, 0x43);
|
outb(0x36, 0x43);
|
||||||
|
@ -164,7 +181,7 @@ pub fn set_pit_3(freq: u32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset_pit_for_cpu() {
|
pub fn reset_pit_for_cpu() {
|
||||||
set_pit_1(1000);
|
set_pit_1(50);
|
||||||
set_pit_2(1000);
|
set_pit_2(1000);
|
||||||
set_pit_3(1000);
|
set_pit_3(1000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ pub enum HandleResource {
|
||||||
|
|
||||||
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
|
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
|
||||||
pub struct Handle {
|
pub struct Handle {
|
||||||
inner: u128,
|
pub inner: u128,
|
||||||
res: HandleResource,
|
pub res: HandleResource,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Handle {
|
impl Display for Handle {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use alloc::collections::VecDeque;
|
use alloc::collections::VecDeque;
|
||||||
|
|
||||||
|
use super::IPCError;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
||||||
pub struct ChannelPermission {
|
pub struct ChannelPermission {
|
||||||
|
@ -13,26 +15,33 @@ pub struct ChannelPermission {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Channel {
|
pub struct Channel {
|
||||||
// public: bool,
|
pub public: bool,
|
||||||
|
name: String,
|
||||||
inner: VecDeque<ChannelMessage>,
|
inner: VecDeque<ChannelMessage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Channel {
|
impl Channel {
|
||||||
pub fn new() -> Self {
|
pub fn new<S: Into<String>>(name: S, public: bool) -> Self {
|
||||||
let deq = VecDeque::from([]);
|
let deq = VecDeque::from([]);
|
||||||
|
|
||||||
Self { inner: deq }
|
Self {
|
||||||
|
public,
|
||||||
|
name: name.into(),
|
||||||
|
inner: deq,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&mut self) -> Result<ChannelMessage, ChannelError> {
|
pub fn read(&mut self) -> Result<ChannelMessage, IPCError> {
|
||||||
if let Some(msg) = self.inner.pop_front() {
|
if let Some(msg) = self.inner.pop_front() {
|
||||||
return Ok(msg);
|
return Ok(msg);
|
||||||
}
|
}
|
||||||
return Err(ChannelError::EmptyBuffer);
|
return Err(IPCError::EmptyChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(&mut self, data: ChannelMessage) {
|
pub fn write(&mut self, data: ChannelMessage) -> Result<(), IPCError> {
|
||||||
self.inner.push_back(data);
|
self.inner.push_back(data);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,8 +56,20 @@ pub struct ChannelMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChannelMessage {
|
impl ChannelMessage {
|
||||||
pub fn new(data: [u8; 4096]) -> Self {
|
pub fn new<S: Into<String>>(data: S) -> Result<Self, IPCError> {
|
||||||
Self { inner: data }
|
let data = data.into();
|
||||||
|
let mut message = Self { inner: [0; 4096] };
|
||||||
|
|
||||||
|
if data.len() > 4096 {
|
||||||
|
return Err(IPCError::InvalidMessage);
|
||||||
|
} else {
|
||||||
|
let mut idx = 0;
|
||||||
|
for b in data.bytes() {
|
||||||
|
message.inner[idx] = b;
|
||||||
|
idx += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(message)
|
||||||
}
|
}
|
||||||
pub fn from_string() {}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
|
||||||
use crate::handle::Handle;
|
use crate::handle::{Handle, HandleResource};
|
||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
channel::Channel,
|
channel::{Channel, ChannelMessage},
|
||||||
socket::{Socket, SocketError},
|
socket::Socket,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod channel;
|
pub mod channel;
|
||||||
|
@ -14,33 +14,148 @@ lazy_static::lazy_static! {
|
||||||
pub static ref IPC: spin::Mutex<IPCService> = spin::Mutex::new(IPCService {
|
pub static ref IPC: spin::Mutex<IPCService> = spin::Mutex::new(IPCService {
|
||||||
sockets: HashMap::new(),
|
sockets: HashMap::new(),
|
||||||
channels: HashMap::new(),
|
channels: HashMap::new(),
|
||||||
|
public_board: vec![],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
pub struct IPCService {
|
pub struct IPCService {
|
||||||
pub sockets: HashMap<Handle, Socket>,
|
pub sockets: HashMap<Handle, Socket>,
|
||||||
pub channels: HashMap<Handle, Socket>,
|
pub channels: HashMap<Handle, Channel>,
|
||||||
// TODO: Add a public board of each down below which use some method of pointing to the above
|
// TODO: Add a public board of each down below which use some method of pointing to the above
|
||||||
|
pub public_board: Vec<Handle>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IPCService {
|
||||||
|
pub fn examine_board(&self) -> Vec<Handle> {
|
||||||
|
self.public_board.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Socket Related Impl
|
// Socket Related Impl
|
||||||
impl IPCService {
|
impl IPCService {
|
||||||
pub fn create_socket(&mut self) -> Handle {
|
pub fn create_socket<S: Into<String>>(&mut self, name: S, public: bool) -> Handle {
|
||||||
let handle = Handle::new(crate::handle::HandleResource::Socket);
|
let handle = Handle::new(crate::handle::HandleResource::Socket);
|
||||||
|
|
||||||
let sock = Socket::new();
|
let mut sock = Socket::new(name.into());
|
||||||
|
if public {
|
||||||
|
sock.public = true;
|
||||||
|
|
||||||
|
self.public_board.push(handle);
|
||||||
|
}
|
||||||
|
|
||||||
self.sockets.insert(handle.clone(), sock);
|
self.sockets.insert(handle.clone(), sock);
|
||||||
|
|
||||||
handle
|
handle
|
||||||
}
|
}
|
||||||
|
pub fn send_socket<S: Into<Vec<u8>>>(
|
||||||
|
&mut self,
|
||||||
|
handle: Handle,
|
||||||
|
data: S,
|
||||||
|
) -> Result<(), IPCError> {
|
||||||
|
trace!("Sending data to {}", handle);
|
||||||
|
match handle {
|
||||||
|
Handle {
|
||||||
|
inner: _inner,
|
||||||
|
res: HandleResource::Socket,
|
||||||
|
} => {
|
||||||
|
let sock = self.sockets.get_mut(&handle);
|
||||||
|
|
||||||
pub fn send_socket(&mut self, handle: Handle, data: String) -> Result<(), SocketError> {
|
match sock {
|
||||||
let sock = self.sockets.get_mut(&handle);
|
Some(socket) => {
|
||||||
|
return socket.write(data.into());
|
||||||
match sock {
|
}
|
||||||
Some(socket) => {
|
None => return Err(IPCError::NonexistantSocket),
|
||||||
return socket.write(data);
|
}
|
||||||
}
|
}
|
||||||
None => return Err(SocketError::NonexistantSocket),
|
_ => return Err(IPCError::InvalidHandle),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_socket(&mut self, handle: Handle) -> Result<Vec<u8>, IPCError> {
|
||||||
|
trace!("Reading data from {}", handle);
|
||||||
|
|
||||||
|
match handle {
|
||||||
|
Handle {
|
||||||
|
inner: _inner,
|
||||||
|
res: HandleResource::Socket,
|
||||||
|
} => {
|
||||||
|
let sock = self.sockets.get_mut(&handle);
|
||||||
|
|
||||||
|
match sock {
|
||||||
|
Some(socket) => {
|
||||||
|
return socket.read();
|
||||||
|
}
|
||||||
|
None => return Err(IPCError::NonexistantSocket),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => return Err(IPCError::InvalidHandle),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IPCService {
|
||||||
|
pub fn create_channel<S: Into<String>>(&mut self, name: S, public: bool) -> Handle {
|
||||||
|
let handle = Handle::new(crate::handle::HandleResource::Channel);
|
||||||
|
|
||||||
|
let mut chan = Channel::new(name.into(), public);
|
||||||
|
if public {
|
||||||
|
chan.public = true;
|
||||||
|
|
||||||
|
self.public_board.push(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.channels.insert(handle.clone(), chan);
|
||||||
|
|
||||||
|
handle
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_channel(&mut self, handle: Handle) -> Result<ChannelMessage, IPCError> {
|
||||||
|
trace!("Reading data from {}", handle);
|
||||||
|
|
||||||
|
match handle {
|
||||||
|
Handle {
|
||||||
|
inner: _inner,
|
||||||
|
res: HandleResource::Channel,
|
||||||
|
} => {
|
||||||
|
let sock = self.channels.get_mut(&handle);
|
||||||
|
|
||||||
|
match sock {
|
||||||
|
Some(socket) => {
|
||||||
|
return socket.read();
|
||||||
|
}
|
||||||
|
None => return Err(IPCError::NonexistantSocket),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => return Err(IPCError::InvalidHandle),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_channel(&mut self, handle: Handle, data: ChannelMessage) -> Result<(), IPCError> {
|
||||||
|
trace!("Sending data to {}", handle);
|
||||||
|
match handle {
|
||||||
|
Handle {
|
||||||
|
inner: _inner,
|
||||||
|
res: HandleResource::Channel,
|
||||||
|
} => {
|
||||||
|
let sock = self.channels.get_mut(&handle);
|
||||||
|
|
||||||
|
match sock {
|
||||||
|
Some(socket) => {
|
||||||
|
return socket.write(data);
|
||||||
|
}
|
||||||
|
None => return Err(IPCError::NonexistantSocket),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => return Err(IPCError::InvalidHandle),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub enum IPCError {
|
||||||
|
InvalidHandle,
|
||||||
|
NonexistantSocket,
|
||||||
|
EmptySocket,
|
||||||
|
EmptyChannel,
|
||||||
|
InvalidMessage,
|
||||||
|
}
|
||||||
|
|
|
@ -1,40 +1,43 @@
|
||||||
// SEEALSO: https://git.ablecorp.us/able/ableos/src/branch/master/ableos/src/relib/network/socket.rs
|
// SEEALSO: https://git.ablecorp.us/able/ableos/src/branch/master/ableos/src/relib/network/socket.rs
|
||||||
|
|
||||||
pub enum SocketError {
|
use super::IPCError;
|
||||||
NonexistantSocket,
|
|
||||||
EmptySocket,
|
|
||||||
}
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Socket {
|
pub struct Socket {
|
||||||
name: Option<String>,
|
pub public: bool,
|
||||||
|
name: String,
|
||||||
stream: Vec<u8>,
|
stream: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Socket {
|
impl Socket {
|
||||||
pub fn new() -> Self {
|
pub fn new<S: Into<String>>(name: S) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: None,
|
public: false,
|
||||||
|
name: name.into(),
|
||||||
stream: vec![],
|
stream: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn write(&mut self, data: String) -> Result<(), SocketError> {
|
|
||||||
for c in data.chars() {
|
// <S: Into<String>>(name: S)
|
||||||
|
|
||||||
|
pub fn write<S: Into<Vec<u8>>>(&mut self, data: S) -> Result<(), IPCError> {
|
||||||
|
for c in data.into() {
|
||||||
self.stream.push(c as u8);
|
self.stream.push(c as u8);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn read(&mut self) -> Result<Vec<u8>, SocketError> {
|
pub fn read(&mut self) -> Result<Vec<u8>, IPCError> {
|
||||||
if self.stream.len() != 0 {
|
if self.stream.len() != 0 {
|
||||||
let skt = self.stream.clone();
|
let skt = self.stream.clone();
|
||||||
self.stream = vec![];
|
self.stream = vec![];
|
||||||
|
|
||||||
return Ok(skt);
|
return Ok(skt);
|
||||||
}
|
}
|
||||||
return Err(SocketError::EmptySocket);
|
return Err(IPCError::EmptySocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&mut self, name: String) {
|
pub fn rename(&mut self, name: String) {
|
||||||
self.name = Some(name);
|
self.name = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
use core::sync::atomic::Ordering;
|
use core::sync::atomic::Ordering;
|
||||||
|
|
||||||
use crate::arch::drivers::sysinfo::master;
|
use crate::arch::drivers::sysinfo::master;
|
||||||
|
use crate::ipc::channel::ChannelMessage;
|
||||||
use crate::ipc::{self, IPC};
|
use crate::ipc::{self, IPC};
|
||||||
use crate::scheduler::SCHEDULER;
|
use crate::scheduler::SCHEDULER;
|
||||||
use crate::time::fetch_time;
|
use crate::time::fetch_time;
|
||||||
|
use crate::SectionType;
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::{init, sloop},
|
arch::{init, sloop},
|
||||||
relib::network::socket::{SimpleSock, Socket},
|
relib::network::socket::{SimpleSock, Socket},
|
||||||
|
@ -13,7 +15,9 @@ use crate::{
|
||||||
};
|
};
|
||||||
use crate::{boot_conf::KernelConfig, systeminfo::RELEASE_TYPE};
|
use crate::{boot_conf::KernelConfig, systeminfo::RELEASE_TYPE};
|
||||||
use kernel::{KERNEL_VERSION, TICK};
|
use kernel::{KERNEL_VERSION, TICK};
|
||||||
|
use libwasm::syscalls::time_calls::get_time;
|
||||||
use spin::Lazy;
|
use spin::Lazy;
|
||||||
|
use x86_64::instructions::interrupts::{disable, enable};
|
||||||
|
|
||||||
// TODO: Change this structure to allow for multiple cores loaded
|
// TODO: Change this structure to allow for multiple cores loaded
|
||||||
pub static KERNEL_CONF: Lazy<KernelConfig> = Lazy::new(KernelConfig::new);
|
pub static KERNEL_CONF: Lazy<KernelConfig> = Lazy::new(KernelConfig::new);
|
||||||
|
@ -31,18 +35,34 @@ pub fn kernel_main() -> ! {
|
||||||
|
|
||||||
let mut ipc_service = IPC.lock();
|
let mut ipc_service = IPC.lock();
|
||||||
// create some channels or whatever here then drop it
|
// create some channels or whatever here then drop it
|
||||||
let handle = ipc_service.create_socket();
|
let log_handle = ipc_service.create_channel("LOG", true);
|
||||||
ipc_service.send_socket(handle, "nerd".to_string());
|
|
||||||
|
|
||||||
drop(ipc_service);
|
drop(ipc_service);
|
||||||
|
|
||||||
x86_64::instructions::interrupts::without_interrupts(|| {
|
x86_64::instructions::interrupts::without_interrupts(|| {
|
||||||
SCHEDULER.lock().enqueue_spawn(scratchpad);
|
let mut scheduler = SCHEDULER.lock();
|
||||||
|
|
||||||
|
// TODO: This task never gets run
|
||||||
|
scheduler.enqueue_spawn(traceloop);
|
||||||
|
|
||||||
|
//
|
||||||
|
scheduler.enqueue_spawn(scratchpad);
|
||||||
});
|
});
|
||||||
|
|
||||||
sloop()
|
sloop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn traceloop() {
|
||||||
|
let mut last_time = 0.0;
|
||||||
|
loop {
|
||||||
|
// let time = fetch_time();
|
||||||
|
// if time > last_time {
|
||||||
|
// last_time = time;
|
||||||
|
// trace!("Timer");
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn cpu_socket_startup() {
|
pub fn cpu_socket_startup() {
|
||||||
let mut cpu_info_socket = SimpleSock::new();
|
let mut cpu_info_socket = SimpleSock::new();
|
||||||
cpu_info_socket.register_protocol("CPU_INFO".to_string());
|
cpu_info_socket.register_protocol("CPU_INFO".to_string());
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl log::Log for SimpleLogger {
|
||||||
record.args()
|
record.args()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
let log_socket_id = SimpleSock::grab_socket("Logger".to_string());
|
let log_socket_id = SimpleSock::grab_socket("Logger".to_string());
|
||||||
match log_socket_id {
|
match log_socket_id {
|
||||||
Some(mut log_socket_id) => {
|
Some(mut log_socket_id) => {
|
||||||
|
@ -54,6 +54,7 @@ impl log::Log for SimpleLogger {
|
||||||
}
|
}
|
||||||
None => warn!("No socket found for Logger"),
|
None => warn!("No socket found for Logger"),
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Clear the log buffer
|
/// Clear the log buffer
|
||||||
|
|
|
@ -3,11 +3,9 @@ use kernel::TICK;
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub fn fetch_time() -> f64 {
|
pub fn fetch_time() -> f64 {
|
||||||
use x86_64::instructions::interrupts::{disable, enable};
|
let time = x86_64::instructions::interrupts::without_interrupts(|| {
|
||||||
|
TICK.load(Ordering::Relaxed) as f64
|
||||||
disable();
|
});
|
||||||
let time = TICK.load(Ordering::Relaxed) as f64;
|
|
||||||
enable();
|
|
||||||
time
|
time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue