• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "los_sched_pri.h"
32 #include "los_process_pri.h"
33 
34 STATIC VOID IdleDequeue(SchedRunqueue *rq, LosTaskCB *taskCB);
35 STATIC VOID IdleEnqueue(SchedRunqueue *rq, LosTaskCB *taskCB);
36 STATIC UINT32 IdleWait(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 ticks);
37 STATIC VOID IdleWake(LosTaskCB *resumedTask);
38 STATIC UINT32 IdleSchedParamGet(const LosTaskCB *taskCB, SchedParam *param);
39 STATIC VOID IdleYield(LosTaskCB *runTask);
40 STATIC VOID IdleStartToRun(SchedRunqueue *rq, LosTaskCB *taskCB);
41 STATIC UINT32 IdleResume(LosTaskCB *taskCB, BOOL *needSched);
42 STATIC UINT64 IdleTimeSliceGet(const LosTaskCB *taskCB);
43 STATIC VOID IdleTimeSliceUpdate(SchedRunqueue *rq, LosTaskCB *taskCB, UINT64 currTime);
44 STATIC INT32 IdleParamCompare(const SchedPolicy *sp1, const SchedPolicy *sp2);
45 STATIC VOID IdlePriorityInheritance(LosTaskCB *owner, const SchedParam *param);
46 STATIC VOID IdlePriorityRestore(LosTaskCB *owner, const LOS_DL_LIST *list, const SchedParam *param);
47 
48 const STATIC SchedOps g_idleOps = {
49     .dequeue = IdleDequeue,
50     .enqueue = IdleEnqueue,
51     .waitTimeGet = NULL,
52     .wait = IdleWait,
53     .wake = IdleWake,
54     .schedParamModify = NULL,
55     .schedParamGet = IdleSchedParamGet,
56     .delay = NULL,
57     .yield = IdleYield,
58     .start = IdleStartToRun,
59     .exit = NULL,
60     .suspend = NULL,
61     .resume = IdleResume,
62     .deadlineGet = IdleTimeSliceGet,
63     .timeSliceUpdate = IdleTimeSliceUpdate,
64     .schedParamCompare = IdleParamCompare,
65     .priorityInheritance = IdlePriorityInheritance,
66     .priorityRestore = IdlePriorityRestore,
67 };
68 
IdleTimeSliceUpdate(SchedRunqueue * rq,LosTaskCB * taskCB,UINT64 currTime)69 STATIC VOID IdleTimeSliceUpdate(SchedRunqueue *rq, LosTaskCB *taskCB, UINT64 currTime)
70 {
71     (VOID)rq;
72 
73     taskCB->startTime = currTime;
74 }
75 
IdleTimeSliceGet(const LosTaskCB * taskCB)76 STATIC UINT64 IdleTimeSliceGet(const LosTaskCB *taskCB)
77 {
78     (VOID)taskCB;
79     return (OS_SCHED_MAX_RESPONSE_TIME - OS_TICK_RESPONSE_PRECISION);
80 }
81 
IdleEnqueue(SchedRunqueue * rq,LosTaskCB * taskCB)82 STATIC VOID IdleEnqueue(SchedRunqueue *rq, LosTaskCB *taskCB)
83 {
84     (VOID)rq;
85 
86     taskCB->taskStatus &= ~OS_TASK_STATUS_BLOCKED;
87     taskCB->taskStatus |= OS_TASK_STATUS_READY;
88 }
89 
IdleDequeue(SchedRunqueue * rq,LosTaskCB * taskCB)90 STATIC VOID IdleDequeue(SchedRunqueue *rq, LosTaskCB *taskCB)
91 {
92     (VOID)rq;
93 
94     taskCB->taskStatus &= ~OS_TASK_STATUS_READY;
95 }
96 
IdleStartToRun(SchedRunqueue * rq,LosTaskCB * taskCB)97 STATIC VOID IdleStartToRun(SchedRunqueue *rq, LosTaskCB *taskCB)
98 {
99     IdleDequeue(rq, taskCB);
100 }
101 
IdleYield(LosTaskCB * runTask)102 STATIC VOID IdleYield(LosTaskCB *runTask)
103 {
104     (VOID)runTask;
105     return;
106 }
107 
IdleWait(LosTaskCB * runTask,LOS_DL_LIST * list,UINT32 ticks)108 STATIC UINT32 IdleWait(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 ticks)
109 {
110     (VOID)runTask;
111     (VOID)list;
112     (VOID)ticks;
113 
114     return LOS_NOK;
115 }
116 
IdleWake(LosTaskCB * resumedTask)117 STATIC VOID IdleWake(LosTaskCB *resumedTask)
118 {
119     LOS_ListDelete(&resumedTask->pendList);
120     resumedTask->taskStatus &= ~OS_TASK_STATUS_PENDING;
121 
122     if (resumedTask->taskStatus & OS_TASK_STATUS_PEND_TIME) {
123         OsSchedTimeoutQueueDelete(resumedTask);
124         resumedTask->taskStatus &= ~OS_TASK_STATUS_PEND_TIME;
125     }
126 
127     if (!(resumedTask->taskStatus & OS_TASK_STATUS_SUSPENDED)) {
128 #ifdef LOSCFG_SCHED_DEBUG
129         resumedTask->schedStat.pendTime += OsGetCurrSchedTimeCycle() - resumedTask->startTime;
130         resumedTask->schedStat.pendCount++;
131 #endif
132         resumedTask->ops->enqueue(OsSchedRunqueue(), resumedTask);
133     }
134 }
135 
IdleResume(LosTaskCB * taskCB,BOOL * needSched)136 STATIC UINT32 IdleResume(LosTaskCB *taskCB, BOOL *needSched)
137 {
138     *needSched = FALSE;
139 
140     taskCB->taskStatus &= ~OS_TASK_STATUS_SUSPENDED;
141     if (!OsTaskIsBlocked(taskCB)) {
142         taskCB->ops->enqueue(OsSchedRunqueue(), taskCB);
143         *needSched = TRUE;
144     }
145     return LOS_OK;
146 }
147 
IdleSchedParamGet(const LosTaskCB * taskCB,SchedParam * param)148 STATIC UINT32 IdleSchedParamGet(const LosTaskCB *taskCB, SchedParam *param)
149 {
150     SchedHPF *sched = (SchedHPF *)&taskCB->sp;
151     param->policy = sched->policy;
152     param->basePrio = sched->basePrio;
153     param->priority = sched->priority;
154     param->timeSlice = 0;
155     return LOS_OK;
156 }
157 
IdleParamCompare(const SchedPolicy * sp1,const SchedPolicy * sp2)158 STATIC INT32 IdleParamCompare(const SchedPolicy *sp1, const SchedPolicy *sp2)
159 {
160     return 0;
161 }
162 
IdlePriorityInheritance(LosTaskCB * owner,const SchedParam * param)163 STATIC VOID IdlePriorityInheritance(LosTaskCB *owner, const SchedParam *param)
164 {
165     (VOID)owner;
166     (VOID)param;
167     return;
168 }
169 
IdlePriorityRestore(LosTaskCB * owner,const LOS_DL_LIST * list,const SchedParam * param)170 STATIC VOID IdlePriorityRestore(LosTaskCB *owner, const LOS_DL_LIST *list, const SchedParam *param)
171 {
172     (VOID)owner;
173     (VOID)list;
174     (VOID)param;
175     return;
176 }
177 
IdleTaskSchedParamInit(LosTaskCB * taskCB)178 VOID IdleTaskSchedParamInit(LosTaskCB *taskCB)
179 {
180     SchedHPF *sched = (SchedHPF *)&taskCB->sp;
181     sched->policy = LOS_SCHED_IDLE;
182     sched->basePrio = OS_PROCESS_PRIORITY_LOWEST;
183     sched->priority = OS_TASK_PRIORITY_LOWEST;
184     sched->initTimeSlice = 0;
185     taskCB->timeSlice = sched->initTimeSlice;
186     taskCB->taskStatus = OS_TASK_STATUS_SUSPENDED;
187     taskCB->ops = &g_idleOps;
188 }
189