forked from xuos/xiuos
Fix multithread awaking.
This commit is contained in:
parent
c2e21257d0
commit
99899900a1
|
@ -31,7 +31,6 @@ int IPC_DO_SERVE_FUNC(Ipc_hello_string)(char* buf, int* len)
|
||||||
}
|
}
|
||||||
|
|
||||||
IPC_SERVER_INTERFACE(Ipc_add, 2);
|
IPC_SERVER_INTERFACE(Ipc_add, 2);
|
||||||
//IPC_SERVER_THREAD_INTERFACE(Ipc_add, 2);
|
|
||||||
IPC_SERVER_INTERFACE(Ipc_hello_string, 2);
|
IPC_SERVER_INTERFACE(Ipc_hello_string, 2);
|
||||||
IPC_SERVER_REGISTER_INTERFACES(IpcSimpleServer, 2, Ipc_hello_string, Ipc_add);
|
IPC_SERVER_REGISTER_INTERFACES(IpcSimpleServer, 2, Ipc_hello_string, Ipc_add);
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
SRC_DIR :=
|
|
||||||
|
SRC_DIR := hal
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
SRC_DIR := $(BOARD) rk-3568
|
SRC_DIR := $(BOARD)
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
|
@ -9,14 +9,8 @@ ld = ${toolchain}g++
|
||||||
objdump = ${toolchain}objdump
|
objdump = ${toolchain}objdump
|
||||||
user_ldflags = -N -Ttext 0
|
user_ldflags = -N -Ttext 0
|
||||||
|
|
||||||
cflags = -std=c11 -march=armv7-a -mcpu=cortex-a9 -mtune=cortex-a9 -g \
|
cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic \
|
||||||
-Wno-unused -Wno-format -fno-common -ffreestanding -fno-builtin -static \
|
-static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie
|
||||||
-Wno-unaligned-access -fdce -Wall -Werror -Wno-uninitialized -Wno-strict-aliasing -fdiagnostics-show-option \
|
|
||||||
-mapcs -marm -mfpu=neon -ftree-vectorize -fno-math-errno -funsafe-math-optimizations -fno-signed-zeros -mfloat-abi=softfp \
|
|
||||||
-fno-omit-frame-pointer -fno-stack-protector -fno-pie
|
|
||||||
|
|
||||||
# cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic \
|
|
||||||
# -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie
|
|
||||||
|
|
||||||
c_useropts = -O0
|
c_useropts = -O0
|
||||||
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
|
|
||||||
SRC_DIR := hal
|
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
|
|
@ -182,7 +182,6 @@ void ipc_server_loop(struct IpcNode* ipc_node)
|
||||||
/* handle each session */
|
/* handle each session */
|
||||||
for (int i = 0; i < NR_MAX_SESSION; i++) {
|
for (int i = 0; i < NR_MAX_SESSION; i++) {
|
||||||
if (session_list[i].buf == NULL) {
|
if (session_list[i].buf == NULL) {
|
||||||
yield(SYS_TASK_YIELD_NO_REASON);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cur_sess_id = session_list[i].id;
|
cur_sess_id = session_list[i].id;
|
||||||
|
|
|
@ -27,8 +27,12 @@ Author: AIIT XUOS Lab
|
||||||
Modification:
|
Modification:
|
||||||
1. first version
|
1. first version
|
||||||
*************************************************/
|
*************************************************/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include "task.h"
|
#include "bitmap64.h"
|
||||||
|
#include "buddy.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "share_page.h"
|
||||||
|
|
||||||
struct ThreadStackPointer {
|
struct ThreadStackPointer {
|
||||||
int argc;
|
int argc;
|
||||||
|
@ -37,6 +41,22 @@ struct ThreadStackPointer {
|
||||||
uintptr_t user_stack_vaddr;
|
uintptr_t user_stack_vaddr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct MemSpace {
|
||||||
|
/* task memory resources */
|
||||||
|
struct TopLevelPageDirectory pgdir; // [phy] vm pgtbl base address
|
||||||
|
uintptr_t heap_base; // mem size of proc used(allocated by kernel)
|
||||||
|
uintptr_t mem_size;
|
||||||
|
/* task communication mem resources */
|
||||||
|
struct KBuddy* massive_ipc_allocator;
|
||||||
|
|
||||||
|
/* thread using this memspace */
|
||||||
|
struct bitmap64 thread_stack_idx_bitmap;
|
||||||
|
struct double_list_node thread_list_guard;
|
||||||
|
|
||||||
|
// thread to notify when sub-thread exit
|
||||||
|
struct Thread* thread_to_notify;
|
||||||
|
};
|
||||||
|
|
||||||
struct MemSpace* alloc_memspace();
|
struct MemSpace* alloc_memspace();
|
||||||
void free_memspace(struct MemSpace* pmemspace);
|
void free_memspace(struct MemSpace* pmemspace);
|
||||||
uintptr_t* load_memspace(struct MemSpace* pmemspace, char* img_start);
|
uintptr_t* load_memspace(struct MemSpace* pmemspace, char* img_start);
|
||||||
|
|
|
@ -31,10 +31,10 @@ Modification:
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
|
|
||||||
#include "bitmap64.h"
|
|
||||||
#include "buddy.h"
|
#include "buddy.h"
|
||||||
#include "ksemaphore.h"
|
#include "ksemaphore.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "memspace.h"
|
||||||
#include "object_allocator.h"
|
#include "object_allocator.h"
|
||||||
#include "pagetable.h"
|
#include "pagetable.h"
|
||||||
#include "share_page.h"
|
#include "share_page.h"
|
||||||
|
@ -54,19 +54,6 @@ enum ProcState {
|
||||||
NEVER_RUN,
|
NEVER_RUN,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MemSpace {
|
|
||||||
/* task memory resources */
|
|
||||||
struct TopLevelPageDirectory pgdir; // [phy] vm pgtbl base address
|
|
||||||
uintptr_t heap_base; // mem size of proc used(allocated by kernel)
|
|
||||||
uintptr_t mem_size;
|
|
||||||
/* task communication mem resources */
|
|
||||||
struct KBuddy* massive_ipc_allocator;
|
|
||||||
|
|
||||||
/* thread using this memspace */
|
|
||||||
struct bitmap64 thread_stack_idx_bitmap;
|
|
||||||
struct double_list_node thread_list_guard;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Thread Control Block */
|
/* Thread Control Block */
|
||||||
struct ThreadContext {
|
struct ThreadContext {
|
||||||
struct Thread* task; // process of current thread
|
struct Thread* task; // process of current thread
|
||||||
|
@ -105,8 +92,8 @@ struct Thread {
|
||||||
/* task communication resources */
|
/* task communication resources */
|
||||||
struct double_list_node cli_sess_listhead;
|
struct double_list_node cli_sess_listhead;
|
||||||
struct double_list_node svr_sess_listhead;
|
struct double_list_node svr_sess_listhead;
|
||||||
bool current_ipc_handled;
|
|
||||||
struct TraceTag server_identifier;
|
struct TraceTag server_identifier;
|
||||||
|
bool advance_unblock;
|
||||||
|
|
||||||
/* task schedule attributes */
|
/* task schedule attributes */
|
||||||
struct double_list_node node;
|
struct double_list_node node;
|
||||||
|
|
|
@ -70,7 +70,7 @@ int sys_poll_session(struct Session* userland_session_arr, int arr_capacity)
|
||||||
if (client->state == BLOCKED) {
|
if (client->state == BLOCKED) {
|
||||||
xizi_task_manager.task_unblock(client);
|
xizi_task_manager.task_unblock(client);
|
||||||
} else {
|
} else {
|
||||||
client->current_ipc_handled = true;
|
client->advance_unblock = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
server_session->head = userland_session_arr[i].head;
|
server_session->head = userland_session_arr[i].head;
|
||||||
|
@ -120,8 +120,12 @@ int sys_poll_session(struct Session* userland_session_arr, int arr_capacity)
|
||||||
if (session_idx < arr_capacity) {
|
if (session_idx < arr_capacity) {
|
||||||
userland_session_arr[session_idx].buf = NULL;
|
userland_session_arr[session_idx].buf = NULL;
|
||||||
if (!has_middle_delete && nr_sessions_need_to_handle == 0) {
|
if (!has_middle_delete && nr_sessions_need_to_handle == 0) {
|
||||||
xizi_task_manager.task_yield_noschedule(cur_task, false);
|
if (cur_task->advance_unblock) {
|
||||||
xizi_task_manager.task_block(&xizi_task_manager.task_blocked_list_head, cur_task);
|
cur_task->advance_unblock = false;
|
||||||
|
} else {
|
||||||
|
xizi_task_manager.task_yield_noschedule(cur_task, false);
|
||||||
|
xizi_task_manager.task_block(&xizi_task_manager.task_blocked_list_head, cur_task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,11 @@ int sys_new_thread(struct MemSpace* pmemspace, struct Thread* task, uintptr_t en
|
||||||
// init pcb schedule attributes
|
// init pcb schedule attributes
|
||||||
xizi_task_manager.task_set_default_schedule_attr(task);
|
xizi_task_manager.task_set_default_schedule_attr(task);
|
||||||
|
|
||||||
|
// thread init done by here
|
||||||
|
if (pmemspace->thread_to_notify == NULL) {
|
||||||
|
pmemspace->thread_to_notify = task;
|
||||||
|
}
|
||||||
|
|
||||||
return task->tid;
|
return task->tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,8 @@ int sys_yield(task_yield_reason reason)
|
||||||
|
|
||||||
// handle ipc block
|
// handle ipc block
|
||||||
if ((reason & SYS_TASK_YIELD_BLOCK_IPC) != 0) {
|
if ((reason & SYS_TASK_YIELD_BLOCK_IPC) != 0) {
|
||||||
if (cur_task->current_ipc_handled) {
|
if (cur_task->advance_unblock) {
|
||||||
cur_task->current_ipc_handled = false;
|
cur_task->advance_unblock = false;
|
||||||
} else {
|
} else {
|
||||||
xizi_task_manager.task_block(&xizi_task_manager.task_blocked_list_head, cur_task);
|
xizi_task_manager.task_block(&xizi_task_manager.task_blocked_list_head, cur_task);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ struct MemSpace* alloc_memspace()
|
||||||
pmemspace->heap_base = 0;
|
pmemspace->heap_base = 0;
|
||||||
pmemspace->mem_size = 0;
|
pmemspace->mem_size = 0;
|
||||||
pmemspace->pgdir.pd_addr = 0;
|
pmemspace->pgdir.pd_addr = 0;
|
||||||
|
pmemspace->thread_to_notify = NULL;
|
||||||
return pmemspace;
|
return pmemspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,19 @@ static void _dealloc_task_cb(struct Thread* task)
|
||||||
|
|
||||||
/* free memspace if needed to */
|
/* free memspace if needed to */
|
||||||
if (task->memspace != NULL) {
|
if (task->memspace != NULL) {
|
||||||
|
// awake deamon in this memspace
|
||||||
|
if (task->memspace->thread_to_notify != NULL) {
|
||||||
|
if (task->memspace->thread_to_notify != task) {
|
||||||
|
if (task->memspace->thread_to_notify->state == BLOCKED) {
|
||||||
|
xizi_task_manager.task_unblock(task->memspace->thread_to_notify);
|
||||||
|
} else {
|
||||||
|
task->memspace->thread_to_notify->advance_unblock = true;
|
||||||
|
}
|
||||||
|
} else if (task->memspace->thread_to_notify == task) {
|
||||||
|
task->memspace->thread_to_notify = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
doubleListDel(&task->memspace_list_node);
|
doubleListDel(&task->memspace_list_node);
|
||||||
/* free memspace if thread is the last one using it */
|
/* free memspace if thread is the last one using it */
|
||||||
if (IS_DOUBLE_LIST_EMPTY(&task->memspace->thread_list_guard)) {
|
if (IS_DOUBLE_LIST_EMPTY(&task->memspace->thread_list_guard)) {
|
||||||
|
|
Loading…
Reference in New Issue