32#ifndef _LOS_SCHED_PRI_H
33#define _LOS_SCHED_PRI_H
39#ifdef LOSCFG_SCHED_DEBUG
44#ifdef LOSCFG_KERNEL_PM
48#ifdef LOSCFG_KERNEL_CPUP
51#ifdef LOSCFG_KERNEL_LITEIPC
62#define OS_SCHED_MINI_PERIOD (OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI)
63#define OS_TICK_RESPONSE_PRECISION (UINT32)((OS_SCHED_MINI_PERIOD * 75) / 100)
64#define OS_SCHED_MAX_RESPONSE_TIME OS_SORT_LINK_INVALID_TIME
65#define OS_SCHED_TICK_TO_CYCLE(ticks) ((UINT64)ticks * OS_CYCLE_PER_TICK)
66#define AFFI_MASK_TO_CPUID(mask) ((UINT16)((mask) - 1))
69#define OS_SCHEDULER_ACTIVE (g_taskScheduled & (1U << ArchCurrCpuid()))
70#define OS_SCHEDULER_ALL_ACTIVE (g_taskScheduled == LOSCFG_KERNEL_CPU_MASK)
86#define OS_PRIORITY_QUEUE_NUM 32
89 UINT32 readyTasks[OS_PRIORITY_QUEUE_NUM];
181 BOOL preemptible = FALSE;
184#ifdef LOSCFG_KERNEL_SMP
212#define LOS_SCHED_NORMAL 0U
213#define LOS_SCHED_FIFO 1U
214#define LOS_SCHED_RR 2U
215#define LOS_SCHED_IDLE 3U
266#define OS_TASK_PRIORITY_HIGHEST 0
274#define OS_TASK_PRIORITY_LOWEST 31
282#define OS_TASK_STATUS_INIT 0x0001U
290#define OS_TASK_STATUS_READY 0x0002U
298#define OS_TASK_STATUS_RUNNING 0x0004U
306#define OS_TASK_STATUS_SUSPENDED 0x0008U
314#define OS_TASK_STATUS_PENDING 0x0010U
322#define OS_TASK_STATUS_DELAY 0x0020U
330#define OS_TASK_STATUS_TIMEOUT 0x0040U
338#define OS_TASK_STATUS_PEND_TIME 0x0080U
346#define OS_TASK_STATUS_EXIT 0x0100U
348#define OS_TASK_STATUS_BLOCKED (OS_TASK_STATUS_INIT | OS_TASK_STATUS_PENDING | \
349 OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME)
357#define OS_TASK_STATUS_FROZEN 0x0200U
358#define OS_TCB_NAME_LEN 32
386#ifdef LOSCFG_KERNEL_CPUP
392#ifdef LOSCFG_KERNEL_SMP
396#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
399#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
403#ifdef LOSCFG_SCHED_DEBUG
406#ifdef LOSCFG_KERNEL_VM
420#ifdef LOSCFG_KERNEL_LITEIPC
423#ifdef LOSCFG_KERNEL_PERF
432 return ((taskCB->
taskStatus & OS_TASK_STATUS_RUNNING) != 0);
437 return ((taskCB->
taskStatus & OS_TASK_STATUS_READY) != 0);
442 return ((taskCB->
taskStatus & (OS_TASK_STATUS_INIT | OS_TASK_STATUS_EXIT)) != 0);
447 return ((taskCB->
taskStatus & OS_TASK_STATUS_PENDING) != 0);
452 return ((taskCB->
taskStatus & OS_TASK_STATUS_SUSPENDED) != 0);
457 return ((taskCB->
taskStatus & (OS_TASK_STATUS_SUSPENDED | OS_TASK_STATUS_PENDING | OS_TASK_STATUS_DELAY)) != 0);
487#ifdef LOSCFG_KERNEL_SMP
496 if (nodeNum > temp) {
501 }
while (cpuid < LOSCFG_KERNEL_CORE_NUM);
507#ifdef LOSCFG_KERNEL_SMP
509 if (cpuid >= LOSCFG_KERNEL_CORE_NUM) {
519#ifdef LOSCFG_KERNEL_SMP
520 if ((cpuid !=
ArchCurrCpuid()) && (responseTime < rq->responseTime)) {
530#ifdef LOSCFG_KERNEL_SMP
535 UINT64 oldResponseTime = GET_SORTLIST_VALUE(node);
537 if (oldResponseTime <= rq->responseTime) {
546#ifdef LOSCFG_KERNEL_SMP
563#ifdef LOSCFG_KERNEL_PM
569 if (!(taskCB->
taskStatus & (OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY))) {
573 responseTime = GET_SORTLIST_VALUE(&taskCB->
sortList);
575 SET_SORTLIST_VALUE(&taskCB->
sortList, responseTime);
582 UINT64 currTime, responseTime;
584 if (!(taskCB->
taskStatus & OS_TASK_STATUS_FROZEN)) {
590 responseTime = GET_SORTLIST_VALUE(&taskCB->
sortList);
591 if (responseTime > currTime) {
596 SET_SORTLIST_VALUE(&taskCB->
sortList, OS_SORT_LINK_INVALID_TIME);
597 if (taskCB->
taskStatus & OS_TASK_STATUS_PENDING) {
600 taskCB->
taskStatus &= ~OS_TASK_STATUS_BLOCKED;
608#define OS_SCHEDULER_SET(cpuid) do { \
609 g_taskScheduled |= (1U << (cpuid)); \
612#define OS_SCHEDULER_CLR(cpuid) do { \
613 g_taskScheduled &= ~(1U << (cpuid)); \
620#ifdef LOSCFG_KERNEL_SMP
625 UINT32 basePrio = CLZ(baseBitmap);
629 UINT32 priority = CLZ(bitmap);
630 LOS_DL_LIST_FOR_EACH_ENTRY(newTask, &queueList->
priQueList[priority],
LosTaskCB, pendList) {
631#ifdef LOSCFG_KERNEL_SMP
635#ifdef LOSCFG_KERNEL_SMP
639 bitmap &= ~(1U << (OS_PRIORITY_QUEUE_NUM - priority - 1));
641 baseBitmap &= ~(1U << (OS_PRIORITY_QUEUE_NUM - basePrio - 1));
STATIC INLINE VOID LOS_IntRestore(UINT32 intSave)
Restore interrupts. | 恢复到使用LOS_IntLock关闭所有中断之前的状态
STATIC INLINE UINT32 LOS_IntLock(VOID)
Disable all interrupts. | 关闭当前处理器所有中断响应
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
VOID *(* TSK_ENTRY_FUNC)(UINTPTR param1, UINTPTR param2, UINTPTR param3, UINTPTR param4)
Define the type of a task entrance function.
UINT64 HalClockGetCycles(VOID)
STATIC INLINE VOID ArchCurrUserTaskSet(UINTPTR val)
向协处理器写入用户态任务ID TPIDRURO 仅用于用户态
STATIC INLINE UINT32 ArchCurrCpuid(VOID)
STATIC INLINE VOID * ArchCurrTaskGet(VOID)
获取当前task的地址
STATIC INLINE VOID ArchCurrTaskSet(VOID *val)
向CP15 - > C13 保存当前任务的地址
VOID LOS_MpSchedule(UINT32 target)
STATIC INLINE BOOL OsSchedUnlockResch(VOID)
VOID OsSchedIrqEndCheckNeedSched(VOID)
STATIC INLINE VOID OsSchedUnlock(VOID)
VOID OsSchedRunqueueInit(VOID)
STATIC INLINE BOOL OsTaskIsPending(const LosTaskCB *taskCB)
VOID OsSchedExpireTimeUpdate(VOID)
STATIC INLINE BOOL OsTaskIsRunning(const LosTaskCB *taskCB)
STATIC INLINE UINT64 OsGetCurrSchedTimeCycle(VOID)
struct TagTaskCB LosTaskCB
STATIC INLINE LosTaskCB * OsCurrTaskGet(VOID)
VOID OsSchedRunqueueIdleInit(UINT32 idleTaskID)
STATIC INLINE VOID OsSchedIrqUsedTimeUpdate(VOID)
STATIC INLINE UINT32 OsSchedLockCountGet(VOID)
STATIC INLINE UINT32 OsSchedTimeoutQueueAdjust(LosTaskCB *taskCB, UINT64 responseTime)
LOS_DL_LIST * OsSchedLockPendFindPos(const LosTaskCB *runTask, LOS_DL_LIST *lockList)
STATIC INLINE BOOL OsPreemptableInSched(VOID)
STATIC INLINE SchedRunqueue * OsSchedRunqueueByID(UINT16 id)
STATIC INLINE BOOL OsPreemptable(VOID)
STATIC INLINE SchedRunqueue * OsSchedRunqueue(VOID)
STATIC INLINE VOID SchedTaskFreeze(LosTaskCB *taskCB)
STATIC INLINE BOOL OsTaskIsReady(const LosTaskCB *taskCB)
STATIC INLINE VOID OsSchedIrqStartTime(VOID)
获取中断开始时间
STATIC INLINE VOID OsSchedTimeoutQueueAdd(LosTaskCB *taskCB, UINT64 responseTime)
STATIC INLINE VOID OsSchedRunqueuePendingSet(VOID)
STATIC INLINE UINT32 OsSchedRunqueueIdleGet(VOID)
STATIC INLINE VOID OsCurrUserTaskSet(UINTPTR thread)
INT32 OsSchedParamCompare(const LosTaskCB *task1, const LosTaskCB *task2)
BOOL(* SCHED_TL_FIND_FUNC)(UINTPTR, UINTPTR)
STATIC INLINE BOOL OsTaskIsInactive(const LosTaskCB *taskCB)
STATIC INLINE VOID OsSchedLockSet(UINT32 count)
VOID IdleTaskSchedParamInit(LosTaskCB *taskCB)
STATIC INLINE VOID IdleRunqueueFind(UINT16 *idleCpuid)
UINT32 OsSchedParamInit(LosTaskCB *taskCB, UINT16 policy, const SchedParam *parentParam, const TSK_INIT_PARAM_S *param)
VOID HPFSchedPolicyInit(SchedRunqueue *rq)
STATIC INLINE VOID OsSchedTimeoutQueueDelete(LosTaskCB *taskCB)
STATIC INLINE LosTaskCB * HPFRunqueueTopTaskGet(HPFRunqueue *rq)
STATIC INLINE VOID SchedTaskUnfreeze(LosTaskCB *taskCB)
STATIC INLINE VOID OsCurrTaskSet(LosTaskCB *task)
注意任务地址由硬件保存,见于 CP15 | TPIDRPRW
VOID OsSchedProcessDefaultSchedParamGet(UINT16 policy, SchedParam *param)
STATIC INLINE BOOL OsTaskIsSuspended(const LosTaskCB *taskCB)
VOID HPFProcessDefaultSchedParamGet(SchedParam *param)
STATIC INLINE BOOL OsTaskIsBlocked(const LosTaskCB *taskCB)
STATIC INLINE VOID OsSchedLock(VOID)
VOID OsSchedToUserReleaseLock(VOID)
VOID OsSchedResponseTimeReset(UINT64 responseTime)
STATIC INLINE BOOL OsSchedIsLock(VOID)
VOID OsSchedPriorityInheritance(LosTaskCB *owner, const SchedParam *param)
VOID HPFTaskSchedParamInit(LosTaskCB *taskCB, UINT16 policy, const SchedParam *parentParam, const TSK_INIT_PARAM_S *param)
SchedRunqueue g_schedRunqueue[LOSCFG_KERNEL_CORE_NUM]
VOID OsSchedResched(VOID)
VOID OsDeleteFromSortLink(SortLinkAttribute *head, SortLinkList *node)
VOID OsAdd2SortLink(SortLinkAttribute *head, SortLinkList *node, UINT64 responseTime, UINT16 idleCpu)
UINT32 OsSortLinkAdjustNodeResponseTime(SortLinkAttribute *head, SortLinkList *node, UINT64 responseTime)
STATIC INLINE UINT32 OsGetSortLinkNodeNum(const SortLinkAttribute *head)
每个futex node对应一个被挂起的task ,key值唯一标识一把用户态锁,具有相同key值的node被queue_list串联起来表示被同一把锁阻塞的task队列。
LOS_DL_LIST priQueList[OS_PRIORITY_QUEUE_NUM]
HPFQueue queueList[OS_PRIORITY_QUEUE_NUM]
UINT32 initTimeSlice
初始化时间片
SortLinkAttribute timeoutQueue
HPFRunqueue * hpfRunqueue
FutexNode futex
指明任务在等待哪把快锁,一次只等一锁,锁和任务的关系是(1:N)关系
IpcTaskInfo * ipcTaskInfo
任务间通讯信息结构体
sig_cb sig
信号控制块,用于异步通信,类似于 linux singal模块
UINTPTR userMapBase
用户空间的栈顶位置,内存来自用户空间,和topOfStack有本质的区别.
CHAR taskName[OS_TCB_NAME_LEN]
UINTPTR userArea
用户空间的堆区开始位置