From 5f02994f3b156be1b93ee5fbf611c5eeb5bad366 Mon Sep 17 00:00:00 2001 From: chenjiafan Date: Wed, 11 Oct 2023 16:31:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=9A=E6=A0=B8smp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 方案描述: 1, 新增自旋锁的支持 2, 将接口LOS_IntLock替换为SCHEDULER_LOCK 3, 将接口LOS_IntRestore替换为SCHEDULER_UNLOCK 4, 修正创建idle接口 5, 按格式, 打印栈内容, 在sp位置用*标注 6, 释放分配的内存 BREAKING CHANGE: 新增多核启动适配接口,需要适配接口描述: 适配API: VOID ArchCpuOn(UINT32 cpuNum, ArchCoreStartFunc func, struct SmpOps *ops, VOID *arg); INT32 ArchCurrCpuid(VOID); 新增自旋锁接口,对外变更描述: 新增API: STATIC INLINE VOID LOS_SpinInit(Spinlock *lock) STATIC INLINE VOID LOS_SpinLock(Spinlock *lock) STATIC INLINE VOID LOS_SpinUnlock(Spinlock *lock) STATIC INLINE VOID LOS_SpinLockSave(Spinlock *lock, UINT32 *intSave) STATIC INLINE VOID LOS_SpinUnlockRestore(Spinlock *lock, UINT32 intSave) 修正创建idle任务接口,增加核心绑定能力,对外变更描述: 旧API: UINT32 OsIdleTaskCreate(VOID); 变更后: UINT32 OsIdleTaskCreate(UINT32 cpuid); Change-Id: I280fc1383bd98d9d765db28c4d592bad4f589fa7 Signed-off-by: chenjiafan --- Kconfig | 13 + arch/arm/arm9/gcc/los_interrupt.c | 5 +- arch/arm/cortex-m3/keil/los_interrupt.c | 5 +- arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c | 5 +- .../gcc/TZ/non_secure/los_interrupt.c | 5 +- arch/arm/cortex-m33/iar/NTZ/los_interrupt.c | 5 +- .../iar/TZ/non_secure/los_interrupt.c | 5 +- arch/arm/cortex-m4/gcc/los_interrupt.c | 5 +- arch/arm/cortex-m4/iar/los_interrupt.c | 5 +- arch/arm/cortex-m55/gcc/NTZ/los_interrupt.c | 5 +- .../gcc/TZ/non_secure/los_interrupt.c | 5 +- arch/arm/cortex-m55/iar/NTZ/los_interrupt.c | 5 +- .../iar/TZ/non_secure/los_interrupt.c | 5 +- arch/arm/cortex-m7/gcc/los_interrupt.c | 5 +- arch/arm/cortex-m7/iar/los_interrupt.c | 5 +- arch/csky/v2/gcc/los_interrupt.c | 5 +- arch/include/los_core.h | 50 +++ arch/include/los_interrupt.h | 12 + arch/include/los_spinlock.h | 114 +++++ arch/risc-v/nuclei/gcc/los_context.c | 5 +- arch/risc-v/riscv32/gcc/los_interrupt.c | 5 +- arch/xtensa/lx6/gcc/los_interrupt.c | 5 +- components/backtrace/los_backtrace.c | 5 +- components/cpup/los_cpup.c | 49 ++- components/debugtools/los_hwidump.c | 4 +- components/debugtools/los_stackdump.c | 16 +- components/exchook/los_exchook.c | 23 +- components/lmk/los_lmk.c | 51 ++- components/lms/los_lms.c | 2 +- components/power/los_pm.c | 95 +++-- components/security/box/los_box.c | 3 +- components/security/syscall/pthread_syscall.c | 18 +- components/shell/src/base/shmsg.c | 3 + components/signal/los_signal.c | 70 ++-- components/trace/Kconfig | 2 +- components/trace/cnv/trace_cnv.c | 8 +- kal/cmsis/cmsis_liteos2.c | 110 ++--- kal/posix/src/poll.c | 21 +- kal/posix/src/pthread.c | 76 ++-- kal/posix/src/pthread_cond.c | 3 +- kal/posix/src/pthread_mutex.c | 39 +- kal/posix/src/time.c | 21 +- kernel/BUILD.gn | 5 + kernel/include/los_config.h | 16 +- kernel/include/los_cpu.h | 41 ++ kernel/include/los_mp.h | 39 ++ kernel/include/los_sched.h | 32 +- kernel/include/los_task.h | 111 ++++- kernel/src/los_event.c | 49 ++- kernel/src/los_init.c | 10 +- kernel/src/los_mp.c | 52 +++ kernel/src/los_mux.c | 57 +-- kernel/src/los_queue.c | 69 ++-- kernel/src/los_sched.c | 147 ++++--- kernel/src/los_sem.c | 48 ++- kernel/src/los_sortlink.c | 8 +- kernel/src/los_swtmr.c | 57 ++- kernel/src/los_task.c | 391 ++++++++++++------ kernel/src/los_tick.c | 32 +- kernel/src/mm/los_memory.c | 4 +- testsuites/include/osTest.h | 27 +- testsuites/sample/kernel/event/It_los_event.h | 2 +- .../sample/kernel/mux/It_los_mutex_026.c | 15 +- .../sample/kernel/mux/It_los_mutex_027.c | 12 +- .../sample/kernel/mux/It_los_mutex_029.c | 12 +- .../sample/kernel/mux/It_los_mutex_030.c | 12 +- .../sample/kernel/mux/It_los_mutex_031.c | 12 +- .../sample/kernel/mux/It_los_mutex_033.c | 12 +- .../sample/kernel/mux/It_los_mutex_034.c | 12 +- testsuites/sample/kernel/swtmr/It_los_swtmr.h | 2 +- testsuites/sample/kernel/task/It_los_task.h | 2 +- .../sample/kernel/task/It_los_task_023.c | 3 +- .../sample/kernel/task/It_los_task_032.c | 5 +- .../sample/kernel/task/It_los_task_047.c | 5 +- .../sample/kernel/task/It_los_task_105.c | 3 +- utils/los_debug.c | 12 +- 76 files changed, 1542 insertions(+), 672 deletions(-) create mode 100644 arch/include/los_core.h create mode 100644 arch/include/los_spinlock.h create mode 100644 kernel/include/los_cpu.h create mode 100644 kernel/include/los_mp.h create mode 100644 kernel/src/los_mp.c diff --git a/Kconfig b/Kconfig index 1a9a242c..b5175346 100644 --- a/Kconfig +++ b/Kconfig @@ -192,6 +192,19 @@ menu "Kernel" ######################### config options of extended ##################### +config KERNEL_SMP + bool "Enable Kernel SMP" + default n + help + kernel smp support + +config KERNEL_CORE_NUM + int "core num" + default 2 + depends on KERNEL_SMP + help + kernel smp core num + config KERNEL_EXTKERNEL bool "Enable Extend Kernel" default y diff --git a/arch/arm/arm9/gcc/los_interrupt.c b/arch/arm/arm9/gcc/los_interrupt.c index 995546a6..ee58ab65 100644 --- a/arch/arm/arm9/gcc/los_interrupt.c +++ b/arch/arm/arm9/gcc/los_interrupt.c @@ -285,6 +285,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -299,9 +300,9 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } else { g_excInfo.phase = OS_EXC_IN_INIT; g_excInfo.thrdPid = OS_NULL_INT; diff --git a/arch/arm/cortex-m3/keil/los_interrupt.c b/arch/arm/cortex-m3/keil/los_interrupt.c index c44a667a..75ee109b 100644 --- a/arch/arm/cortex-m3/keil/los_interrupt.c +++ b/arch/arm/cortex-m3/keil/los_interrupt.c @@ -350,6 +350,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -360,13 +361,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c b/arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c index a7557def..987d5ce3 100644 --- a/arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c +++ b/arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c @@ -352,6 +352,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -362,13 +363,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/arm/cortex-m33/gcc/TZ/non_secure/los_interrupt.c b/arch/arm/cortex-m33/gcc/TZ/non_secure/los_interrupt.c index eb033f17..d360e49e 100644 --- a/arch/arm/cortex-m33/gcc/TZ/non_secure/los_interrupt.c +++ b/arch/arm/cortex-m33/gcc/TZ/non_secure/los_interrupt.c @@ -352,6 +352,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -362,13 +363,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/arm/cortex-m33/iar/NTZ/los_interrupt.c b/arch/arm/cortex-m33/iar/NTZ/los_interrupt.c index b8c0e8c0..0aa4f808 100644 --- a/arch/arm/cortex-m33/iar/NTZ/los_interrupt.c +++ b/arch/arm/cortex-m33/iar/NTZ/los_interrupt.c @@ -352,6 +352,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -362,13 +363,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/arm/cortex-m33/iar/TZ/non_secure/los_interrupt.c b/arch/arm/cortex-m33/iar/TZ/non_secure/los_interrupt.c index b8c0e8c0..0aa4f808 100644 --- a/arch/arm/cortex-m33/iar/TZ/non_secure/los_interrupt.c +++ b/arch/arm/cortex-m33/iar/TZ/non_secure/los_interrupt.c @@ -352,6 +352,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -362,13 +363,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/arm/cortex-m4/gcc/los_interrupt.c b/arch/arm/cortex-m4/gcc/los_interrupt.c index e5b4a2d8..fcd30bb5 100644 --- a/arch/arm/cortex-m4/gcc/los_interrupt.c +++ b/arch/arm/cortex-m4/gcc/los_interrupt.c @@ -351,6 +351,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -361,13 +362,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/arm/cortex-m4/iar/los_interrupt.c b/arch/arm/cortex-m4/iar/los_interrupt.c index 3a7760ba..338bcf37 100644 --- a/arch/arm/cortex-m4/iar/los_interrupt.c +++ b/arch/arm/cortex-m4/iar/los_interrupt.c @@ -351,6 +351,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -361,13 +362,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/arm/cortex-m55/gcc/NTZ/los_interrupt.c b/arch/arm/cortex-m55/gcc/NTZ/los_interrupt.c index 9ee1fd73..b1432eaa 100644 --- a/arch/arm/cortex-m55/gcc/NTZ/los_interrupt.c +++ b/arch/arm/cortex-m55/gcc/NTZ/los_interrupt.c @@ -355,6 +355,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -365,13 +366,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/arm/cortex-m55/gcc/TZ/non_secure/los_interrupt.c b/arch/arm/cortex-m55/gcc/TZ/non_secure/los_interrupt.c index a9aea8d9..6bedae53 100644 --- a/arch/arm/cortex-m55/gcc/TZ/non_secure/los_interrupt.c +++ b/arch/arm/cortex-m55/gcc/TZ/non_secure/los_interrupt.c @@ -352,6 +352,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -362,13 +363,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/arm/cortex-m55/iar/NTZ/los_interrupt.c b/arch/arm/cortex-m55/iar/NTZ/los_interrupt.c index b8c0e8c0..0aa4f808 100644 --- a/arch/arm/cortex-m55/iar/NTZ/los_interrupt.c +++ b/arch/arm/cortex-m55/iar/NTZ/los_interrupt.c @@ -352,6 +352,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -362,13 +363,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/arm/cortex-m55/iar/TZ/non_secure/los_interrupt.c b/arch/arm/cortex-m55/iar/TZ/non_secure/los_interrupt.c index d45b53de..3c9c5312 100644 --- a/arch/arm/cortex-m55/iar/TZ/non_secure/los_interrupt.c +++ b/arch/arm/cortex-m55/iar/TZ/non_secure/los_interrupt.c @@ -353,6 +353,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -363,13 +364,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/arm/cortex-m7/gcc/los_interrupt.c b/arch/arm/cortex-m7/gcc/los_interrupt.c index c44a667a..75ee109b 100644 --- a/arch/arm/cortex-m7/gcc/los_interrupt.c +++ b/arch/arm/cortex-m7/gcc/los_interrupt.c @@ -350,6 +350,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -360,13 +361,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/arm/cortex-m7/iar/los_interrupt.c b/arch/arm/cortex-m7/iar/los_interrupt.c index e6ec70a4..d4d531c5 100644 --- a/arch/arm/cortex-m7/iar/los_interrupt.c +++ b/arch/arm/cortex-m7/iar/los_interrupt.c @@ -354,6 +354,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr) { UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */ + UINT32 cpuID = ArchCurrCpuid(); g_intCount++; g_excInfo.nestCnt++; @@ -364,13 +365,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, U } else { g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR; } - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag & OS_EXC_FLAG_IN_HWI) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = pid; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/csky/v2/gcc/los_interrupt.c b/arch/csky/v2/gcc/los_interrupt.c index 6af1f8a9..f04f4a59 100644 --- a/arch/csky/v2/gcc/los_interrupt.c +++ b/arch/csky/v2/gcc/los_interrupt.c @@ -368,6 +368,7 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(EXC_CONTEXT_S *excBufAddr, UINT32 faultAddr) { + UINT32 cpuID = ArchCurrCpuid(); UINT16 tmpFlag = ((excBufAddr->EPSR >> PSR_VEC_OFFSET) & MASK_8_BITS); g_excInfo.nestCnt++; UINT32 excType = (HalGetPsr() >> PSR_VEC_OFFSET) & MASK_8_BITS; @@ -375,13 +376,13 @@ LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(EXC_CONTEXT_S *excBufAddr, UINT32 f g_excInfo.faultAddr = faultAddr; - if (g_losTask.runTask != NULL) { + if (g_losTask[cpuID].runTask != NULL) { if (tmpFlag > 0) { g_excInfo.phase = OS_EXC_IN_HWI; g_excInfo.thrdPid = tmpFlag; } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } } else { g_excInfo.phase = OS_EXC_IN_INIT; diff --git a/arch/include/los_core.h b/arch/include/los_core.h new file mode 100644 index 00000000..ff803b7a --- /dev/null +++ b/arch/include/los_core.h @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _LOS_CORE_H +#define _LOS_CORE_H + +#include "los_config.h" +#include "los_compiler.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#ifdef LOSCFG_KERNEL_SMP +struct SmpOps { + INT32 (*SmpCpuOn)(UINT32 cpuNum, UINTPTR startEntry); /* The startEntry is physical addr. */ +}; + +typedef VOID (*ArchCoreStartFunc)(VOID); + +VOID ArchCpuOn(UINT32 cpuNum, ArchCoreStartFunc func, struct SmpOps *ops, VOID *arg); +UINT32 ArchCurrCpuid(VOID); +#else +STATIC INLINE UINT32 ArchCurrCpuid(VOID) +{ + return 0; +} +#endif + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/arch/include/los_interrupt.h b/arch/include/los_interrupt.h index 4929def6..b9f43e01 100644 --- a/arch/include/los_interrupt.h +++ b/arch/include/los_interrupt.h @@ -155,6 +155,13 @@ UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority); UINT32 ArchIntCurIrqNum(VOID); HwiControllerOps *ArchIntOpsGet(VOID); +#ifdef LOSCFG_KERNEL_SMP +VOID ArchIntIpiEnable(VOID); +VOID ArchIntIpiDisable(VOID); +VOID ArchIntSendIpi(UINT32 target, UINT32 ipi); +VOID ArchIntSetAffinity(UINT32 vector, UINT32 cpuMask); +#endif + #define OS_INT_ACTIVE (ArchIsIntActive()) #define OS_INT_INACTIVE (!(OS_INT_ACTIVE)) #define LOS_IntLock ArchIntLock @@ -170,6 +177,11 @@ HwiControllerOps *ArchIntOpsGet(VOID); #define LOS_HwiCurIrqNum ArchIntCurIrqNum #define LOS_HwiOpsGet ArchIntOpsGet +#ifdef LOSCFG_KERNEL_SMP +#define LOS_HwiSendIpi ArchIntSendIpi +#define LOS_HwiSetAffinity ArchIntSetAffinity +#endif + #ifdef __cplusplus #if __cplusplus } diff --git a/arch/include/los_spinlock.h b/arch/include/los_spinlock.h new file mode 100644 index 00000000..26d1cd4c --- /dev/null +++ b/arch/include/los_spinlock.h @@ -0,0 +1,114 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _LOS_SPINLOCK_H +#define _LOS_SPINLOCK_H + +#include "los_config.h" +#include "los_compiler.h" +#include "los_interrupt.h" + +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +VOID ArchSpinLock(UINT32 *lock); +VOID ArchSpinUnlock(UINT32 *lock); + +typedef struct { + UINT32 rawLock; +} Spinlock; + +#define SPIN_LOCK_INITIALIZER(lockName) \ +{ \ + .rawLock = 0U, \ +} + +#ifdef LOSCFG_KERNEL_SMP + +STATIC INLINE VOID LOS_SpinInit(Spinlock *lock) +{ + lock->rawLock = 0; +} + +STATIC INLINE VOID LOS_SpinLock(Spinlock *lock) +{ + ArchSpinLock(&lock->rawLock); +} + +STATIC INLINE VOID LOS_SpinUnlock(Spinlock *lock) +{ + ArchSpinUnlock(&lock->rawLock); +} + +STATIC INLINE VOID LOS_SpinLockSave(Spinlock *lock, UINT32 *intSave) +{ + LOS_ASSERT(lock); + + *intSave = ArchIntLock(); + LOS_SpinLock(lock); +} + +STATIC INLINE VOID LOS_SpinUnlockRestore(Spinlock *lock, UINT32 intSave) +{ + LOS_ASSERT(lock); + + LOS_SpinUnlock(lock); + ArchIntRestore(intSave); +} + +#else + +STATIC INLINE VOID LOS_SpinInit(Spinlock *lock) +{ + lock->rawLock = 0; +} + +STATIC INLINE VOID LOS_SpinLock(Spinlock *lock) +{ + (VOID)lock; +} + +STATIC INLINE VOID LOS_SpinUnlock(Spinlock *lock) +{ + (VOID)lock; +} + +STATIC INLINE VOID LOS_SpinLockSave(Spinlock *lock, UINT32 *intSave) +{ + (VOID)lock; + *intSave = ArchIntLock(); +} + +STATIC INLINE VOID LOS_SpinUnlockRestore(Spinlock *lock, UINT32 intSave) +{ + (VOID)lock; + ArchIntRestore(intSave); +} +#endif + +#define SPIN_LOCK_INIT(lock) Spinlock lock = SPIN_LOCK_INITIALIZER(lock) + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/arch/risc-v/nuclei/gcc/los_context.c b/arch/risc-v/nuclei/gcc/los_context.c index 49712e93..9f5ae048 100644 --- a/arch/risc-v/nuclei/gcc/los_context.c +++ b/arch/risc-v/nuclei/gcc/los_context.c @@ -63,7 +63,7 @@ LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VO return (VOID *)context; } -extern LosTask g_losTask; +extern LosTask g_losTask[LOSCFG_KERNEL_CORE_NUM]; LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID) { (VOID)LOS_IntLock(); @@ -79,9 +79,10 @@ VOID ArchTaskSchedule(VOID) VOID HalTaskSwitch(VOID) { + UINT32 cpuID = ArchCurrCpuid(); SysTimer_ClearSWIRQ(); OsSchedTaskSwitch(); /* Set newTask to runTask */ - g_losTask.runTask = g_losTask.newTask; + g_losTask[cpuID].runTask = g_losTask[cpuID].newTask; } diff --git a/arch/risc-v/riscv32/gcc/los_interrupt.c b/arch/risc-v/riscv32/gcc/los_interrupt.c index b080ea27..ad2df80a 100644 --- a/arch/risc-v/riscv32/gcc/los_interrupt.c +++ b/arch/risc-v/riscv32/gcc/los_interrupt.c @@ -270,6 +270,7 @@ STATIC VOID ExcInfoDisplayContext(const LosExcInfo *exc) STATIC VOID ExcInfoDisplay(VOID) { + UINT32 cpuID = ArchCurrCpuid(); PRINTK("\nException Information \n"); if (g_excInfo.type < RISCV_EXC_TYPE_NUM) { @@ -279,8 +280,8 @@ STATIC VOID ExcInfoDisplay(VOID) } if (LOS_TaskIsRunning()) { - PRINTK("taskName = %s\n", g_losTask.runTask->taskName); - PRINTK("taskID = %u\n", g_losTask.runTask->taskID); + PRINTK("taskName = %s\n", g_losTask[cpuID].runTask->taskName); + PRINTK("taskID = %u\n", g_losTask[cpuID].runTask->taskID); } else { PRINTK("The exception occurs during system startup!\n"); } diff --git a/arch/xtensa/lx6/gcc/los_interrupt.c b/arch/xtensa/lx6/gcc/los_interrupt.c index aafc37cf..de9d5381 100644 --- a/arch/xtensa/lx6/gcc/los_interrupt.c +++ b/arch/xtensa/lx6/gcc/los_interrupt.c @@ -339,11 +339,12 @@ STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo) VOID HalExcHandleEntry(UINTPTR faultAddr, EXC_CONTEXT_S *excBufAddr, UINT32 type) { + UINT32 cpuID = ArchCurrCpuid(); g_excInfo.nestCnt++; g_excInfo.faultAddr = faultAddr; g_excInfo.type = type; - LosTaskCB *taskCB = g_losTask.runTask; + LosTaskCB *taskCB = g_losTask[cpuID].runTask; if ((taskCB == NULL) || (taskCB == OS_TCB_FROM_TID(g_taskMaxNum))) { g_excInfo.phase = OS_EXC_IN_INIT; @@ -353,7 +354,7 @@ VOID HalExcHandleEntry(UINTPTR faultAddr, EXC_CONTEXT_S *excBufAddr, UINT32 type g_excInfo.thrdPid = HwiNumGet(); } else { g_excInfo.phase = OS_EXC_IN_TASK; - g_excInfo.thrdPid = g_losTask.runTask->taskID; + g_excInfo.thrdPid = g_losTask[cpuID].runTask->taskID; } g_excInfo.context = excBufAddr; diff --git a/components/backtrace/los_backtrace.c b/components/backtrace/los_backtrace.c index 8c0eb4b5..a93008ae 100644 --- a/components/backtrace/los_backtrace.c +++ b/components/backtrace/los_backtrace.c @@ -711,12 +711,13 @@ VOID LOS_BackTrace(VOID) { UINTPTR LR[BACKTRACE_MAX_DEPTH] = {0}; UINT32 index; + UINT32 cpuID = ArchCurrCpuid(); LOS_RecordLR(LR, BACKTRACE_MAX_DEPTH, OS_BACKTRACE_START, 0); if (LOS_TaskIsRunning()) { - PRINTK("taskName = %s\n", g_losTask.runTask->taskName); - PRINTK("taskID = %u\n", g_losTask.runTask->taskID); + PRINTK("taskName = %s\n", g_losTask[cpuID].runTask->taskName); + PRINTK("taskID = %u\n", g_losTask[cpuID].runTask->taskID); } PRINTK("----- traceback start -----\r\n"); diff --git a/components/cpup/los_cpup.c b/components/cpup/los_cpup.c index 0c3e2cf7..595e8c9f 100644 --- a/components/cpup/los_cpup.c +++ b/components/cpup/los_cpup.c @@ -81,7 +81,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID) UINT32 loop; UINT32 intSave; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); prevPos = g_irqHisPos; if (g_irqHisPos == OS_CPUP_HISTORY_RECORD_NUM - 1) { @@ -98,7 +98,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID) g_irqCpup[loop].historyTime[prevPos] = g_irqCpup[loop].allTime; g_cpuHistoryTime[prevPos] += g_irqCpup[loop].allTime; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return; } @@ -188,12 +188,13 @@ Return : None LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleStart(VOID) { UINT32 taskID; + UINT32 cpuID = ArchCurrCpuid(); if (g_cpupInitFlg == 0) { return; } - taskID = g_losTask.newTask->taskID; + taskID = g_losTask[cpuID].newTask->taskID; g_cpup[taskID].cpupID = taskID; g_cpup[taskID].startTime = CpupTimeUsGet(); @@ -210,12 +211,13 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEnd(VOID) { UINT32 taskID; UINT64 cpuTime; + UINT32 cpuID = ArchCurrCpuid(); if (g_cpupInitFlg == 0) { return; } - taskID = g_losTask.runTask->taskID; + taskID = g_losTask[cpuID].runTask->taskID; if (g_cpup[taskID].startTime == 0) { return; @@ -243,12 +245,13 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEndStart(VOID) UINT32 taskID; UINT64 cpuTime; UINT16 loopNum; + UINT32 cpuID = ArchCurrCpuid(); if (g_cpupInitFlg == 0) { return; } - taskID = g_losTask.runTask->taskID; + taskID = g_losTask[cpuID].runTask->taskID; cpuTime = CpupTimeUsGet(); if (g_cpup[taskID].startTime != 0) { @@ -260,7 +263,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEndStart(VOID) g_cpup[taskID].startTime = 0; } - taskID = g_losTask.newTask->taskID; + taskID = g_losTask[cpuID].newTask->taskID; g_cpup[taskID].cpupID = taskID; g_cpup[taskID].startTime = cpuTime; @@ -316,13 +319,14 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_SysCpuUsage(VOID) UINT32 cpupRet = 0; UINT16 loopNum; UINT32 intSave; + UINT32 cpuID = ArchCurrCpuid(); if (g_cpupInitFlg == 0) { return LOS_ERRNO_CPUP_NO_INIT; } // get end time of current task - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); OsTskCycleEnd(); for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) { @@ -331,11 +335,11 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_SysCpuUsage(VOID) if (cpuTimeAll) { cpupRet = LOS_CPUP_PRECISION - (UINT32)((LOS_CPUP_PRECISION * - g_cpup[g_idleTaskID].allTime) / cpuTimeAll); + g_cpup[g_idleTaskID[cpuID]].allTime) / cpuTimeAll); } OsTskCycleStart(); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return cpupRet; } @@ -355,13 +359,14 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage(UINT16 mode) UINT16 curPos; UINT16 prePos = 0; UINT32 intSave; + UINT32 cpuID = ArchCurrCpuid(); if (g_cpupInitFlg == 0) { return LOS_ERRNO_CPUP_NO_INIT; } // get end time of current task - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); OsTskCycleEnd(); OsGetPositions(mode, &curPos, &prePos); @@ -375,10 +380,10 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage(UINT16 mode) } if (mode == CPUP_IN_1S) { - idleCycleAll += g_cpup[g_idleTaskID].historyTime[curPos] - - g_cpup[g_idleTaskID].historyTime[prePos]; + idleCycleAll += g_cpup[g_idleTaskID[cpuID]].historyTime[curPos] - + g_cpup[g_idleTaskID[cpuID]].historyTime[prePos]; } else { - idleCycleAll += g_cpup[g_idleTaskID].allTime - g_cpup[g_idleTaskID].historyTime[curPos]; + idleCycleAll += g_cpup[g_idleTaskID[cpuID]].allTime - g_cpup[g_idleTaskID[cpuID]].historyTime[curPos]; } if (cpuTimeAll) { @@ -386,7 +391,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage(UINT16 mode) } OsTskCycleStart(); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return cpupRet; } @@ -416,7 +421,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuUsage(UINT32 taskID) if ((g_cpup[taskID].status & OS_TASK_STATUS_UNUSED) || (g_cpup[taskID].status == 0)) { return LOS_ERRNO_CPUP_THREAD_NO_CREATED; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); OsTskCycleEnd(); /* get total Cycle */ @@ -432,7 +437,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuUsage(UINT32 taskID) } OsTskCycleStart(); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return cpupRet; } @@ -465,7 +470,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode if ((g_cpup[taskID].status & OS_TASK_STATUS_UNUSED) || (g_cpup[taskID].status == 0)) { return LOS_ERRNO_CPUP_THREAD_NO_CREATED; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); OsTskCycleEnd(); OsGetPositions(mode, &curPos, &prePos); @@ -493,7 +498,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode } OsTskCycleStart(); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return cpupRet; } @@ -515,7 +520,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16 return LOS_ERRNO_CPUP_TASK_PTR_NULL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); OsTskCycleEnd(); OsGetPositions(mode, &curPos, &prePos); @@ -553,7 +558,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16 } OsTskCycleStart(); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -722,7 +727,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_GetAllIrqCpuUsage(UINT16 mode, CPUP_INFO_S *cp return LOS_ERRNO_CPUP_TASK_PTR_NULL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); OsGetIrqPositions(mode, &curPos, &prePos); if (mode == CPUP_IN_10S) { @@ -749,7 +754,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_GetAllIrqCpuUsage(UINT16 mode, CPUP_INFO_S *cp } } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } #endif diff --git a/components/debugtools/los_hwidump.c b/components/debugtools/los_hwidump.c index 33c83530..30e0f218 100644 --- a/components/debugtools/los_hwidump.c +++ b/components/debugtools/los_hwidump.c @@ -67,9 +67,9 @@ STATIC VOID ShellCmdHwiInfoShow(OsIrqCpupCB *irqData, CPUP_INFO_S *hwiCpup1s, continue; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); (VOID)memcpy_s(irqData, IRQ_DATA_SIZE, &irqDataBase[i], IRQ_DATA_SIZE); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); if (irqData->status == 0) { continue; diff --git a/components/debugtools/los_stackdump.c b/components/debugtools/los_stackdump.c index 14b5a31a..26884806 100644 --- a/components/debugtools/los_stackdump.c +++ b/components/debugtools/los_stackdump.c @@ -106,16 +106,16 @@ VOID LOS_TaskStackDump(UINT32 taskID) return; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); info.waterLine = OsGetTaskWaterLine(taskID); if (info.waterLine == OS_NULL_INT) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return; } buf = (UINTPTR *)LOS_MemAlloc(OS_SYS_MEM_ADDR, info.waterLine); if (buf == NULL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); PRINT_ERR("alloc failed for dump\n"); return; } @@ -123,14 +123,14 @@ VOID LOS_TaskStackDump(UINT32 taskID) ret = DumpTaskInfo(taskID, buf, &info); if (ret != LOS_OK) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); (VOID)LOS_MemFree(OS_SYS_MEM_ADDR, buf); PRINT_ERR("SP 0x%x may error or memcpy_s failed, stack space from 0x%x to 0x%x\r\n", \ info.taskSP, info.taskSPTop, info.taskSPLimit); return; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); PRINTK("Task %u, SP 0x%x, WaterLine 0x%x", taskID, info.taskSP, info.waterLine); ShowFormat(buf, &info); (VOID)LOS_MemFree(OS_SYS_MEM_ADDR, buf); @@ -139,17 +139,17 @@ VOID LOS_TaskStackDump(UINT32 taskID) } UINT32 OsShellCmdStackDump(INT32 argc, const CHAR **argv) -{ +{ UINT32 taskID; if (argc != 1) { PRINT_ERR("\nUsage: stack taskID\n"); return LOS_NOK; - } + } taskID = (UINT32)atoi(argv[0]); LOS_TaskStackDump(taskID); - return LOS_OK; + return LOS_OK; } #endif /* LOSCFG_STACK_DUMP == 1 */ diff --git a/components/exchook/los_exchook.c b/components/exchook/los_exchook.c index c5171b57..5b5f827d 100644 --- a/components/exchook/los_exchook.c +++ b/components/exchook/los_exchook.c @@ -44,6 +44,15 @@ struct Node { STATIC struct Node g_excNodes[LOSCFG_BASE_EXC_HOOK_LIMIT]; STATIC struct Node *g_excHeads[EXC_TYPE_END + 1]; /* EXC_TYPE_END is used for the free list. */ +#if (LOSCFG_KERNEL_SMP == 1) +LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_excHookSpin); +#define EXC_HOOK_LOCK(state) LOS_SpinLockSave(&g_excHookSpin, &(state)) +#define EXC_HOOK_UNLOCK(state) LOS_SpinUnlockRestore(&g_excHookSpin, (state)) +#else +#define EXC_HOOK_LOCK(state) (state) = LOS_IntLock() +#define EXC_HOOK_UNLOCK(state) LOS_IntRestore(state) +#endif + STATIC VOID DoExcHookInRegOrder(EXC_TYPE excType, struct Node *node) { if (node != NULL) { @@ -58,9 +67,9 @@ STATIC VOID DoExcHook(EXC_TYPE excType) if (excType >= EXC_TYPE_END) { return; } - intSave = LOS_IntLock(); + EXC_HOOK_LOCK(intSave); DoExcHookInRegOrder(excType, g_excHeads[excType]); - LOS_IntRestore(intSave); + EXC_HOOK_UNLOCK(intSave); } STATIC struct Node *GetFreeNode(VOID) @@ -94,17 +103,17 @@ UINT32 LOS_RegExcHook(EXC_TYPE excType, ExcHookFn excHookFn) return LOS_ERRNO_SYS_PTR_NULL; } - intSave = LOS_IntLock(); + EXC_HOOK_LOCK(intSave); node = GetFreeNode(); if (node == NULL) { - LOS_IntRestore(intSave); + EXC_HOOK_UNLOCK(intSave); return LOS_ERRNO_SYS_HOOK_IS_FULL; } node->excHookFn = excHookFn; node->next = g_excHeads[excType]; g_excHeads[excType] = node; - LOS_IntRestore(intSave); + EXC_HOOK_UNLOCK(intSave); return LOS_OK; } @@ -117,7 +126,7 @@ UINT32 LOS_UnRegExcHook(EXC_TYPE excType, ExcHookFn excHookFn) return LOS_ERRNO_SYS_PTR_NULL; } - intSave = LOS_IntLock(); + EXC_HOOK_LOCK(intSave); for (node = g_excHeads[excType]; node != NULL; node = node->next) { if (node->excHookFn == excHookFn) { if (preNode) { @@ -131,6 +140,6 @@ UINT32 LOS_UnRegExcHook(EXC_TYPE excType, ExcHookFn excHookFn) } preNode = node; } - LOS_IntRestore(intSave); + EXC_HOOK_UNLOCK(intSave); return LOS_OK; } diff --git a/components/lmk/los_lmk.c b/components/lmk/los_lmk.c index 9cefcd60..339df5ab 100644 --- a/components/lmk/los_lmk.c +++ b/components/lmk/los_lmk.c @@ -38,6 +38,15 @@ #if (LOSCFG_KERNEL_LMK == 1) STATIC LosLmkOps g_losLmkOps; +#if (LOSCFG_KERNEL_SMP == 1) +LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_lmkSpin); +#define LMK_LOCK(state) LOS_SpinLockSave(&g_lmkSpin, &(state)) +#define LMK_UNLOCK(state) LOS_SpinUnlockRestore(&g_lmkSpin, (state)) +#else +#define LMK_LOCK(state) (state) = LOS_IntLock() +#define LMK_UNLOCK(state) LOS_IntRestore(state) +#endif + STATIC BOOL OsIsLmkOpsNodeRegistered(LosLmkOpsNode *lmkNode) { LosLmkOpsNode *opsNode = NULL; @@ -62,14 +71,14 @@ UINT32 LOS_LmkOpsNodeRegister(LosLmkOpsNode *lmkNode) return LOS_ERRNO_LMK_INVALID_PARAMETER; } - intSave = LOS_IntLock(); + LMK_LOCK(intSave); if (OsIsLmkOpsNodeRegistered(lmkNode)) { - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); return LOS_ERRNO_LMK_ALREADY_REGISTERED; } if (LOS_ListEmpty(&g_losLmkOps.lmkOpsList)) { LOS_ListHeadInsert(&g_losLmkOps.lmkOpsList, &lmkNode->node); - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); return LOS_OK; } @@ -77,7 +86,7 @@ UINT32 LOS_LmkOpsNodeRegister(LosLmkOpsNode *lmkNode) opsNode = LOS_DL_LIST_ENTRY(g_losLmkOps.lmkOpsList.pstNext, LosLmkOpsNode, node); if (lmkNode->priority <= opsNode->priority) { LOS_ListHeadInsert(&g_losLmkOps.lmkOpsList, &lmkNode->node); - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); return LOS_OK; } @@ -85,7 +94,7 @@ UINT32 LOS_LmkOpsNodeRegister(LosLmkOpsNode *lmkNode) opsNode = LOS_DL_LIST_ENTRY(g_losLmkOps.lmkOpsList.pstPrev, LosLmkOpsNode, node); if (lmkNode->priority >= opsNode->priority) { LOS_ListTailInsert(&g_losLmkOps.lmkOpsList, &lmkNode->node); - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); return LOS_OK; } @@ -97,7 +106,7 @@ UINT32 LOS_LmkOpsNodeRegister(LosLmkOpsNode *lmkNode) } } - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); return LOS_OK; } @@ -109,13 +118,13 @@ UINT32 LOS_LmkOpsNodeUnregister(LosLmkOpsNode *lmkNode) return LOS_ERRNO_LMK_INVALID_PARAMETER; } - intSave = LOS_IntLock(); + LMK_LOCK(intSave); if (LOS_ListEmpty(&g_losLmkOps.lmkOpsList) || !OsIsLmkOpsNodeRegistered(lmkNode)) { - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); return LOS_ERRNO_LMK_NOT_REGISTERED; } LOS_ListDelete(&lmkNode->node); - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); return LOS_OK; } @@ -126,27 +135,27 @@ UINT32 LOS_LmkTasksKill(VOID) LosLmkOpsNode *opsNode = NULL; FreeMemByKillingTask freeMem = NULL; - intSave = LOS_IntLock(); + LMK_LOCK(intSave); // if tasks already killed, no need to do it again. if (g_losLmkOps.isMemFreed) { - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); return LOS_ERRNO_LMK_MEMORY_ALREADY_FREED; } else { g_losLmkOps.isMemFreed = TRUE; } LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) { freeMem = opsNode->freeMem; - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); if (freeMem != NULL) { ret = freeMem(); if (ret != LOS_OK) { return LOS_ERRNO_LMK_FREE_MEMORY_FAILURE; } } - intSave = LOS_IntLock(); + LMK_LOCK(intSave); } - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); return LOS_OK; } @@ -158,27 +167,27 @@ UINT32 LOS_LmkTasksRestore(VOID) LosLmkOpsNode *opsNode = NULL; RestoreKilledTask restore = NULL; - intSave = LOS_IntLock(); + LMK_LOCK(intSave); // if no tasks killed, no need to restore. if (!g_losLmkOps.isMemFreed) { - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); return LOS_ERRNO_LMK_RESTORE_NOT_NEEDED; } else { g_losLmkOps.isMemFreed = FALSE; } LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) { restore = opsNode->restoreTask; - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); if (restore != NULL) { ret = restore(); if (ret != LOS_OK) { return LOS_ERRNO_LMK_RESTORE_TASKS_FAILURE; } } - intSave = LOS_IntLock(); + LMK_LOCK(intSave); } - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); return LOS_OK; } @@ -189,12 +198,12 @@ VOID LOS_LmkOpsNodeInfoShow(VOID) UINT32 intSave; LosLmkOpsNode *opsNode = NULL; - intSave = LOS_IntLock(); + LMK_LOCK(intSave); LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) { PRINTK("Priority: %-4u Free:0x%-8x Restore:0x%-8x\n", opsNode->priority, (UINT32)(UINTPTR)opsNode->freeMem, (UINT32)(UINTPTR)opsNode->restoreTask); } - LOS_IntRestore(intSave); + LMK_UNLOCK(intSave); } #endif diff --git a/components/lms/los_lms.c b/components/lms/los_lms.c index fe96866a..00e07137 100644 --- a/components/lms/los_lms.c +++ b/components/lms/los_lms.c @@ -433,7 +433,7 @@ STATIC UINT32 OsLmsCheckAddr(UINTPTR addr) UINT32 shadowValue = INVALID_SHADOW_VALUE; /* do not check nested or before all cpu start */ LMS_LOCK(intSave); - if ((g_checkDepth != 0) || (!g_taskScheduled)) { + if ((g_checkDepth != 0) || (!OS_SCHEDULER_ACTIVE)) { LMS_UNLOCK(intSave); return 0; } diff --git a/components/power/los_pm.c b/components/power/los_pm.c index f13e80ac..b09473fe 100644 --- a/components/power/los_pm.c +++ b/components/power/los_pm.c @@ -230,11 +230,11 @@ STATIC UINT32 OsPmSuspendCheck(LosPmCB *pm, Suspend *sysSuspendEarly, Suspend *d { UINT32 intSave; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); pm->sysMode = pm->pmMode; if (pm->lock > 0) { pm->sysMode = LOS_SYS_NORMAL_SLEEP; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_NOK; } @@ -244,7 +244,7 @@ STATIC UINT32 OsPmSuspendCheck(LosPmCB *pm, Suspend *sysSuspendEarly, Suspend *d *mode = pm->sysMode; *sysSuspendEarly = pm->sysctrl->early; *deviceSuspend = pm->device->suspend; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -263,12 +263,12 @@ STATIC UINT32 OsPmSuspendSleep(LosPmCB *pm) ret = OsPmSuspendPrepare(sysSuspendEarly, deviceSuspend, (UINT32)mode, &prepare); if (ret != LOS_OK) { - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); LOS_TaskLock(); goto EXIT; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); LOS_TaskLock(); if (pm->isWake || (pm->lock > 0)) { goto EXIT; @@ -294,7 +294,7 @@ STATIC UINT32 OsPmSuspendSleep(LosPmCB *pm) EXIT: pm->sysMode = LOS_SYS_NORMAL_SLEEP; OsPmResumePrepare(pm, (UINT32)mode, prepare); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); LOS_TaskUnlock(); return ret; @@ -308,13 +308,13 @@ STATIC VOID OsPmNormalSleep(VOID) UINT32 intSave; LosPmCB *pm = &g_pmCB; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); OsPmCpuSuspend(pm); OsPmCpuResume(pm); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); #endif } @@ -326,9 +326,9 @@ STATIC UINT32 OsPmDeviceRegister(LosPmCB *pm, LosPmDevice *device) return LOS_ERRNO_PM_INVALID_PARAM; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); pm->device = device; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -345,12 +345,12 @@ STATIC UINT32 OsPmTickTimerRegister(LosPmCB *pm, LosPmTickTimer *tickTimer) (tickTimer->timerCycleGet == NULL) && (tickTimer->freq == 0)) || ((tickTimer->timerStart != NULL) && (tickTimer->timerStop != NULL) && (tickTimer->timerCycleGet != NULL) && (tickTimer->freq != 0))) { - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); #if (LOSCFG_BASE_CORE_TICK_WTIMER == 0) pm->enterSleepTime = 0; #endif pm->tickTimer = tickTimer; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -359,7 +359,9 @@ STATIC UINT32 OsPmTickTimerRegister(LosPmCB *pm, LosPmTickTimer *tickTimer) STATIC UINT32 OsPmSysctrlRegister(LosPmCB *pm, LosPmSysctrl *sysctrl) { - UINT32 intSave = LOS_IntLock(); + UINT32 intSave; + + SCHEDULER_LOCK(intSave); if (sysctrl->early != NULL) { pm->sysctrl->early = sysctrl->early; } @@ -393,7 +395,7 @@ STATIC UINT32 OsPmSysctrlRegister(LosPmCB *pm, LosPmSysctrl *sysctrl) if (sysctrl->shutdownResume != NULL) { pm->sysctrl->shutdownResume = sysctrl->shutdownResume; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -423,15 +425,15 @@ STATIC UINT32 OsPmDeviceUnregister(LosPmCB *pm, LosPmDevice *device) { UINT32 intSave; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (pm->device == device) { pm->device = NULL; pm->pmMode = LOS_SYS_NORMAL_SLEEP; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_PM_INVALID_NODE; } @@ -439,28 +441,29 @@ STATIC UINT32 OsPmTickTimerUnregister(LosPmCB *pm, LosPmTickTimer *tickTimer) { UINT32 intSave; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (pm->tickTimer == tickTimer) { pm->tickTimer = NULL; if ((pm->pmMode != LOS_SYS_NORMAL_SLEEP) && (pm->pmMode != LOS_SYS_LIGHT_SLEEP)) { pm->pmMode = LOS_SYS_NORMAL_SLEEP; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_PM_INVALID_NODE; } STATIC UINT32 OsPmSysctrlUnregister(LosPmCB *pm, LosPmSysctrl *sysctrl) { (VOID)sysctrl; + UINT32 intSave; - UINT32 intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); OsPmSysctrlInit(); pm->pmMode = LOS_SYS_NORMAL_SLEEP; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -491,9 +494,9 @@ VOID LOS_PmWakeSet(VOID) UINT32 intSave; LosPmCB *pm = &g_pmCB; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); pm->isWake = TRUE; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return; } @@ -501,10 +504,11 @@ LOS_SysSleepEnum LOS_PmModeGet(VOID) { LOS_SysSleepEnum mode; LosPmCB *pm = &g_pmCB; - - UINT32 intSave = LOS_IntLock(); + UINT32 intSave; + + SCHEDULER_LOCK(intSave); mode = pm->pmMode; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return mode; } @@ -519,29 +523,29 @@ UINT32 LOS_PmModeSet(LOS_SysSleepEnum mode) return LOS_ERRNO_PM_INVALID_MODE; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((mode != LOS_SYS_NORMAL_SLEEP) && (pm->device == NULL)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_PM_DEVICE_NULL; } if ((mode == LOS_SYS_LIGHT_SLEEP) && (pm->sysctrl->lightSuspend == NULL)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_PM_HANDLER_NULL; } if ((mode == LOS_SYS_DEEP_SLEEP) && (pm->sysctrl->deepSuspend == NULL)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_PM_HANDLER_NULL; } if ((mode == LOS_SYS_SHUTDOWN) && (pm->sysctrl->shutdownSuspend == NULL)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_PM_HANDLER_NULL; } pm->pmMode = mode; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -557,13 +561,13 @@ VOID LOS_PmLockInfoShow(VOID) PRINTK("Name Count\n\r"); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); while (list != head) { lock = LOS_DL_LIST_ENTRY(list, OsPmLockCB, list); PRINTK("%-30s%5u\n\r", lock->name, lock->count); list = list->pstNext; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return; } @@ -579,7 +583,7 @@ UINT32 OsPmLockRequest(const CHAR *name, UINT32 swtmrID) LOS_DL_LIST *head = &pm->lockList; LOS_DL_LIST *list = head->pstNext; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); while (list != head) { listNode = LOS_DL_LIST_ENTRY(list, OsPmLockCB, list); if (strcmp(name, listNode->name) == 0) { @@ -593,7 +597,7 @@ UINT32 OsPmLockRequest(const CHAR *name, UINT32 swtmrID) if (lock == NULL) { lock = LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, sizeof(OsPmLockCB)); if (lock == NULL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_NOK; } lock->name = (CHAR *)name; @@ -606,7 +610,7 @@ UINT32 OsPmLockRequest(const CHAR *name, UINT32 swtmrID) if ((lock->swtmrID != OS_INVALID) && (lock->count > 1)) { lock->count--; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_PM_ALREADY_LOCK; } @@ -615,7 +619,7 @@ UINT32 OsPmLockRequest(const CHAR *name, UINT32 swtmrID) ret = LOS_OK; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return ret; } @@ -645,7 +649,7 @@ UINT32 LOS_PmLockRelease(const CHAR *name) return LOS_ERRNO_PM_INVALID_PARAM; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); mode = (UINT32)pm->pmMode; while (list != head) { listNode = LOS_DL_LIST_ENTRY(list, OsPmLockCB, list); @@ -658,7 +662,7 @@ UINT32 LOS_PmLockRelease(const CHAR *name) } if (lock == NULL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_PM_NOT_LOCK; } else if (lock->count > 0) { lock->count--; @@ -675,7 +679,7 @@ UINT32 LOS_PmLockRelease(const CHAR *name) } ret = LOS_OK; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); if (lockFree != NULL) { (VOID)LOS_SwtmrDelete(lockFree->swtmrID); @@ -752,13 +756,14 @@ UINT32 LOS_PmSuspend(UINT32 wakeCount) BOOL OsIsPmMode(VOID) { LosPmCB *pm = &g_pmCB; + UINT32 intSave; - UINT32 intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((pm->sysMode != LOS_SYS_NORMAL_SLEEP) && (pm->lock == 0)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return TRUE; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return FALSE; } diff --git a/components/security/box/los_box.c b/components/security/box/los_box.c index 05e77a3b..6a361bf0 100644 --- a/components/security/box/los_box.c +++ b/components/security/box/los_box.c @@ -39,13 +39,14 @@ static LosBoxCB g_boxCB[1]; VOID OsUserTaskInit(UINT32 taskID, UINTPTR entry, UINTPTR userArea, UINTPTR userSp) { + INT32 cpuID = ArchCurrCpuid(); LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID); taskCB->taskStatus |= OS_TASK_FLAG_USER_TASK; HalUserTaskStackInit(taskCB->stackPointer, entry, userSp); g_UserTaskCBArray[taskID].userArea = userArea; g_UserTaskCBArray[taskID].userSp = userSp; - g_UserTaskCBArray[taskID].boxID = g_UserTaskCBArray[g_losTask.runTask->taskID].boxID; + g_UserTaskCBArray[taskID].boxID = g_UserTaskCBArray[g_losTask[cpuID].runTask->taskID].boxID; } VOID OsUserTaskDelete(UINT32 taskID) diff --git a/components/security/syscall/pthread_syscall.c b/components/security/syscall/pthread_syscall.c index 747addcc..2d587709 100644 --- a/components/security/syscall/pthread_syscall.c +++ b/components/security/syscall/pthread_syscall.c @@ -96,20 +96,21 @@ int *SysSchedGetArea(unsigned int tid) return NULL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); area = (int *)OsGetUserTaskCB(tid)->userArea; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return area; } int SysSetThreadArea(const char *area) { unsigned int intSave; + INT32 cpuID = ArchCurrCpuid(); - intSave = LOS_IntLock(); - LosTaskCB *runTask = g_losTask.runTask; + SCHEDULER_LOCK(intSave); + LosTaskCB *runTask = g_losTask[cpuID].runTask; OsGetUserTaskCB(runTask->taskID)->userArea = (unsigned long)(uintptr_t)area; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return 0; } @@ -117,10 +118,11 @@ char *SysGetThreadArea(void) { unsigned int intSave; char *area = NULL; + INT32 cpuID = ArchCurrCpuid(); - intSave = LOS_IntLock(); - LosTaskCB *runTask = g_losTask.runTask; + SCHEDULER_LOCK(intSave); + LosTaskCB *runTask = g_losTask[cpuID].runTask; area = (char *)OsGetUserTaskCB(runTask->taskID)->userArea; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return area; } diff --git a/components/shell/src/base/shmsg.c b/components/shell/src/base/shmsg.c index 720af9be..9facde3d 100644 --- a/components/shell/src/base/shmsg.c +++ b/components/shell/src/base/shmsg.c @@ -261,6 +261,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LosShellInit(VOID) task1.uwStackSize = LOSCFG_SHELL_STACK_SIZE; task1.pcName = "ShellTaskEntry"; task1.usTaskPrio = LOSCFG_SHELL_PRIO; +#ifdef LOSCFG_KERNEL_SMP + task1.usCpuAffiMask = CPUID_TO_AFFI_MASK(0); +#endif ret = LOS_TaskCreate(&taskID1, &task1); if (ret != LOS_OK) { PRINTK("Create Shell Task failed! ERROR: 0x%x\n", ret); diff --git a/components/signal/los_signal.c b/components/signal/los_signal.c index 069fbc6c..36dcce45 100644 --- a/components/signal/los_signal.c +++ b/components/signal/los_signal.c @@ -114,10 +114,10 @@ STATIC VOID SignalHandle(LosTaskCB *task, BOOL cleanStatus) UINT32 intSave; OsSigCB *sigCB = NULL; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); sigCB = task->sig; if (sigCB == NULL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return; } @@ -128,18 +128,18 @@ STATIC VOID SignalHandle(LosTaskCB *task, BOOL cleanStatus) SIG_HANDLER handler = sigCB->sigHandlers[sigNo - 1]; sigCB->sigPendFlag &= ~LOS_SIGNAL_MASK(sigNo); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); if (handler != NULL) { handler(sigNo); } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (cleanStatus == TRUE) { task->taskStatus &= ~OS_TASK_FLAG_SIGNAL; } } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); } STATIC VOID SignalEntry(INT32 sigNo) @@ -154,7 +154,9 @@ STATIC VOID SignalEntry(INT32 sigNo) sigCB->sigSaveSP = NULL; sigCB->sigRestoreSP = task->stackPointer; task->taskStatus &= ~OS_TASK_FLAG_SIGNAL; - +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(OS_MP_CPU_ALL); +#endif LOS_Schedule(); } @@ -164,10 +166,10 @@ STATIC VOID SignalSend(LosTaskCB *task, INT32 sigNo) OsSigCB *sigCB = NULL; sigset_t mask = LOS_SIGNAL_MASK(sigNo); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); sigCB = task->sig; if (sigCB == NULL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return; } @@ -177,7 +179,7 @@ STATIC VOID SignalSend(LosTaskCB *task, INT32 sigNo) if (task == OsCurrTaskGet()) { task->taskStatus |= OS_TASK_FLAG_SIGNAL; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); if (!OS_INT_ACTIVE) { SignalHandle(task, TRUE); @@ -196,7 +198,10 @@ STATIC VOID SignalSend(LosTaskCB *task, INT32 sigNo) task->stackPointer = ArchSignalContextInit(task->stackPointer, (VOID *)task->topOfStack, (UINTPTR)SignalEntry, sigNo); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(OS_MP_CPU_ALL); +#endif LOS_Schedule(); } } @@ -241,10 +246,10 @@ SIG_HANDLER LOS_SignalSet(INT32 sigNo, SIG_HANDLER handler) return SIG_ERR; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); sigCB = SignalCBInit(task); if (sigCB == NULL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return SIG_ERR; } @@ -259,7 +264,7 @@ SIG_HANDLER LOS_SignalSet(INT32 sigNo, SIG_HANDLER handler) sigCB->sigHandlers[sigNo - 1] = handler; sigCB->sigSetFlag |= LOS_SIGNAL_MASK(sigNo); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return old; } @@ -274,10 +279,10 @@ UINT32 LOS_SignalMask(INT32 how, const sigset_t *set, sigset_t *oldSet) return LOS_ERRNO_SIGNAL_CAN_NOT_CALL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); sigCB = SignalCBInit(task); if (sigCB == NULL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_SIGNAL_NO_MEMORY; } @@ -286,7 +291,7 @@ UINT32 LOS_SignalMask(INT32 how, const sigset_t *set, sigset_t *oldSet) } if (set == NULL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_SIGNAL_INVALID; } @@ -304,7 +309,7 @@ UINT32 LOS_SignalMask(INT32 how, const sigset_t *set, sigset_t *oldSet) PRINT_ERR("The error parameter how = %d\n", how); break; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -315,12 +320,12 @@ STATIC INLINE UINT32 SignalTimedWait(LosTaskCB *task, const sigset_t *set, UINT3 INT32 sigNo; if (timeout == 0) { - LOS_IntRestore(*intSave); + SCHEDULER_UNLOCK(*intSave); return LOS_ERRNO_SIGNAL_INVALID; } if (OS_INT_ACTIVE) { - LOS_IntRestore(*intSave); + SCHEDULER_UNLOCK(*intSave); return LOS_ERRNO_SIGNAL_PEND_INTERR; } @@ -328,16 +333,19 @@ STATIC INLINE UINT32 SignalTimedWait(LosTaskCB *task, const sigset_t *set, UINT3 sigCB->sigStatus |= OS_SIGNAL_STATUS_WAIT; OsSchedTaskWait(&g_waitSignalList, timeout); - LOS_IntRestore(*intSave); + SCHEDULER_UNLOCK(*intSave); +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(OS_MP_CPU_ALL); +#endif LOS_Schedule(); - *intSave = LOS_IntLock(); + SCHEDULER_LOCK(*intSave); task->taskStatus &= ~OS_TASK_FLAG_SIGNAL; sigCB->sigStatus &= ~OS_SIGNAL_STATUS_WAIT; sigCB->sigWaitFlag = 0; if (task->taskStatus & OS_TASK_STATUS_TIMEOUT) { task->taskStatus &= ~OS_TASK_STATUS_TIMEOUT; - LOS_IntRestore(*intSave); + SCHEDULER_UNLOCK(*intSave); return LOS_ERRNO_SIGNAL_TIMEOUT; } sigNo = sigCB->sigInfo.si_signo; @@ -361,10 +369,10 @@ UINT32 LOS_SignalWait(const sigset_t *set, siginfo_t *info, UINT32 timeout) return LOS_ERRNO_SIGNAL_CAN_NOT_CALL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); sigCB = SignalCBInit(task); if (sigCB == NULL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_SIGNAL_NO_MEMORY; } @@ -376,7 +384,7 @@ UINT32 LOS_SignalWait(const sigset_t *set, siginfo_t *info, UINT32 timeout) } else { sigNo = SignalTimedWait(task, set, timeout, &intSave); if (sigNo > LOS_SIGNAL_SUPPORT_MAX) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return sigNo; } } @@ -384,7 +392,7 @@ UINT32 LOS_SignalWait(const sigset_t *set, siginfo_t *info, UINT32 timeout) if (info != NULL) { (VOID)memcpy_s(info, sizeof(siginfo_t), &sigCB->sigInfo, sizeof(siginfo_t)); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return sigNo; } @@ -408,25 +416,25 @@ UINT32 LOS_SignalSend(UINT32 taskID, INT32 sigNo) info.si_code = SI_USER; info.si_value.sival_ptr = NULL; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); task = OS_TCB_FROM_TID(taskID); sigCB = SignalCBInit(task); if (sigCB == NULL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_SIGNAL_NO_MEMORY; } if (!(sigCB->sigSetFlag & LOS_SIGNAL_MASK(sigNo))) { /* the signal has not been set */ - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_SIGNAL_NO_SET; } UINT32 ret = AddSigInfoToList(sigCB, &info); if (ret != LOS_OK) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_SIGNAL_NO_MEMORY; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); /* send signal to this thread */ SignalSend(task, sigNo); diff --git a/components/trace/Kconfig b/components/trace/Kconfig index 908c5c4b..8f5f3180 100644 --- a/components/trace/Kconfig +++ b/components/trace/Kconfig @@ -9,7 +9,7 @@ config TRACE_MSG_EXTEND depends on KERNEL_TRACE config TRACE_FRAME_CORE_MSG - bool "Record cpuid, hardware interrupt status, task lock status" + bool "Record cpuID, hardware interrupt status, task lock status" default n depends on TRACE_MSG_EXTEND diff --git a/components/trace/cnv/trace_cnv.c b/components/trace/cnv/trace_cnv.c index 9ac1948e..5e476960 100644 --- a/components/trace/cnv/trace_cnv.c +++ b/components/trace/cnv/trace_cnv.c @@ -169,8 +169,9 @@ STATIC VOID LOS_TraceTaskDelete(const LosTaskCB *taskCB) STATIC VOID LOS_TraceTaskSwitchedIn(VOID) { - LosTaskCB *newTask = g_losTask.newTask; - LosTaskCB *runTask = g_losTask.runTask; + INT32 cpuID = ArchCurrCpuid(); + LosTaskCB *newTask = g_losTask[cpuID].newTask; + LosTaskCB *runTask = g_losTask[cpuID].runTask; LOS_TRACE(TASK_SWITCH, newTask->taskID, runTask->priority, runTask->taskStatus, newTask->priority, newTask->taskStatus); } @@ -182,7 +183,8 @@ STATIC VOID LOS_TraceTaskResume(const LosTaskCB *taskCB) STATIC VOID LOS_TraceTaskSuspend(const LosTaskCB *taskCB) { - LOS_TRACE(TASK_SUSPEND, taskCB->taskID, taskCB->taskStatus, g_losTask.runTask->taskID); + INT32 cpuID = ArchCurrCpuid(); + LOS_TRACE(TASK_SUSPEND, taskCB->taskID, taskCB->taskStatus, g_losTask[cpuID].runTask->taskID); } STATIC VOID LOS_TraceIsrEnter(UINT32 hwiNum) diff --git a/kal/cmsis/cmsis_liteos2.c b/kal/cmsis/cmsis_liteos2.c index 8ed9bb2f..32f82fc9 100644 --- a/kal/cmsis/cmsis_liteos2.c +++ b/kal/cmsis/cmsis_liteos2.c @@ -31,6 +31,7 @@ #include "cmsis_os2.h" #include "kal.h" +#include "los_sched.h" #include "los_event.h" #include "los_membox.h" #include "los_memory.h" @@ -117,13 +118,15 @@ osStatus_t osKernelGetInfo(osVersion_t *version, char *id_buf, uint32_t id_size) osKernelState_t osKernelGetState(void) { - if (!g_taskScheduled) { + UINT32 cpuID = ArchCurrCpuid(); + + if (!OS_SCHEDULER_ACTIVE) { if (g_kernelState == osKernelReady) { return osKernelReady; } else { return osKernelInactive; } - } else if (g_losTaskLock > 0) { + } else if (g_losTaskLock[cpuID] > 0) { return osKernelLocked; } else { return osKernelRunning; @@ -149,17 +152,18 @@ osStatus_t osKernelStart(void) int32_t osKernelLock(void) { + UINT32 cpuID = ArchCurrCpuid(); int32_t lock; if (OS_INT_ACTIVE) { return (int32_t)osErrorISR; } - if (!g_taskScheduled) { + if (!OS_SCHEDULER_ACTIVE) { return (int32_t)osError; } - if (g_losTaskLock > 0) { + if (g_losTaskLock[cpuID] > 0) { lock = KERNEL_LOCKED; } else { LOS_TaskLock(); @@ -172,18 +176,21 @@ int32_t osKernelLock(void) int32_t osKernelUnlock(void) { int32_t lock; + UINT32 cpuID; + + cpuID = ArchCurrCpuid(); if (OS_INT_ACTIVE) { return (int32_t)osErrorISR; } - if (!g_taskScheduled) { + if (!OS_SCHEDULER_ACTIVE) { return (int32_t)osError; } - if (g_losTaskLock > 0) { + if (g_losTaskLock[cpuID] > 0) { LOS_TaskUnlock(); - if (g_losTaskLock != 0) { + if (g_losTaskLock[cpuID] != 0) { return (int32_t)osError; } lock = KERNEL_LOCKED; @@ -196,18 +203,20 @@ int32_t osKernelUnlock(void) int32_t osKernelRestoreLock(int32_t lock) { + UINT32 cpuID = ArchCurrCpuid(); + if (OS_INT_ACTIVE) { return (int32_t)osErrorISR; } - if (!g_taskScheduled) { + if (!OS_SCHEDULER_ACTIVE) { return (int32_t)osError; } switch (lock) { case KERNEL_UNLOCKED: LOS_TaskUnlock(); - if (g_losTaskLock != 0) { + if (g_losTaskLock[cpuID] != 0) { break; } return KERNEL_UNLOCKED; @@ -307,7 +316,8 @@ const char *osThreadGetName(osThreadId_t thread_id) osThreadId_t osThreadGetId(void) { - return (osThreadId_t)(g_losTask.runTask); + UINT32 cpuID = ArchCurrCpuid(); + return (osThreadId_t)(g_losTask[cpuID].runTask); } void *osThreadGetArgument(void) @@ -377,11 +387,11 @@ uint32_t osTaskStackWaterMarkGet(UINT32 taskID) return 0; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); pstTaskCB = OS_TCB_FROM_TID(taskID); if (OS_TASK_STATUS_UNUSED & (pstTaskCB->taskStatus)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return 0; } @@ -395,7 +405,7 @@ uint32_t osTaskStackWaterMarkGet(UINT32 taskID) count *= sizeof(UINT32); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return count; } @@ -749,6 +759,7 @@ osTimerId_t osTimerExtNew(osTimerFunc_t func, osTimerType_t type, void *argument osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks) { UINT32 ret; + UINT32 intSave; SWTMR_CTRL_S *pstSwtmr = NULL; if (OS_INT_ACTIVE) { return osErrorISR; @@ -757,11 +768,11 @@ osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks) return osErrorParameter; } - UINT32 intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); pstSwtmr = (SWTMR_CTRL_S *)timer_id; pstSwtmr->uwInterval = ticks; ret = LOS_SwtmrStart(pstSwtmr->usTimerID); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); if (ret == LOS_OK) { return osOK; } else if (ret == LOS_ERRNO_SWTMR_ID_INVALID) { @@ -900,11 +911,11 @@ uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags) return (uint32_t)osFlagsErrorParameter; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); rflags = pstEventCB->uwEventID; ret = LOS_EventClear(pstEventCB, ~flags); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); if (ret == LOS_OK) { return rflags; } else { @@ -922,9 +933,9 @@ uint32_t osEventFlagsGet(osEventFlagsId_t ef_id) return 0; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); rflags = pstEventCB->uwEventID; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return rflags; } @@ -985,11 +996,11 @@ osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id) if (OS_INT_ACTIVE) { return osErrorISR; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (LOS_EventDestroy(pstEventCB) != LOS_OK) { ret = osErrorParameter; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); if (LOS_MemFree(m_aucSysMem0, (void *)pstEventCB) != LOS_OK) { ret = osErrorParameter; @@ -1085,9 +1096,9 @@ osThreadId_t osMutexGetOwner(osMutexId_t mutex_id) return NULL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); pstTaskCB = ((LosMuxCB *)mutex_id)->owner; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return (osThreadId_t)pstTaskCB; } @@ -1196,14 +1207,14 @@ uint32_t osSemaphoreGetCount(osSemaphoreId_t semaphore_id) return 0; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (semCB->semStat == 0) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return 0; } count = semCB->semCount; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return (uint32_t)count; } @@ -1519,7 +1530,7 @@ void *osMemoryPoolAlloc(osMemoryPoolId_t mp_id, uint32_t timeout) return NULL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((mp->status & MEM_POOL_VALID) == MEM_POOL_VALID) { node = mp->poolInfo.stFreeList.pstNext; if (node != NULL) { @@ -1527,7 +1538,7 @@ void *osMemoryPoolAlloc(osMemoryPoolId_t mp_id, uint32_t timeout) mp->poolInfo.uwBlkCnt++; } } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return node; } @@ -1544,15 +1555,15 @@ osStatus_t osMemoryPoolFree(osMemoryPoolId_t mp_id, void *block) return osErrorParameter; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((mp->status & MEM_POOL_VALID) != MEM_POOL_VALID) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return osErrorResource; } if (((UINTPTR)block < (UINTPTR)mp->poolBase) || ((UINTPTR)block >= ((UINTPTR)mp->poolBase + (UINTPTR)mp->poolSize))) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return osErrorParameter; } @@ -1561,7 +1572,7 @@ osStatus_t osMemoryPoolFree(osMemoryPoolId_t mp_id, void *block) mp->poolInfo.stFreeList.pstNext = node; node->pstNext = nodeTmp; mp->poolInfo.uwBlkCnt--; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return osOK; } @@ -1579,9 +1590,9 @@ osStatus_t osMemoryPoolDelete(osMemoryPoolId_t mp_id) return osErrorParameter; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((mp->status & MEM_POOL_VALID) != MEM_POOL_VALID) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return osErrorResource; } @@ -1596,7 +1607,7 @@ osStatus_t osMemoryPoolDelete(osMemoryPoolId_t mp_id) if (mp->status & MP_ALLOC) { (void)LOS_MemFree(OS_SYS_MEM_ADDR, mp); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return osOK; } @@ -1611,13 +1622,13 @@ uint32_t osMemoryPoolGetCapacity(osMemoryPoolId_t mp_id) return 0; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((mp->status & MEM_POOL_VALID) != MEM_POOL_VALID) { num = 0; } else { num = mp->poolInfo.uwBlkNum; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return num; } @@ -1632,13 +1643,13 @@ uint32_t osMemoryPoolGetBlockSize(osMemoryPoolId_t mp_id) return 0; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((mp->status & MEM_POOL_VALID) != MEM_POOL_VALID) { size = 0; } else { size = mp->poolInfo.uwBlkSize; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return size; } @@ -1653,13 +1664,13 @@ uint32_t osMemoryPoolGetCount(osMemoryPoolId_t mp_id) return 0; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((mp->status & MEM_POOL_VALID) != MEM_POOL_VALID) { count = 0; } else { count = mp->poolInfo.uwBlkCnt; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return count; } @@ -1674,13 +1685,13 @@ uint32_t osMemoryPoolGetSpace(osMemoryPoolId_t mp_id) return 0; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((mp->status & MEM_POOL_VALID) != MEM_POOL_VALID) { space = 0; } else { space = mp->poolInfo.uwBlkNum - mp->poolInfo.uwBlkCnt; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return space; @@ -1700,11 +1711,11 @@ const char *osMemoryPoolGetName(osMemoryPoolId_t mp_id) return NULL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((mp->status & MEM_POOL_VALID) == MEM_POOL_VALID) { p = mp->name; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return p; } @@ -1739,12 +1750,13 @@ uint32_t osThreadFlagsClear(uint32_t flags) UINT32 saveFlags; LosTaskCB *runTask = NULL; EVENT_CB_S *eventCB = NULL; + UINT32 cpuID = ArchCurrCpuid(); if (OS_INT_ACTIVE) { return (uint32_t)osFlagsErrorUnknown; } - runTask = g_losTask.runTask; + runTask = g_losTask[cpuID].runTask; eventCB = &(runTask->event); saveFlags = eventCB->uwEventID; @@ -1760,12 +1772,13 @@ uint32_t osThreadFlagsGet(void) { LosTaskCB *runTask = NULL; EVENT_CB_S *eventCB = NULL; + UINT32 cpuID = ArchCurrCpuid(); if (OS_INT_ACTIVE) { return (uint32_t)osFlagsErrorUnknown; } - runTask = g_losTask.runTask; + runTask = g_losTask[cpuID].runTask; eventCB = &(runTask->event); return (uint32_t)(eventCB->uwEventID); @@ -1777,6 +1790,7 @@ uint32_t osThreadFlagsWait(uint32_t flags, uint32_t options, uint32_t timeout) UINT32 mode = 0; LosTaskCB *runTask = NULL; EVENT_CB_S *eventCB = NULL; + UINT32 cpuID = ArchCurrCpuid(); if (OS_INT_ACTIVE) { return (uint32_t)osFlagsErrorUnknown; @@ -1798,7 +1812,7 @@ uint32_t osThreadFlagsWait(uint32_t flags, uint32_t options, uint32_t timeout) mode |= LOS_WAITMODE_CLR; } - runTask = g_losTask.runTask; + runTask = g_losTask[cpuID].runTask; eventCB = &(runTask->event); ret = LOS_EventRead(eventCB, (UINT32)flags, mode, (UINT32)timeout); diff --git a/kal/posix/src/poll.c b/kal/posix/src/poll.c index 1a25e86c..6c7a3bf7 100644 --- a/kal/posix/src/poll.c +++ b/kal/posix/src/poll.c @@ -36,6 +36,15 @@ #include "los_interrupt.h" #include "los_memory.h" +#if (LOSCFG_KERNEL_SMP == 1) +LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_pollSpin); +#define POLL_LOCK(state) LOS_SpinLockSave(&g_pollSpin, &(state)) +#define POLL_UNLOCK(state) LOS_SpinUnlockRestore(&g_pollSpin, (state)) +#else +#define POLL_LOCK(state) (state) = LOS_IntLock() +#define POLL_UNLOCK(state) LOS_IntRestore(state) +#endif + VOID PollWaitQueueInit(struct PollWaitQueue *waitQueue) { if (waitQueue == NULL) { @@ -54,9 +63,9 @@ STATIC VOID DestroyPollWait(struct PollTable *table) UINT32 intSave; struct PollWaitNode *waitNode = table->node; - intSave = LOS_IntLock(); + POLL_LOCK(intSave); LOS_ListDelete(&waitNode->node); - LOS_IntRestore(intSave); + POLL_UNLOCK(intSave); (VOID)LOS_MemFree(OS_SYS_MEM_ADDR, waitNode); if (LOS_SemDelete(table->sem) != LOS_OK) { @@ -72,11 +81,11 @@ STATIC VOID AddPollWaitQueue(struct PollWaitQueue *waitQueue, struct PollTable * return; } - intSave = LOS_IntLock(); + POLL_LOCK(intSave); waitNode->table = table; LOS_ListAdd(&waitQueue->queue, &waitNode->node); table->node = waitNode; - LOS_IntRestore(intSave); + POLL_UNLOCK(intSave); } STATIC INT32 WaitSemTime(struct PollTable *table, UINT32 timeout) @@ -132,7 +141,7 @@ VOID PollNotify(struct PollWaitQueue *waitQueue, PollEvent event) return; } - intSave = LOS_IntLock(); + POLL_LOCK(intSave); LOS_DL_LIST_FOR_EACH_ENTRY(waitNode, &waitQueue->queue, struct PollWaitNode, node) { if (!event || (event & waitNode->table->event)) { if (LOS_SemPost(waitNode->table->sem) != LOS_OK) { @@ -140,7 +149,7 @@ VOID PollNotify(struct PollWaitQueue *waitQueue, PollEvent event) } } } - LOS_IntRestore(intSave); + POLL_UNLOCK(intSave); } VOID PollWait(struct PollWaitQueue *waitQueue, struct PollTable *table) diff --git a/kal/posix/src/pthread.c b/kal/posix/src/pthread.c index 695eb1ed..a0383778 100644 --- a/kal/posix/src/pthread.c +++ b/kal/posix/src/pthread.c @@ -181,13 +181,13 @@ static int CheckForCancel(void) } tcb = OS_TCB_FROM_TID((UINT32)thread); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); PthreadData *pthreadData = (PthreadData *)(UINTPTR)tcb->arg; if ((pthreadData->canceled) && (pthreadData->cancelState == PTHREAD_CANCEL_ENABLE)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return 1; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return 0; } @@ -215,13 +215,13 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, } PthreadData *pthreadData = (PthreadData *)taskInitParam.uwArg; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (g_pthreadListHead.pstNext == NULL) { LOS_ListInit(&g_pthreadListHead); } LOS_ListAdd(&g_pthreadListHead, &pthreadData->threadList); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); *thread = (pthread_t)taskID; @@ -282,10 +282,10 @@ int pthread_once(pthread_once_t *onceControl, void (*initRoutine)(void)) if ((onceControl == NULL) || (initRoutine == NULL)) { return EINVAL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); old = *onceControl; *onceControl = 1; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); if (!old) { initRoutine(); @@ -315,10 +315,10 @@ int pthread_setcancelstate(int state, int *oldState) } tcb = OS_TCB_FROM_TID((UINT32)thread); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); pthreadData = (PthreadData *)(UINTPTR)tcb->arg; if (pthreadData == NULL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return EINVAL; } @@ -326,7 +326,7 @@ int pthread_setcancelstate(int state, int *oldState) *oldState = pthreadData->cancelState; } pthreadData->cancelState = (UINT8)state; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return 0; } @@ -348,10 +348,10 @@ int pthread_setcanceltype(int type, int *oldType) } tcb = OS_TCB_FROM_TID((UINT32)thread); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); pthreadData = (PthreadData *)(UINTPTR)tcb->arg; if (pthreadData == NULL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return EINVAL; } @@ -360,7 +360,7 @@ int pthread_setcanceltype(int type, int *oldType) } pthreadData->cancelType = (UINT8)type; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return 0; } @@ -424,7 +424,7 @@ int pthread_cancel(pthread_t thread) PRINT_ERR("[%s:%d] This task %lu is not a posix thread!!!\n", __FUNCTION__, __LINE__, thread); return EINVAL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); tcb = OS_TCB_FROM_TID((UINT32)thread); pthreadData = (PthreadData *)(UINTPTR)tcb->arg; pthreadData->canceled = 1; @@ -436,11 +436,11 @@ int pthread_cancel(pthread_t thread) * We also release the thread out of any current wait to make it wake up. */ if (DoPthreadCancel(tcb) == LOS_NOK) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return ESRCH; } } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return 0; } @@ -527,10 +527,10 @@ void pthread_exit(void *retVal) PthreadExitKeyDtor(pthreadData); } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); LOS_ListDelete(&pthreadData->threadList); tcb->taskName = PTHREAD_DEFAULT_NAME; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); free(pthreadData); (void)LOS_TaskDelete(tcb->taskID); EXIT: @@ -559,19 +559,19 @@ int pthread_setname_np(pthread_t thread, const char *name) } taskCB = OS_TCB_FROM_TID((UINT32)thread); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (taskCB->taskStatus & OS_TASK_STATUS_EXIT) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return EINVAL; } if (taskCB->taskEntry == PthreadEntry) { (void)strcpy_s(taskName, PTHREAD_NAMELEN, name); } else { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return EINVAL; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return 0; } @@ -605,22 +605,22 @@ static void PthreadExitKeyDtor(PthreadData *pthreadData) PthreadKey *keys = NULL; unsigned int intSave; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); for (unsigned int count = 0; count < PTHREAD_KEYS_MAX; count++) { keys = &g_pthreadKeyData[count]; if (keys->flag == PTHREAD_KEY_UNUSED) { continue; } PthreadKeyDtor dtor = keys->destructor; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); if ((dtor != NULL) && (pthreadData->key[count] != 0)) { dtor((void *)pthreadData->key[count]); } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); free((void *)pthreadData->key); } @@ -641,9 +641,9 @@ int pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) return EINVAL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (g_pthreadkeyCount >= PTHREAD_KEYS_MAX) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return EAGAIN; } @@ -658,7 +658,7 @@ int pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) keys->destructor = dtor; keys->flag = PTHREAD_KEY_USED; g_pthreadkeyCount++; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); *k = count; @@ -679,9 +679,9 @@ int pthread_key_delete(pthread_key_t k) return EINVAL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((g_pthreadkeyCount == 0) || (g_pthreadKeyData[k].flag == PTHREAD_KEY_UNUSED)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return EAGAIN; } @@ -700,7 +700,7 @@ int pthread_key_delete(pthread_key_t k) g_pthreadKeyData[k].destructor = NULL; g_pthreadKeyData[k].flag = PTHREAD_KEY_UNUSED; g_pthreadkeyCount--; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return 0; } @@ -730,9 +730,9 @@ int pthread_setspecific(pthread_key_t k, const void *x) (void)memset_s(key, sizeof(uintptr_t) * PTHREAD_KEYS_MAX, 0, sizeof(uintptr_t) * PTHREAD_KEYS_MAX); } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (g_pthreadKeyData[k].flag == PTHREAD_KEY_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); free(key); return EAGAIN; } @@ -742,7 +742,7 @@ int pthread_setspecific(pthread_key_t k, const void *x) } pthreadData->key[k] = (uintptr_t)x; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return 0; } @@ -763,14 +763,14 @@ void *pthread_getspecific(pthread_key_t k) LosTaskCB *taskCB = OS_TCB_FROM_TID((UINT32)self); PthreadData *pthreadData = (PthreadData *)taskCB->arg; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((g_pthreadKeyData[k].flag == PTHREAD_KEY_UNUSED) || (pthreadData->key == NULL)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return NULL; } key = (void *)pthreadData->key[k]; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return key; } diff --git a/kal/posix/src/pthread_cond.c b/kal/posix/src/pthread_cond.c index 508ba7dc..7fbe8590 100644 --- a/kal/posix/src/pthread_cond.c +++ b/kal/posix/src/pthread_cond.c @@ -269,13 +269,14 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, INT32 ret; UINT64 absTicks; LosMuxCB *muxPosted = NULL; + UINT32 cpuID = ArchCurrCpuid(); pthread_testcancel(); if ((cond == NULL) || (mutex == NULL) || (ts == NULL) || (mutex->magic != _MUX_MAGIC)) { return EINVAL; } muxPosted = GET_MUX(mutex->handle); - if ((mutex->stAttr.type == PTHREAD_MUTEX_ERRORCHECK) && (g_losTask.runTask != muxPosted->owner)) { + if ((mutex->stAttr.type == PTHREAD_MUTEX_ERRORCHECK) && (g_losTask[cpuID].runTask != muxPosted->owner)) { return EPERM; } diff --git a/kal/posix/src/pthread_mutex.c b/kal/posix/src/pthread_mutex.c index 312b2c14..6744084c 100644 --- a/kal/posix/src/pthread_mutex.c +++ b/kal/posix/src/pthread_mutex.c @@ -218,34 +218,35 @@ STATIC UINT32 MuxPendForPosix(pthread_mutex_t *mutex, UINT32 timeout) UINT32 retErr; LosTaskCB *runningTask = NULL; UINT32 muxHandle = mutex->handle; + UINT32 cpuID = ArchCurrCpuid(); muxPended = GET_MUX(muxHandle); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (muxPended->muxStat == OS_MUX_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID); } - runningTask = (LosTaskCB *)g_losTask.runTask; + runningTask = (LosTaskCB *)g_losTask[cpuID].runTask; if (muxPended->muxCount == 0) { muxPended->muxCount++; muxPended->owner = runningTask; muxPended->priority = runningTask->priority; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended, timeout); return LOS_OK; } if ((muxPended->owner == runningTask) && (mutex->stAttr.type == PTHREAD_MUTEX_RECURSIVE)) { muxPended->muxCount++; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended, timeout); return LOS_OK; } if (!timeout) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_RETURN_ERROR(LOS_ERRNO_MUX_UNAVAILABLE); } @@ -257,19 +258,19 @@ STATIC UINT32 MuxPendForPosix(pthread_mutex_t *mutex, UINT32 timeout) OsSchedTaskWait(&muxPended->muxList, timeout); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended, timeout); LOS_Schedule(); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (runningTask->taskStatus & OS_TASK_STATUS_TIMEOUT) { runningTask->taskStatus &= (~OS_TASK_STATUS_TIMEOUT); retErr = LOS_ERRNO_MUX_TIMEOUT; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_RETURN_ERROR(retErr); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -280,23 +281,24 @@ STATIC UINT32 MuxPostForPosix(pthread_mutex_t *mutex) LosTaskCB *resumedTask = NULL; LosTaskCB *runningTask = NULL; UINT32 muxHandle = mutex->handle; + UINT32 cpuID = ArchCurrCpuid(); muxPosted = GET_MUX(muxHandle); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (muxPosted->muxStat == OS_MUX_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID); } - runningTask = (LosTaskCB *)g_losTask.runTask; + runningTask = (LosTaskCB *)g_losTask[cpuID].runTask; if ((muxPosted->muxCount == 0) || (muxPosted->owner != runningTask)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID); } if ((--(muxPosted->muxCount) != 0) && (mutex->stAttr.type == PTHREAD_MUTEX_RECURSIVE)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_MUX_POST, muxPosted); return LOS_OK; } @@ -315,12 +317,15 @@ STATIC UINT32 MuxPostForPosix(pthread_mutex_t *mutex) OsSchedTaskWake(resumedTask); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_MUX_POST, muxPosted); +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(OS_MP_CPU_ALL); +#endif LOS_Schedule(); } else { muxPosted->owner = NULL; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); } return LOS_OK; diff --git a/kal/posix/src/time.c b/kal/posix/src/time.c index 07bf4497..e6d8de06 100644 --- a/kal/posix/src/time.c +++ b/kal/posix/src/time.c @@ -79,6 +79,15 @@ STATIC struct RtcTimeHook g_rtcTimeFunc; STATIC UINT64 g_rtcTimeBase = 0; STATIC UINT64 g_systickBase = 0; +#if (LOSCFG_KERNEL_SMP == 1) +LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_timeSpin); +#define TIME_LOCK(state) LOS_SpinLockSave(&g_timeSpin, &(state)) +#define TIME_UNLOCK(state) LOS_SpinUnlockRestore(&g_timeSpin, (state)) +#else +#define TIME_LOCK(state) (state) = LOS_IntLock() +#define TIME_UNLOCK(state) LOS_IntRestore(state) +#endif + VOID LOS_RtcHookRegister(struct RtcTimeHook *cfg) { if (cfg == NULL) { @@ -211,13 +220,13 @@ int timer_settime(timer_t timerID, int flags, return -1; } - intSave = LOS_IntLock(); + TIME_LOCK(intSave); swtmr = OS_SWT_FROM_SID(swtmrID); swtmr->ucMode = (interval ? LOS_SWTMR_MODE_PERIOD : LOS_SWTMR_MODE_NO_SELFDELETE); swtmr->uwInterval = (interval ? interval : expiry); swtmr->ucOverrun = 0; - LOS_IntRestore(intSave); + TIME_UNLOCK(intSave); if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0)) { /* @@ -290,11 +299,11 @@ STATIC VOID OsGetRealTime(struct timespec *realTime) UINT32 intSave; struct timespec hwTime = {0}; OsGetHwTime(&hwTime); - intSave = LOS_IntLock(); + TIME_LOCK(intSave); realTime->tv_nsec = hwTime.tv_nsec + g_accDeltaFromSet.tv_nsec; realTime->tv_sec = hwTime.tv_sec + g_accDeltaFromSet.tv_sec + (realTime->tv_nsec >= OS_SYS_NS_PER_SECOND); realTime->tv_nsec %= OS_SYS_NS_PER_SECOND; - LOS_IntRestore(intSave); + TIME_UNLOCK(intSave); } STATIC VOID OsSetRealTime(const struct timespec *realTime) @@ -302,11 +311,11 @@ STATIC VOID OsSetRealTime(const struct timespec *realTime) UINT32 intSave; struct timespec hwTime = {0}; OsGetHwTime(&hwTime); - intSave = LOS_IntLock(); + TIME_LOCK(intSave); g_accDeltaFromSet.tv_nsec = realTime->tv_nsec - hwTime.tv_nsec; g_accDeltaFromSet.tv_sec = realTime->tv_sec - hwTime.tv_sec - (g_accDeltaFromSet.tv_nsec < 0); g_accDeltaFromSet.tv_nsec = (g_accDeltaFromSet.tv_nsec + OS_SYS_NS_PER_SECOND) % OS_SYS_NS_PER_SECOND; - LOS_IntRestore(intSave); + TIME_UNLOCK(intSave); } int clock_settime(clockid_t clockID, const struct timespec *tp) diff --git a/kernel/BUILD.gn b/kernel/BUILD.gn index 0cd77d50..2f4ee630 100644 --- a/kernel/BUILD.gn +++ b/kernel/BUILD.gn @@ -45,6 +45,11 @@ kernel_module(module_name) { "src/mm/los_membox.c", "src/mm/los_memory.c", ] + + if (defined(LOSCFG_KERNEL_SMP)) { + sources += [ "src/los_mp.c" ] + } + configs += [ "$LITEOSTOPDIR:warn_config" ] } diff --git a/kernel/include/los_config.h b/kernel/include/los_config.h index db3a5170..ed3c0eb8 100644 --- a/kernel/include/los_config.h +++ b/kernel/include/los_config.h @@ -684,9 +684,23 @@ extern UINT8 *m_aucSysMem0; * Configuration item to set shell stack size. */ #ifndef LOSCFG_SHELL_STACK_SIZE -#define LOSCFG_SHELL_STACK_SIZE 0x1000 +#define LOSCFG_SHELL_STACK_SIZE 0x1000 #endif +/** + * @ingroup los_config + * Configuration item to set cpu core number. + */ +#ifndef LOSCFG_KERNEL_CORE_NUM +#define LOSCFG_KERNEL_CORE_NUM 1 +#endif + +/** + * @ingroup los_config + * Configuration item to set cpu mask. + */ +#define LOSCFG_KERNEL_CPU_MASK ((1 << LOSCFG_KERNEL_CORE_NUM) - 1) + #ifdef __cplusplus #if __cplusplus } diff --git a/kernel/include/los_cpu.h b/kernel/include/los_cpu.h new file mode 100644 index 00000000..42a7dfa4 --- /dev/null +++ b/kernel/include/los_cpu.h @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _LOS_CPU_H +#define _LOS_CPU_H + +#include "los_config.h" +#include "los_compiler.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#ifdef LOSCFG_KERNEL_SMP + +UINT32 OsCpuLock(VOID); +VOID OsCpuUnlock(UINT32 intSave); + +#endif + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/kernel/include/los_mp.h b/kernel/include/los_mp.h new file mode 100644 index 00000000..d7302aea --- /dev/null +++ b/kernel/include/los_mp.h @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _LOS_MP_H +#define _LOS_MP_H + +#include "los_core.h" +#ifdef LOSCFG_KERNEL_SMP +#include "los_spinlock.h" +#endif + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +VOID LOS_SmpOpsSet(struct SmpOps *ops); +VOID OsSmpInit(VOID); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_SCHED_H */ diff --git a/kernel/include/los_sched.h b/kernel/include/los_sched.h index 4dbb3861..cdc7704d 100644 --- a/kernel/include/los_sched.h +++ b/kernel/include/los_sched.h @@ -36,6 +36,8 @@ #include "los_interrupt.h" #include "los_tick.h" #include "los_sortlink.h" +#include "los_core.h" +#include "los_spinlock.h" #ifdef __cplusplus #if __cplusplus @@ -46,9 +48,35 @@ extern "C" { #define OS_SCHED_MINI_PERIOD (g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI) #define OS_SCHED_MAX_RESPONSE_TIME OS_SORT_LINK_UINT64_MAX +#define OS_MP_CPU_ALL LOSCFG_KERNEL_CPU_MASK + +#define BIT(nr) (1UL << (nr)) +#define LOS_MP_IPI_SCHEDULE BIT(0) + extern UINT32 g_taskScheduled; +#define OS_SCHEDULER_ACTIVE (g_taskScheduled & (1U << ArchCurrCpuid())) +#define OS_SCHEDULER_ALL_ACTIVE (g_taskScheduled == LOSCFG_KERNEL_CPU_MASK) + +/* + * Schedule flag, one bit represents one core. + * This flag is used to prevent kernel scheduling before OSStartToRun. + */ +#define OS_SCHEDULER_SET(cpuID) do { \ + g_taskScheduled |= (1U << (cpuID)); \ +} while (0); + +#define OS_SCHEDULER_CLR(cpuID) do { \ + g_taskScheduled &= ~(1U << (cpuID)); \ +} while (0); + typedef BOOL (*SchedScan)(VOID); +typedef struct { + UINT16 tickIntLock; + UINT64 responseTime; + UINT32 responseID; +} SchedRunqueue; + VOID OsSchedResetSchedResponseTime(UINT64 responseTime); VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask); @@ -98,7 +126,7 @@ STATIC INLINE UINT64 OsGetCurrSchedTimeCycle(VOID) STATIC INLINE BOOL OsCheckKernelRunning(VOID) { - return (g_taskScheduled && LOS_CHECK_SCHEDULE); + return (OS_SCHEDULER_ACTIVE && LOS_CHECK_SCHEDULE); } /** @@ -155,6 +183,8 @@ extern VOID LOS_SchedTickHandler(VOID); */ extern VOID LOS_Schedule(VOID); +extern VOID LOS_MpSchedule(UINT32 target); + #ifdef __cplusplus #if __cplusplus } diff --git a/kernel/include/los_task.h b/kernel/include/los_task.h index e9424644..1f74d06b 100644 --- a/kernel/include/los_task.h +++ b/kernel/include/los_task.h @@ -42,6 +42,8 @@ #include "los_event.h" #include "los_tick.h" #include "los_sortlink.h" +#include "los_core.h" +#include "los_spinlock.h" #ifdef __cplusplus #if __cplusplus @@ -49,6 +51,16 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ +/* scheduler lock */ +extern Spinlock g_taskSpin; +#define SCHEDULER_LOCK(state) LOS_SpinLockSave(&g_taskSpin, &(state)) +#define SCHEDULER_UNLOCK(state) LOS_SpinUnlockRestore(&g_taskSpin, state) + +#define CPUID_TO_AFFI_MASK(cpuID) (0x1u << (cpuID)) + +/* default and non-running task's ownership id */ +#define OS_TASK_INVALID_CPUID 0xFFFF + /** * @ingroup los_task * Task error code: Insufficient memory for task creation. @@ -440,6 +452,16 @@ extern "C" { */ #define LOS_ERRNO_TSK_PROCESS_SIGNAL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x29) +/** + * @ingroup los_task + * Task error code: The cpu affinity mask is incorrect. + * + * Value: 0x0200022a + * + * Solution: Please set the correct cpu affinity mask. + */ +#define LOS_ERRNO_TSK_CPU_AFFINITY_MASK_ERR LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x2a) + /** * @ingroup los_task * Define the type of the task entry function. @@ -460,6 +482,9 @@ typedef struct tagTskInitParam { UINTPTR stackAddr; /**< Task stack memory */ UINT32 uwStackSize; /**< Task stack size */ CHAR *pcName; /**< Task name */ +#ifdef LOSCFG_KERNEL_SMP + UINT32 usCpuAffiMask; /**< Task cpu affinity */ +#endif UINT32 uwResved; /**< Reserved */ } TSK_INIT_PARAM_S; @@ -1503,6 +1528,10 @@ typedef struct { #ifdef LOSCFG_TASK_STRUCT_EXTENSION LOSCFG_TASK_STRUCT_EXTENSION; /**< Task extension field */ #endif +#ifdef LOSCFG_KERNEL_SMP + UINT32 cpuAffiMask; /**< CPU affinity mask, support up to 32 cores */ + UINT16 currCpu; /**< CPU core number of this task is running on */ +#endif } LosTaskCB; STATIC INLINE BOOL OsTaskIsExit(const LosTaskCB *taskCB) @@ -1552,20 +1581,20 @@ typedef struct { extern TaskSwitchInfo g_taskSwitchInfo; #endif -extern LosTask g_losTask; +extern LosTask g_losTask[LOSCFG_KERNEL_CORE_NUM]; /** * @ingroup los_task * Task lock flag. * */ -extern UINT16 g_losTaskLock; +extern UINT16 g_losTaskLock[LOSCFG_KERNEL_CORE_NUM]; /* * * @ingroup los_hw * Check task schedule. */ -#define LOS_CHECK_SCHEDULE (!g_losTaskLock) +#define LOS_CHECK_SCHEDULE (!g_losTaskLock[ArchCurrCpuid()]) /** * @ingroup los_task @@ -1579,7 +1608,7 @@ extern UINT32 g_taskMaxNum; * Idle task ID. * */ -extern UINT32 g_idleTaskID; +extern UINT32 g_idleTaskID[LOSCFG_KERNEL_CORE_NUM]; /** * @ingroup los_task @@ -1644,14 +1673,36 @@ extern UINT32 OsTaskInit(VOID); *
  • None.
  • * * - * @param None. + * @param cpuID [IN] Type #UINT32 current cpu id. * * @retval UINT32 Create result. * @par Dependency: *
    • los_task.h: the header file that contains the API declaration.
    * @see */ -extern UINT32 OsIdleTaskCreate(VOID); +extern UINT32 OsIdleTaskCreate(UINT32 cpuID); + +/** + * @ingroup los_task + * @brief Check task id is idle task. + * + * @par Description: + * This API is used to check task id is idle task. + * + * @attention + *
      + *
    • None.
    • + *
    + * + * @param taskID [IN] Type #UINT32 task id. + * + * @retval #TRUE Tasks id is idle task. + * @retval #FALSE Tasks id is not idle task. + * @par Dependency: + *
    • los_task.h: the header file that contains the API declaration.
    + * @see + */ +extern BOOL OsIsIdleTask(UINT32 taskID); /** * @ingroup los_task @@ -1779,13 +1830,59 @@ extern UINT8 *OsConvertTskStatus(UINT16 taskStatus); */ extern UINT32 OsGetAllTskInfo(VOID); +/** + * @ingroup los_task + * @brief Set the affinity mask of the task scheduling cpu. + * + * @par Description: + * This API is used to set the affinity mask of the task scheduling cpu. + * + * @attention + *
      + *
    • If any low LOSCFG_KERNEL_CORE_NUM bit of the mask is not set, an error is reported.
    • + *
    + * + * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation. + * @param cpuAffiMask [IN] Type #UINT32 The scheduling cpu mask.The low to high bit of the mask corresponds to + * the cpu number, the high bit that exceeding the CPU number is ignored. + * + * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid task ID. + * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created. + * @retval #LOS_ERRNO_TSK_CPU_AFFINITY_MASK_ERR The task cpu affinity mask is incorrect. + * @retval #LOS_OK The task cpu affinity mask is successfully set. + * @par Dependency: + *
    • los_task.h: the header file that contains the API declaration.
    + * @see LOS_TaskCpuAffiGet + */ +extern UINT32 LOS_TaskCpuAffiSet(UINT32 taskID, UINT16 cpuAffiMask); + +/** + * @ingroup los_task + * @brief Get the affinity mask of the task scheduling cpu. + * + * @par Description: + * This API is used to get the affinity mask of the task scheduling cpu. + * + * @attention None. + * + * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation. + * + * @retval #0 The cpu affinity mask fails to be obtained. + * @retval #UINT16 The scheduling cpu mask. The low to high bit of the mask corresponds to the cpu number. + * @par Dependency: + *
    • los_task.h: the header file that contains the API declaration.
    + * @see LOS_TaskCpuAffiSet + */ +UINT32 LOS_TaskCpuAffiGet(UINT32 taskID); + extern VOID *OsTskUserStackInit(VOID* stackPtr, VOID* userSP, UINT32 userStackSize); extern UINT32 OsPmEnterHandlerSet(VOID (*func)(VOID)); STATIC INLINE LosTaskCB *OsCurrTaskGet(VOID) { - return g_losTask.runTask; + UINT32 cpuID = ArchCurrCpuid(); + return g_losTask[cpuID].runTask; } extern VOID LOS_TaskResRecycle(VOID); diff --git a/kernel/src/los_event.c b/kernel/src/los_event.c index df4c4a42..48ab08ef 100644 --- a/kernel/src/los_event.c +++ b/kernel/src/los_event.c @@ -55,7 +55,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventID, UINT32 eventMask, UINT32 if (eventID == NULL) { return LOS_ERRNO_EVENT_PTR_NULL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (mode & LOS_WAITMODE_OR) { if ((*eventID & eventMask) != 0) { ret = *eventID & eventMask; @@ -68,7 +68,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventID, UINT32 eventMask, UINT32 if (ret && (mode & LOS_WAITMODE_CLR)) { *eventID = *eventID & ~(ret); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return ret; } @@ -99,6 +99,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UIN UINT32 ret; UINT32 intSave; LosTaskCB *runTsk = NULL; + UINT32 cpuId = ArchCurrCpuid(); ret = OsEventReadParamCheck(eventCB, eventMask, mode); if (ret != LOS_OK) { @@ -108,40 +109,41 @@ LITE_OS_SEC_TEXT UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UIN if (OS_INT_ACTIVE) { return LOS_ERRNO_EVENT_READ_IN_INTERRUPT; } - if (g_losTask.runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) { + if (g_losTask[cpuId].runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) { return LOS_ERRNO_EVENT_READ_IN_SYSTEM_TASK; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); ret = LOS_EventPoll(&(eventCB->uwEventID), eventMask, mode); OsHookCall(LOS_HOOK_TYPE_EVENT_READ, eventCB, eventMask, mode, timeOut); if (ret == 0) { if (timeOut == 0) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return ret; } - if (g_losTaskLock) { - LOS_IntRestore(intSave); + if (g_losTaskLock[cpuId]) { + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_EVENT_READ_IN_LOCK; } - runTsk = g_losTask.runTask; + + runTsk = g_losTask[cpuId].runTask; runTsk->eventMask = eventMask; runTsk->eventMode = mode; OsSchedTaskWait(&eventCB->stEventList, timeOut); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); LOS_Schedule(); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (runTsk->taskStatus & OS_TASK_STATUS_TIMEOUT) { runTsk->taskStatus &= ~OS_TASK_STATUS_TIMEOUT; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_EVENT_READ_TIMEOUT; } ret = LOS_EventPoll(&eventCB->uwEventID, eventMask, mode); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return ret; } @@ -160,7 +162,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events) if (events & LOS_ERRTYPE_ERROR) { return LOS_ERRNO_EVENT_SETBIT_INVALID; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); OsHookCall(LOS_HOOK_TYPE_EVENT_WRITE, eventCB, events); eventCB->uwEventID |= events; if (!LOS_ListEmpty(&eventCB->stEventList)) { @@ -179,13 +181,16 @@ LITE_OS_SEC_TEXT UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events) } if (exitFlag == 1) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(OS_MP_CPU_ALL); +#endif LOS_Schedule(); return LOS_OK; } } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -195,15 +200,15 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB) if (eventCB == NULL) { return LOS_ERRNO_EVENT_PTR_NULL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (!LOS_ListEmpty(&eventCB->stEventList)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_EVENT_SHOULD_NOT_DESTROYED; } - eventCB->stEventList.pstNext = (LOS_DL_LIST *)NULL; - eventCB->stEventList.pstPrev = (LOS_DL_LIST *)NULL; - LOS_IntRestore(intSave); + eventCB->uwEventID = 0; + LOS_ListDelInit(&eventCB->stEventList); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_EVENT_DESTROY, eventCB); return LOS_OK; } @@ -215,8 +220,8 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 eventMa return LOS_ERRNO_EVENT_PTR_NULL; } OsHookCall(LOS_HOOK_TYPE_EVENT_CLEAR, eventCB, eventMask); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); eventCB->uwEventID &= eventMask; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } diff --git a/kernel/src/los_init.c b/kernel/src/los_init.c index e5ed4b32..ec4e6827 100644 --- a/kernel/src/los_init.c +++ b/kernel/src/los_init.c @@ -42,6 +42,10 @@ #include "los_interrupt.h" #endif +#if (LOSCFG_KERNEL_SMP == 1) +#include "los_mp.h" +#endif + #if (LOSCFG_BASE_CORE_SWTMR == 1) #include "los_swtmr.h" #endif @@ -153,6 +157,10 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID) ArchInit(); +#ifdef LOSCFG_KERNEL_SMP + OsSmpInit(); +#endif + ret = OsTickTimerInit(); if (ret != LOS_OK) { PRINT_ERR("OsTickTimerInit error! 0x%x\n", ret); @@ -223,7 +231,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID) } #endif - ret = OsIdleTaskCreate(); + ret = OsIdleTaskCreate(0); if (ret != LOS_OK) { return ret; } diff --git a/kernel/src/los_mp.c b/kernel/src/los_mp.c new file mode 100644 index 00000000..72fdac11 --- /dev/null +++ b/kernel/src/los_mp.c @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "los_mp.h" +#include "los_config.h" +#include "los_debug.h" + +#ifdef LOSCFG_KERNEL_SMP +STATIC struct SmpOps *g_smpOps = NULL; + +STATIC VOID OsSmpSecondaryInit(VOID) +{ + UINT32 cpuID = ArchCurrCpuid(); + + OsIdleTaskCreate(cpuID); + + OsSchedStart(); +} + +VOID LOS_SmpOpsSet(struct SmpOps *ops) +{ + g_smpOps = ops; +} + +LITE_OS_SEC_TEXT_INIT VOID OsSmpInit(VOID) +{ + UINT32 cpuID = 1; + + ArchIntIpiEnable(); + + if (g_smpOps == NULL) { + PRINT_ERR("Must call the interface(LOS_SmpOpsSet) to register smp operations firstly!\n"); + return; + } + + for (; cpuID < LOSCFG_KERNEL_CORE_NUM; cpuID++) { + ArchCpuOn(cpuID, OsSmpSecondaryInit, g_smpOps, 0); + } +} +#endif \ No newline at end of file diff --git a/kernel/src/los_mux.c b/kernel/src/los_mux.c index 51dbf352..f3dd5275 100644 --- a/kernel/src/los_mux.c +++ b/kernel/src/los_mux.c @@ -97,9 +97,9 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxCreate(UINT32 *muxHandle) return LOS_ERRNO_MUX_PTR_NULL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (LOS_ListEmpty(&g_unusedMuxList)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_ALL_BUSY); } @@ -112,7 +112,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxCreate(UINT32 *muxHandle) muxCreated->owner = (LosTaskCB *)NULL; LOS_ListInit(&muxCreated->muxList); *muxHandle = (UINT32)muxCreated->muxID; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_MUX_CREATE, muxCreated); return LOS_OK; ERR_HANDLER: @@ -138,14 +138,14 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxDelete(UINT32 muxHandle) } muxDeleted = GET_MUX(muxHandle); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (muxDeleted->muxStat == OS_MUX_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_INVALID); } if ((!LOS_ListEmpty(&muxDeleted->muxList)) || muxDeleted->muxCount) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_PENDED); } @@ -154,7 +154,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxDelete(UINT32 muxHandle) #if (LOSCFG_MUTEX_CREATE_TRACE == 1) muxDeleted->createInfo = 0; #endif - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_MUX_DELETE, muxDeleted); return LOS_OK; @@ -164,6 +164,8 @@ ERR_HANDLER: STATIC_INLINE UINT32 OsMuxValidCheck(LosMuxCB *muxPended) { + UINT32 cpuId = ArchCurrCpuid(); + if (muxPended->muxStat == OS_MUX_UNUSED) { return LOS_ERRNO_MUX_INVALID; } @@ -172,12 +174,12 @@ STATIC_INLINE UINT32 OsMuxValidCheck(LosMuxCB *muxPended) return LOS_ERRNO_MUX_IN_INTERR; } - if (g_losTaskLock) { + if (g_losTaskLock[cpuId]) { PRINT_ERR("!!!LOS_ERRNO_MUX_PEND_IN_LOCK!!!\n"); return LOS_ERRNO_MUX_PEND_IN_LOCK; } - if (g_losTask.runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) { + if (g_losTask[cpuId].runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) { return LOS_ERRNO_MUX_PEND_IN_SYSTEM_TASK; } @@ -198,30 +200,31 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout) LosMuxCB *muxPended = NULL; UINT32 retErr; LosTaskCB *runningTask = NULL; + UINT32 cpuId = ArchCurrCpuid(); if (muxHandle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT) { OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID); } muxPended = GET_MUX(muxHandle); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); retErr = OsMuxValidCheck(muxPended); if (retErr) { goto ERROR_MUX_PEND; } - runningTask = (LosTaskCB *)g_losTask.runTask; + runningTask = (LosTaskCB *)g_losTask[cpuId].runTask; if (muxPended->muxCount == 0) { muxPended->muxCount++; muxPended->owner = runningTask; muxPended->priority = runningTask->priority; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); goto HOOK; } if (muxPended->owner == runningTask) { muxPended->muxCount++; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); goto HOOK; } @@ -238,18 +241,18 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout) OsSchedTaskWait(&muxPended->muxList, timeout); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended, timeout); LOS_Schedule(); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (runningTask->taskStatus & OS_TASK_STATUS_TIMEOUT) { runningTask->taskStatus &= (~OS_TASK_STATUS_TIMEOUT); retErr = LOS_ERRNO_MUX_TIMEOUT; goto ERROR_MUX_PEND; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; HOOK: @@ -257,7 +260,7 @@ HOOK: return LOS_OK; ERROR_MUX_PEND: - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_RETURN_ERROR(retErr); } @@ -274,28 +277,29 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxPost(UINT32 muxHandle) LosMuxCB *muxPosted = GET_MUX(muxHandle); LosTaskCB *resumedTask = NULL; LosTaskCB *runningTask = NULL; + UINT32 cpuId = ArchCurrCpuid(); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if ((muxHandle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT) || (muxPosted->muxStat == OS_MUX_UNUSED)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID); } if (OS_INT_ACTIVE) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_RETURN_ERROR(LOS_ERRNO_MUX_IN_INTERR); } - runningTask = (LosTaskCB *)g_losTask.runTask; + runningTask = (LosTaskCB *)g_losTask[cpuId].runTask; if ((muxPosted->muxCount == 0) || (muxPosted->owner != runningTask)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID); } if (--(muxPosted->muxCount) != 0) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_MUX_POST, muxPosted); return LOS_OK; } @@ -314,12 +318,15 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxPost(UINT32 muxHandle) OsSchedTaskWake(resumedTask); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_MUX_POST, muxPosted); +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(OS_MP_CPU_ALL); +#endif LOS_Schedule(); } else { muxPosted->owner = NULL; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); } return LOS_OK; diff --git a/kernel/src/los_queue.c b/kernel/src/los_queue.c index 1e639fb0..840047df 100644 --- a/kernel/src/los_queue.c +++ b/kernel/src/los_queue.c @@ -144,10 +144,10 @@ static UINT32 OsQueueCreate(const CHAR *queueName, #if (LOSCFG_BASE_IPC_QUEUE_STATIC == 1) if (staticMem != NULL) { queue = staticMem; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (LOS_ListEmpty(&g_freeStaticQueueList)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_QUEUE_CB_UNAVAILABLE; } unusedQueue = LOS_DL_LIST_FIRST(&(g_freeStaticQueueList)); @@ -157,9 +157,9 @@ static UINT32 OsQueueCreate(const CHAR *queueName, return LOS_ERRNO_QUEUE_CREATE_NO_MEMORY; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (LOS_ListEmpty(&g_freeQueueList)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); (VOID)LOS_MemFree(m_aucSysMem0, queue); return LOS_ERRNO_QUEUE_CB_UNAVAILABLE; } @@ -171,9 +171,9 @@ static UINT32 OsQueueCreate(const CHAR *queueName, return LOS_ERRNO_QUEUE_CREATE_NO_MEMORY; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (LOS_ListEmpty(&g_freeQueueList)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); (VOID)LOS_MemFree(m_aucSysMem0, queue); return LOS_ERRNO_QUEUE_CB_UNAVAILABLE; } @@ -194,7 +194,7 @@ static UINT32 OsQueueCreate(const CHAR *queueName, LOS_ListInit(&queueCB->readWriteList[OS_QUEUE_READ]); LOS_ListInit(&queueCB->readWriteList[OS_QUEUE_WRITE]); LOS_ListInit(&queueCB->memList); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); *queueID = queueCB->queueID; @@ -384,9 +384,10 @@ UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT UINT32 ret; UINT32 readWrite = OS_QUEUE_READ_WRITE_GET(operateType); UINT32 readWriteTmp = !readWrite; - - UINT32 intSave = LOS_IntLock(); - + UINT32 cpuId = ArchCurrCpuid(); + UINT32 intSave; + + SCHEDULER_LOCK(intSave); queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID); ret = OsQueueOperateParamCheck(queueCB, operateType, bufferSize); if (ret != LOS_OK) { @@ -399,17 +400,17 @@ UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT goto QUEUE_END; } - if (g_losTaskLock) { + if (g_losTaskLock[cpuId]) { ret = LOS_ERRNO_QUEUE_PEND_IN_LOCK; goto QUEUE_END; } - LosTaskCB *runTsk = (LosTaskCB *)g_losTask.runTask; + LosTaskCB *runTsk = (LosTaskCB *)g_losTask[cpuId].runTask; OsSchedTaskWait(&queueCB->readWriteList[readWrite], timeOut); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); LOS_Schedule(); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (runTsk->taskStatus & OS_TASK_STATUS_TIMEOUT) { runTsk->taskStatus &= ~OS_TASK_STATUS_TIMEOUT; ret = LOS_ERRNO_QUEUE_TIMEOUT; @@ -424,7 +425,10 @@ UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT if (!LOS_ListEmpty(&queueCB->readWriteList[readWriteTmp])) { resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&queueCB->readWriteList[readWriteTmp])); OsSchedTaskWake(resumedTask); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(OS_MP_CPU_ALL); +#endif LOS_Schedule(); return LOS_OK; } else { @@ -432,7 +436,7 @@ UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT } QUEUE_END: - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return ret; } @@ -561,6 +565,7 @@ LITE_OS_SEC_TEXT VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 t UINT32 intSave; LosQueueCB *queueCB = (LosQueueCB *)NULL; LosTaskCB *runTsk = (LosTaskCB *)NULL; + UINT32 cpuId = ArchCurrCpuid(); if (queueID >= OS_ALL_IPC_QUEUE_LIMIT) { return NULL; @@ -576,7 +581,7 @@ LITE_OS_SEC_TEXT VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 t } } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); queueCB = GET_QUEUE_HANDLE(queueID); if (queueCB->queueState == OS_QUEUE_UNUSED) { goto END; @@ -588,12 +593,12 @@ LITE_OS_SEC_TEXT VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 t goto END; } - runTsk = (LosTaskCB *)g_losTask.runTask; + runTsk = (LosTaskCB *)g_losTask[cpuId].runTask; OsSchedTaskWait(&queueCB->memList, timeOut); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); LOS_Schedule(); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (runTsk->taskStatus & OS_TASK_STATUS_TIMEOUT) { runTsk->taskStatus &= (~OS_TASK_STATUS_TIMEOUT); goto END; @@ -607,7 +612,7 @@ LITE_OS_SEC_TEXT VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 t } END: - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return mem; } @@ -634,10 +639,10 @@ LITE_OS_SEC_TEXT UINT32 OsQueueMailFree(UINT32 queueID, VOID *mailPool, VOID *ma return LOS_ERRNO_QUEUE_MAIL_PTR_INVALID; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); queueCB = GET_QUEUE_HANDLE(queueID); if (queueCB->queueState == OS_QUEUE_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_QUEUE_NOT_CREATE; } @@ -648,15 +653,15 @@ LITE_OS_SEC_TEXT UINT32 OsQueueMailFree(UINT32 queueID, VOID *mailPool, VOID *ma */ resumedTask->msg = mailMem; OsSchedTaskWake(resumedTask); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); LOS_Schedule(); } else { /* No task waiting for the mailMem, so free it. */ if (LOS_MemboxFree(mailPool, mailMem)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_QUEUE_MAIL_FREE_ERROR; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); } return LOS_OK; @@ -680,7 +685,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueID) return LOS_ERRNO_QUEUE_NOT_FOUND; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID); if (queueCB->queueState == OS_QUEUE_UNUSED) { ret = LOS_ERRNO_QUEUE_NOT_CREATE; @@ -716,12 +721,12 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueID) #if (LOSCFG_BASE_IPC_QUEUE_STATIC == 1) if (queueID >= LOSCFG_BASE_IPC_QUEUE_LIMIT && queueID < OS_ALL_IPC_QUEUE_LIMIT) { LOS_ListAdd(&g_freeStaticQueueList, &queueCB->readWriteList[OS_QUEUE_WRITE]); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } #endif LOS_ListAdd(&g_freeQueueList, &queueCB->readWriteList[OS_QUEUE_WRITE]); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_QUEUE_DELETE, queueCB); @@ -729,7 +734,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueID) return ret; QUEUE_END: - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return ret; } @@ -749,7 +754,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_QueueInfoGet(UINT32 queueID, QUEUE_INFO_S *que } (VOID)memset_s((VOID *)queueInfo, sizeof(QUEUE_INFO_S), 0, sizeof(QUEUE_INFO_S)); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID); if (queueCB->queueState == OS_QUEUE_UNUSED) { @@ -781,7 +786,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_QueueInfoGet(UINT32 queueID, QUEUE_INFO_S *que } QUEUE_END: - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return ret; } diff --git a/kernel/src/los_sched.c b/kernel/src/los_sched.c index d042aec8..d646c70e 100644 --- a/kernel/src/los_sched.c +++ b/kernel/src/los_sched.c @@ -57,9 +57,7 @@ STATIC SortLinkAttribute *g_taskSortLinkList = NULL; STATIC LOS_DL_LIST g_priQueueList[OS_PRIORITY_QUEUE_NUM]; STATIC UINT32 g_queueBitmap; -STATIC UINT32 g_schedResponseID = 0; -STATIC UINT16 g_tickIntLock = 0; -STATIC UINT64 g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME; +SchedRunqueue g_schedRunqueue[LOSCFG_KERNEL_CORE_NUM] = {0}; STATIC INT32 g_schedTimeSlice; STATIC INT32 g_schedTimeSliceMin; @@ -68,8 +66,9 @@ STATIC UINT32 g_tickResponsePrecision; VOID OsSchedResetSchedResponseTime(UINT64 responseTime) { - if (responseTime <= g_schedResponseTime) { - g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME; + UINT32 cpuID = ArchCurrCpuid(); + if (responseTime <= g_schedRunqueue[cpuID].responseTime) { + g_schedRunqueue[cpuID].responseTime = OS_SCHED_MAX_RESPONSE_TIME; } } @@ -78,7 +77,7 @@ STATIC INLINE VOID OsTimeSliceUpdate(LosTaskCB *taskCB, UINT64 currTime) LOS_ASSERT(currTime >= taskCB->startTime); INT32 incTime = currTime - taskCB->startTime; - if (taskCB->taskID != g_idleTaskID) { + if (!OsIsIdleTask(taskCB->taskID)) { taskCB->timeSlice -= incTime; } taskCB->startTime = currTime; @@ -88,6 +87,7 @@ STATIC INLINE VOID OsSchedSetNextExpireTime(UINT32 responseID, UINT64 taskEndTim { UINT64 nextResponseTime; BOOL isTimeSlice = FALSE; + UINT32 cpuID = ArchCurrCpuid(); UINT64 currTime = OsGetCurrSchedTimeCycle(); UINT64 nextExpireTime = OsGetNextExpireTime(currTime, g_tickResponsePrecision); @@ -97,39 +97,40 @@ STATIC INLINE VOID OsSchedSetNextExpireTime(UINT32 responseID, UINT64 taskEndTim isTimeSlice = TRUE; } - if ((g_schedResponseTime <= nextExpireTime) || - ((g_schedResponseTime - nextExpireTime) < g_tickResponsePrecision)) { + if ((g_schedRunqueue[cpuID].responseTime <= nextExpireTime) + || ((g_schedRunqueue[cpuID].responseTime - nextExpireTime) < g_tickResponsePrecision)) { return; } if (isTimeSlice) { /* The expiration time of the current system is the thread's slice expiration time */ - g_schedResponseID = responseID; + g_schedRunqueue[cpuID].responseID = responseID; } else { - g_schedResponseID = OS_INVALID; + g_schedRunqueue[cpuID].responseID = OS_INVALID; } nextResponseTime = nextExpireTime - currTime; if (nextResponseTime < g_tickResponsePrecision) { nextResponseTime = g_tickResponsePrecision; } - g_schedResponseTime = currTime + OsTickTimerReload(nextResponseTime); + g_schedRunqueue[cpuID].responseTime = currTime + OsTickTimerReload(nextResponseTime); } VOID OsSchedUpdateExpireTime(VOID) { + UINT32 cpuID = ArchCurrCpuid(); UINT64 endTime; BOOL isPmMode = FALSE; - LosTaskCB *runTask = g_losTask.runTask; + LosTaskCB *runTask = g_losTask[cpuID].runTask; - if (!g_taskScheduled || g_tickIntLock) { + if (!OS_SCHEDULER_ACTIVE || g_schedRunqueue[cpuID].tickIntLock) { return; } #if (LOSCFG_KERNEL_PM == 1) isPmMode = OsIsPmMode(); #endif - if ((runTask->taskID != g_idleTaskID) && !isPmMode) { + if (!OsIsIdleTask(runTask->taskID) && !isPmMode) { INT32 timeSlice = (runTask->timeSlice <= g_schedTimeSliceMin) ? g_schedTimeSlice : runTask->timeSlice; endTime = runTask->startTime + timeSlice; } else { @@ -225,7 +226,7 @@ VOID OsSchedTaskEnQueue(LosTaskCB *taskCB) { LOS_ASSERT(!(taskCB->taskStatus & OS_TASK_STATUS_READY)); - if (taskCB->taskID != g_idleTaskID) { + if (!OsIsIdleTask(taskCB->taskID)) { if (taskCB->timeSlice > g_schedTimeSliceMin) { OsSchedPriQueueEnHead(&taskCB->pendList, taskCB->priority); } else { @@ -244,7 +245,7 @@ VOID OsSchedTaskEnQueue(LosTaskCB *taskCB) VOID OsSchedTaskDeQueue(LosTaskCB *taskCB) { if (taskCB->taskStatus & OS_TASK_STATUS_READY) { - if (taskCB->taskID != g_idleTaskID) { + if (!OsIsIdleTask(taskCB->taskID)) { OsSchedPriQueueDelete(&taskCB->pendList, taskCB->priority); } @@ -270,7 +271,8 @@ VOID OsSchedTaskExit(LosTaskCB *taskCB) VOID OsSchedYield(VOID) { - LosTaskCB *runTask = g_losTask.runTask; + UINT32 cpuID = ArchCurrCpuid(); + LosTaskCB *runTask = g_losTask[cpuID].runTask; runTask->timeSlice = 0; } @@ -283,7 +285,8 @@ VOID OsSchedDelay(LosTaskCB *runTask, UINT32 tick) VOID OsSchedTaskWait(LOS_DL_LIST *list, UINT32 ticks) { - LosTaskCB *runTask = g_losTask.runTask; + UINT32 cpuID = ArchCurrCpuid(); + LosTaskCB *runTask = g_losTask[cpuID].runTask; runTask->taskStatus |= OS_TASK_STATUS_PEND; LOS_ListTailInsert(list, &runTask->pendList); @@ -409,9 +412,11 @@ UINT32 OsSchedSwtmrScanRegister(SchedScan func) UINT32 OsTaskNextSwitchTimeGet(VOID) { - UINT32 intSave = LOS_IntLock(); + UINT32 intSave; + + SCHEDULER_LOCK(intSave); UINT32 ticks = OsSortLinkGetNextExpireTime(g_taskSortLinkList); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return ticks; } @@ -441,7 +446,9 @@ STATIC VOID TaskSchedTimeConvertFreq(UINT32 oldFreq) STATIC VOID SchedTimeBaseInit(VOID) { - g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME; + UINT32 cpuID = ArchCurrCpuid(); + + g_schedRunqueue[cpuID].responseTime = OS_SCHED_MAX_RESPONSE_TIME; g_schedTickMinPeriod = g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI; g_tickResponsePrecision = (g_schedTickMinPeriod * 75) / 100; /* 75 / 100: minimum accuracy */ @@ -476,6 +483,33 @@ UINT32 OsSchedInit(VOID) return LOS_OK; } +#ifdef LOSCFG_KERNEL_SMP +LosTaskCB *OsGetTopTask(VOID) +{ + UINT32 priority; + LosTaskCB *newTask = NULL; + UINT32 bitmap = g_queueBitmap; + UINT32 cpuID = ArchCurrCpuid(); + + while (bitmap) { + priority = CLZ(bitmap); + LOS_DL_LIST_FOR_EACH_ENTRY(newTask, &g_priQueueList[priority], LosTaskCB, pendList) { + if (newTask == NULL) { + break; + } + if (newTask->cpuAffiMask & CPUID_TO_AFFI_MASK(cpuID)) { + newTask->currCpu = cpuID & 0xFF; + return newTask; + } + } + bitmap &= ~(PRIQUEUE_PRIOR0_BIT >> priority); + } + + newTask = OS_TCB_FROM_TID(g_idleTaskID[cpuID]); + newTask->currCpu = cpuID & 0xFF; + return newTask; +} +#else LosTaskCB *OsGetTopTask(VOID) { UINT32 priority; @@ -484,22 +518,23 @@ LosTaskCB *OsGetTopTask(VOID) priority = CLZ(g_queueBitmap); newTask = LOS_DL_LIST_ENTRY(((LOS_DL_LIST *)&g_priQueueList[priority])->pstNext, LosTaskCB, pendList); } else { - newTask = OS_TCB_FROM_TID(g_idleTaskID); + newTask = OS_TCB_FROM_TID(g_idleTaskID[ArchCurrCpuid()]); } - return newTask; } +#endif VOID OsSchedStart(VOID) { PRINTK("Entering scheduler\n"); (VOID)LOS_IntLock(); + UINT32 cpuID = ArchCurrCpuid(); LosTaskCB *newTask = OsGetTopTask(); newTask->taskStatus |= OS_TASK_STATUS_RUNNING; - g_losTask.newTask = newTask; - g_losTask.runTask = g_losTask.newTask; + g_losTask[cpuID].newTask = newTask; + g_losTask[cpuID].runTask = g_losTask[cpuID].newTask; newTask->startTime = OsGetCurrSchedTimeCycle(); OsSchedTaskDeQueue(newTask); @@ -511,18 +546,22 @@ VOID OsSchedStart(VOID) #endif /* Initialize the schedule timeline and enable scheduling */ - g_taskScheduled = TRUE; + OS_SCHEDULER_SET(cpuID); - g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME; - g_schedResponseID = OS_INVALID; + g_schedRunqueue[cpuID].responseTime = OS_SCHED_MAX_RESPONSE_TIME; + g_schedRunqueue[cpuID].responseID = OS_INVALID; OsSchedSetNextExpireTime(newTask->taskID, newTask->startTime + newTask->timeSlice); } BOOL OsSchedTaskSwitch(VOID) { + UINT32 intSave; UINT64 endTime; BOOL isTaskSwitch = FALSE; - LosTaskCB *runTask = g_losTask.runTask; + UINT32 cpuID = ArchCurrCpuid(); + LosTaskCB *runTask = g_losTask[cpuID].runTask; + + SCHEDULER_LOCK(intSave); OsTimeSliceUpdate(runTask, OsGetCurrSchedTimeCycle()); if (runTask->taskStatus & (OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY)) { @@ -532,7 +571,7 @@ BOOL OsSchedTaskSwitch(VOID) } LosTaskCB *newTask = OsGetTopTask(); - g_losTask.newTask = newTask; + g_losTask[cpuID].newTask = newTask; if (runTask != newTask) { #if (LOSCFG_BASE_CORE_TSK_MONITOR == 1) @@ -551,16 +590,17 @@ BOOL OsSchedTaskSwitch(VOID) OsSchedTaskDeQueue(newTask); - if (newTask->taskID != g_idleTaskID) { + if (!OsIsIdleTask(newTask->taskID)) { endTime = newTask->startTime + newTask->timeSlice; } else { endTime = OS_SCHED_MAX_RESPONSE_TIME - g_tickResponsePrecision; } - if (g_schedResponseID == runTask->taskID) { - g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME; + if (g_schedRunqueue[cpuID].responseID == runTask->taskID) { + g_schedRunqueue[cpuID].responseTime = OS_SCHED_MAX_RESPONSE_TIME; } OsSchedSetNextExpireTime(newTask->taskID, endTime); + SCHEDULER_UNLOCK(intSave); return isTaskSwitch; } @@ -570,11 +610,12 @@ UINT64 LOS_SchedTickTimeoutNsGet(VOID) UINT32 intSave; UINT64 responseTime; UINT64 currTime; + UINT32 cpuID = ArchCurrCpuid(); - intSave = LOS_IntLock(); - responseTime = g_schedResponseTime; + SCHEDULER_LOCK(intSave); + responseTime = g_schedRunqueue[cpuID].responseTime; currTime = OsGetCurrSchedTimeCycle(); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); if (responseTime > currTime) { responseTime = responseTime - currTime; @@ -587,33 +628,37 @@ UINT64 LOS_SchedTickTimeoutNsGet(VOID) VOID LOS_SchedTickHandler(VOID) { - if (!g_taskScheduled) { + UINT32 intSave; + UINT32 cpuID = ArchCurrCpuid(); + + if (!OS_SCHEDULER_ACTIVE) { return; } - UINT32 intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); UINT64 tickStartTime = OsGetCurrSchedTimeCycle(); - if (g_schedResponseID == OS_INVALID) { - g_tickIntLock++; - if (g_swtmrScan != NULL) { + SchedRunqueue *rq = &g_schedRunqueue[cpuID]; + if (rq->responseID == OS_INVALID) { + rq->tickIntLock++; + if (cpuID == 0 && g_swtmrScan != NULL) { (VOID)g_swtmrScan(); } (VOID)OsSchedScanTimerList(); - g_tickIntLock--; + rq->tickIntLock--; } - OsTimeSliceUpdate(g_losTask.runTask, tickStartTime); - g_losTask.runTask->startTime = OsGetCurrSchedTimeCycle(); + OsTimeSliceUpdate(g_losTask[cpuID].runTask, tickStartTime); + g_losTask[cpuID].runTask->startTime = OsGetCurrSchedTimeCycle(); - g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME; + rq->responseTime = OS_SCHED_MAX_RESPONSE_TIME; if (LOS_CHECK_SCHEDULE) { ArchTaskSchedule(); } else { OsSchedUpdateExpireTime(); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); } VOID LOS_Schedule(VOID) @@ -622,3 +667,13 @@ VOID LOS_Schedule(VOID) ArchTaskSchedule(); } } + +#ifdef LOSCFG_KERNEL_SMP +VOID LOS_MpSchedule(UINT32 target) +{ + UINT32 cpuID = ArchCurrCpuid(); + + target &= ~CPUID_TO_AFFI_MASK(cpuID); + LOS_HwiSendIpi(target, LOS_MP_IPI_SCHEDULE); +} +#endif diff --git a/kernel/src/los_sem.c b/kernel/src/los_sem.c index cbd777c9..9b292b07 100644 --- a/kernel/src/los_sem.c +++ b/kernel/src/los_sem.c @@ -100,10 +100,10 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSemCreate(UINT16 count, UINT16 maxCount, UINT32 * OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_OVERFLOW); } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (LOS_ListEmpty(&g_unusedSemList)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_ALL_BUSY); } @@ -115,7 +115,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSemCreate(UINT16 count, UINT16 maxCount, UINT32 * semCreated->maxSemCount = maxCount; LOS_ListInit(&semCreated->semList); *semHandle = (UINT32)semCreated->semID; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_SEM_CREATE, semCreated); return LOS_OK; @@ -166,20 +166,20 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemDelete(UINT32 semHandle) } semDeleted = GET_SEM(semHandle); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (semDeleted->semStat == OS_SEM_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_INVALID); } if (!LOS_ListEmpty(&semDeleted->semList)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_PENDED); } LOS_ListAdd(&g_unusedSemList, &semDeleted->semList); semDeleted->semStat = OS_SEM_UNUSED; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_SEM_DELETE, semDeleted); return LOS_OK; ERR_HANDLER: @@ -188,6 +188,8 @@ ERR_HANDLER: STATIC_INLINE UINT32 OsSemValidCheck(LosSemCB *semPended) { + UINT32 cpuId = ArchCurrCpuid(); + if (semPended->semStat == OS_SEM_UNUSED) { return LOS_ERRNO_SEM_INVALID; } @@ -197,12 +199,12 @@ STATIC_INLINE UINT32 OsSemValidCheck(LosSemCB *semPended) return LOS_ERRNO_SEM_PEND_INTERR; } - if (g_losTaskLock) { + if (g_losTaskLock[cpuId]) { PRINT_ERR("!!!LOS_ERRNO_SEM_PEND_IN_LOCK!!!\n"); return LOS_ERRNO_SEM_PEND_IN_LOCK; } - if (g_losTask.runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) { + if (g_losTask[cpuId].runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) { return LOS_ERRNO_SEM_PEND_IN_SYSTEM_TASK; } return LOS_OK; @@ -222,24 +224,25 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout) LosSemCB *semPended = NULL; UINT32 retErr; LosTaskCB *runningTask = NULL; + UINT32 cpuId = ArchCurrCpuid(); if (semHandle >= (UINT32)LOSCFG_BASE_IPC_SEM_LIMIT) { OS_RETURN_ERROR(LOS_ERRNO_SEM_INVALID); } semPended = GET_SEM(semHandle); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); retErr = OsSemValidCheck(semPended); if (retErr) { goto ERROR_SEM_PEND; } - runningTask = (LosTaskCB *)g_losTask.runTask; + runningTask = (LosTaskCB *)g_losTask[cpuId].runTask; if (semPended->semCount > 0) { semPended->semCount--; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_SEM_PEND, semPended, runningTask, timeout); return LOS_OK; } @@ -251,22 +254,22 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout) runningTask->taskSem = (VOID *)semPended; OsSchedTaskWait(&semPended->semList, timeout); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_SEM_PEND, semPended, runningTask, timeout); LOS_Schedule(); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (runningTask->taskStatus & OS_TASK_STATUS_TIMEOUT) { runningTask->taskStatus &= (~OS_TASK_STATUS_TIMEOUT); retErr = LOS_ERRNO_SEM_TIMEOUT; goto ERROR_SEM_PEND; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; ERROR_SEM_PEND: - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_RETURN_ERROR(retErr); } @@ -287,15 +290,15 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle) return LOS_ERRNO_SEM_INVALID; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (semPosted->semStat == OS_SEM_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_RETURN_ERROR(LOS_ERRNO_SEM_INVALID); } if (semPosted->maxSemCount == semPosted->semCount) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OS_RETURN_ERROR(LOS_ERRNO_SEM_OVERFLOW); } if (!LOS_ListEmpty(&semPosted->semList)) { @@ -303,12 +306,15 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle) resumedTask->taskSem = NULL; OsSchedTaskWake(resumedTask); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_SEM_POST, semPosted, resumedTask); +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(OS_MP_CPU_ALL); +#endif LOS_Schedule(); } else { semPosted->semCount++; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_SEM_POST, semPosted, resumedTask); } diff --git a/kernel/src/los_sortlink.c b/kernel/src/los_sortlink.c index c3cf3d3e..6d592193 100644 --- a/kernel/src/los_sortlink.c +++ b/kernel/src/los_sortlink.c @@ -90,22 +90,22 @@ VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, Sort LOS_Panic("Sort link type error : %u\n", type); } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); SET_SORTLIST_VALUE(node, startTime + OS_SYS_TICK_TO_CYCLE(waitTicks)); OsAddNode2SortLink(sortLinkHead, node); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); } VOID OsDeleteSortLink(SortLinkList *node) { UINT32 intSave; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (node->responseTime != OS_SORT_LINK_INVALID_TIME) { OsSchedResetSchedResponseTime(node->responseTime); OsDeleteNodeSortLink(node); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); } STATIC INLINE VOID SortLinkNodeTimeUpdate(SortLinkAttribute *sortLinkHead, UINT32 oldFreq) diff --git a/kernel/src/los_swtmr.c b/kernel/src/los_swtmr.c index 76411679..6ee06ad2 100644 --- a/kernel/src/los_swtmr.c +++ b/kernel/src/los_swtmr.c @@ -47,6 +47,15 @@ LITE_OS_SEC_BSS SWTMR_CTRL_S *g_swtmrCBArray = NULL; /* first addres LITE_OS_SEC_BSS SWTMR_CTRL_S *g_swtmrFreeList = NULL; /* Free list of Software Timer */ LITE_OS_SEC_BSS SortLinkAttribute *g_swtmrSortLinkList = NULL; /* The software timer count list */ +#if (LOSCFG_KERNEL_SMP == 1) +LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_swtmrSpin); +#define SWTMR_LOCK(state) LOS_SpinLockSave(&g_swtmrSpin, &(state)) +#define SWTMR_UNLOCK(state) LOS_SpinUnlockRestore(&g_swtmrSpin, (state)) +#else +#define SWTMR_LOCK(state) (state) = LOS_IntLock() +#define SWTMR_UNLOCK(state) LOS_IntRestore(state) +#endif + #if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1) typedef struct SwtmrAlignDataStr { UINT32 times : 24; @@ -87,16 +96,16 @@ LITE_OS_SEC_TEXT VOID OsSwtmrTask(VOID) continue; } - intSave = LOS_IntLock(); + SWTMR_LOCK(intSave); swtmr = g_swtmrCBArray + swtmrHandle.swtmrID % LOSCFG_BASE_CORE_SWTMR_LIMIT; if (swtmr->usTimerID != swtmrHandle.swtmrID) { - LOS_IntRestore(intSave); + SWTMR_UNLOCK(intSave); continue; } if (swtmr->ucMode == LOS_SWTMR_MODE_ONCE) { OsSwtmrDelete(swtmr); } - LOS_IntRestore(intSave); + SWTMR_UNLOCK(intSave); tick = LOS_TickCountGet(); swtmrHandle.handler(swtmrHandle.arg); @@ -129,6 +138,9 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID) swtmrTask.uwStackSize = LOSCFG_BASE_CORE_TSK_SWTMR_STACK_SIZE; swtmrTask.pcName = "Swt_Task"; swtmrTask.usTaskPrio = 0; +#ifdef LOSCFG_KERNEL_SMP + swtmrTask.usCpuAffiMask = CPUID_TO_AFFI_MASK(0); +#endif ret = LOS_TaskCreate(&g_swtmrTaskID, &swtmrTask); if (ret == LOS_OK) { OS_TCB_FROM_TID(g_swtmrTaskID)->taskStatus |= OS_TASK_FLAG_SYSTEM_TASK; @@ -353,9 +365,12 @@ Return : Count of the Timer list *****************************************************************************/ LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID) { - UINT32 intSave = LOS_IntLock(); - UINT64 time = OsSortLinkGetNextExpireTime(g_swtmrSortLinkList); - LOS_IntRestore(intSave); + UINT32 intSave; + UINT64 time; + + SWTMR_LOCK(intSave); + time = OsSortLinkGetNextExpireTime(g_swtmrSortLinkList); + SWTMR_UNLOCK(intSave); time = OS_SYS_CYCLE_TO_TICK(time); if (time > OS_NULL_INT) { time = OS_NULL_INT; @@ -501,15 +516,15 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval, } #endif - intSave = LOS_IntLock(); + SWTMR_LOCK(intSave); if (g_swtmrFreeList == NULL) { - LOS_IntRestore(intSave); + SWTMR_UNLOCK(intSave); return LOS_ERRNO_SWTMR_MAXSIZE; } swtmr = g_swtmrFreeList; g_swtmrFreeList = swtmr->pstNext; - LOS_IntRestore(intSave); + SWTMR_UNLOCK(intSave); swtmr->pfnHandler = handler; swtmr->ucMode = mode; swtmr->uwInterval = interval; @@ -543,10 +558,10 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT32 swtmrId) return LOS_ERRNO_SWTMR_ID_INVALID; } - intSave = LOS_IntLock(); + SWTMR_LOCK(intSave); SWTMR_CTRL_S *swtmr = g_swtmrCBArray + swtmrId % LOSCFG_BASE_CORE_SWTMR_LIMIT; if (swtmr->usTimerID != swtmrId) { - LOS_IntRestore(intSave); + SWTMR_UNLOCK(intSave); return LOS_ERRNO_SWTMR_NOT_CREATED; } @@ -577,7 +592,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT32 swtmrId) break; } - LOS_IntRestore(intSave); + SWTMR_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_SWTMR_START, swtmr); return ret; } @@ -599,11 +614,11 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT32 swtmrId) if (swtmrId >= OS_SWTMR_MAX_TIMERID) { return LOS_ERRNO_SWTMR_ID_INVALID; } - intSave = LOS_IntLock(); + SWTMR_LOCK(intSave); swtmrCbId = swtmrId % LOSCFG_BASE_CORE_SWTMR_LIMIT; swtmr = g_swtmrCBArray + swtmrCbId; if (swtmr->usTimerID != swtmrId) { - LOS_IntRestore(intSave); + SWTMR_UNLOCK(intSave); return LOS_ERRNO_SWTMR_NOT_CREATED; } @@ -622,7 +637,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT32 swtmrId) break; } - LOS_IntRestore(intSave); + SWTMR_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_SWTMR_STOP, swtmr); return ret; } @@ -642,11 +657,11 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT32 swtmrId, UINT32 *tick) return LOS_ERRNO_SWTMR_TICK_PTR_NULL; } - intSave = LOS_IntLock(); + SWTMR_LOCK(intSave); swtmrCbId = swtmrId % LOSCFG_BASE_CORE_SWTMR_LIMIT; swtmr = g_swtmrCBArray + swtmrCbId; if (swtmr->usTimerID != swtmrId) { - LOS_IntRestore(intSave); + SWTMR_UNLOCK(intSave); return LOS_ERRNO_SWTMR_NOT_CREATED; } switch (swtmr->ucState) { @@ -663,7 +678,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT32 swtmrId, UINT32 *tick) ret = LOS_ERRNO_SWTMR_STATUS_INVALID; break; } - LOS_IntRestore(intSave); + SWTMR_UNLOCK(intSave); return ret; } @@ -684,11 +699,11 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT32 swtmrId) if (swtmrId >= OS_SWTMR_MAX_TIMERID) { return LOS_ERRNO_SWTMR_ID_INVALID; } - intSave = LOS_IntLock(); + SWTMR_LOCK(intSave); swtmrCbId = swtmrId % LOSCFG_BASE_CORE_SWTMR_LIMIT; swtmr = g_swtmrCBArray + swtmrCbId; if (swtmr->usTimerID != swtmrId) { - LOS_IntRestore(intSave); + SWTMR_UNLOCK(intSave); return LOS_ERRNO_SWTMR_NOT_CREATED; } @@ -707,7 +722,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT32 swtmrId) break; } - LOS_IntRestore(intSave); + SWTMR_UNLOCK(intSave); OsHookCall(LOS_HOOK_TYPE_SWTMR_DELETE, swtmr); return ret; } diff --git a/kernel/src/los_task.c b/kernel/src/los_task.c index c9177e40..bb053411 100644 --- a/kernel/src/los_task.c +++ b/kernel/src/los_task.c @@ -98,10 +98,10 @@ #endif LITE_OS_SEC_BSS LosTaskCB *g_taskCBArray = NULL; -LITE_OS_SEC_BSS LosTask g_losTask; -LITE_OS_SEC_BSS UINT16 g_losTaskLock; +LITE_OS_SEC_BSS LosTask g_losTask[LOSCFG_KERNEL_CORE_NUM] = {0}; +LITE_OS_SEC_BSS UINT16 g_losTaskLock[LOSCFG_KERNEL_CORE_NUM] = {0}; LITE_OS_SEC_BSS UINT32 g_taskMaxNum; -LITE_OS_SEC_BSS UINT32 g_idleTaskID; +LITE_OS_SEC_BSS UINT32 g_idleTaskID[LOSCFG_KERNEL_CORE_NUM]; #if (LOSCFG_BASE_CORE_SWTMR == 1) LITE_OS_SEC_BSS UINT32 g_swtmrTaskID; @@ -109,7 +109,8 @@ LITE_OS_SEC_BSS UINT32 g_swtmrTaskID; LITE_OS_SEC_DATA_INIT LOS_DL_LIST g_losFreeTask; LITE_OS_SEC_DATA_INIT LOS_DL_LIST g_taskRecycleList; -LITE_OS_SEC_BSS BOOL g_taskScheduled = FALSE; +LITE_OS_SEC_BSS BOOL g_taskScheduled; +LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_taskSpin); STATIC VOID (*PmEnter)(VOID) = NULL; @@ -120,7 +121,7 @@ TaskSwitchInfo g_taskSwitchInfo; STATIC_INLINE UINT32 OsCheckTaskIDValid(UINT32 taskID) { UINT32 ret = LOS_OK; - if (taskID == g_idleTaskID) { + if (OsIsIdleTask(taskID)) { ret = LOS_ERRNO_TSK_OPERATE_IDLE; #if (LOSCFG_BASE_CORE_SWTMR == 1) } else if (taskID == g_swtmrTaskID) { @@ -163,18 +164,18 @@ STATIC VOID OsRecycleFinishedTask(VOID) UINT32 intSave; UINTPTR stackPtr; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); while (!LOS_ListEmpty(&g_taskRecycleList)) { taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&g_taskRecycleList)); LOS_ListDelete(LOS_DL_LIST_FIRST(&g_taskRecycleList)); stackPtr = 0; OsRecycleTaskResources(taskCB, &stackPtr); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); (VOID)LOS_MemFree(OS_TASK_STACK_ADDR, (VOID *)stackPtr); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); } UINT32 OsPmEnterHandlerSet(VOID (*func)(VOID)) @@ -332,6 +333,9 @@ STATIC VOID PrintTskInfoHeader(VOID) #if (LOSCFG_BASE_CORE_CPUP == 1) PRINTK(" CPUUSE CPUUSE10s CPUUSE1s "); #endif /* LOSCFG_BASE_CORE_CPUP */ +#if defined(LOSCFG_KERNEL_SMP) + PRINTK(" Affi Cpu "); +#endif /* LOSCFG_KERNEL_SMP */ PRINTK(" TaskEntry name\n"); PRINTK(" --- -------- -------- "); PRINTK("--------- --------- ---------- ---------- --------- ------ "); @@ -341,6 +345,9 @@ STATIC VOID PrintTskInfoHeader(VOID) #if (LOSCFG_BASE_CORE_CPUP == 1) PRINTK("------- --------- -------- "); #endif /* LOSCFG_BASE_CORE_CPUP */ +#if defined(LOSCFG_KERNEL_SMP) + PRINTK("---- "); +#endif /* LOSCFG_KERNEL_SMP */ PRINTK("---------- ----\n"); } @@ -399,6 +406,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllTskInfo(VOID) cpuOneSec[taskCB->taskID].uwUsage / LOS_CPUP_PRECISION_MULT, cpuOneSec[taskCB->taskID].uwUsage % LOS_CPUP_PRECISION_MULT); #endif /* LOSCFG_BASE_CORE_CPUP */ +#if defined(LOSCFG_KERNEL_SMP) + PRINTK(" %#4x %3d ", taskCB->cpuAffiMask, taskCB->currCpu); +#endif /* LOSCFG_KERNEL_SMP */ PRINTK("%#10x %-32s\n", (UINT32)(UINTPTR)taskCB->taskEntry, taskCB->taskName); } @@ -422,9 +432,10 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID) { UINT32 size; UINT32 index; + UINT32 cpuID; - g_taskMaxNum = LOSCFG_BASE_CORE_TSK_LIMIT + 1; /* Reserved 1 for IDLE */ - size = (g_taskMaxNum + 1) * sizeof(LosTaskCB); + g_taskMaxNum = LOSCFG_BASE_CORE_TSK_LIMIT + LOSCFG_KERNEL_CORE_NUM; /* Reserved 1 for IDLE */ + size = (g_taskMaxNum + LOSCFG_KERNEL_CORE_NUM) * sizeof(LosTaskCB); g_taskCBArray = (LosTaskCB *)LOS_MemAlloc(m_aucSysMem0, size); if (g_taskCBArray == NULL) { return LOS_ERRNO_TSK_NO_MEMORY; @@ -434,7 +445,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID) (VOID)memset_s(g_taskCBArray, size, 0, size); LOS_ListInit(&g_losFreeTask); LOS_ListInit(&g_taskRecycleList); - for (index = 0; index <= LOSCFG_BASE_CORE_TSK_LIMIT; index++) { + for (index = 0; index < g_taskMaxNum; index++) { g_taskCBArray[index].taskStatus = OS_TASK_STATUS_UNUSED; g_taskCBArray[index].taskID = index; LOS_ListTailInsert(&g_losFreeTask, &g_taskCBArray[index].pendList); @@ -442,12 +453,15 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID) // Ignore the return code when matching CSEC rule 6.6(4). (VOID)memset_s((VOID *)(&g_losTask), sizeof(g_losTask), 0, sizeof(g_losTask)); - g_losTask.runTask = &g_taskCBArray[g_taskMaxNum]; - g_losTask.runTask->taskID = index; - g_losTask.runTask->taskStatus = (OS_TASK_STATUS_UNUSED | OS_TASK_STATUS_RUNNING); - g_losTask.runTask->priority = OS_TASK_PRIORITY_LOWEST + 1; - g_idleTaskID = OS_INVALID; + for (cpuID = 0; cpuID < LOSCFG_KERNEL_CORE_NUM; cpuID++) { + g_losTask[cpuID].runTask = &g_taskCBArray[g_taskMaxNum + cpuID]; + g_losTask[cpuID].runTask->taskID = g_taskMaxNum + cpuID; + g_losTask[cpuID].runTask->taskStatus = (OS_TASK_STATUS_UNUSED | OS_TASK_STATUS_RUNNING); + g_losTask[cpuID].runTask->priority = OS_TASK_PRIORITY_LOWEST + 1; + + g_idleTaskID[cpuID] = OS_INVALID; + } return OsSchedInit(); } @@ -455,11 +469,11 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID) /***************************************************************************** Function : OsIdleTaskCreate Description : Create idle task. - Input : None + Input : cpuID --- Current CPU ID Output : None Return : LOS_OK on success or error code on failure *****************************************************************************/ -LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID) +LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(UINT32 cpuID) { UINT32 retVal; TSK_INIT_PARAM_S taskInitParam; @@ -469,15 +483,29 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID) taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE; taskInitParam.pcName = "IdleCore000"; taskInitParam.usTaskPrio = OS_TASK_PRIORITY_LOWEST; - retVal = LOS_TaskCreateOnly(&g_idleTaskID, &taskInitParam); +#ifdef LOSCFG_KERNEL_SMP + taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(cpuID); +#endif + retVal = LOS_TaskCreateOnly(&g_idleTaskID[cpuID], &taskInitParam); if (retVal != LOS_OK) { return retVal; } + OsSchedSetIdleTaskSchedParam(OS_TCB_FROM_TID(g_idleTaskID[cpuID])); - OsSchedSetIdleTaskSchedParam(OS_TCB_FROM_TID(g_idleTaskID)); return LOS_OK; } +LITE_OS_SEC_TEXT BOOL OsIsIdleTask(UINT32 taskID) +{ + UINT32 cpuID; + for (cpuID = 0; cpuID < LOSCFG_KERNEL_CORE_NUM; cpuID++) { + if (taskID == g_idleTaskID[cpuID]) { + return TRUE; + } + } + return FALSE; +} + /***************************************************************************** Function : LOS_CurTaskIDGet Description : get id of current running task. @@ -487,10 +515,11 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID) *****************************************************************************/ LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID) { - if (g_losTask.runTask == NULL) { + UINT32 cpuID = ArchCurrCpuid(); + if (g_losTask[cpuID].runTask == NULL) { return LOS_ERRNO_TSK_ID_INVALID; } - return g_losTask.runTask->taskID; + return g_losTask[cpuID].runTask->taskID; } /***************************************************************************** @@ -502,9 +531,10 @@ LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID) *****************************************************************************/ LITE_OS_SEC_TEXT UINT32 LOS_NextTaskIDGet(VOID) { - UINT32 intSave = LOS_IntLock(); + UINT32 intSave; + SCHEDULER_LOCK(intSave); UINT32 taskID = OsGetTopTask()->taskID; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return taskID; } @@ -519,9 +549,10 @@ LITE_OS_SEC_TEXT UINT32 LOS_NextTaskIDGet(VOID) LITE_OS_SEC_TEXT CHAR *LOS_CurTaskNameGet(VOID) { CHAR *taskName = NULL; + UINT32 cpuID = ArchCurrCpuid(); - if (g_losTask.runTask != NULL) { - taskName = g_losTask.runTask->taskName; + if (g_losTask[cpuID].runTask != NULL) { + taskName = g_losTask[cpuID].runTask->taskName; } return taskName; @@ -538,8 +569,9 @@ LITE_OS_SEC_TEXT CHAR *LOS_CurTaskNameGet(VOID) *****************************************************************************/ LITE_OS_SEC_TEXT STATIC VOID OsHandleRunTaskStackOverflow(VOID) { + UINT32 cpuID = ArchCurrCpuid(); PRINT_ERR("CURRENT task ID: %s:%d stack overflow!\n", - g_losTask.runTask->taskName, g_losTask.runTask->taskID); + g_losTask[cpuID].runTask->taskName, g_losTask[cpuID].runTask->taskID); OsDoExcHook(EXC_STACKOVERFLOW); } @@ -553,27 +585,28 @@ LITE_OS_SEC_TEXT STATIC VOID OsHandleRunTaskStackOverflow(VOID) LITE_OS_SEC_TEXT STATIC VOID OsHandleNewTaskStackOverflow(VOID) { LosTaskCB *tmp = NULL; + UINT32 cpuID = ArchCurrCpuid(); PRINT_ERR("HIGHEST task ID: %s:%d SP error!\n", - g_losTask.newTask->taskName, g_losTask.newTask->taskID); + g_losTask[cpuID].newTask->taskName, g_losTask[cpuID].newTask->taskID); PRINT_ERR("HIGHEST task StackPointer: 0x%x TopOfStack: 0x%x\n", - (UINT32)(UINTPTR)(g_losTask.newTask->stackPointer), g_losTask.newTask->topOfStack); + (UINT32)(UINTPTR)(g_losTask[cpuID].newTask->stackPointer), g_losTask[cpuID].newTask->topOfStack); /* * make sure LOS_CurTaskIDGet and LOS_CurTaskNameGet returns the ID and name of which task * that occurred stack overflow exception in OsDoExcHook temporary. */ - tmp = g_losTask.runTask; - g_losTask.runTask = g_losTask.newTask; + tmp = g_losTask[cpuID].runTask; + g_losTask[cpuID].runTask = g_losTask[cpuID].newTask; OsDoExcHook(EXC_STACKOVERFLOW); - g_losTask.runTask = tmp; + g_losTask[cpuID].runTask = tmp; } #else LITE_OS_SEC_TEXT STATIC VOID OsTaskStackProtect(VOID) { MPU_CFG_PARA mpuAttr = {0}; STATIC INT32 id = -1; - + UINT32 cpuID = ArchCurrCpuid(); if (id == -1) { id = ArchMpuUnusedRegionGet(); if (id < 0) { @@ -582,7 +615,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsTaskStackProtect(VOID) } } - mpuAttr.baseAddr = g_losTask.newTask->topOfStack - OS_TASK_STACK_PROTECT_SIZE; + mpuAttr.baseAddr = g_losTask[cpuID].newTask->topOfStack - OS_TASK_STACK_PROTECT_SIZE; mpuAttr.size = OS_TASK_STACK_PROTECT_SIZE; mpuAttr.memType = MPU_MEM_ON_CHIP_RAM; mpuAttr.executable = MPU_NON_EXECUTABLE; @@ -607,15 +640,18 @@ LITE_OS_SEC_TEXT STATIC VOID OsTaskStackProtect(VOID) #if (LOSCFG_BASE_CORE_TSK_MONITOR == 1) LITE_OS_SEC_TEXT VOID OsTaskSwitchCheck(VOID) { - UINT32 intSave = LOS_IntLock(); + UINT32 intSave; + UINT32 cpuID = ArchCurrCpuid(); + + SCHEDULER_LOCK(intSave); #if (LOSCFG_EXC_HARDWARE_STACK_PROTECTION == 0) - UINT32 endOfStack = g_losTask.newTask->topOfStack + g_losTask.newTask->stackSize; + UINT32 endOfStack = g_losTask[cpuID].newTask->topOfStack + g_losTask[cpuID].newTask->stackSize; - if ((*(UINT32 *)(UINTPTR)(g_losTask.runTask->topOfStack)) != OS_TASK_MAGIC_WORD) { + if ((*(UINT32 *)(UINTPTR)(g_losTask[cpuID].runTask->topOfStack)) != OS_TASK_MAGIC_WORD) { OsHandleRunTaskStackOverflow(); } - if (((UINT32)(UINTPTR)(g_losTask.newTask->stackPointer) <= (g_losTask.newTask->topOfStack)) || - ((UINT32)(UINTPTR)(g_losTask.newTask->stackPointer) > endOfStack)) { + if (((UINT32)(UINTPTR)(g_losTask[cpuID].newTask->stackPointer) <= (g_losTask[cpuID].newTask->topOfStack)) || + ((UINT32)(UINTPTR)(g_losTask[cpuID].newTask->stackPointer) > endOfStack)) { OsHandleNewTaskStackOverflow(); } #else @@ -624,10 +660,10 @@ LITE_OS_SEC_TEXT VOID OsTaskSwitchCheck(VOID) #if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == 1) /* record task switch info */ - g_taskSwitchInfo.pid[g_taskSwitchInfo.idx] = (UINT16)(g_losTask.newTask->taskID); + g_taskSwitchInfo.pid[g_taskSwitchInfo.idx] = (UINT16)(g_losTask[cpuID].newTask->taskID); errno_t ret = memcpy_s(g_taskSwitchInfo.name[g_taskSwitchInfo.idx], LOS_TASK_NAMELEN, - g_losTask.newTask->taskName, LOS_TASK_NAMELEN); + g_losTask[cpuID].newTask->taskName, LOS_TASK_NAMELEN); if (ret != EOK) { PRINT_ERR("exc task switch copy file name failed!\n"); } @@ -644,7 +680,7 @@ LITE_OS_SEC_TEXT VOID OsTaskSwitchCheck(VOID) #if (LOSCFG_BASE_CORE_CPUP == 1) OsTskCycleEndStart(); #endif /* LOSCFG_BASE_CORE_CPUP */ - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); } LITE_OS_SEC_TEXT_MINOR VOID OsTaskMonInit(VOID) @@ -732,6 +768,10 @@ STATIC UINT32 OsNewTaskInit(LosTaskCB *taskCB, TSK_INIT_PARAM_S *taskInitParam) #if (LOSCFG_KERNEL_SIGNAL == 1) taskCB->sig = NULL; #endif +#if defined(LOSCFG_KERNEL_SMP) + taskCB->cpuAffiMask = (taskInitParam->usCpuAffiMask) ? (taskInitParam->usCpuAffiMask) : LOSCFG_KERNEL_CPU_MASK; + taskCB->currCpu = OS_TASK_INVALID_CPUID; +#endif SET_SORTLIST_VALUE(&taskCB->sortList, OS_SORT_LINK_INVALID_TIME); LOS_EventInit(&(taskCB->event)); @@ -794,31 +834,31 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S OsRecycleFinishedTask(); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (LOS_ListEmpty(&g_losFreeTask)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_TSK_TCB_UNAVAILABLE; } taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&g_losFreeTask)); LOS_ListDelete(LOS_DL_LIST_FIRST(&g_losFreeTask)); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); retVal = OsNewTaskInit(taskCB, taskInitParam); if (retVal != LOS_OK) { - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); OsInsertTCBToFreeList(taskCB); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return retVal; } LOSCFG_TASK_CREATE_EXTENSION_HOOK(taskCB); #if (LOSCFG_BASE_CORE_CPUP == 1) - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); g_cpup[taskCB->taskID].cpupID = taskCB->taskID; g_cpup[taskCB->taskID].status = taskCB->taskStatus; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); #endif *taskID = taskCB->taskID; OsHookCall(LOS_HOOK_TYPE_TASK_CREATE, taskCB); @@ -844,12 +884,15 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *ta } taskCB = OS_TCB_FROM_TID(*taskID); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); OsSchedTaskEnQueue(taskCB); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); - if (g_taskScheduled) { +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(OS_MP_CPU_ALL); +#endif + if (OS_SCHEDULER_ACTIVE) { LOS_Schedule(); } @@ -876,7 +919,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskID) } taskCB = OS_TCB_FROM_TID(taskID); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); tempStatus = taskCB->taskStatus; if (tempStatus & OS_TASK_STATUS_UNUSED) { @@ -888,17 +931,20 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskID) } needSched = OsSchedResume(taskCB); - if (needSched && g_taskScheduled) { - LOS_IntRestore(intSave); + if (needSched && OS_SCHEDULER_ACTIVE) { + SCHEDULER_UNLOCK(intSave); +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(OS_MP_CPU_ALL); +#endif LOS_Schedule(); return LOS_OK; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; LOS_ERREND: - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return retErr; } @@ -915,6 +961,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskSuspend(UINT32 taskID) LosTaskCB *taskCB = NULL; UINT16 tempStatus; UINT32 retErr; + UINT32 cpuID = ArchCurrCpuid(); retErr = OsCheckTaskIDValid(taskID); if (retErr != LOS_OK) { @@ -922,7 +969,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskSuspend(UINT32 taskID) } taskCB = OS_TCB_FROM_TID(taskID); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); tempStatus = taskCB->taskStatus; if (tempStatus & OS_TASK_STATUS_UNUSED) { @@ -940,24 +987,24 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskSuspend(UINT32 taskID) OS_GOTO_ERREND(); } - if ((tempStatus & OS_TASK_STATUS_RUNNING) && (g_losTaskLock != 0)) { + if ((tempStatus & OS_TASK_STATUS_RUNNING) && (g_losTaskLock[cpuID] != 0)) { retErr = LOS_ERRNO_TSK_SUSPEND_LOCKED; OS_GOTO_ERREND(); } OsSchedSuspend(taskCB); - if (taskID == g_losTask.runTask->taskID) { - LOS_IntRestore(intSave); + if (taskID == g_losTask[cpuID].runTask->taskID) { + SCHEDULER_UNLOCK(intSave); LOS_Schedule(); return LOS_OK; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; LOS_ERREND: - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return retErr; } @@ -1006,6 +1053,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval) UINTPTR stackPtr = 0; UINT32 intSave; UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); ret = OsCheckTaskIDValid(taskID); if (ret != LOS_OK) { @@ -1016,7 +1064,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval) return LOS_ERRNO_TSK_NOT_ALLOW_IN_INT; } - if (g_losTaskLock != 0) { + if (g_losTaskLock[cpuID] != 0) { return LOS_ERRNO_TSK_SCHED_LOCKED; } @@ -1025,14 +1073,14 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval) } taskCB = OS_TCB_FROM_TID(taskID); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_TSK_NOT_CREATED; } ret = OsTaskJoinPendUnsafe(taskCB); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); if (ret == LOS_OK) { LOS_Schedule(); @@ -1040,10 +1088,10 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval) *retval = taskCB->joinRetval; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); taskCB->taskStatus &= ~OS_TASK_FLAG_JOINABLE; OsRecycleTaskResources(taskCB, &stackPtr); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); (VOID)LOS_MemFree(OS_TASK_STACK_ADDR, (VOID *)stackPtr); return LOS_OK; } @@ -1067,30 +1115,31 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDetach(UINT32 taskID) } taskCB = OS_TCB_FROM_TID(taskID); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_TSK_NOT_CREATED; } if (taskCB->taskStatus & OS_TASK_STATUS_EXIT) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_TaskJoin(taskID, NULL); } ret = OsTaskSetDetachUnsafe(taskCB); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return ret; } LITE_OS_SEC_TEXT_INIT STATIC_INLINE VOID OsRunningTaskDelete(UINT32 taskID, LosTaskCB *taskCB) { + UINT32 cpuID = ArchCurrCpuid(); LOS_ListTailInsert(&g_taskRecycleList, &taskCB->pendList); - g_losTask.runTask = &g_taskCBArray[g_taskMaxNum]; - g_losTask.runTask->taskID = taskID; - g_losTask.runTask->taskStatus = taskCB->taskStatus | OS_TASK_STATUS_RUNNING; - g_losTask.runTask->topOfStack = taskCB->topOfStack; - g_losTask.runTask->taskName = taskCB->taskName; + g_losTask[cpuID].runTask = &g_taskCBArray[g_taskMaxNum + cpuID]; + g_losTask[cpuID].runTask->taskID = taskID; + g_losTask[cpuID].runTask->taskStatus = taskCB->taskStatus | OS_TASK_STATUS_RUNNING; + g_losTask[cpuID].runTask->topOfStack = taskCB->topOfStack; + g_losTask[cpuID].runTask->taskName = taskCB->taskName; } /***************************************************************************** Function : LOS_TaskDelete @@ -1104,6 +1153,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID) UINT32 intSave; UINTPTR stackPtr = 0; LosTaskCB *taskCB = NULL; + UINT32 cpuID = ArchCurrCpuid(); UINT32 ret = OsCheckTaskIDValid(taskID); if (ret != LOS_OK) { @@ -1111,31 +1161,31 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID) } taskCB = OS_TCB_FROM_TID(taskID); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (taskCB->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK; } if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_TSK_NOT_CREATED; } if (taskCB->taskStatus & OS_TASK_STATUS_EXIT) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_TSK_ALREADY_EXIT; } if (taskCB->taskStatus & OS_TASK_FLAG_SIGNAL) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_TSK_PROCESS_SIGNAL; } /* If the task is running and scheduler is locked then you can not delete it */ - if (((taskCB->taskStatus) & OS_TASK_STATUS_RUNNING) && (g_losTaskLock != 0)) { + if (((taskCB->taskStatus) & OS_TASK_STATUS_RUNNING) && (g_losTaskLock[cpuID] != 0)) { PRINT_INFO("In case of task lock, task deletion is not recommended\n"); - g_losTaskLock = 0; + g_losTaskLock[cpuID] = 0; } OsHookCall(LOS_HOOK_TYPE_TASK_DELETE, taskCB); @@ -1164,14 +1214,17 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID) taskCB->taskStatus |= OS_TASK_STATUS_UNUSED; OsRunningTaskDelete(taskID, taskCB); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(CPUID_TO_AFFI_MASK(taskCB->currCpu)); +#endif LOS_Schedule(); return LOS_OK; } taskCB->joinRetval = LOS_CurTaskIDGet(); OsRecycleTaskResources(taskCB, &stackPtr); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); (VOID)LOS_MemFree(OS_TASK_STACK_ADDR, (VOID *)stackPtr); return LOS_OK; } @@ -1186,26 +1239,27 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID) LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick) { UINT32 intSave; + UINT32 cpuID = ArchCurrCpuid(); if (OS_INT_ACTIVE) { return LOS_ERRNO_TSK_DELAY_IN_INT; } - if (g_losTaskLock != 0) { + if (g_losTaskLock[cpuID] != 0) { return LOS_ERRNO_TSK_DELAY_IN_LOCK; } - if (g_losTask.runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) { + if (g_losTask[cpuID].runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) { return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK; } OsHookCall(LOS_HOOK_TYPE_TASK_DELAY, tick); if (tick == 0) { return LOS_TaskYield(); } else { - intSave = LOS_IntLock(); - OsSchedDelay(g_losTask.runTask, tick); - OsHookCall(LOS_HOOK_TYPE_MOVEDTASKTODELAYEDLIST, g_losTask.runTask); - LOS_IntRestore(intSave); + SCHEDULER_LOCK(intSave); + OsSchedDelay(g_losTask[cpuID].runTask, tick); + OsHookCall(LOS_HOOK_TYPE_MOVEDTASKTODELAYEDLIST, g_losTask[cpuID].runTask); + SCHEDULER_UNLOCK(intSave); LOS_Schedule(); } @@ -1224,15 +1278,15 @@ LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskPriGet(UINT32 taskID) taskCB = OS_TCB_FROM_TID(taskID); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return (UINT16)OS_INVALID; } priority = taskCB->priority; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return priority; } @@ -1247,7 +1301,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio) return LOS_ERRNO_TSK_PRIOR_ERROR; } - if (taskID == g_idleTaskID) { + if (OsIsIdleTask(taskID)) { return LOS_ERRNO_TSK_OPERATE_IDLE; } @@ -1262,21 +1316,24 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio) } taskCB = OS_TCB_FROM_TID(taskID); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); tempStatus = taskCB->taskStatus; if (tempStatus & OS_TASK_STATUS_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_TSK_NOT_CREATED; } if (tempStatus & OS_TASK_FLAG_SYSTEM_TASK) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK; } isReady = OsSchedModifyTaskSchedParam(taskCB, taskPrio); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); /* delete the task and insert with right priority into ready queue */ if (isReady) { +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(OS_MP_CPU_ALL); +#endif LOS_Schedule(); } @@ -1285,7 +1342,8 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio) LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CurTaskPriSet(UINT16 taskPrio) { - return LOS_TaskPriSet(g_losTask.runTask->taskID, taskPrio); + UINT32 cpuID = ArchCurrCpuid(); + return LOS_TaskPriSet(g_losTask[cpuID].runTask->taskID, taskPrio); } /***************************************************************************** @@ -1299,9 +1357,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID) { UINT32 intSave; - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); OsSchedYield(); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); LOS_Schedule(); return LOS_OK; } @@ -1315,11 +1373,12 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID) *****************************************************************************/ LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskLock(VOID) { + INT32 cpuID = ArchCurrCpuid(); UINT32 intSave; - intSave = LOS_IntLock(); - g_losTaskLock++; - LOS_IntRestore(intSave); + SCHEDULER_LOCK(intSave); + g_losTaskLock[cpuID]++; + SCHEDULER_UNLOCK(intSave); } /***************************************************************************** @@ -1332,18 +1391,19 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskLock(VOID) LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskUnlock(VOID) { UINT32 intSave; + INT32 cpuID = ArchCurrCpuid(); - intSave = LOS_IntLock(); - if (g_losTaskLock > 0) { - g_losTaskLock--; - if (g_losTaskLock == 0) { - LOS_IntRestore(intSave); + SCHEDULER_LOCK(intSave); + if (g_losTaskLock[cpuID] > 0) { + g_losTaskLock[cpuID]--; + if (g_losTaskLock[cpuID] == 0) { + SCHEDULER_UNLOCK(intSave); LOS_Schedule(); return; } } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); } LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInfo) @@ -1360,10 +1420,10 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInf } taskCB = OS_TCB_FROM_TID(taskID); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_TSK_NOT_CREATED; } @@ -1390,7 +1450,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInf taskInfo->uwCurrUsed = taskInfo->uwBottomOfStack - taskInfo->uwSP; taskInfo->uwPeakUsed = OsGetTaskWaterLine(taskID); taskInfo->bOvf = (taskInfo->uwPeakUsed == OS_NULL_INT) ? TRUE : FALSE; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -1409,16 +1469,16 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskStatusGet(UINT32 taskID, UINT32 *taskStatu } taskCB = OS_TCB_FROM_TID(taskID); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_TSK_NOT_CREATED; } *taskStatus = taskCB->taskStatus; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -1438,7 +1498,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskSwitchInfoGet(UINT32 index, UINT32 *taskSw return LOS_ERRNO_TSK_PTR_NULL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); (*taskSwitchInfo) = g_taskSwitchInfo.pid[curIndex]; @@ -1447,7 +1507,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskSwitchInfoGet(UINT32 index, UINT32 *taskSw PRINT_ERR("LOS_TaskSwitchInfoGet copy task name failed\n"); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } #endif @@ -1476,7 +1536,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoMonitor(VOID) *****************************************************************************/ LITE_OS_SEC_TEXT_MINOR BOOL LOS_TaskIsRunning(VOID) { - return g_taskScheduled; + return OS_SCHEDULER_ACTIVE; } /***************************************************************************** @@ -1509,12 +1569,12 @@ LITE_OS_SEC_TEXT CHAR* LOS_TaskNameGet(UINT32 taskID) taskCB = OS_TCB_FROM_TID(taskID); - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return NULL; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return taskCB->taskName; } @@ -1543,3 +1603,82 @@ VOID LOS_TaskResRecycle(VOID) { OsRecycleFinishedTask(); } + +LITE_OS_SEC_TEXT BOOL OsTaskCpuAffiSetUnsafe(UINT32 taskID, UINT16 newCpuAffiMask, UINT16 *oldCpuAffiMask) +{ +#ifdef LOSCFG_KERNEL_SMP + LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID); + + taskCB->cpuAffiMask = newCpuAffiMask; + *oldCpuAffiMask = CPUID_TO_AFFI_MASK(taskCB->currCpu); + if (!((*oldCpuAffiMask) & newCpuAffiMask)) { + return TRUE; + } +#else + (VOID)taskID; + (VOID)newCpuAffiMask; + (VOID)oldCpuAffiMask; +#endif /* LOSCFG_KERNEL_SMP */ + return FALSE; +} + +LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskID, UINT16 cpuAffiMask) +{ + BOOL needSched = FALSE; + UINT32 intSave; + UINT16 currCpuMask; + + if (OS_TASK_ID_CHECK(taskID)) { + return LOS_ERRNO_TSK_ID_INVALID; + } + + if (!(cpuAffiMask & LOSCFG_KERNEL_CPU_MASK)) { + return LOS_ERRNO_TSK_CPU_AFFINITY_MASK_ERR; + } + + LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID); + SCHEDULER_LOCK(intSave); + if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { + SCHEDULER_UNLOCK(intSave); + return LOS_ERRNO_TSK_NOT_CREATED; + } + needSched = OsTaskCpuAffiSetUnsafe(taskID, cpuAffiMask, &currCpuMask); + + SCHEDULER_UNLOCK(intSave); + if (needSched && OS_SCHEDULER_ACTIVE) { +#ifdef LOSCFG_KERNEL_SMP + LOS_MpSchedule(currCpuMask); +#endif + LOS_Schedule(); + } + + return LOS_OK; +} + +LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiGet(UINT32 taskID) +{ +#ifdef LOSCFG_KERNEL_SMP +#define INVALID_CPU_AFFI_MASK 0 + UINT32 intSave; + UINT16 cpuAffiMask; + + if (OS_TASK_ID_CHECK(taskID)) { + return INVALID_CPU_AFFI_MASK; + } + LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID); + SCHEDULER_LOCK(intSave); + if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { + SCHEDULER_UNLOCK(intSave); + return INVALID_CPU_AFFI_MASK; + } + + cpuAffiMask = taskCB->cpuAffiMask; + SCHEDULER_UNLOCK(intSave); + + return cpuAffiMask; +#else + (VOID)taskID; + return 1; +#endif +} + diff --git a/kernel/src/los_tick.c b/kernel/src/los_tick.c index 4d14083d..17f042e3 100644 --- a/kernel/src/los_tick.c +++ b/kernel/src/los_tick.c @@ -93,7 +93,9 @@ LITE_OS_SEC_TEXT UINT64 LOS_SysCycleGet(VOID) return g_sysTickTimer->getCycle(NULL); #else UINT32 period = 0; - UINT32 intSave = LOS_IntLock(); + UINT32 intSave; + + SCHEDULER_LOCK(intSave); UINT64 time = g_sysTickTimer->getCycle(&period); UINT64 schedTime = g_tickTimerBase + time; if (schedTime < g_oldTickTimerBase) { @@ -106,7 +108,7 @@ LITE_OS_SEC_TEXT UINT64 LOS_SysCycleGet(VOID) LOS_ASSERT(schedTime >= g_oldTickTimerBase); g_oldTickTimerBase = schedTime; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return schedTime; #endif } @@ -161,20 +163,20 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTickTimerInit(VOID) tickHandler = g_sysTickTimer->tickHandler; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); ret = g_sysTickTimer->init(tickHandler); if (ret != LOS_OK) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return ret; } if ((g_sysTickTimer->freq == 0) || (g_sysTickTimer->freq < LOSCFG_BASE_CORE_TICK_PER_SECOND)) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_SYS_CLOCK_INVALID; } if (g_sysTickTimer->irqNum > (INT32)LOSCFG_PLATFORM_HWI_LIMIT) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_TICK_CFG_INVALID; } @@ -182,7 +184,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTickTimerInit(VOID) g_cyclesPerTick = g_sysTickTimer->freq / LOSCFG_BASE_CORE_TICK_PER_SECOND; g_sysTimerIsInit = TRUE; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -202,13 +204,13 @@ LITE_OS_SEC_TEXT UINT32 LOS_TickTimerRegister(const ArchTickTimer *timer, const return ret; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (g_sysTickTimer == NULL) { g_sysTickTimer = LOS_SysTickTimerGet(); } if (g_sysTickTimer == timer) { - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_SYS_TIMER_ADDR_FAULT; } @@ -217,7 +219,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_TickTimerRegister(const ArchTickTimer *timer, const PRINT_ERR("%s timer addr fault! errno %d\n", __FUNCTION__, errRet); ret = LOS_ERRNO_SYS_TIMER_ADDR_FAULT; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return ret; } @@ -225,13 +227,13 @@ LITE_OS_SEC_TEXT UINT32 LOS_TickTimerRegister(const ArchTickTimer *timer, const return LOS_ERRNO_SYS_TIMER_IS_RUNNING; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); if (g_sysTickTimer == NULL) { g_sysTickTimer = LOS_SysTickTimerGet(); } g_sysTickTimer->tickHandler = tickHandler; - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } @@ -245,7 +247,7 @@ UINT32 LOS_SysTickClockFreqAdjust(const SYS_TICK_FREQ_ADJUST_FUNC handler, UINTP return LOS_ERRNO_SYS_HOOK_IS_NULL; } - intSave = LOS_IntLock(); + SCHEDULER_LOCK(intSave); g_sysTickTimer->lock(); #if (LOSCFG_BASE_CORE_TICK_WTIMER == 0) UINT64 currTimeCycle = LOS_SysCycleGet(); @@ -254,7 +256,7 @@ UINT32 LOS_SysTickClockFreqAdjust(const SYS_TICK_FREQ_ADJUST_FUNC handler, UINTP freq = handler(param); if ((freq == 0) || (freq == g_sysClock)) { g_sysTickTimer->unlock(); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_ERRNO_SYS_CLOCK_INVALID; } @@ -271,7 +273,7 @@ UINT32 LOS_SysTickClockFreqAdjust(const SYS_TICK_FREQ_ADJUST_FUNC handler, UINTP g_sysClock = g_sysTickTimer->freq; g_cyclesPerTick = g_sysTickTimer->freq / LOSCFG_BASE_CORE_TICK_PER_SECOND; OsSchedTimeConvertFreq(oldFreq); - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); return LOS_OK; } diff --git a/kernel/src/mm/los_memory.c b/kernel/src/mm/los_memory.c index 2b0a5388..f100039b 100644 --- a/kernel/src/mm/los_memory.c +++ b/kernel/src/mm/los_memory.c @@ -116,12 +116,12 @@ struct OsMemUsedNodeHead { #define MEM_LOCK(pool, state) do { \ if (!((pool)->info.attr & OS_MEM_POOL_UNLOCK_ENABLE)) { \ - (state) = LOS_IntLock(); \ + SCHEDULER_LOCK(state); \ } \ } while (0); #define MEM_UNLOCK(pool, state) do { \ if (!((pool)->info.attr & OS_MEM_POOL_UNLOCK_ENABLE)) { \ - LOS_IntRestore(state); \ + SCHEDULER_UNLOCK(state); \ } \ } while (0); diff --git a/testsuites/include/osTest.h b/testsuites/include/osTest.h index 93199aa0..cecef3fb 100644 --- a/testsuites/include/osTest.h +++ b/testsuites/include/osTest.h @@ -63,6 +63,24 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ +#define TEST_TASK_PARAM_INIT(testTask, task_name, entry, prio) do { \ + (void)memset_s(&(testTask), sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S)); \ + testTask.pfnTaskEntry = (TSK_ENTRY_FUNC)entry; \ + testTask.uwStackSize = 0x1000; \ + testTask.pcName = task_name; \ + testTask.usTaskPrio = prio; \ + testTask.uwResved = LOS_TASK_STATUS_DETACHED; \ + } while (0); + +#ifdef LOSCFG_KERNEL_SMP +#define TEST_TASK_PARAM_INIT_AFFI(testTask, task_name, entry, prio, affi) \ + TEST_TASK_PARAM_INIT(testTask, task_name, entry, prio) \ + testTask.usCpuAffiMask = affi; +#else +#define TEST_TASK_PARAM_INIT_AFFI(stTestTask, task_name, entry, prio, affi) \ + TEST_TASK_PARAM_INIT(stTestTask, task_name, entry, prio) +#endif + #define PRINTF(fmt, args...) \ do { \ printf(fmt, ##args); \ @@ -122,6 +140,7 @@ extern UINT32 g_usSemID; extern UINT32 g_usSemID2; extern UINT32 g_mutexTest; +extern UINT32 g_testPeriod; extern UINT16 g_usSwTmrID; extern UINT32 g_usSemID; extern UINT32 g_testQueueID01; @@ -210,6 +229,7 @@ extern EVENT_CB_S g_exampleEvent; #define TASK_PRIO_TEST 25 #define TASK_PRIO_TEST_NORMAL 20 +#define TASK_PRIO_TEST_SWTMR 4 #define TASK_LOOP_NUM 0x100000 #define QUEUE_LOOP_NUM 100 @@ -249,6 +269,11 @@ extern UINT32 TaskUsedCountGet(VOID); #define TASK_EXISTED_NUM TaskUsedCountGet() #define QUEUE_EXISTED_NUM QueueUsedCountGet() +extern UINT64 TestTickCountGet(VOID); +extern UINT64 TestTickCountByCurrCpuid(VOID); +extern VOID TestBusyTaskDelay(UINT32 tick); +extern VOID TestAssertBusyTaskDelay(UINT32 timeout, UINT32 flag); + #define HWI_NUM_INT_NEG (-4) #define HWI_NUM_INT0 0 #define HWI_NUM_INT1 1 @@ -392,7 +417,7 @@ extern UINT32 g_taskMaxNum; extern LITE_OS_SEC_BSS_INIT LOS_DL_LIST g_stUnusedSemList; -extern LosTask g_losTask; +extern LosTask g_losTask[LOSCFG_KERNEL_CORE_NUM]; extern VOID LOS_Schedule(VOID); extern LosTaskCB *g_taskCBArray; diff --git a/testsuites/sample/kernel/event/It_los_event.h b/testsuites/sample/kernel/event/It_los_event.h index c3cd85b4..48388575 100644 --- a/testsuites/sample/kernel/event/It_los_event.h +++ b/testsuites/sample/kernel/event/It_los_event.h @@ -50,7 +50,7 @@ extern UINT32 g_testTaskID01; extern UINT32 g_testTaskID02; extern UINT32 g_testTaskID03; extern UINT32 g_testQueueID01; -extern UINT32 g_idleTaskID; +extern UINT32 g_idleTaskID[LOSCFG_KERNEL_CORE_NUM]; extern UINT32 g_testTskHandle; extern UINT32 g_usSwTmrMaxNum; diff --git a/testsuites/sample/kernel/mux/It_los_mutex_026.c b/testsuites/sample/kernel/mux/It_los_mutex_026.c index 5511d2e4..2ca7a7c0 100644 --- a/testsuites/sample/kernel/mux/It_los_mutex_026.c +++ b/testsuites/sample/kernel/mux/It_los_mutex_026.c @@ -37,6 +37,7 @@ static VOID TaskFuncC(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; // 4, Here, assert that g_testCount is equal to 4. @@ -51,7 +52,7 @@ static VOID TaskFuncC(VOID) g_testCount++; // 3, Here, assert that priority is equal to 3. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 3, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 3, g_losTask[cpuID].runTask->priority); // 6, Here, assert that g_testCount is equal to 6. ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 6, g_testCount); @@ -61,7 +62,7 @@ static VOID TaskFuncC(VOID) static VOID TaskFuncB(VOID) { UINT32 ret; - + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 2, g_testCount); // 2, Here, assert that g_testCount is equal to 2. @@ -76,7 +77,7 @@ static VOID TaskFuncB(VOID) g_testCount++; // 5, Here, assert that priority is equal to 5. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 5, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 5, g_losTask[cpuID].runTask->priority); // 8, Here, assert that g_testCount is equal to 8. ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 8, g_testCount); g_testCount++; @@ -85,6 +86,7 @@ static VOID TaskFuncB(VOID) static VOID TaskFuncA(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); TSK_INIT_PARAM_S task1 = {0}; TSK_INIT_PARAM_S task2 = {0}; @@ -139,18 +141,19 @@ static VOID TaskFuncA(VOID) ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 9, g_testCount); // 9, Here, assert that g_testCount is equal to 9. // 10, Here, assert that priority is equal to 10. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 10, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 10, g_losTask[cpuID].runTask->priority); } static UINT32 Testcase(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); TSK_INIT_PARAM_S task = {0}; g_testCount = 0; // 25, Here, assert that priority is equal to 25. - ICUNIT_ASSERT_EQUAL(g_losTask.runTask->priority, 25, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL(g_losTask[cpuID].runTask->priority, 25, g_losTask[cpuID].runTask->priority); ret = LOS_MuxCreate(&g_mutexTest1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); @@ -167,7 +170,7 @@ static UINT32 Testcase(VOID) // 9, Here, assert that g_testCount is equal to 9. ICUNIT_ASSERT_EQUAL(g_testCount, 9, g_testCount); // 25, Here, assert that priority is equal to 25. - ICUNIT_ASSERT_EQUAL(g_losTask.runTask->priority, 25, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL(g_losTask[cpuID].runTask->priority, 25, g_losTask[cpuID].runTask->priority); return LOS_OK; } diff --git a/testsuites/sample/kernel/mux/It_los_mutex_027.c b/testsuites/sample/kernel/mux/It_los_mutex_027.c index 720f167f..e1007d91 100644 --- a/testsuites/sample/kernel/mux/It_los_mutex_027.c +++ b/testsuites/sample/kernel/mux/It_los_mutex_027.c @@ -37,6 +37,7 @@ static VOID TaskFuncC(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3. @@ -50,13 +51,14 @@ static VOID TaskFuncC(VOID) // 3, Here, assert that g_testCount is equal to 3. ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, Here, assert that priority is equal to 3. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 3, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 3, g_losTask[cpuID].runTask->priority); g_testCount++; } static VOID TaskFuncB(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 2, g_testCount); // 2, Here, assert that g_testCount is equal to 2. @@ -71,7 +73,7 @@ static VOID TaskFuncB(VOID) ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 4, g_testCount); // 5, Here, assert that priority is equal to 5. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 5, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 5, g_losTask[cpuID].runTask->priority); g_testCount++; } @@ -80,6 +82,7 @@ static VOID TaskFuncA(VOID) UINT32 ret; TSK_INIT_PARAM_S task1 = {0}; TSK_INIT_PARAM_S task2 = {0}; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount); // 1, Here, assert that g_testCount is equal to 1. @@ -116,7 +119,7 @@ static VOID TaskFuncA(VOID) ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); // 10, Here, assert that priority is equal to 10. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 10, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 10, g_losTask[cpuID].runTask->priority); ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 5, g_testCount); // 5, Here, assert that g_testCount is equal to 5. } @@ -125,6 +128,7 @@ static UINT32 Testcase(void) { UINT32 ret; TSK_INIT_PARAM_S task = {0}; + UINT32 cpuID = ArchCurrCpuid(); g_testCount = 0; ret = LOS_MuxCreate(&g_mutexTest1); @@ -142,7 +146,7 @@ static UINT32 Testcase(void) ICUNIT_ASSERT_EQUAL(g_testCount, 5, g_testCount); // 5, Here, assert that g_testCount is equal to 5. // 25, Here, assert that priority is equal to 25. - ICUNIT_ASSERT_EQUAL(g_losTask.runTask->priority, 25, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL(g_losTask[cpuID].runTask->priority, 25, g_losTask[cpuID].runTask->priority); return LOS_OK; } diff --git a/testsuites/sample/kernel/mux/It_los_mutex_029.c b/testsuites/sample/kernel/mux/It_los_mutex_029.c index cbff8eb8..661eb819 100644 --- a/testsuites/sample/kernel/mux/It_los_mutex_029.c +++ b/testsuites/sample/kernel/mux/It_los_mutex_029.c @@ -37,6 +37,7 @@ static VOID TaskFuncD(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3. @@ -50,7 +51,7 @@ static VOID TaskFuncD(VOID) g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 4, g_testCount); // 4, Here, assert that g_testCount is equal to 4. // 2, Here, assert that priority is equal to 2. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 2, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 2, g_losTask[cpuID].runTask->priority); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 5, g_testCount); // 5, Here, assert that g_testCount is equal to 5. } @@ -58,6 +59,7 @@ static VOID TaskFuncD(VOID) static VOID TaskFuncC(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 2, g_testCount); // 2, Here, assert that g_testCount is equal to 2. @@ -71,7 +73,7 @@ static VOID TaskFuncC(VOID) g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 6, g_testCount); // 6, Here, assert that g_testCount is equal to 6. // 5, Here, assert that priority is equal to 5. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 5, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 5, g_losTask[cpuID].runTask->priority); g_testCount++; } @@ -80,6 +82,7 @@ static VOID TaskFuncA(VOID) UINT32 ret; TSK_INIT_PARAM_S task1 = {0}; TSK_INIT_PARAM_S task2 = {0}; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount); // 1, Here, assert that g_testCount is equal to 1. @@ -122,7 +125,7 @@ static VOID TaskFuncA(VOID) ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 7, g_testCount); // 7, Here, assert that g_testCount is equal to 7. // 10, Here, assert that priority is equal to 10. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 10, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 10, g_losTask[cpuID].runTask->priority); g_testCount++; } @@ -130,6 +133,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; TSK_INIT_PARAM_S task = {0}; + UINT32 cpuID = ArchCurrCpuid(); g_testCount = 0; ret = LOS_MuxCreate(&g_mutexTest1); @@ -151,7 +155,7 @@ static UINT32 Testcase(VOID) // 8, Here, assert that g_testCount is equal to 8. ICUNIT_ASSERT_EQUAL(g_testCount, 8, g_testCount); // 25, Here, assert that priority is equal to 25. - ICUNIT_ASSERT_EQUAL(g_losTask.runTask->priority, 25, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL(g_losTask[cpuID].runTask->priority, 25, g_losTask[cpuID].runTask->priority); return LOS_OK; } diff --git a/testsuites/sample/kernel/mux/It_los_mutex_030.c b/testsuites/sample/kernel/mux/It_los_mutex_030.c index 64c5f61a..40f9856e 100644 --- a/testsuites/sample/kernel/mux/It_los_mutex_030.c +++ b/testsuites/sample/kernel/mux/It_los_mutex_030.c @@ -37,6 +37,7 @@ static VOID TaskFuncC(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3. @@ -49,7 +50,7 @@ static VOID TaskFuncC(VOID) ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); // 3, Here, assert that priority is equal to 3. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 3, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 3, g_losTask[cpuID].runTask->priority); ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 5, g_testCount); // 5, Here, assert that g_testCount is equal to 5. g_testCount++; @@ -58,6 +59,7 @@ static VOID TaskFuncC(VOID) static VOID TaskFuncB(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 2, g_testCount); // 2, Here, assert that g_testCount is equal to 2. @@ -65,7 +67,7 @@ static VOID TaskFuncB(VOID) ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_ERRNO_MUX_TIMEOUT, ret); // 5, Here, assert that priority is equal to 5. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 5, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 5, g_losTask[cpuID].runTask->priority); ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3. g_testCount++; } @@ -75,6 +77,7 @@ static VOID TaskFuncA(VOID) UINT32 ret; TSK_INIT_PARAM_S task1 = {0}; TSK_INIT_PARAM_S task2 = {0}; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount); // 1, Here, assert that g_testCount is equal to 1. @@ -116,13 +119,14 @@ static VOID TaskFuncA(VOID) ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); // 10, Here, assert that priority is equal to 10. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 10, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 10, g_losTask[cpuID].runTask->priority); } static UINT32 Testcase(VOID) { UINT32 ret; TSK_INIT_PARAM_S task = {0}; + UINT32 cpuID = ArchCurrCpuid(); g_testCount = 0; ret = LOS_MuxCreate(&g_mutexTest1); @@ -143,7 +147,7 @@ static UINT32 Testcase(VOID) ICUNIT_ASSERT_EQUAL(g_testCount, 7, g_testCount); // 7, Here, assert that g_testCount is equal to 7. // 25, Here, assert that priority is equal to 25. - ICUNIT_ASSERT_EQUAL(g_losTask.runTask->priority, 25, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL(g_losTask[cpuID].runTask->priority, 25, g_losTask[cpuID].runTask->priority); return LOS_OK; } diff --git a/testsuites/sample/kernel/mux/It_los_mutex_031.c b/testsuites/sample/kernel/mux/It_los_mutex_031.c index 9afd0804..e631d50a 100644 --- a/testsuites/sample/kernel/mux/It_los_mutex_031.c +++ b/testsuites/sample/kernel/mux/It_los_mutex_031.c @@ -37,6 +37,7 @@ static VOID TaskFuncC(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3. @@ -49,13 +50,14 @@ static VOID TaskFuncC(VOID) ret = LOS_MuxPost(g_mutexTest2); ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); // 3, Here, assert that priority is equal to 3. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 3, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 3, g_losTask[cpuID].runTask->priority); g_testCount++; } static VOID TaskFuncB(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 2, g_testCount); // 2, Here, assert that g_testCount is equal to 2. @@ -68,7 +70,7 @@ static VOID TaskFuncB(VOID) ret = LOS_MuxPost(g_mutexTest1); ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); // 5, Here, assert that priority is equal to 5. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 5, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 5, g_losTask[cpuID].runTask->priority); g_testCount++; } @@ -78,6 +80,7 @@ static VOID TaskFuncA(VOID) UINT32 ret; TSK_INIT_PARAM_S task1 = {0}; TSK_INIT_PARAM_S task2 = {0}; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount); // 1, Here, assert that g_testCount is equal to 1. @@ -119,7 +122,7 @@ static VOID TaskFuncA(VOID) ret = LOS_MuxPost(g_mutexTest2); ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); // 10, Here, assert that priority is equal to 10. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 10, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 10, g_losTask[cpuID].runTask->priority); // 6, Here, assert that g_testCount is equal to 6. ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 6, g_testCount); g_testCount++; @@ -129,6 +132,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; TSK_INIT_PARAM_S task = {0}; + UINT32 cpuID = ArchCurrCpuid(); g_testCount = 0; ret = LOS_MuxCreate(&g_mutexTest1); @@ -155,7 +159,7 @@ static UINT32 Testcase(VOID) // 7, Here, assert that g_testCount is equal to 7. ICUNIT_ASSERT_EQUAL(g_testCount, 7, g_testCount); // 25, Here, assert that priority is equal to 25. - ICUNIT_ASSERT_EQUAL(g_losTask.runTask->priority, 25, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL(g_losTask[cpuID].runTask->priority, 25, g_losTask[cpuID].runTask->priority); return LOS_OK; } diff --git a/testsuites/sample/kernel/mux/It_los_mutex_033.c b/testsuites/sample/kernel/mux/It_los_mutex_033.c index f7315987..d839dd42 100644 --- a/testsuites/sample/kernel/mux/It_los_mutex_033.c +++ b/testsuites/sample/kernel/mux/It_los_mutex_033.c @@ -38,6 +38,7 @@ static VOID TaskFuncC(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3. @@ -49,7 +50,7 @@ static VOID TaskFuncC(VOID) ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); // 5, Here, assert that priority is equal to 5. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 5, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 5, g_losTask[cpuID].runTask->priority); // 3, Here, assert that g_testCount is equal to 3. ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); @@ -59,6 +60,7 @@ static VOID TaskFuncC(VOID) static VOID TaskFuncB(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 2, g_testCount); // 2, Here, assert that g_testCount is equal to 2. @@ -70,7 +72,7 @@ static VOID TaskFuncB(VOID) ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); // 8, Here, assert that priority is equal to 8. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 8, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 8, g_losTask[cpuID].runTask->priority); // 4, Here, assert that g_testCount is equal to 4. ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 4, g_testCount); @@ -83,6 +85,7 @@ static VOID TaskFuncA(VOID) UINT32 ret; TSK_INIT_PARAM_S task1 = {0}; TSK_INIT_PARAM_S task2 = {0}; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount); // 1, Here, assert that g_testCount is equal to 1. @@ -116,7 +119,7 @@ static VOID TaskFuncA(VOID) ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); // 10, Here, assert that priority is equal to 10. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 10, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 10, g_losTask[cpuID].runTask->priority); // 5, Here, assert that g_testCount is equal to 5. ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 5, g_testCount); } @@ -125,6 +128,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; TSK_INIT_PARAM_S task = {0}; + UINT32 cpuID = ArchCurrCpuid(); g_testCount = 0; ret = LOS_MuxCreate(&g_mutexTest1); @@ -148,7 +152,7 @@ static UINT32 Testcase(VOID) ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); // 25, Here, assert that priority is equal to 25. - ICUNIT_ASSERT_EQUAL(g_losTask.runTask->priority, 25, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL(g_losTask[cpuID].runTask->priority, 25, g_losTask[cpuID].runTask->priority); ICUNIT_ASSERT_EQUAL(g_testCount, 5, g_testCount); // 5, Here, assert that g_testCount is equal to 5. return LOS_OK; diff --git a/testsuites/sample/kernel/mux/It_los_mutex_034.c b/testsuites/sample/kernel/mux/It_los_mutex_034.c index 62d876c0..c2a296c5 100644 --- a/testsuites/sample/kernel/mux/It_los_mutex_034.c +++ b/testsuites/sample/kernel/mux/It_los_mutex_034.c @@ -37,6 +37,7 @@ static VOID TaskFuncC(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 3, g_testCount); // 3, Here, assert that g_testCount is equal to 3. @@ -51,7 +52,7 @@ static VOID TaskFuncC(VOID) ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); // 5, Here, assert that priority is equal to 5. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 5, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 5, g_losTask[cpuID].runTask->priority); g_testCount++; } @@ -59,6 +60,7 @@ static VOID TaskFuncC(VOID) static VOID TaskFuncB(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 2, g_testCount); // 2, Here, assert that g_testCount is equal to 2. @@ -72,7 +74,7 @@ static VOID TaskFuncB(VOID) ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); // 8, Here, assert that priority is equal to 8. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 8, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 8, g_losTask[cpuID].runTask->priority); g_testCount++; } @@ -81,6 +83,7 @@ static VOID TaskFuncA(VOID) UINT32 ret; TSK_INIT_PARAM_S task1 = {0}; TSK_INIT_PARAM_S task2 = {0}; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount); // 1, Here, assert that g_testCount is equal to 1. @@ -114,7 +117,7 @@ static VOID TaskFuncA(VOID) ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); // 10, Here, assert that priority is equal to 10. - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, 10, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, 10, g_losTask[cpuID].runTask->priority); ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 6, g_testCount); // 6, Here, assert that g_testCount is equal to 6. } @@ -123,6 +126,7 @@ static UINT32 Testcase(VOID) { UINT32 ret; TSK_INIT_PARAM_S task = {0}; + UINT32 cpuID = ArchCurrCpuid(); g_testCount = 0; ret = LOS_MuxCreate(&g_mutexTest1); @@ -145,7 +149,7 @@ static UINT32 Testcase(VOID) ret = LOS_MuxDelete(g_mutexTest1); ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret); // 25, Here, assert that priority is equal to 25. - ICUNIT_ASSERT_EQUAL(g_losTask.runTask->priority, 25, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL(g_losTask[cpuID].runTask->priority, 25, g_losTask[cpuID].runTask->priority); ICUNIT_ASSERT_EQUAL(g_testCount, 6, g_testCount); // 6, Here, assert that g_testCount is equal to 6. return LOS_OK; diff --git a/testsuites/sample/kernel/swtmr/It_los_swtmr.h b/testsuites/sample/kernel/swtmr/It_los_swtmr.h index db83abde..bfe3adc5 100644 --- a/testsuites/sample/kernel/swtmr/It_los_swtmr.h +++ b/testsuites/sample/kernel/swtmr/It_los_swtmr.h @@ -54,7 +54,7 @@ extern EVENT_CB_S g_eventCB3; #define TIMER_LOS_HANDLER_PARAMETER 0xFF #define TIMER_LOS_SELF_DELETED 1 -extern UINT32 g_idleTaskID; +extern UINT32 g_idleTaskID[LOSCFG_KERNEL_CORE_NUM]; extern UINT32 g_swtmrId1; extern UINT32 g_swtmrId2; diff --git a/testsuites/sample/kernel/task/It_los_task.h b/testsuites/sample/kernel/task/It_los_task.h index 4d04643e..2c93be84 100644 --- a/testsuites/sample/kernel/task/It_los_task.h +++ b/testsuites/sample/kernel/task/It_los_task.h @@ -55,7 +55,7 @@ extern UINT32 g_testTaskID01; extern UINT32 g_testTaskID02; extern UINT32 g_testTaskID03; extern UINT32 g_testQueueID01; -extern UINT32 g_idleTaskID; +extern UINT32 g_idleTaskID[LOSCFG_KERNEL_CORE_NUM]; extern UINT32 g_testTskHandle; extern UINT32 g_usSwTmrMaxNum; diff --git a/testsuites/sample/kernel/task/It_los_task_023.c b/testsuites/sample/kernel/task/It_los_task_023.c index 97cf538d..41f34162 100644 --- a/testsuites/sample/kernel/task/It_los_task_023.c +++ b/testsuites/sample/kernel/task/It_los_task_023.c @@ -36,8 +36,9 @@ static UINT32 TestCase(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); - ret = LOS_TaskDelete(g_idleTaskID); + ret = LOS_TaskDelete(g_idleTaskID[cpuID]); ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_TSK_OPERATE_IDLE, ret); return LOS_OK; diff --git a/testsuites/sample/kernel/task/It_los_task_032.c b/testsuites/sample/kernel/task/It_los_task_032.c index d7bc0240..58503e06 100644 --- a/testsuites/sample/kernel/task/It_los_task_032.c +++ b/testsuites/sample/kernel/task/It_los_task_032.c @@ -36,11 +36,12 @@ static UINT32 TestCase(VOID) { UINT32 ret; + UINT32 cpuID = ArchCurrCpuid(); - ret = LOS_TaskSuspend(g_idleTaskID); + ret = LOS_TaskSuspend(g_idleTaskID[cpuID]); ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_TSK_OPERATE_IDLE, ret); - ret = LOS_TaskResume(g_idleTaskID); + ret = LOS_TaskResume(g_idleTaskID[cpuID]); ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_TSK_NOT_SUSPENDED, ret); return LOS_OK; diff --git a/testsuites/sample/kernel/task/It_los_task_047.c b/testsuites/sample/kernel/task/It_los_task_047.c index 86ff1df8..90598f4d 100644 --- a/testsuites/sample/kernel/task/It_los_task_047.c +++ b/testsuites/sample/kernel/task/It_los_task_047.c @@ -37,17 +37,18 @@ static VOID TaskF01(VOID) { UINT32 ret, newPrio; + UINT32 cpuID = ArchCurrCpuid(); g_testCount++; ret = LOS_CurTaskPriSet(OS_TASK_PRIORITY_HIGHEST); ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, OS_TASK_PRIORITY_HIGHEST, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, OS_TASK_PRIORITY_HIGHEST, g_losTask[cpuID].runTask->priority); newPrio = TASK_PRIO_TEST - 4; // 4,get new priority, it is higher than the task of testsuit. ret = LOS_CurTaskPriSet(newPrio); ICUNIT_ASSERT_EQUAL_VOID(ret, LOS_OK, ret); - ICUNIT_ASSERT_EQUAL_VOID(g_losTask.runTask->priority, newPrio, g_losTask.runTask->priority); + ICUNIT_ASSERT_EQUAL_VOID(g_losTask[cpuID].runTask->priority, newPrio, g_losTask[cpuID].runTask->priority); ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 1, g_testCount); ret = LOS_CurTaskPriSet(OS_TASK_PRIORITY_LOWEST); diff --git a/testsuites/sample/kernel/task/It_los_task_105.c b/testsuites/sample/kernel/task/It_los_task_105.c index e80462ec..44b11d1e 100644 --- a/testsuites/sample/kernel/task/It_los_task_105.c +++ b/testsuites/sample/kernel/task/It_los_task_105.c @@ -54,6 +54,7 @@ static UINT32 TestCase(VOID) { UINT32 ret; TSK_INIT_PARAM_S task1 = { 0 }; + UINT32 cpuID = ArchCurrCpuid(); task1.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskF01; task1.uwStackSize = TASK_STACK_SIZE_TEST; task1.pcName = "Tsk105A"; @@ -65,7 +66,7 @@ static UINT32 TestCase(VOID) ret = LOS_TaskPriSet(g_testTaskID01, TASK_PRIO_TEST - 1); ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_TSK_NOT_CREATED, ret); - ret = LOS_TaskPriSet(g_idleTaskID, TASK_PRIO_TEST - 1); + ret = LOS_TaskPriSet(g_idleTaskID[cpuID], TASK_PRIO_TEST - 1); ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_TSK_OPERATE_IDLE, ret); ret = LOS_TaskPriSet(g_taskMaxNum + 1, TASK_PRIO_TEST - 1); diff --git a/utils/los_debug.c b/utils/los_debug.c index 0af5a980..efa5ae00 100644 --- a/utils/los_debug.c +++ b/utils/los_debug.c @@ -67,20 +67,24 @@ VOID OsBackTraceHookCall(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR S VOID OsExcHookRegister(ExcHookFn excHookFn) { - UINT32 intSave = LOS_IntLock(); + UINT32 intSave; + + SCHEDULER_LOCK(intSave); if (!g_excHook) { g_excHook = excHookFn; } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); } VOID OsDoExcHook(EXC_TYPE excType) { - UINT32 intSave = LOS_IntLock(); + UINT32 intSave; + + SCHEDULER_LOCK(intSave); if (g_excHook) { g_excHook(excType); } - LOS_IntRestore(intSave); + SCHEDULER_UNLOCK(intSave); } #if (LOSCFG_KERNEL_PRINTF == 1)