Skip to content

Commit

Permalink
[runtime] Enhancement: Use runtime instead of libos
Browse files Browse the repository at this point in the history
  • Loading branch information
iyzhang committed Dec 8, 2023
1 parent 469c125 commit b5c027d
Show file tree
Hide file tree
Showing 14 changed files with 471 additions and 530 deletions.
34 changes: 2 additions & 32 deletions src/rust/catcollar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,8 @@ use crate::{
QToken,
QType,
},
scheduler::{
TaskHandle,
Yielder,
},
types::{
demi_qresult_t,
demi_sgarray_t,
},
scheduler::Yielder,
types::demi_sgarray_t,
DemiRuntime,
SharedDemiRuntime,
},
Expand Down Expand Up @@ -663,30 +657,6 @@ impl CatcollarLibOS {
}
}

pub fn poll(&mut self) {
self.runtime.poll()
}

pub fn schedule(&mut self, qt: QToken) -> Result<TaskHandle, Fail> {
self.runtime.from_task_id(qt.into())
}

pub fn pack_result(&mut self, handle: TaskHandle, qt: QToken) -> Result<demi_qresult_t, Fail> {
self.runtime.remove_coroutine_and_get_result(&handle, qt.into())
}

/// Allocates a scatter-gather array.
pub fn sgaalloc(&self, size: usize) -> Result<demi_sgarray_t, Fail> {
trace!("sgalloc() size={:?}", size);
self.runtime.alloc_sgarray(size)
}

/// Frees a scatter-gather array.
pub fn sgafree(&self, sga: demi_sgarray_t) -> Result<(), Fail> {
trace!("sgafree()");
self.runtime.free_sgarray(sga)
}

fn get_shared_queue(&self, qd: &QDesc) -> Result<CatcollarQueue, Fail> {
Ok(self.runtime.get_shared_queue::<CatcollarQueue>(qd)?.clone())
}
Expand Down
29 changes: 2 additions & 27 deletions src/rust/catloop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use crate::{
Yielder,
YielderHandle,
},
types::demi_qresult_t,
Operation,
OperationResult,
QDesc,
Expand Down Expand Up @@ -124,10 +123,11 @@ impl SharedCatloopLibOS {
};

// Create fake socket.
let runtime: SharedDemiRuntime = self.runtime.clone();
let catmem: SharedCatmemLibOS = self.catmem.clone();
let qd: QDesc = self
.runtime
.alloc_queue::<SharedCatloopQueue>(SharedCatloopQueue::new(qtype, catmem)?);
.alloc_queue::<SharedCatloopQueue>(SharedCatloopQueue::new(qtype, runtime, catmem)?);
Ok(qd)
}

Expand Down Expand Up @@ -471,31 +471,6 @@ impl SharedCatloopLibOS {
}
}

/// Allocates a scatter-gather array.
pub fn sgaalloc(&self, size: usize) -> Result<demi_sgarray_t, Fail> {
self.runtime.alloc_sgarray(size)
}

/// Releases a scatter-gather array.
pub fn sgafree(&self, sga: demi_sgarray_t) -> Result<(), Fail> {
self.runtime.free_sgarray(sga)
}

/// Inserts a queue token into the scheduler.
pub fn schedule(&mut self, qt: QToken) -> Result<TaskHandle, Fail> {
self.runtime.from_task_id(qt.into())
}

/// Constructs an operation result from a scheduler handler and queue token pair.
pub fn pack_result(&mut self, handle: TaskHandle, qt: QToken) -> Result<demi_qresult_t, Fail> {
self.runtime.remove_coroutine_and_get_result(&handle, qt.into())
}

/// Polls scheduling queues.
pub fn poll(&mut self) {
self.runtime.poll()
}

fn get_queue(&self, qd: &QDesc) -> Result<SharedCatloopQueue, Fail> {
Ok(self.runtime.get_qtable().get::<SharedCatloopQueue>(qd)?.clone())
}
Expand Down
9 changes: 5 additions & 4 deletions src/rust/catloop/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
OperationResult,
QDesc,
QToken,
SharedDemiRuntime,
SharedObject,
},
};
Expand Down Expand Up @@ -60,10 +61,10 @@ pub struct SharedCatloopQueue(SharedObject<CatloopQueue>);

impl CatloopQueue {
/// Allocates a new Catloop queue.
pub fn new(qtype: QType, catmem: SharedCatmemLibOS) -> Result<Self, Fail> {
pub fn new(qtype: QType, runtime: SharedDemiRuntime, catmem: SharedCatmemLibOS) -> Result<Self, Fail> {
Ok(Self {
qtype,
socket: Socket::new(catmem)?,
socket: Socket::new(runtime, catmem)?,
})
}

Expand All @@ -75,8 +76,8 @@ impl CatloopQueue {

impl SharedCatloopQueue {
/// Allocates a new shared Catloop queue.
pub fn new(qtype: QType, catmem: SharedCatmemLibOS) -> Result<Self, Fail> {
Ok(Self(SharedObject::new(CatloopQueue::new(qtype, catmem)?)))
pub fn new(qtype: QType, runtime: SharedDemiRuntime, catmem: SharedCatmemLibOS) -> Result<Self, Fail> {
Ok(Self(SharedObject::new(CatloopQueue::new(qtype, runtime, catmem)?)))
}

/// Returns the local address to which the target queue is bound.
Expand Down
Loading

0 comments on commit b5c027d

Please sign in to comment.