fastipc初版

This commit is contained in:
zhangzheng
2024-12-27 08:23:26 +08:00
parent 90407a8777
commit a1f149e2f3
19 changed files with 536 additions and 141 deletions

View File

@@ -16,4 +16,9 @@ msg_tag_t task_unmap(obj_handler_t task_han, vpage_t vpage);
msg_tag_t task_alloc_ram_base(obj_handler_t task_han, umword_t size, addr_t *alloc_addr);
msg_tag_t task_copy_data(obj_handler_t task_obj, void *st_addr, umword_t size);
msg_tag_t task_copy_data_to(obj_handler_t task_obj, obj_handler_t dst_task_obj, void *st_addr, void *dst_addr, umword_t size);
msg_tag_t task_set_com_point(obj_handler_t task_obj, void *com_point_func, addr_t stack);
msg_tag_t task_set_com_point(obj_handler_t task_obj, void *com_point_func,
addr_t stack, umword_t stack_size,
void *bitmap, int bitmap_len,
void *msg_buf);
msg_tag_t task_com_unlock(obj_handler_t task_obj);
msg_tag_t task_com_lock(obj_handler_t task_obj);

View File

@@ -7,9 +7,9 @@
#define MSG_BUF_RECV_R_FLAGS 0x02U //!< 接收上次发送数据的接收者
#define MSG_BUF_REPLY_FLAGS 0x04U //!<
#define IPC_MSG_SIZE (CONFIG_THREAD_IPC_MSG_LEN * sizeof(void*))
#define MAP_BUF_SIZE (CONFIG_THREAD_MAP_BUF_LEN * sizeof(void*))
#define IPC_USER_SIZE (CONFIG_THREAD_USER_BUF_LEN * sizeof(void*))
#define IPC_MSG_SIZE (CONFIG_THREAD_IPC_MSG_LEN * sizeof(void *))
#define MAP_BUF_SIZE (CONFIG_THREAD_MAP_BUF_LEN * sizeof(void *))
#define IPC_USER_SIZE (CONFIG_THREAD_USER_BUF_LEN * sizeof(void *))
#if IS_ENABLED(CONFIG_VCPU)
#define IPC_VPUC_MSG_OFFSET (3 * 1024) //!< vcpu 传递消息的偏移量
@@ -71,8 +71,8 @@ msg_tag_t thread_ipc_wait(ipc_timeout_t timeout, umword_t *obj, obj_handler_t ip
msg_tag_t thread_ipc_reply(msg_tag_t in_tag, ipc_timeout_t timeout);
msg_tag_t thread_ipc_send(msg_tag_t in_tag, obj_handler_t target_th_obj, ipc_timeout_t timeout);
msg_tag_t thread_ipc_call(msg_tag_t in_tag, obj_handler_t target_th_obj, ipc_timeout_t timeout);
msg_tag_t thread_ipc_fast_call(msg_tag_t in_tag, obj_handler_t target_obj);
msg_tag_t thread_ipc_fast_replay(obj_handler_t target_obj);
msg_tag_t thread_ipc_fast_call(msg_tag_t in_tag, obj_handler_t target_obj, umword_t arg0, umword_t arg1, umword_t arg2);
msg_tag_t thread_ipc_fast_replay(msg_tag_t in_tag, obj_handler_t target_obj, int unlock_bitmap);
static inline ipc_msg_t *thread_get_cur_ipc_msg(void)
{

View File

@@ -14,7 +14,9 @@ enum task_op_code
TASK_COPY_DATA,
TASK_SET_OBJ_NAME,
TASK_COPY_DATA_TO, //!< 从当前task拷贝数据到目的task
TASK_SET_COM_POINT
TASK_SET_COM_POINT,
TASK_COM_UNLOCK,
TASK_COM_LOCK,
};
msg_tag_t task_set_obj_name(obj_handler_t dst_task, obj_handler_t obj, const char *name)
@@ -196,13 +198,50 @@ msg_tag_t task_copy_data_to(obj_handler_t task_obj, obj_handler_t dst_task_obj,
return msg_tag_init(r0);
}
msg_tag_t task_set_com_point(obj_handler_t task_obj, void *com_point_func, addr_t stack)
msg_tag_t task_set_com_point(obj_handler_t task_obj, void *com_point_func, addr_t stack, umword_t stack_size, void *bitmap, int bitmap_len, void *msg_buf)
{
register volatile umword_t r0 asm(ARCH_REG_0);
mk_syscall(syscall_prot_create(TASK_SET_COM_POINT, TASK_PROT, task_obj).raw,
com_point_func,
stack,
stack_size,
bitmap,
bitmap_len,
msg_buf);
asm __volatile__(""
:
:
: ARCH_REG_0, ARCH_REG_1);
return msg_tag_init(r0);
}
msg_tag_t task_com_unlock(obj_handler_t task_obj)
{
register volatile umword_t r0 asm(ARCH_REG_0);
mk_syscall(syscall_prot_create(TASK_COM_UNLOCK, TASK_PROT, task_obj).raw,
0,
0,
0,
0,
0,
0);
asm __volatile__(""
:
:
: ARCH_REG_0, ARCH_REG_1);
return msg_tag_init(r0);
}
msg_tag_t task_com_lock(obj_handler_t task_obj)
{
register volatile umword_t r0 asm(ARCH_REG_0);
mk_syscall(syscall_prot_create(TASK_COM_LOCK, TASK_PROT, task_obj).raw,
0,
0,
0,
0,
0,

View File

@@ -92,15 +92,15 @@ msg_tag_t thread_ipc_call(msg_tag_t in_tag, obj_handler_t target_th_obj, ipc_tim
: ARCH_REG_0);
return msg_tag_init(r0);
}
msg_tag_t thread_ipc_fast_call(msg_tag_t in_tag, obj_handler_t target_obj)
msg_tag_t thread_ipc_fast_call(msg_tag_t in_tag, obj_handler_t target_obj, umword_t arg0, umword_t arg1, umword_t arg2)
{
register volatile umword_t r0 asm(ARCH_REG_0);
mk_syscall(syscall_prot_create4(DO_IPC, THREAD_PROT, target_obj, TRUE).raw,
in_tag.raw,
IPC_FAST_CALL,
0,
0,
0,
arg0,
arg1,
arg2,
0);
asm __volatile__(""
:
@@ -108,13 +108,13 @@ msg_tag_t thread_ipc_fast_call(msg_tag_t in_tag, obj_handler_t target_obj)
: ARCH_REG_0);
return msg_tag_init(r0);
}
msg_tag_t thread_ipc_fast_replay(obj_handler_t target_obj)
msg_tag_t thread_ipc_fast_replay(msg_tag_t in_tag, obj_handler_t target_obj, int unlock_bitmap)
{
register volatile umword_t r0 asm(ARCH_REG_0);
mk_syscall(syscall_prot_create4(DO_IPC, THREAD_PROT, target_obj, TRUE).raw,
0,
in_tag.raw,
IPC_FAST_REPLAY,
0,
unlock_bitmap,
0,
0,
0);
@@ -147,7 +147,7 @@ msg_tag_t thread_msg_buf_set(obj_handler_t obj, void *msg)
register volatile umword_t r1 asm(ARCH_REG_1);
register volatile umword_t r2 asm(ARCH_REG_2);
mk_syscall(syscall_prot_create(MSG_BUG_SET, THREAD_PROT, obj).raw,
mk_syscall(syscall_prot_create4(MSG_BUG_SET, THREAD_PROT, obj, TRUE).raw,
0,
msg,
0,

View File

@@ -29,26 +29,81 @@
#include "parse_cfg.h"
#include <assert.h>
#include <stdio.h>
static ATTR_ALIGN(8) uint8_t cons_stack[2048];
#include <string.h>
#define DEFAULT_INIT_CFG "init.cfg"
static void init_com_point_test_func(int r0,int r1,int r2,int r3)
#define STACK_SIZE 2048
#define STASCK_NUM 4
static ATTR_ALIGN(8) uint8_t com_stack[512];
static ATTR_ALIGN(8) uint8_t cons_stack[STASCK_NUM][STACK_SIZE];
static uint8_t cons_msg_buf[STASCK_NUM][MSG_BUG_LEN];
static umword_t cons_stack_bitmap;
static uint8_t cons_msg_buf_main[MSG_BUG_LEN];
static inline umword_t arch_get_sp(void)
{
printf("comm r0:%d r1:%d r2:%d r3:%d\n", r0, r1, r2, r3);
printf("comm\n");
printf("comm\n");
printf("comm\n");
printf("comm\n");
thread_ipc_fast_replay(-1);
umword_t ret;
__asm__ __volatile__(
"mov %0, sp\n"
: "=r"(ret)
:
:);
return ret;
}
#define SET_SP(sp) \
do \
{ \
__asm__ __volatile__("mov sp, %0" ::"r"(sp)); \
__asm__ __volatile__("" \
: \
: \
: "sp"); \
} while (0)
int setsp(int i, void *stack, msg_tag_t tag, int arg0, int arg1);
void last_process(int j, msg_tag_t tag, int arg0, int arg1)
{
thread_msg_buf_set(-1, (void *)(cons_msg_buf[j]));
task_com_unlock(TASK_THIS);
// printf("j:%d sp:0x%x\n", j, arch_get_sp());
// printf("j:%d comm tag:%x r0:%d r1:%d\n", j, tag.raw, arg0, arg1);
// printf("%s\n", cons_msg_buf[j]);
// strcpy((void *)cons_msg_buf[j], "okay");
// u_sleep_ms(100);
// *((uint8_t *)0) = 0;
task_com_lock(TASK_THIS);
memcpy(cons_msg_buf_main, cons_msg_buf[j], MSG_BUG_LEN);
tag = msg_tag_init4(0, 2, 0, 0);
thread_ipc_fast_replay(tag, -1, j);
}
static void init_com_point_test_func(msg_tag_t tag, int arg0, int arg1, int arg2)
{
int i;
for (i = 0; i < STASCK_NUM; i++)
{
if ((cons_stack_bitmap & (1 << i)) == 0)
{
cons_stack_bitmap |= (1 << i);
break;
}
}
memcpy(cons_msg_buf[i], cons_msg_buf_main, MSG_BUG_LEN);
setsp(i, &cons_stack[i][STACK_SIZE - 8], tag, arg0, arg1);
}
int main(int argc, char *args[])
{
int ret;
uenv_t *env;
#if 1
#if 0
thread_run(-1, 4);
#endif
task_set_com_point(TASK_THIS,&init_com_point_test_func, (addr_t)(cons_stack + sizeof(cons_stack) - 8));
task_set_com_point(TASK_THIS, &init_com_point_test_func, (addr_t)com_stack,
sizeof(com_stack), &cons_stack_bitmap, STASCK_NUM, cons_msg_buf_main);
task_set_obj_name(TASK_THIS, TASK_THIS, "tk_init");
task_set_obj_name(TASK_THIS, THREAD_MAIN, "th_init");

View File

@@ -0,0 +1,12 @@
.syntax unified
@ .cpu cortex-m3
.thumb
.global setsp
.global last_process
/**
* @brief syscall结束时到这儿
*/
.type setsp, %function
setsp:
mov sp, r1
bl last_process

View File

@@ -9,14 +9,47 @@
#include <u_task.h>
#include <u_thread.h>
#include <u_env.h>
#include <pthread.h>
void *test_func(void *arg)
{
msg_tag_t tag;
ipc_msg_t *msg;
tag = thread_msg_buf_get(-1, (void *)(&msg), NULL);
strcpy((void *)msg->msg_buf, "hello");
for (int i = 0; i < 10000; i++)
{
thread_ipc_fast_call(msg_tag_init4(0, 2, 0, 0), u_get_global_env()->ns_hd, 1111, 2222, 3333);
// printf("%s\n", (void *)msg->msg_buf);
}
// while (1)
// {
// u_sleep_ms(100000);
// }
return NULL;
}
pthread_t pth1;
pthread_t pth2;
pthread_t pth3;
pthread_t pth4;
void fast_ipc_test(void)
{
pthread_create(&pth1, NULL, test_func, NULL);
pthread_create(&pth2, NULL, test_func, NULL);
pthread_create(&pth3, NULL, test_func, NULL);
pthread_create(&pth4, NULL, test_func, NULL);
}
int main(int argc, char *args[])
{
task_set_obj_name(TASK_THIS, TASK_THIS, "tk_sh");
task_set_obj_name(TASK_THIS, THREAD_MAIN, "th_sh");
#if 1
#if 0
thread_run(-1, 3);
#endif
// thread_ipc_fast_call(msg_tag_init(0), u_get_global_env()->ns_hd);
fast_ipc_test();
for (int i = 0; i < argc; i++)
{
printf("args[%d]:%s\n", i, args[i]);