Skip to content

Commit

Permalink
Lets client process resume a server process
Browse files Browse the repository at this point in the history
  • Loading branch information
HAKarlsson committed Oct 21, 2024
1 parent e97d0c6 commit 3abab54
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
30 changes: 19 additions & 11 deletions kernel/src/cap_ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ static err_t do_send(cap_t cap, const ipc_msg_t *msg, proc_t **next)
if (cap.sock.mode == IPC_YIELD
&& curr_time + recv->regs[REG_SERVTIME] >= timeout)
return ERR_NO_RECEIVER;
channels[cap.sock.chan].server = NULL;
}

if (proc_ipc_acquire(recv, cap.sock.chan)) {
Expand Down Expand Up @@ -111,13 +110,6 @@ static err_t send(cte_t sock, cap_t cap, const ipc_msg_t *msg, proc_t **next)
return do_send(cap, msg, next);
}

static err_t recv(cte_t sock, cap_t cap, cte_t cap_buf, proc_t **next)
{
do_recv(cap, cap_buf, *next);
*next = NULL;
return ERR_TIMEOUT;
}

static err_t replyrecv(cte_t sock, cap_t cap, const ipc_msg_t *msg,
proc_t **next)
{
Expand Down Expand Up @@ -196,15 +188,31 @@ err_t cap_sock_recv(cte_t sock, cte_t cap_buf, proc_t **next)
return ERR_EMPTY;
if (cap.type != CAPTY_SOCKET)
return ERR_INVALID_CAPABILITY;
if (cap.sock.tag != 0)
return ERR_INVALID_SOCKET;
if ((cap.sock.perm & IPC_CCAP) && !cte_is_empty(cap_buf))
return ERR_DST_OCCUPIED;
if ((*next)->state & PSF_SUSPENDED) {
*next = NULL;
return ERR_PREEMPTED;
}
return recv(sock, cap, cap_buf, next);

if (cap.sock.tag == 0) {
// server
do_recv(cap, cap_buf, *next);
*next = NULL;
return ERR_TIMEOUT;
} else if (channels[cap.sock.chan].client == *next) {
proc_t *server = channels[cap.sock.chan].server;
proc_t *client = *next;
if (server && cap.sock.mode == IPC_YIELD
&& proc_acquire(server)) {
proc_ipc_wait(client, cap.sock.chan);
channels[cap.sock.chan].cap_buf = cap_buf;
server->timeout = (*next)->timeout;
*next = server;
}
return ERR_TIMEOUT;
}
return ERR_INVALID_STATE;
}

err_t cap_sock_sendrecv(cte_t sock, const ipc_msg_t *msg, proc_t **next)
Expand Down
7 changes: 3 additions & 4 deletions projects/ping-pong/app0/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ void setup_app1(uint64_t tmp)
s3k_mon_pmp_load(MONITOR, APP1_PID, 1, 1);

// derive a time slice capability
s3k_cap_derive(HART0_TIME, tmp,
s3k_mk_time(S3K_MIN_HART, 0, S3K_SLOT_CNT / 2));
s3k_mon_cap_move(MONITOR, APP0_PID, tmp, APP1_PID, 2);
// s3k_cap_derive(HART0_TIME, tmp,
// s3k_mk_time(S3K_MIN_HART, 0, S3K_SLOT_CNT / 2));
s3k_mon_cap_move(MONITOR, APP0_PID, HART0_TIME, APP1_PID, 2);

// Write start PC of app1 to PC
s3k_mon_reg_write(MONITOR, APP1_PID, S3K_REG_PC, 0x80020000);
Expand Down Expand Up @@ -89,7 +89,6 @@ int main(void)
s3k_msg_t msg;
s3k_reply_t reply;
memcpy(msg.data, "pong", 5);
s3k_reg_write(S3K_REG_SERVTIME, 100);
while (1) {
do {
reply = s3k_sock_sendrecv(11, &msg);
Expand Down
4 changes: 3 additions & 1 deletion projects/ping-pong/app1/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ int main(void)
while (1) {
do {
reply = s3k_sock_sendrecv(3, &msg);
if (reply.err == S3K_ERR_TIMEOUT)
while (reply.err == S3K_ERR_TIMEOUT) {
alt_puts("timeout");
reply = s3k_sock_recv(3, msg.cap_idx);
}
} while (reply.err);
alt_puts((char *)reply.data);
}
Expand Down

0 comments on commit 3abab54

Please sign in to comment.