Support blocking server.
This commit is contained in:
@@ -24,7 +24,7 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \
|
||||
-I$(KERNEL_ROOT)/services/app
|
||||
|
||||
ifeq ($(BOARD), imx6q-sabrelite)
|
||||
all: init test_fs simple_client simple_server shell fs_server test_irq_hdlr test_irq_send readme.txt | bin
|
||||
all: init test_fs simple_client simple_server shell fs_server test_irq_hdlr test_irq_block test_irq_send readme.txt | bin
|
||||
else
|
||||
all: init test_fs simple_client simple_server shell fs_server test_irq_hdlr readme.txt | bin
|
||||
endif
|
||||
@@ -42,6 +42,10 @@ test_irq_send: test_irq_sender.o usyscall.o libserial.o
|
||||
@${objdump} -S $@ > $@.asm
|
||||
endif
|
||||
|
||||
test_irq_block: test_irq_block.o libserial.o libipc.o session.o usyscall.o libmem.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
test_irq_hdlr: test_irq_handler.o libserial.o libipc.o session.o usyscall.o libmem.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
#include "libipc.h"
|
||||
#include "libserial.h"
|
||||
#include "usyscall.h"
|
||||
|
||||
IPC_SERVICES(IpcSwIntrHandler, Ipc_intr_3, Ipc_wait_intr_3);
|
||||
|
||||
enum {
|
||||
SW_INTERRUPT_3 = 3,
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
#include "test_irq.h"
|
||||
|
||||
IPC_INTERFACE(Ipc_wait_intr_3, 1, ignore, 0);
|
||||
int wait_intr(struct Session* session, void* ignore_param)
|
||||
{
|
||||
return IPC_CALL(Ipc_wait_intr_3)(session, NULL);
|
||||
}
|
||||
|
||||
static char prog_name[] = "TEST_IRQ_BLOCK";
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
struct Session session;
|
||||
if (connect_session(&session, "TestIRQ", 4096) < 0) {
|
||||
printf("connect session failed\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
printf("%s start waiting for IRQ.\n", prog_name);
|
||||
wait_intr(&session, NULL);
|
||||
printf("%s return from waiting for IRQ.\n", prog_name);
|
||||
|
||||
exit();
|
||||
}
|
||||
@@ -10,35 +10,45 @@
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
#include "libipc.h"
|
||||
#include "libserial.h"
|
||||
#include "usyscall.h"
|
||||
#include "test_irq.h"
|
||||
|
||||
IPC_SERVICES(IpcSwIntrHandler, Ipc_intr_3);
|
||||
|
||||
enum {
|
||||
SW_INTERRUPT_3 = 3,
|
||||
};
|
||||
|
||||
void sgi_test_handler(void)
|
||||
static bool has_one_interrupt = false;
|
||||
int IPC_DO_SERVE_FUNC(Ipc_intr_3)(void* ignore)
|
||||
{
|
||||
printf("TEST_SW_HDLR: In %s()\n", __func__);
|
||||
has_one_interrupt = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IPC_DO_SERVE_FUNC(Ipc_intr_3)(void* useless)
|
||||
int IPC_DO_SERVE_FUNC(Ipc_wait_intr_3)(void* ignore)
|
||||
{
|
||||
sgi_test_handler();
|
||||
// delay the this handle
|
||||
if (!has_one_interrupt) {
|
||||
delay_session();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// serve can be done by now
|
||||
has_one_interrupt = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
IPC_SERVER_INTERFACE(Ipc_intr_3, 1);
|
||||
IPC_SERVER_REGISTER_INTERFACES(IpcSwIntrHandler, 1, Ipc_intr_3);
|
||||
IPC_SERVER_INTERFACE(Ipc_wait_intr_3, 1);
|
||||
IPC_SERVER_REGISTER_INTERFACES(IpcSwIntrHandler, 2, Ipc_intr_3, Ipc_wait_intr_3);
|
||||
int main()
|
||||
{
|
||||
if (register_irq(SW_INTERRUPT_3, Ipc_intr_3) == -1) {
|
||||
if (register_irq(SW_INTERRUPT_3, Ipc_intr_3) < 0) {
|
||||
printf("TEST_SW_HDLR: bind failed");
|
||||
exit();
|
||||
}
|
||||
|
||||
static char prog_name[] = "TestIRQ";
|
||||
if (register_server("TestIRQ") < 0) {
|
||||
printf("register server name: %s failed.\n", prog_name);
|
||||
exit();
|
||||
}
|
||||
|
||||
ipc_server_loop(&IpcSwIntrHandler);
|
||||
|
||||
exit();
|
||||
|
||||
@@ -88,7 +88,7 @@ struct Inode {
|
||||
};
|
||||
|
||||
// directory entry
|
||||
#define DIR_NAME_SIZE 14
|
||||
#define DIR_NAME_SIZE 30
|
||||
struct DirectEntry {
|
||||
uint16_t inum;
|
||||
char name[DIR_NAME_SIZE];
|
||||
|
||||
@@ -156,6 +156,11 @@ void delay_session(void)
|
||||
session_delayed = true;
|
||||
}
|
||||
|
||||
bool is_cur_session_delayed(void)
|
||||
{
|
||||
return session_delayed;
|
||||
}
|
||||
|
||||
void ipc_server_loop(struct IpcNode* ipc_node)
|
||||
{
|
||||
struct Session session_list[NR_MAX_SESSION];
|
||||
@@ -168,43 +173,46 @@ void ipc_server_loop(struct IpcNode* ipc_node)
|
||||
*/
|
||||
poll_session(session_list, NR_MAX_SESSION);
|
||||
/* handle each session */
|
||||
for (int i = 0; i < NR_MAX_SESSION; i++) {
|
||||
if (session_list[i].buf == NULL) {
|
||||
yield(SYS_TASK_YIELD_NO_REASON);
|
||||
break;
|
||||
}
|
||||
cur_sess_id = session_list[i].id;
|
||||
struct IpcMsg* msg = IPCSESSION_MSG(&session_list[i]);
|
||||
/* handle every message in current session
|
||||
a session could be delay in case one of its message(current message) needs to wait for an interrupt message's arrival
|
||||
interfaces[opcode] should explicitly call delay_session() and return to delay this session
|
||||
*/
|
||||
while (msg->header.magic == IPC_MSG_MAGIC && msg->header.valid == 1 && msg->header.done == 0) {
|
||||
// printf("session %d [%d, %d]\n", session_list[i].id, session_list[i].head, session_list[i].tail);
|
||||
if (session_used_size(&session_list[i]) == 0 && session_forward_tail(&session_list[i], msg->header.len) < 0) {
|
||||
break;
|
||||
for (int repeat = 0; repeat <= 1; repeat++) {
|
||||
for (int i = 0; i < NR_MAX_SESSION; i++) {
|
||||
if (session_list[i].buf == NULL) {
|
||||
yield(SYS_TASK_YIELD_NO_REASON);
|
||||
continue;
|
||||
}
|
||||
|
||||
// this is a message needs to handle
|
||||
if (ipc_node->interfaces[msg->header.opcode]) {
|
||||
ipc_node->interfaces[msg->header.opcode](msg);
|
||||
// check if this session is delayed by op handler, all messages after the delayed message in current session is blocked.
|
||||
if (session_delayed) {
|
||||
session_delayed = false;
|
||||
cur_sess_id = session_list[i].id;
|
||||
struct IpcMsg* msg = IPCSESSION_MSG(&session_list[i]);
|
||||
/* handle every message in current session
|
||||
a session could be delay in case one of its message(current message) needs to wait for an interrupt message's arrival
|
||||
interfaces[opcode] should explicitly call delay_session() and return to delay this session
|
||||
*/
|
||||
while (msg->header.magic == IPC_MSG_MAGIC && msg->header.valid == 1 && msg->header.done == 0) {
|
||||
// printf("session %d [%d, %d]\n", session_list[i].id, session_list[i].head, session_list[i].tail);
|
||||
if (session_used_size(&session_list[i]) == 0 && session_forward_tail(&session_list[i], msg->header.len) < 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
printf("Unsupport opcode(%d) for server: %s\n", msg->header.opcode, ipc_node->name);
|
||||
|
||||
// this is a message needs to handle
|
||||
if (ipc_node->interfaces[msg->header.opcode]) {
|
||||
ipc_node->interfaces[msg->header.opcode](msg);
|
||||
// check if this session is delayed by op handler, all messages after the delayed message in current session is blocked.
|
||||
if (is_cur_session_delayed()) {
|
||||
msg->header.delayed = 1;
|
||||
session_delayed = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
printf("Unsupport opcode(%d) for server: %s\n", msg->header.opcode, ipc_node->name);
|
||||
}
|
||||
// current msg is a message that needs to ignore
|
||||
// finish this message in server's perspective
|
||||
if (session_forward_head(&session_list[i], msg->header.len) < 0) {
|
||||
break;
|
||||
}
|
||||
msg = IPCSESSION_MSG(&session_list[i]);
|
||||
}
|
||||
// current msg is a message that needs to ignore
|
||||
// finish this message in server's perspective
|
||||
if (session_forward_head(&session_list[i], msg->header.len) < 0) {
|
||||
break;
|
||||
}
|
||||
msg = IPCSESSION_MSG(&session_list[i]);
|
||||
// stop handle this session
|
||||
cur_sess_id = -1;
|
||||
}
|
||||
// stop handle this session
|
||||
cur_sess_id = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ typedef struct {
|
||||
uint64_t valid : 1; // for server to peek new msg
|
||||
uint64_t done : 1; // for client to check request done
|
||||
uint64_t init : 1; // for client to check request done
|
||||
uint64_t reserved : 1;
|
||||
uint64_t delayed : 1;
|
||||
uint64_t nr_args : 4;
|
||||
uint64_t opcode : 8;
|
||||
uint64_t len : 16;
|
||||
@@ -225,6 +225,7 @@ void ipc_server_loop(struct IpcNode* ipc_node);
|
||||
return res; \
|
||||
}
|
||||
|
||||
bool is_cur_session_delayed(void);
|
||||
#define IPC_SERVER_INTERFACE(ipc_name, argc) \
|
||||
static int IPC_SERVE(ipc_name)(struct IpcMsg * msg) \
|
||||
{ \
|
||||
@@ -233,8 +234,10 @@ void ipc_server_loop(struct IpcNode* ipc_node);
|
||||
argv[i] = ipc_msg_get_nth_arg_buf(msg, i); \
|
||||
} \
|
||||
int32_t _ret = IPC_DO_SERVE##argc(ipc_name); \
|
||||
ipc_msg_set_return(msg, &_ret); \
|
||||
msg->header.done = 1; \
|
||||
if (!is_cur_session_delayed()) { \
|
||||
ipc_msg_set_return(msg, &_ret); \
|
||||
msg->header.done = 1; \
|
||||
} \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ struct Inode {
|
||||
};
|
||||
|
||||
// Directory is a file containing a sequence of DirEntry structures.
|
||||
#define DIR_NAME_SIZE 14
|
||||
#define DIR_NAME_SIZE 30
|
||||
struct DirEntry {
|
||||
ushort inum;
|
||||
char name[DIR_NAME_SIZE];
|
||||
|
||||
Reference in New Issue
Block a user