未验证 提交 046d8def 编写于 作者: O openharmony_ci 提交者: Gitee

!791 feat: 调度相关模块间依赖优化

Merge pull request !791 from zhushengle/sched_rq
......@@ -33,6 +33,7 @@
#include "los_memory_pri.h"
#include "los_printf_pri.h"
#include "los_task_pri.h"
#include "los_percpu_pri.h"
#include "los_hw_pri.h"
#ifdef LOSCFG_SAVE_EXCINFO
#include "los_excinfo_pri.h"
......@@ -58,6 +59,7 @@
#include "los_bitmap.h"
#include "los_process_pri.h"
#include "los_exc_pri.h"
#include "los_sched_pri.h"
#ifdef LOSCFG_FS_VFS
#include "console.h"
#endif
......@@ -191,7 +193,7 @@ UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT3
return LOS_ERRNO_VM_NOT_FOUND;
}
#if defined(LOSCFG_KERNEL_SMP) && defined(LOSCFG_DEBUG_VERSION)
BOOL irqEnable = !(LOS_SpinHeld(&g_taskSpin) && (OsPercpuGet()->taskLockCnt != 0));
BOOL irqEnable = !(LOS_SpinHeld(&g_taskSpin) && OsSchedIsLock());
if (irqEnable) {
ArchIrqEnable();
} else {
......@@ -535,9 +537,9 @@ STATIC VOID OsExcRestore(VOID)
g_intCount[currCpuID] = 0;
g_curNestCount[currCpuID] = 0;
#ifdef LOSCFG_KERNEL_SMP
OsPercpuGet()->excFlag = CPU_RUNNING;
OsCpuStatusSet(CPU_RUNNING);
#endif
OsPercpuGet()->taskLockCnt = 0;
OsSchedLockSet(0);
}
STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
......@@ -977,28 +979,6 @@ VOID OsDataAbortExcHandleEntry(ExcContext *excBufAddr)
#define EXC_WAIT_INTER 50U
#define EXC_WAIT_TIME 2000U
STATIC VOID OsAllCpuStatusOutput(VOID)
{
UINT32 i;
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
switch (g_percpu[i].excFlag) {
case CPU_RUNNING:
PrintExcInfo("cpu%u is running.\n", i);
break;
case CPU_HALT:
PrintExcInfo("cpu%u is halted.\n", i);
break;
case CPU_EXC:
PrintExcInfo("cpu%u is in exc.\n", i);
break;
default:
break;
}
}
PrintExcInfo("The current handling the exception is cpu%u !\n", ArchCurrCpuid());
}
STATIC VOID WaitAllCpuStop(UINT32 cpuID)
{
UINT32 i;
......@@ -1006,7 +986,7 @@ STATIC VOID WaitAllCpuStop(UINT32 cpuID)
while (time < EXC_WAIT_TIME) {
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
if ((i != cpuID) && (g_percpu[i].excFlag != CPU_HALT)) {
if ((i != cpuID) && !OsCpuStatusIsHalt(i)) {
LOS_Mdelay(EXC_WAIT_INTER);
time += EXC_WAIT_INTER;
break;
......@@ -1044,7 +1024,7 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
UINT32 currCpuID = ArchCurrCpuid();
UINT32 ret, target;
OsPercpuGet()->excFlag = CPU_EXC;
OsCpuStatusSet(CPU_EXC);
LOCKDEP_CLEAR_LOCKS();
LOS_SpinLock(&g_excSerializerSpin);
......@@ -1152,15 +1132,15 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsPrintExcHead(UINT32 far)
STATIC VOID OsSysStateSave(UINT32 *intCount, UINT32 *lockCount)
{
*intCount = g_intCount[ArchCurrCpuid()];
*lockCount = OsPercpuGet()->taskLockCnt;
*lockCount = OsSchedLockCountGet();
g_intCount[ArchCurrCpuid()] = 0;
OsPercpuGet()->taskLockCnt = 0;
OsSchedLockSet(0);
}
STATIC VOID OsSysStateRestore(UINT32 intCount, UINT32 lockCount)
{
g_intCount[ArchCurrCpuid()] = intCount;
OsPercpuGet()->taskLockCnt = lockCount;
OsSchedLockSet(lockCount);
}
#endif
......@@ -1177,7 +1157,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
#endif
/* Task scheduling is not allowed during exception handling */
OsPercpuGet()->taskLockCnt++;
OsSchedLock();
g_curNestCount[ArchCurrCpuid()]++;
......
......@@ -810,7 +810,6 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSystemProcessCreate(VOID)
kerInitProcess->processStatus &= ~OS_PROCESS_STATUS_INIT;
g_processGroup = kerInitProcess->group;
LOS_ListInit(&g_processGroup->groupList);
OsCurrProcessSet(kerInitProcess);
LosProcessCB *idleProcess = OS_PCB_FROM_PID(g_kernelIdleProcess);
ret = OsInitPCB(idleProcess, OS_KERNEL_MODE, OS_TASK_PRIORITY_LOWEST, "KIdle");
......@@ -832,7 +831,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSystemProcessCreate(VOID)
if (ret != LOS_OK) {
return ret;
}
idleProcess->threadGroupID = OsPercpuGet()->idleTaskID;
idleProcess->threadGroupID = OsGetIdleTaskId();
return LOS_OK;
}
......@@ -907,7 +906,7 @@ LITE_OS_SEC_TEXT INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio
}
#endif
needSched = OsSchedModifyProcessSchedParam(processCB, policy, prio);
needSched = OsSchedModifyProcessSchedParam(pid, policy, prio);
SCHEDULER_UNLOCK(intSave);
LOS_MpSchedule(OS_MP_CPU_ALL);
......
......@@ -45,8 +45,6 @@ STATIC VOID OsSmpSecondaryInit(VOID *arg)
{
UNUSED(arg);
OsCurrProcessSet(OS_PCB_FROM_PID(OsGetKernelInitProcessID()));
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
OsSwtmrInit();
#endif
......
......@@ -52,13 +52,13 @@ 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))
LITE_OS_SEC_TEXT VOID OsSwtmrTask(VOID)
STATIC VOID SwtmrTask(VOID)
{
SwtmrHandlerItemPtr swtmrHandlePtr = NULL;
SwtmrHandlerItem swtmrHandle;
UINT32 ret, swtmrHandlerQueue;
swtmrHandlerQueue = OsPercpuGet()->swtmrHandlerQueue;
swtmrHandlerQueue = OsSchedSwtmrHandlerQueueGet();
for (;;) {
ret = LOS_QueueRead(swtmrHandlerQueue, &swtmrHandlePtr, sizeof(CHAR *), LOS_WAIT_FOREVER);
if ((ret == LOS_OK) && (swtmrHandlePtr != NULL)) {
......@@ -72,14 +72,13 @@ LITE_OS_SEC_TEXT VOID OsSwtmrTask(VOID)
}
}
LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID)
STATIC UINT32 SwtmrTaskCreate(UINT16 cpuid, UINT32 *swtmrTaskID)
{
UINT32 ret, swtmrTaskID;
UINT32 ret;
TSK_INIT_PARAM_S swtmrTask;
UINT32 cpuid = ArchCurrCpuid();
(VOID)memset_s(&swtmrTask, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S));
swtmrTask.pfnTaskEntry = (TSK_ENTRY_FUNC)OsSwtmrTask;
swtmrTask.pfnTaskEntry = (TSK_ENTRY_FUNC)SwtmrTask;
swtmrTask.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
swtmrTask.pcName = "Swt_Task";
swtmrTask.usTaskPrio = 0;
......@@ -87,15 +86,22 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID)
#ifdef LOSCFG_KERNEL_SMP
swtmrTask.usCpuAffiMask = CPUID_TO_AFFI_MASK(cpuid);
#endif
ret = LOS_TaskCreate(&swtmrTaskID, &swtmrTask);
ret = LOS_TaskCreate(swtmrTaskID, &swtmrTask);
if (ret == LOS_OK) {
g_percpu[cpuid].swtmrTaskID = swtmrTaskID;
OS_TCB_FROM_TID(swtmrTaskID)->taskStatus |= OS_TASK_FLAG_SYSTEM_TASK;
OS_TCB_FROM_TID(*swtmrTaskID)->taskStatus |= OS_TASK_FLAG_SYSTEM_TASK;
}
return ret;
}
BOOL OsIsSwtmrTask(const LosTaskCB *taskCB)
{
if (taskCB->taskEntry == (TSK_ENTRY_FUNC)SwtmrTask) {
return TRUE;
}
return FALSE;
}
LITE_OS_SEC_TEXT_INIT VOID OsSwtmrRecycle(UINT32 processID)
{
for (UINT16 index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++) {
......@@ -113,6 +119,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
SWTMR_CTRL_S *swtmr = NULL;
UINT32 swtmrHandlePoolSize;
UINT32 cpuid = ArchCurrCpuid();
UINT32 swtmrTaskID, swtmrHandlerQueue;
if (cpuid == 0) {
size = sizeof(SWTMR_CTRL_S) * LOSCFG_BASE_CORE_SWTMR_LIMIT;
swtmr = (SWTMR_CTRL_S *)LOS_MemAlloc(m_aucSysMem0, size); /* system resident resource */
......@@ -142,31 +150,21 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
ret = LOS_ERRNO_SWTMR_HANDLER_POOL_NO_MEM;
goto ERROR;
}
ret = OsSchedSwtmrScanRegister((SchedScan)OsSwtmrScan);
if (ret != LOS_OK) {
goto ERROR;
}
}
ret = LOS_QueueCreate(NULL, OS_SWTMR_HANDLE_QUEUE_SIZE, &g_percpu[cpuid].swtmrHandlerQueue, 0, sizeof(CHAR *));
ret = LOS_QueueCreate(NULL, OS_SWTMR_HANDLE_QUEUE_SIZE, &swtmrHandlerQueue, 0, sizeof(CHAR *));
if (ret != LOS_OK) {
ret = LOS_ERRNO_SWTMR_QUEUE_CREATE_FAILED;
goto ERROR;
}
ret = OsSwtmrTaskCreate();
ret = SwtmrTaskCreate(cpuid, &swtmrTaskID);
if (ret != LOS_OK) {
ret = LOS_ERRNO_SWTMR_TASK_CREATE_FAILED;
goto ERROR;
}
ret = OsSortLinkInit(&g_percpu[cpuid].swtmrSortLink);
if (ret != LOS_OK) {
ret = LOS_ERRNO_SWTMR_SORTLINK_CREATE_FAILED;
goto ERROR;
}
OsSchedRunQueSwtmrInit(swtmrTaskID, swtmrHandlerQueue);
return LOS_OK;
ERROR:
......@@ -178,7 +176,7 @@ ERROR:
* Description: Start Software Timer
* Input : swtmr --- Need to start software timer
*/
LITE_OS_SEC_TEXT VOID OsSwtmrStart(UINT64 currTime, SWTMR_CTRL_S *swtmr)
LITE_OS_SEC_TEXT VOID OsSwtmrStart(SWTMR_CTRL_S *swtmr)
{
UINT32 ticks;
......@@ -191,8 +189,8 @@ LITE_OS_SEC_TEXT VOID OsSwtmrStart(UINT64 currTime, SWTMR_CTRL_S *swtmr)
}
swtmr->ucState = OS_SWTMR_STATUS_TICKING;
OsAdd2SortLink(&swtmr->stSortList, swtmr->startTime, ticks, OS_SORT_LINK_SWTMR);
OsSchedUpdateExpireTime(currTime);
OsSchedAddSwtmr2TimeList(&swtmr->stSortList, swtmr->startTime, ticks);
OsSchedUpdateExpireTime();
return;
}
......@@ -208,15 +206,18 @@ STATIC INLINE VOID OsSwtmrDelete(SWTMR_CTRL_S *swtmr)
swtmr->uwOwnerPid = 0;
}
STATIC INLINE VOID OsWakePendTimeSwtmr(Percpu *cpu, UINT64 currTime, SWTMR_CTRL_S *swtmr)
VOID OsSwtmrWake(SchedRunQue *rq, UINT64 startTime, SortLinkList *sortList)
{
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
OsHookCall(LOS_HOOK_TYPE_SWTMR_EXPIRED, swtmr);
LOS_SpinLock(&g_swtmrSpin);
SwtmrHandlerItemPtr swtmrHandler = (SwtmrHandlerItemPtr)LOS_MemboxAlloc(g_swtmrHandlerPool);
if (swtmrHandler != NULL) {
swtmrHandler->handler = swtmr->pfnHandler;
swtmrHandler->arg = swtmr->uwArg;
if (LOS_QueueWrite(cpu->swtmrHandlerQueue, swtmrHandler, sizeof(CHAR *), LOS_NO_WAIT)) {
if (LOS_QueueWrite(rq->swtmrHandlerQueue, swtmrHandler, sizeof(CHAR *), LOS_NO_WAIT)) {
(VOID)LOS_MemboxFree(g_swtmrHandlerPool, swtmrHandler);
}
}
......@@ -233,81 +234,32 @@ STATIC INLINE VOID OsWakePendTimeSwtmr(Percpu *cpu, UINT64 currTime, SWTMR_CTRL_
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
} else {
swtmr->uwOverrun++;
OsSwtmrStart(currTime, swtmr);
swtmr->startTime = startTime;
OsSwtmrStart(swtmr);
}
LOS_SpinUnlock(&g_swtmrSpin);
}
/*
* Description: Tick interrupt interface module of software timer
* Return : LOS_OK on success or error code on failure
*/
LITE_OS_SEC_TEXT VOID OsSwtmrScan(VOID)
VOID OsSwtmrRestart(UINT64 startTime, SortLinkList *sortList)
{
Percpu *cpu = OsPercpuGet();
SortLinkAttribute* swtmrSortLink = &cpu->swtmrSortLink;
LOS_DL_LIST *listObject = &swtmrSortLink->sortLink;
/*
* it needs to be carefully coped with, since the swtmr is in specific sortlink
* while other cores still has the chance to process it, like stop the timer.
*/
LOS_SpinLock(&cpu->swtmrSortLinkSpin);
if (LOS_ListEmpty(listObject)) {
LOS_SpinUnlock(&cpu->swtmrSortLinkSpin);
return;
}
SortLinkList *sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
UINT64 currTime = OsGetCurrSchedTimeCycle();
while (sortList->responseTime <= currTime) {
sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
swtmr->startTime = GET_SORTLIST_VALUE(sortList);
OsDeleteNodeSortLink(swtmrSortLink, sortList);
LOS_SpinUnlock(&cpu->swtmrSortLinkSpin);
OsHookCall(LOS_HOOK_TYPE_SWTMR_EXPIRED, swtmr);
OsWakePendTimeSwtmr(cpu, currTime, swtmr);
LOS_SpinLock(&cpu->swtmrSortLinkSpin);
if (LOS_ListEmpty(listObject)) {
break;
}
sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
}
UINT32 intSave;
LOS_SpinUnlock(&cpu->swtmrSortLinkSpin);
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
SWTMR_LOCK(intSave);
swtmr->startTime = startTime;
OsSwtmrStart(swtmr);
SWTMR_UNLOCK(intSave);
}
LITE_OS_SEC_TEXT VOID OsSwtmrResponseTimeReset(UINT64 startTime)
BOOL OsSwtmrWorkQueueFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg)
{
UINT32 intSave;
Percpu *cpu = OsPercpuGet();
SortLinkAttribute* swtmrSortLink = &cpu->swtmrSortLink;
LOS_DL_LIST *listHead = &swtmrSortLink->sortLink;
LOS_DL_LIST *listNext = listHead->pstNext;
LOS_SpinLock(&cpu->swtmrSortLinkSpin);
while (listNext != listHead) {
SortLinkList *sortList = LOS_DL_LIST_ENTRY(listNext, SortLinkList, sortLinkNode);
OsDeleteNodeSortLink(swtmrSortLink, sortList);
LOS_SpinUnlock(&cpu->swtmrSortLinkSpin);
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
SWTMR_LOCK(intSave);
swtmr->startTime = startTime;
OsSwtmrStart(startTime, swtmr);
SWTMR_UNLOCK(intSave);
LOS_SpinLock(&cpu->swtmrSortLinkSpin);
listNext = listNext->pstNext;
}
LOS_SpinUnlock(&cpu->swtmrSortLinkSpin);
SWTMR_LOCK(intSave);
BOOL find = OsSchedSwtmrTimeListFind(checkFunc, arg);
SWTMR_UNLOCK(intSave);
return find;
}
/*
......@@ -316,7 +268,8 @@ LITE_OS_SEC_TEXT VOID OsSwtmrResponseTimeReset(UINT64 startTime)
*/
LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
{
return OsSortLinkGetNextExpireTime(&OsPercpuGet()->swtmrSortLink);
UINT64 currTime = OsGetCurrSchedTimeCycle();
return (OsSortLinkGetNextExpireTime(currTime, &OsSchedRunQue()->swtmrSortLink) / OS_CYCLE_PER_TICK);
}
/*
......@@ -325,12 +278,12 @@ LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
*/
LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(SWTMR_CTRL_S *swtmr)
{
OsDeleteSortLink(&swtmr->stSortList, OS_SORT_LINK_SWTMR);
OsSchedDeSwtmrFromTimeList(&swtmr->stSortList);
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
swtmr->uwOverrun = 0;
OsSchedUpdateExpireTime(OsGetCurrSchedTimeCycle());
OsSchedUpdateExpireTime();
}
/*
......@@ -339,7 +292,8 @@ LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(SWTMR_CTRL_S *swtmr)
*/
LITE_OS_SEC_TEXT STATIC UINT32 OsSwtmrTimeGet(const SWTMR_CTRL_S *swtmr)
{
return OsSortLinkGetTargetExpireTime(&swtmr->stSortList);
UINT64 currTime = OsGetCurrSchedTimeCycle();
return (OsSortLinkGetTargetExpireTime(currTime, &swtmr->stSortList) / OS_CYCLE_PER_TICK);
}
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
......@@ -427,7 +381,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrID)
/* fall-through */
case OS_SWTMR_STATUS_CREATED:
swtmr->startTime = OsGetCurrSchedTimeCycle();
OsSwtmrStart(swtmr->startTime, swtmr);
OsSwtmrStart(swtmr);
break;
default:
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
......
......@@ -94,6 +94,7 @@ VOID OsSetMainTask()
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
g_mainTask[i].taskStatus = OS_TASK_STATUS_UNUSED;
g_mainTask[i].taskID = LOSCFG_BASE_CORE_TSK_LIMIT;
g_mainTask[i].processID = OS_KERNEL_PROCESS_GROUP;
g_mainTask[i].priority = OS_TASK_PRIORITY_LOWEST;
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
g_mainTask[i].lockDep.lockDepth = 0;
......@@ -216,16 +217,14 @@ EXIT:
UINT32 OsGetIdleTaskId(VOID)
{
Percpu *perCpu = OsPercpuGet();
return perCpu->idleTaskID;
return OsSchedGetRunQueIdle();
}
LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
{
UINT32 ret;
TSK_INIT_PARAM_S taskInitParam;
Percpu *perCpu = OsPercpuGet();
UINT32 *idleTaskID = &perCpu->idleTaskID;
UINT32 idleTaskID;
(VOID)memset_s((VOID *)(&taskInitParam), sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S));
taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)OsIdleTask;
......@@ -236,9 +235,10 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
#ifdef LOSCFG_KERNEL_SMP
taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
#endif
ret = LOS_TaskCreateOnly(idleTaskID, &taskInitParam);
LosTaskCB *idleTask = OS_TCB_FROM_TID(*idleTaskID);
ret = LOS_TaskCreateOnly(&idleTaskID, &taskInitParam);
LosTaskCB *idleTask = OS_TCB_FROM_TID(idleTaskID);
idleTask->taskStatus |= OS_TASK_FLAG_SYSTEM_TASK;
OsSchedRunQueIdleInit(idleTaskID);
OsSchedSetIdleTaskSchedParam(idleTask);
return ret;
......@@ -968,11 +968,6 @@ LITE_OS_SEC_TEXT UINT32 OsTaskDeleteUnsafe(LosTaskCB *taskCB, UINT32 status, UIN
SCHEDULER_LOCK(intSave);
}
#ifdef LOSCFG_KERNEL_SMP
LOS_ASSERT(OsPercpuGet()->taskLockCnt == 1);
#else
LOS_ASSERT(OsPercpuGet()->taskLockCnt == 0);
#endif
OsRunTaskToDelete(taskCB);
EXIT:
......@@ -1149,13 +1144,21 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskLock(VOID)
UINT32 intSave;
intSave = LOS_IntLock();
OsCpuSchedLock(OsPercpuGet());
OsSchedLock();
LOS_IntRestore(intSave);
}
LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskUnlock(VOID)
{
OsCpuSchedUnlock(OsPercpuGet(), LOS_IntLock());
UINT32 intSave;
intSave = LOS_IntLock();
BOOL needSched = OsSchedUnlockResch();
LOS_IntRestore(intSave);
if (needSched) {
LOS_Schedule();
}
}
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInfo)
......
......@@ -34,8 +34,6 @@
#include "los_base.h"
#include "los_hw_cpu.h"
#include "los_spinlock.h"
#include "los_sortlink_pri.h"
#ifdef __cplusplus
#if __cplusplus
......@@ -49,29 +47,11 @@ typedef enum {
CPU_HALT, /* cpu in the halt */
CPU_EXC /* cpu in the exc */
} ExcFlag;
#endif
typedef struct {
SortLinkAttribute taskSortLink; /* task sort link */
SPIN_LOCK_S taskSortLinkSpin; /* task sort link spin lock */
SortLinkAttribute swtmrSortLink; /* swtmr sort link */
SPIN_LOCK_S swtmrSortLinkSpin; /* swtmr sort link spin lock */
UINT64 responseTime; /* Response time for current CPU tick interrupts */
UINT64 tickStartTime; /* The time when the tick interrupt starts processing */
UINT32 responseID; /* The response ID of the current CPU tick interrupt */
UINTPTR runProcess; /* The address of the process control block pointer to which
the current CPU is running */
UINT32 idleTaskID; /* idle task id */
UINT32 taskLockCnt; /* task lock flag */
UINT32 swtmrHandlerQueue; /* software timer timeout queue id */
UINT32 swtmrTaskID; /* software timer task id */
UINT32 schedFlag; /* pending scheduler flag */
#ifdef LOSCFG_KERNEL_SMP
UINT32 excFlag; /* cpu halt or exc flag */
UINT32 excFlag; /* cpu halt or exc flag */
#ifdef LOSCFG_KERNEL_SMP_CALL
LOS_DL_LIST funcLink; /* mp function call link */
#endif
LOS_DL_LIST funcLink; /* mp function call link */
#endif
} Percpu;
......@@ -88,6 +68,19 @@ STATIC INLINE Percpu *OsPercpuGetByID(UINT32 cpuid)
return &g_percpu[cpuid];
}
STATIC INLINE UINT32 OsCpuStatusIsHalt(UINT16 cpuid)
{
return (OsPercpuGetByID(cpuid)->excFlag == CPU_HALT);
}
STATIC INLINE VOID OsCpuStatusSet(ExcFlag flag)
{
OsPercpuGet()->excFlag = flag;
}
VOID OsAllCpuStatusOutput(VOID);
#endif
#ifdef __cplusplus
#if __cplusplus
}
......
......@@ -374,16 +374,11 @@ STATIC INLINE LosProcessCB *OsCurrProcessGet(VOID)
UINT32 intSave;
intSave = LOS_IntLock();
LosProcessCB *runProcess = (LosProcessCB *)OsPercpuGet()->runProcess;
LosProcessCB *runProcess = OS_PCB_FROM_PID(OsCurrTaskGet()->processID);
LOS_IntRestore(intSave);
return runProcess;
}
STATIC INLINE VOID OsCurrProcessSet(const LosProcessCB *process)
{
OsPercpuGet()->runProcess = (UINTPTR)process;
}
#ifdef LOSCFG_SECURITY_CAPABILITY
STATIC INLINE User *OsCurrUserGet(VOID)
{
......@@ -395,8 +390,32 @@ STATIC INLINE User *OsCurrUserGet(VOID)
LOS_IntRestore(intSave);
return user;
}
STATIC INLINE UINT32 OsProcessUserIDGet(const LosTaskCB *taskCB)
{
UINT32 intSave = LOS_IntLock();
UINT32 uid = OS_INVALID;
LosProcessCB *process = OS_PCB_FROM_PID(taskCB->processID);
if (process->user != NULL) {
uid = process->user->userID;
}
LOS_IntRestore(intSave);
return uid;
}
#endif
STATIC INLINE UINT32 OsProcessThreadGroupIDGet(const LosTaskCB *taskCB)
{
return OS_PCB_FROM_PID(taskCB->processID)->threadGroupID;
}
#ifdef LOSCFG_DRIVERS_TZDRIVER
STATIC INLINE struct Vnode *OsProcessExecVnodeGet(const LosProcessCB *processCB)
{
return processCB->execVnode;
}
#endif
/*
* return immediately if no child has exited.
*/
......
......@@ -32,10 +32,8 @@
#ifndef _LOS_SCHED_PRI_H
#define _LOS_SCHED_PRI_H
#include "los_percpu_pri.h"
#include "los_task_pri.h"
#include "los_sys_pri.h"
#include "los_process_pri.h"
#include "los_hwi.h"
#include "hal_timer.h"
......@@ -50,59 +48,93 @@ extern "C" {
#define OS_SCHED_MAX_RESPONSE_TIME (UINT64)(((UINT64)-1) - 1U)
extern UINT32 g_taskScheduled;
typedef BOOL (*SchedScan)(VOID);
#define OS_SCHEDULER_ACTIVE (g_taskScheduled & (1U << ArchCurrCpuid()))
#define OS_SCHEDULER_ALL_ACTIVE (g_taskScheduled == LOSCFG_KERNEL_CPU_MASK)
STATIC INLINE UINT64 OsGetCurrSchedTimeCycle(VOID)
typedef BOOL (*SCHED_TL_FIND_FUNC)(UINTPTR, UINTPTR);
typedef enum {
INT_NO_RESCH = 0x0, /* no needs to schedule */
INT_PEND_RESCH = 0x1, /* pending schedule flag */
INT_PEND_TICK = 0x2, /* pending tick */
} SchedFlag;
typedef struct {
SortLinkAttribute taskSortLink; /* task sort link */
SortLinkAttribute swtmrSortLink; /* swtmr sort link */
UINT64 responseTime; /* Response time for current CPU tick interrupts */
UINT32 responseID; /* The response ID of the current CPU tick interrupt */
UINT32 idleTaskID; /* idle task id */
UINT32 taskLockCnt; /* task lock flag */
UINT32 swtmrTaskID; /* software timer task id */
UINT32 swtmrHandlerQueue; /* software timer timeout queue id */
UINT32 schedFlag; /* pending scheduler flag */
} SchedRunQue;
extern SchedRunQue g_schedRunQue[LOSCFG_KERNEL_CORE_NUM];
STATIC INLINE SchedRunQue *OsSchedRunQue(VOID)
{
return HalClockGetCycles();
return &g_schedRunQue[ArchCurrCpuid()];
}
STATIC INLINE VOID OsSchedIrqUpdateUsedTime(VOID)
STATIC INLINE SchedRunQue *OsSchedRunQueByID(UINT16 id)
{
LosTaskCB *runTask = OsCurrTaskGet();
runTask->irqUsedTime = OsGetCurrSchedTimeCycle() - runTask->irqStartTime;
return &g_schedRunQue[id];
}
STATIC INLINE VOID OsSchedIrqStartTime(VOID)
STATIC INLINE UINT32 OsSchedLockCountGet(VOID)
{
LosTaskCB *runTask = OsCurrTaskGet();
runTask->irqStartTime = OsGetCurrSchedTimeCycle();
return OsSchedRunQue()->taskLockCnt;
}
/*
* 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);
STATIC INLINE VOID OsSchedLockSet(UINT32 count)
{
OsSchedRunQue()->taskLockCnt = count;
}
#define OS_SCHEDULER_CLR(cpuid) do { \
g_taskScheduled &= ~(1U << (cpuid)); \
} while (0);
STATIC INLINE VOID OsSchedLock(VOID)
{
OsSchedRunQue()->taskLockCnt++;
}
#define OS_SCHEDULER_ACTIVE (g_taskScheduled & (1U << ArchCurrCpuid()))
#define OS_SCHEDULER_ALL_ACTIVE (g_taskScheduled == LOSCFG_KERNEL_CPU_MASK)
STATIC INLINE VOID OsSchedUnlock(VOID)
{
OsSchedRunQue()->taskLockCnt--;
}
typedef enum {
INT_NO_RESCH = 0x0, /* no needs to schedule */
INT_PEND_RESCH = 0x1, /* pending schedule flag */
INT_PEND_TICK = 0x2, /* pending tick */
} SchedFlag;
STATIC INLINE BOOL OsSchedUnlockResch(VOID)
{
SchedRunQue *rq = OsSchedRunQue();
if (rq->taskLockCnt > 0) {
rq->taskLockCnt--;
if ((rq->taskLockCnt == 0) && (rq->schedFlag & INT_PEND_RESCH) && OS_SCHEDULER_ACTIVE) {
return TRUE;
}
}
return FALSE;
}
STATIC INLINE BOOL OsSchedIsLock(VOID)
{
return (OsSchedRunQue()->taskLockCnt != 0);
}
/* Check if preemptable with counter flag */
STATIC INLINE BOOL OsPreemptable(VOID)
{
SchedRunQue *rq = OsSchedRunQue();
/*
* Unlike OsPreemptableInSched, the int may be not disabled when OsPreemptable
* is called, needs mannually disable interrupt, to prevent current task from
* being migrated to another core, and get the wrong preeptable status.
*/
UINT32 intSave = LOS_IntLock();
BOOL preemptable = (OsPercpuGet()->taskLockCnt == 0);
BOOL preemptable = (rq->taskLockCnt == 0);
if (!preemptable) {
/* Set schedule flag if preemption is disabled */
OsPercpuGet()->schedFlag |= INT_PEND_RESCH;
rq->schedFlag |= INT_PEND_RESCH;
}
LOS_IntRestore(intSave);
return preemptable;
......@@ -111,105 +143,175 @@ STATIC INLINE BOOL OsPreemptable(VOID)
STATIC INLINE BOOL OsPreemptableInSched(VOID)
{
BOOL preemptable = FALSE;
SchedRunQue *rq = OsSchedRunQue();
#ifdef LOSCFG_KERNEL_SMP
/*
* For smp systems, schedule must hold the task spinlock, and this counter
* will increase by 1 in that case.
*/
preemptable = (OsPercpuGet()->taskLockCnt == 1);
preemptable = (rq->taskLockCnt == 1);
#else
preemptable = (OsPercpuGet()->taskLockCnt == 0);
preemptable = (rq->taskLockCnt == 0);
#endif
if (!preemptable) {
/* Set schedule flag if preemption is disabled */
OsPercpuGet()->schedFlag |= INT_PEND_RESCH;
rq->schedFlag |= INT_PEND_RESCH;
}
return preemptable;
}
STATIC INLINE VOID OsCpuSchedLock(Percpu *cpu)
STATIC INLINE UINT32 OsSchedGetRunQueIdle(VOID)
{
cpu->taskLockCnt++;
return OsSchedRunQue()->idleTaskID;
}
STATIC INLINE VOID OsCpuSchedUnlock(Percpu *cpu, UINT32 intSave)
STATIC INLINE VOID OsSchedRunQuePendingSet(VOID)
{
if (cpu->taskLockCnt > 0) {
cpu->taskLockCnt--;
if ((cpu->taskLockCnt == 0) && (cpu->schedFlag & INT_PEND_RESCH) && OS_SCHEDULER_ACTIVE) {
cpu->schedFlag &= ~INT_PEND_RESCH;
LOS_IntRestore(intSave);
LOS_Schedule();
return;
}
}
LOS_IntRestore(intSave);
OsSchedRunQue()->schedFlag |= INT_PEND_RESCH;
}
extern VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask);
extern UINT32 OsSchedSwtmrScanRegister(SchedScan func);
extern VOID OsSchedResetSchedResponseTime(UINT64 responseTime);
extern VOID OsSchedUpdateExpireTime(UINT64 startTime);
extern VOID OsSchedToUserReleaseLock(VOID);
extern VOID OsSchedTaskDeQueue(LosTaskCB *taskCB);
extern VOID OsSchedTaskEnQueue(LosTaskCB *taskCB);
#ifdef LOSCFG_KERNEL_SMP
STATIC INLINE VOID FindIdleRunQue(UINT16 *idleCpuID)
{
SchedRunQue *idleRq = OsSchedRunQueByID(0);
UINT32 nodeNum = OsGetSortLinkNodeNum(&idleRq->taskSortLink) + OsGetSortLinkNodeNum(&idleRq->swtmrSortLink);
UINT16 cpuID = 1;
do {
SchedRunQue *rq = OsSchedRunQueByID(cpuID);
UINT32 temp = OsGetSortLinkNodeNum(&rq->taskSortLink) + OsGetSortLinkNodeNum(&rq->swtmrSortLink);
if (nodeNum > temp) {
*idleCpuID = cpuID;
nodeNum = temp;
}
cpuID++;
} while (cpuID < LOSCFG_KERNEL_CORE_NUM);
}
#endif
extern UINT32 OsSchedTaskWait(LOS_DL_LIST *list, UINT32 timeout, BOOL needSched);
STATIC INLINE VOID OsSchedAddTask2TimeList(SortLinkList *node, UINT64 startTime, UINT32 waitTicks)
{
UINT16 idleCpu = 0;
#ifdef LOSCFG_KERNEL_SMP
FindIdleRunQue(&idleCpu);
#endif
SchedRunQue *rq = OsSchedRunQueByID(idleCpu);
UINT64 responseTime = startTime + (UINT64)waitTicks * OS_CYCLE_PER_TICK;
OsAdd2SortLink(&rq->taskSortLink, node, responseTime, idleCpu);
}
extern VOID OsSchedTaskWake(LosTaskCB *resumedTask);
STATIC INLINE UINT32 OsSchedSwtmrHandlerQueueGet(VOID)
{
return OsSchedRunQue()->swtmrHandlerQueue;
}
extern BOOL OsSchedModifyTaskSchedParam(LosTaskCB *taskCB, UINT16 policy, UINT16 priority);
STATIC INLINE VOID OsSchedDeTaskFromTimeList(SortLinkList *node)
{
#ifdef LOSCFG_KERNEL_SMP
SchedRunQue *rq = OsSchedRunQueByID(node->cpuid);
#else
SchedRunQue *rq = OsSchedRunQueByID(0);
#endif
OsDeleteFromSortLink(&rq->taskSortLink, node);
}
extern BOOL OsSchedModifyProcessSchedParam(LosProcessCB *processCB, UINT16 policy, UINT16 priority);
STATIC INLINE VOID OsSchedAddSwtmr2TimeList(SortLinkList *node, UINT64 startTime, UINT32 waitTicks)
{
UINT16 idleCpu = 0;
#ifdef LOSCFG_KERNEL_SMP
FindIdleRunQue(&idleCpu);
#endif
SchedRunQue *rq = OsSchedRunQueByID(idleCpu);
UINT64 responseTime = startTime + (UINT64)waitTicks * OS_CYCLE_PER_TICK;
OsAdd2SortLink(&rq->swtmrSortLink, node, responseTime, idleCpu);
}
extern VOID OsSchedSuspend(LosTaskCB *taskCB);
STATIC INLINE VOID OsSchedDeSwtmrFromTimeList(SortLinkList *node)
{
#ifdef LOSCFG_KERNEL_SMP
SchedRunQue *rq = OsSchedRunQueByID(node->cpuid);
#else
SchedRunQue *rq = OsSchedRunQueByID(0);
#endif
OsDeleteFromSortLink(&rq->swtmrSortLink, node);
}
extern BOOL OsSchedResume(LosTaskCB *taskCB);
VOID OsSchedRunQueIdleInit(UINT32 idleTaskID);
VOID OsSchedRunQueSwtmrInit(UINT32 swtmrTaskID, UINT32 swtmrQueue);
VOID OsSchedRunQueInit(VOID);
BOOL OsSchedSwtmrTimeListFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg);
extern VOID OsSchedDelay(LosTaskCB *runTask, UINT32 tick);
STATIC INLINE UINT64 OsGetCurrSchedTimeCycle(VOID)
{
return HalClockGetCycles();
}
extern VOID OsSchedYield(VOID);
STATIC INLINE VOID OsSchedIrqUpdateUsedTime(VOID)
{
LosTaskCB *runTask = OsCurrTaskGet();
runTask->irqUsedTime = OsGetCurrSchedTimeCycle() - runTask->irqStartTime;
}
extern VOID OsSchedTaskExit(LosTaskCB *taskCB);
STATIC INLINE VOID OsSchedIrqStartTime(VOID)
{
LosTaskCB *runTask = OsCurrTaskGet();
runTask->irqStartTime = OsGetCurrSchedTimeCycle();
}
extern VOID OsSchedTick(VOID);
/*
* 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);
extern UINT32 OsSchedInit(VOID);
#define OS_SCHEDULER_CLR(cpuid) do { \
g_taskScheduled &= ~(1U << (cpuid)); \
} while (0);
extern VOID OsSchedStart(VOID);
VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask);
VOID OsSchedResetSchedResponseTime(UINT64 responseTime);
VOID OsSchedUpdateExpireTime(VOID);
VOID OsSchedToUserReleaseLock(VOID);
VOID OsSchedTaskDeQueue(LosTaskCB *taskCB);
VOID OsSchedTaskEnQueue(LosTaskCB *taskCB);
UINT32 OsSchedTaskWait(LOS_DL_LIST *list, UINT32 timeout, BOOL needSched);
VOID OsSchedTaskWake(LosTaskCB *resumedTask);
BOOL OsSchedModifyTaskSchedParam(LosTaskCB *taskCB, UINT16 policy, UINT16 priority);
BOOL OsSchedModifyProcessSchedParam(UINT32 pid, UINT16 policy, UINT16 priority);
VOID OsSchedSuspend(LosTaskCB *taskCB);
BOOL OsSchedResume(LosTaskCB *taskCB);
VOID OsSchedDelay(LosTaskCB *runTask, UINT32 tick);
VOID OsSchedYield(VOID);
VOID OsSchedTaskExit(LosTaskCB *taskCB);
VOID OsSchedTick(VOID);
UINT32 OsSchedInit(VOID);
VOID OsSchedStart(VOID);
/*
* This function simply picks the next task and switches to it.
* Current task needs to already be in the right state or the right
* queues it needs to be in.
*/
extern VOID OsSchedResched(VOID);
extern VOID OsSchedIrqEndCheckNeedSched(VOID);
VOID OsSchedResched(VOID);
VOID OsSchedIrqEndCheckNeedSched(VOID);
/*
* This function inserts the runTask to the lock pending list based on the
* task priority.
*/
extern LOS_DL_LIST *OsSchedLockPendFindPos(const LosTaskCB *runTask, LOS_DL_LIST *lockList);
LOS_DL_LIST *OsSchedLockPendFindPos(const LosTaskCB *runTask, LOS_DL_LIST *lockList);
#ifdef LOSCFG_SCHED_TICK_DEBUG
extern VOID OsSchedDebugRecordData(VOID);
VOID OsSchedDebugRecordData(VOID);
#endif
extern UINT32 OsShellShowTickRespo(VOID);
UINT32 OsShellShowTickRespo(VOID);
extern UINT32 OsShellShowSchedParam(VOID);
UINT32 OsShellShowSchedParam(VOID);
#ifdef __cplusplus
#if __cplusplus
......
......@@ -34,7 +34,7 @@
#include "los_typedef.h"
#include "los_list.h"
#include "los_sys_pri.h"
#include "los_spinlock.h"
#ifdef __cplusplus
#if __cplusplus
......@@ -42,11 +42,6 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef enum {
OS_SORT_LINK_TASK = 1,
OS_SORT_LINK_SWTMR = 2,
} SortLinkType;
typedef struct {
LOS_DL_LIST sortLinkNode;
UINT64 responseTime;
......@@ -58,6 +53,7 @@ typedef struct {
typedef struct {
LOS_DL_LIST sortLink;
UINT32 nodeNum;
SPIN_LOCK_S spinLock; /* swtmr sort link spin lock */
} SortLinkAttribute;
#define OS_SORT_LINK_INVALID_TIME ((UINT64)-1)
......@@ -88,11 +84,16 @@ STATIC INLINE UINT64 OsGetSortLinkNextExpireTime(SortLinkAttribute *sortHeader,
return listSorted->responseTime;
}
extern UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader);
extern VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type);
extern VOID OsDeleteSortLink(SortLinkList *node, SortLinkType type);
extern UINT32 OsSortLinkGetTargetExpireTime(const SortLinkList *targetSortList);
extern UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader);
STATIC INLINE UINT32 OsGetSortLinkNodeNum(SortLinkAttribute *head)
{
return head->nodeNum;
}
VOID OsSortLinkInit(SortLinkAttribute *sortLinkHeader);
VOID OsAdd2SortLink(SortLinkAttribute *head, SortLinkList *node, UINT64 responseTime, UINT16 idleCpu);
VOID OsDeleteFromSortLink(SortLinkAttribute *head, SortLinkList *node);
UINT32 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList);
UINT32 OsSortLinkGetNextExpireTime(UINT64 currTime, const SortLinkAttribute *sortLinkHeader);
#ifdef __cplusplus
#if __cplusplus
......
......@@ -34,6 +34,7 @@
#include "los_swtmr.h"
#include "los_spinlock.h"
#include "los_sched_pri.h"
#ifdef LOSCFG_SECURITY_VID
#include "vid_api.h"
......@@ -75,8 +76,6 @@ typedef SwtmrHandlerItem *SwtmrHandlerItemPtr;
extern SWTMR_CTRL_S *g_swtmrCBArray;
extern SortLinkAttribute g_swtmrSortLink; /* The software timer count list */
#define OS_SWT_FROM_SID(swtmrID) ((SWTMR_CTRL_S *)g_swtmrCBArray + ((swtmrID) % LOSCFG_BASE_CORE_SWTMR_LIMIT))
/**
......@@ -100,11 +99,13 @@ extern SortLinkAttribute g_swtmrSortLink; /* The software timer count list */
* <ul><li>los_swtmr_pri.h: the header file that contains the API declaration.</li></ul>
* @see LOS_SwtmrStop
*/
extern VOID OsSwtmrScan(VOID);
extern BOOL OsIsSwtmrTask(const LosTaskCB *taskCB);
extern VOID OsSwtmrRestart(UINT64 startTime, SortLinkList *sortList);
extern VOID OsSwtmrWake(SchedRunQue *rq, UINT64 currTime, SortLinkList *sortList);
extern UINT32 OsSwtmrInit(VOID);
extern VOID OsSwtmrTask(VOID);
extern VOID OsSwtmrRecycle(UINT32 processID);
extern VOID OsSwtmrResponseTimeReset(UINT64 startTime);
extern BOOL OsSwtmrWorkQueueFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg);
extern SPIN_LOCK_S g_swtmrSpin;
#ifdef __cplusplus
#if __cplusplus
......
......@@ -33,7 +33,7 @@
#define _LOS_TASK_PRI_H
#include "los_task.h"
#include "los_percpu_pri.h"
#include "los_sortlink_pri.h"
#include "los_spinlock.h"
#ifdef LOSCFG_SCHED_DEBUG
#include "los_stat_pri.h"
......@@ -528,7 +528,6 @@ extern LosTaskCB *OsGetMainTask(VOID);
extern VOID OsSetMainTask(VOID);
extern UINT32 OsGetIdleTaskId(VOID);
extern VOID OsTaskEntry(UINT32 taskID);
extern SortLinkAttribute *OsTaskSortLinkGet(VOID);
extern VOID OsTaskProcSignal(VOID);
extern UINT32 OsTaskDeleteUnsafe(LosTaskCB *taskCB, UINT32 status, UINT32 intSave);
extern VOID OsTaskResourcesToFree(LosTaskCB *taskCB);
......
......@@ -602,18 +602,18 @@ STATIC INT32 OsFutexWaitTask(const UINT32 *userVaddr, const UINT32 flags, const
SCHEDULER_LOCK(intSave);
OsTaskWaitSetPendMask(OS_TASK_WAIT_FUTEX, futexKey, timeOut);
OsSchedTaskWait(&(node->pendList), timeOut, FALSE);
OsPercpuGet()->taskLockCnt++;
OsSchedLock();
LOS_SpinUnlock(&g_taskSpin);
futexRet = OsFutexUnlock(&hashNode->listLock);
if (futexRet) {
OsPercpuGet()->taskLockCnt--;
OsSchedUnlock();
LOS_IntRestore(intSave);
goto EXIT_UNLOCK_ERR;
}
LOS_SpinLock(&g_taskSpin);
OsPercpuGet()->taskLockCnt--;
OsSchedUnlock();
/*
* it will immediately do the scheduling, so there's no need to release the
......
......@@ -62,7 +62,7 @@ VOID OsMpScheduleHandler(VOID)
* set schedule flag to differ from wake function,
* so that the scheduler can be triggered at the end of irq.
*/
OsPercpuGet()->schedFlag |= INT_PEND_RESCH;
OsSchedRunQuePendingSet();
}
VOID OsMpHaltHandler(VOID)
......
......@@ -30,7 +30,30 @@
*/
#include "los_percpu_pri.h"
#include "los_printf.h"
#ifdef LOSCFG_KERNEL_SMP
Percpu g_percpu[LOSCFG_KERNEL_CORE_NUM];
VOID OsAllCpuStatusOutput(VOID)
{
UINT32 i;
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
switch (g_percpu[i].excFlag) {
case CPU_RUNNING:
PrintExcInfo("cpu%u is running.\n", i);
break;
case CPU_HALT:
PrintExcInfo("cpu%u is halted.\n", i);
break;
case CPU_EXC:
PrintExcInfo("cpu%u is in exc.\n", i);
break;
default:
break;
}
}
PrintExcInfo("The current handling the exception is cpu%u !\n", ArchCurrCpuid());
}
#endif
......@@ -50,7 +50,7 @@ BOOL LOS_SpinHeld(const SPIN_LOCK_S *lock)
VOID LOS_SpinLock(SPIN_LOCK_S *lock)
{
UINT32 intSave = LOS_IntLock();
OsCpuSchedLock(OsPercpuGet());
OsSchedLock();
LOS_IntRestore(intSave);
LOCKDEP_CHECK_IN(lock);
......@@ -60,17 +60,22 @@ VOID LOS_SpinLock(SPIN_LOCK_S *lock)
INT32 LOS_SpinTrylock(SPIN_LOCK_S *lock)
{
Percpu *cpu = OsPercpuGet();
UINT32 intSave = LOS_IntLock();
OsCpuSchedLock(cpu);
OsSchedLock();
LOS_IntRestore(intSave);
INT32 ret = ArchSpinTrylock(&lock->rawLock);
if (ret == LOS_OK) {
LOCKDEP_CHECK_IN(lock);
LOCKDEP_RECORD(lock);
} else {
OsCpuSchedUnlock(cpu, LOS_IntLock());
return ret;
}
intSave = LOS_IntLock();
BOOL needSched = OsSchedUnlockResch();
LOS_IntRestore(intSave);
if (needSched) {
LOS_Schedule();
}
return ret;
......@@ -78,16 +83,22 @@ INT32 LOS_SpinTrylock(SPIN_LOCK_S *lock)
VOID LOS_SpinUnlock(SPIN_LOCK_S *lock)
{
UINT32 intSave;
LOCKDEP_CHECK_OUT(lock);
ArchSpinUnlock(&lock->rawLock);
OsCpuSchedUnlock(OsPercpuGet(), LOS_IntLock());
intSave = LOS_IntLock();
BOOL needSched = OsSchedUnlockResch();
LOS_IntRestore(intSave);
if (needSched) {
LOS_Schedule();
}
}
VOID LOS_SpinLockSave(SPIN_LOCK_S *lock, UINT32 *intSave)
{
*intSave = LOS_IntLock();
OsCpuSchedLock(OsPercpuGet());
OsSchedLock();
LOCKDEP_CHECK_IN(lock);
ArchSpinLock(&lock->rawLock);
......@@ -99,7 +110,11 @@ VOID LOS_SpinUnlockRestore(SPIN_LOCK_S *lock, UINT32 intSave)
LOCKDEP_CHECK_OUT(lock);
ArchSpinUnlock(&lock->rawLock);
OsCpuSchedUnlock(OsPercpuGet(), intSave);
BOOL needSched = OsSchedUnlockResch();
LOS_IntRestore(intSave);
if (needSched) {
LOS_Schedule();
}
}
#endif
......@@ -30,20 +30,16 @@
*/
#include "los_sortlink_pri.h"
#include "los_memory.h"
#include "los_exc.h"
#include "los_percpu_pri.h"
#include "los_sched_pri.h"
#include "los_mp.h"
UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
VOID OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
{
LOS_ListInit(&sortLinkHeader->sortLink);
LOS_SpinInit(&sortLinkHeader->spinLock);
sortLinkHeader->nodeNum = 0;
return LOS_OK;
}
STATIC INLINE VOID OsAddNode2SortLink(SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
STATIC INLINE VOID AddNode2SortLink(SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
{
LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHeader->sortLink;
......@@ -77,104 +73,42 @@ STATIC INLINE VOID OsAddNode2SortLink(SortLinkAttribute *sortLinkHeader, SortLin
} while (1);
}
STATIC Percpu *OsFindIdleCpu(UINT16 *idleCpuID)
VOID OsAdd2SortLink(SortLinkAttribute *head, SortLinkList *node, UINT64 responseTime, UINT16 idleCpu)
{
Percpu *idleCpu = OsPercpuGetByID(0);
*idleCpuID = 0;
LOS_SpinLock(&head->spinLock);
SET_SORTLIST_VALUE(node, responseTime);
AddNode2SortLink(head, node);
#ifdef LOSCFG_KERNEL_SMP
UINT16 cpuID = 1;
UINT32 nodeNum = idleCpu->taskSortLink.nodeNum + idleCpu->swtmrSortLink.nodeNum;
do {
Percpu *cpu = OsPercpuGetByID(cpuID);
UINT32 temp = cpu->taskSortLink.nodeNum + cpu->swtmrSortLink.nodeNum;
if (nodeNum > temp) {
idleCpu = cpu;
*idleCpuID = cpuID;
}
cpuID++;
} while (cpuID < LOSCFG_KERNEL_CORE_NUM);
node->cpuid = idleCpu;
#endif
LOS_SpinUnlock(&head->spinLock);
return idleCpu;
}
VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type)
{
Percpu *cpu = NULL;
SortLinkAttribute *sortLinkHeader = NULL;
SPIN_LOCK_S *spinLock = NULL;
UINT16 idleCpu;
if (OS_SCHEDULER_ACTIVE) {
cpu = OsFindIdleCpu(&idleCpu);
} else {
idleCpu = ArchCurrCpuid();
cpu = OsPercpuGet();
}
if (type == OS_SORT_LINK_TASK) {
sortLinkHeader = &cpu->taskSortLink;
spinLock = &cpu->taskSortLinkSpin;
} else if (type == OS_SORT_LINK_SWTMR) {
sortLinkHeader = &cpu->swtmrSortLink;
spinLock = &cpu->swtmrSortLinkSpin;
} else {
LOS_Panic("Sort link type error : %u\n", type);
}
LOS_SpinLock(spinLock);
SET_SORTLIST_VALUE(node, startTime + (UINT64)waitTicks * OS_CYCLE_PER_TICK);
OsAddNode2SortLink(sortLinkHeader, node);
#ifdef LOSCFG_KERNEL_SMP
node->cpuid = idleCpu;
if (idleCpu != ArchCurrCpuid()) {
LOS_MpSchedule(CPUID_TO_AFFI_MASK(idleCpu));
}
#endif
LOS_SpinUnlock(spinLock);
}
VOID OsDeleteSortLink(SortLinkList *node, SortLinkType type)
VOID OsDeleteFromSortLink(SortLinkAttribute *head, SortLinkList *node)
{
#ifdef LOSCFG_KERNEL_SMP
Percpu *cpu = OsPercpuGetByID(node->cpuid);
#else
Percpu *cpu = OsPercpuGetByID(0);
#endif
SPIN_LOCK_S *spinLock = NULL;
SortLinkAttribute *sortLinkHeader = NULL;
if (type == OS_SORT_LINK_TASK) {
sortLinkHeader = &cpu->taskSortLink;
spinLock = &cpu->taskSortLinkSpin;
} else if (type == OS_SORT_LINK_SWTMR) {
sortLinkHeader = &cpu->swtmrSortLink;
spinLock = &cpu->swtmrSortLinkSpin;
} else {
LOS_Panic("Sort link type error : %u\n", type);
}
LOS_SpinLock(spinLock);
LOS_SpinLock(&head->spinLock);
if (node->responseTime != OS_SORT_LINK_INVALID_TIME) {
OsDeleteNodeSortLink(sortLinkHeader, node);
OsDeleteNodeSortLink(head, node);
}
LOS_SpinUnlock(spinLock);
LOS_SpinUnlock(&head->spinLock);
}
UINT32 OsSortLinkGetTargetExpireTime(const SortLinkList *targetSortList)
UINT32 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList)
{
UINT64 currTimes = OsGetCurrSchedTimeCycle();
if (currTimes >= targetSortList->responseTime) {
if (currTime >= targetSortList->responseTime) {
return 0;
}
return (UINT32)(targetSortList->responseTime - currTimes) / OS_CYCLE_PER_TICK;
return (UINT32)(targetSortList->responseTime - currTime);
}
UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
UINT32 OsSortLinkGetNextExpireTime(UINT64 currTime, const SortLinkAttribute *sortLinkHeader)
{
LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHeader->sortLink;
......@@ -183,6 +117,6 @@ UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
}
SortLinkList *listSorted = LOS_DL_LIST_ENTRY(head->pstNext, SortLinkList, sortLinkNode);
return OsSortLinkGetTargetExpireTime(listSorted);
return OsSortLinkGetTargetExpireTime(currTime, listSorted);
}
......@@ -48,6 +48,7 @@
#include "los_spinlock.h"
#include "los_swtmr_pri.h"
#include "los_task_pri.h"
#include "los_sched_pri.h"
#include "los_tick.h"
#include "los_vm_boot.h"
#include "los_smp.h"
......@@ -72,6 +73,7 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 EarliestInit(VOID)
/* Must be placed at the beginning of the boot process */
OsSetMainTask();
OsCurrTaskSet(OsGetMainTask());
OsSchedRunQueInit();
g_sysClock = OS_SYS_CLOCK;
g_tickPerSecond = LOSCFG_BASE_CORE_TICK_PER_SECOND;
......
......@@ -185,7 +185,6 @@ STATIC UINT32 OsPmSuspendSleep(LosPmCB *pm)
LOS_SysSleepEnum mode;
UINT32 prepare = 0;
BOOL tickTimerStop = FALSE;
UINT64 currTime;
ret = OsPmSuspendCheck(pm, &sysSuspendEarly, &deviceSuspend, &mode);
if (ret != LOS_OK) {
......@@ -208,9 +207,8 @@ STATIC UINT32 OsPmSuspendSleep(LosPmCB *pm)
tickTimerStop = OsPmTickTimerStop(pm);
if (!tickTimerStop) {
currTime = OsGetCurrSchedTimeCycle();
OsSchedResetSchedResponseTime(0);
OsSchedUpdateExpireTime(currTime);
OsSchedUpdateExpireTime();
}
OsPmCpuSuspend(pm);
......
......@@ -37,6 +37,7 @@
#include "trace_cnv.h"
#include "los_init.h"
#include "los_process.h"
#include "los_sched_pri.h"
#ifdef LOSCFG_KERNEL_SMP
#include "los_mp.h"
......@@ -102,7 +103,7 @@ STATIC VOID OsTraceSetFrame(TraceEventFrame *frame, UINT32 eventType, UINTPTR id
#ifdef LOSCFG_TRACE_FRAME_CORE_MSG
frame->core.cpuId = ArchCurrCpuid();
frame->core.hwiActive = OS_INT_ACTIVE ? TRUE : FALSE;
frame->core.taskLockCnt = MIN(OsPercpuGet()->taskLockCnt, 0xF); /* taskLockCnt is 4 bits, max value = 0xF */
frame->core.taskLockCnt = MIN(OsSchedLockCountGet(), 0xF); /* taskLockCnt is 4 bits, max value = 0xF */
frame->core.paramCount = paramCount;
#endif
......
......@@ -267,7 +267,7 @@ STATIC ssize_t TelnetWrite(struct file *file, const CHAR *buf, const size_t bufL
if (telnetDev->clientFd != 0) {
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
/* DO NOT call blocking API in software timer task */
if (((LosTaskCB*)OsCurrTaskGet())->taskEntry == (TSK_ENTRY_FUNC)OsSwtmrTask) {
if (OsIsSwtmrTask(OsCurrTaskGet())) {
TelnetUnlock();
return ret;
}
......
......@@ -35,6 +35,7 @@
#include "los_cpup_pri.h"
#endif
#include "los_hwi_pri.h"
#include "los_sys_pri.h"
#include "shcmd.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册