mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
kernel: server: allow taking multiple messages from queue
Previously, we would only look at the top item on the server queue. If it was not a known message, we would return an error. This patch changes this behavior to look through the entire queue for something we can take, and then clean it up as we go along. This allow for having outstanding requests in the queue an forms the backbone of the sleep server. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
ccc7264b79
commit
9ab5b4880f
1 changed files with 268 additions and 209 deletions
|
|
@ -387,17 +387,26 @@ impl Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*current_val = QueuedMessage::Empty;
|
*current_val = QueuedMessage::Empty;
|
||||||
|
if idx == self.queue_tail {
|
||||||
self.queue_tail += 1;
|
self.queue_tail += 1;
|
||||||
if self.queue_tail >= self.queue.len() {
|
if self.queue_tail >= self.queue.len() {
|
||||||
self.queue_tail = 0;
|
self.queue_tail = 0;
|
||||||
}
|
}
|
||||||
|
// Advance the pointer in case we have a long string of Empty messages.
|
||||||
|
while self.queue_tail != self.queue_head && self.queue[self.queue_tail] == QueuedMessage::Empty {
|
||||||
|
self.queue_tail += 1;
|
||||||
|
if self.queue_tail >= self.queue.len() {
|
||||||
|
self.queue_tail = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Destructure the PID and context ID from the `pid_tid` field
|
// Destructure the PID and context ID from the `pid_tid` field
|
||||||
klog!(
|
// klog!(
|
||||||
"taking waiting message and returning to pid: {} tid: {}",
|
// "taking waiting message and returning to pid: {} tid: {}",
|
||||||
pid,
|
// pid,
|
||||||
tid
|
// tid
|
||||||
);
|
// );
|
||||||
|
|
||||||
if !is_memory {
|
if !is_memory {
|
||||||
return Ok(WaitingMessage::ScalarMessage(
|
return Ok(WaitingMessage::ScalarMessage(
|
||||||
|
|
@ -442,17 +451,47 @@ impl Server {
|
||||||
/// * **None**: There are no waiting messages
|
/// * **None**: There are no waiting messages
|
||||||
/// ***Some(MessageEnvelope): This message is queued.
|
/// ***Some(MessageEnvelope): This message is queued.
|
||||||
pub fn take_next_message(&mut self, sidx: usize) -> Option<xous_kernel::MessageEnvelope> {
|
pub fn take_next_message(&mut self, sidx: usize) -> Option<xous_kernel::MessageEnvelope> {
|
||||||
// println!(
|
// klog!(
|
||||||
// "queue_head: ((({}))) queue_tail: ((({}))): {:?} CID: ((({})))",
|
// "queue_head: ((({}))) queue_tail: ((({}))): {:?} CID: ((({})))",
|
||||||
// self.queue_head, self.queue_tail, self.queue[self.queue_tail], sidx
|
// self.queue_head,
|
||||||
|
// self.queue_tail,
|
||||||
|
// self.queue[self.queue_tail],
|
||||||
|
// sidx
|
||||||
// );
|
// );
|
||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
let mut sender = SenderID::new(sidx, self.queue_tail, None);
|
let mut queue_idx = self.queue_tail;
|
||||||
let (result, response) = match self.queue[self.queue_tail] {
|
while queue_idx != self.queue_head {
|
||||||
QueuedMessage::Empty => return None,
|
let mut sender = SenderID::new(sidx, queue_idx, None);
|
||||||
QueuedMessage::WaitingReturnMemory(_, _, _, _, _) => return None,
|
// klog!("Message @ server.queue[{}]: {:?}", queue_idx, self.queue[queue_idx]);
|
||||||
QueuedMessage::WaitingForget(_, _, _, _, _) => return None,
|
let (result, response) = match self.queue[queue_idx] {
|
||||||
QueuedMessage::WaitingReturnScalar(_, _, _) => return None,
|
QueuedMessage::Empty => {
|
||||||
|
queue_idx += 1;
|
||||||
|
if queue_idx >= self.queue.len() {
|
||||||
|
queue_idx = 0;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QueuedMessage::WaitingReturnMemory(_, _, _, _, _) => {
|
||||||
|
queue_idx += 1;
|
||||||
|
if queue_idx >= self.queue.len() {
|
||||||
|
queue_idx = 0;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QueuedMessage::WaitingForget(_, _, _, _, _) => {
|
||||||
|
queue_idx += 1;
|
||||||
|
if queue_idx >= self.queue.len() {
|
||||||
|
queue_idx = 0;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QueuedMessage::WaitingReturnScalar(_, _, _) => {
|
||||||
|
queue_idx += 1;
|
||||||
|
if queue_idx >= self.queue.len() {
|
||||||
|
queue_idx = 0;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
QueuedMessage::MemoryMessageROLend(
|
QueuedMessage::MemoryMessageROLend(
|
||||||
pid,
|
pid,
|
||||||
tid,
|
tid,
|
||||||
|
|
@ -564,13 +603,15 @@ impl Server {
|
||||||
(
|
(
|
||||||
xous_kernel::MessageEnvelope {
|
xous_kernel::MessageEnvelope {
|
||||||
sender: sender.into(),
|
sender: sender.into(),
|
||||||
body: xous_kernel::Message::BlockingScalar(xous_kernel::ScalarMessage {
|
body: xous_kernel::Message::BlockingScalar(
|
||||||
|
xous_kernel::ScalarMessage {
|
||||||
id,
|
id,
|
||||||
arg1,
|
arg1,
|
||||||
arg2,
|
arg2,
|
||||||
arg3,
|
arg3,
|
||||||
arg4,
|
arg4,
|
||||||
}),
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
QueuedMessage::WaitingReturnScalar(pid, tid, client_addr),
|
QueuedMessage::WaitingReturnScalar(pid, tid, client_addr),
|
||||||
)
|
)
|
||||||
|
|
@ -595,11 +636,13 @@ impl Server {
|
||||||
valid: MemorySize::new(valid),
|
valid: MemorySize::new(valid),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
self.queue[self.queue_tail] = QueuedMessage::Empty;
|
self.queue[queue_idx] = QueuedMessage::Empty;
|
||||||
|
if queue_idx == self.queue_tail {
|
||||||
self.queue_tail += 1;
|
self.queue_tail += 1;
|
||||||
if self.queue_tail >= self.queue.len() {
|
if self.queue_tail >= self.queue.len() {
|
||||||
self.queue_tail = 0;
|
self.queue_tail = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Some(msg);
|
return Some(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -616,11 +659,13 @@ impl Server {
|
||||||
arg4,
|
arg4,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
self.queue[self.queue_tail] = QueuedMessage::Empty;
|
self.queue[queue_idx] = QueuedMessage::Empty;
|
||||||
|
if queue_idx == self.queue_tail {
|
||||||
self.queue_tail += 1;
|
self.queue_tail += 1;
|
||||||
if self.queue_tail >= self.queue.len() {
|
if self.queue_tail >= self.queue.len() {
|
||||||
self.queue_tail = 0;
|
self.queue_tail = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Some(msg);
|
return Some(msg);
|
||||||
}
|
}
|
||||||
QueuedMessage::BlockingScalarTerminated(
|
QueuedMessage::BlockingScalarTerminated(
|
||||||
|
|
@ -644,17 +689,21 @@ impl Server {
|
||||||
arg4,
|
arg4,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
self.queue[self.queue_tail] = QueuedMessage::Empty;
|
self.queue[queue_idx] = QueuedMessage::Empty;
|
||||||
|
if queue_idx == self.queue_tail {
|
||||||
self.queue_tail += 1;
|
self.queue_tail += 1;
|
||||||
if self.queue_tail >= self.queue.len() {
|
if self.queue_tail >= self.queue.len() {
|
||||||
self.queue_tail = 0;
|
self.queue_tail = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Some(msg);
|
return Some(msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.queue[self.queue_tail] = response;
|
self.queue[queue_idx] = response;
|
||||||
Some(result)
|
return Some(result);
|
||||||
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add the given message to this server's queue.
|
/// Add the given message to this server's queue.
|
||||||
|
|
@ -669,7 +718,12 @@ impl Server {
|
||||||
message: xous_kernel::Message,
|
message: xous_kernel::Message,
|
||||||
original_address: Option<MemoryAddress>,
|
original_address: Option<MemoryAddress>,
|
||||||
) -> core::result::Result<usize, xous_kernel::Error> {
|
) -> core::result::Result<usize, xous_kernel::Error> {
|
||||||
// println!("Queueing message: {:?} for pid: {} tid: {}", message, pid.get(), context);
|
// klog!(
|
||||||
|
// "Queueing message: {:?} for pid: {} tid: {}",
|
||||||
|
// message,
|
||||||
|
// pid.get(),
|
||||||
|
// context
|
||||||
|
// );
|
||||||
if self.queue[self.queue_head] != QueuedMessage::Empty {
|
if self.queue[self.queue_head] != QueuedMessage::Empty {
|
||||||
return Err(xous_kernel::Error::ServerQueueFull);
|
return Err(xous_kernel::Error::ServerQueueFull);
|
||||||
}
|
}
|
||||||
|
|
@ -732,6 +786,11 @@ impl Server {
|
||||||
if self.queue_head >= self.queue.len() {
|
if self.queue_head >= self.queue.len() {
|
||||||
self.queue_head = 0;
|
self.queue_head = 0;
|
||||||
}
|
}
|
||||||
|
// klog!(
|
||||||
|
// "queue head: {} queue_tail: {}",
|
||||||
|
// self.queue_head,
|
||||||
|
// self.queue_tail
|
||||||
|
// );
|
||||||
Ok(idx)
|
Ok(idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue