feat: 同步调度部分优化至liteos_m
1.tick timer与调度进一步剥离 2.性能敏感函数内敛化 Signed-off-by: zhushengle <zhushengle@huawei.com> Change-Id: I00c27216e286dd7ca9c02db3e2377707d628a786
This commit is contained in:
@@ -43,21 +43,20 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OS_SCHED_MINI_PERIOD (g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI)
|
||||
#define OS_TICK_RESPONSE_PRECISION (UINT32)((OS_SCHED_MINI_PERIOD * 75) / 100)
|
||||
#define OS_SCHED_MAX_RESPONSE_TIME (UINT64)(((UINT64)-1) - 1U)
|
||||
|
||||
extern UINT32 g_taskScheduled;
|
||||
typedef BOOL (*SchedScan)(VOID);
|
||||
|
||||
extern UINT64 g_sysSchedStartTime;
|
||||
|
||||
VOID OsSchedResetSchedResponseTime(UINT64 responseTime);
|
||||
|
||||
VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask);
|
||||
|
||||
UINT32 OsSchedSwtmrScanRegister(SchedScan func);
|
||||
|
||||
VOID OsSchedUpdateExpireTime(UINT64 startTime);
|
||||
VOID OsSchedUpdateExpireTime(VOID);
|
||||
|
||||
UINT64 OsSchedGetNextExpireTime(UINT64 startTime);
|
||||
|
||||
VOID OsSchedTaskDeQueue(LosTaskCB *taskCB);
|
||||
|
||||
@@ -89,15 +88,9 @@ BOOL OsSchedTaskSwitch(VOID);
|
||||
|
||||
LosTaskCB *OsGetTopTask(VOID);
|
||||
|
||||
UINT32 OsSchedRealSleepTimeSet(VOID (*func)(UINT64));
|
||||
|
||||
STATIC INLINE UINT64 OsGetCurrSchedTimeCycle(VOID)
|
||||
{
|
||||
if (g_sysSchedStartTime != OS_64BIT_MAX) {
|
||||
return (LOS_SysCycleGet() - g_sysSchedStartTime);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return LOS_SysCycleGet();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,10 +55,15 @@ typedef struct {
|
||||
LOS_DL_LIST sortLink;
|
||||
} SortLinkAttribute;
|
||||
|
||||
extern SortLinkAttribute g_taskSortLink;
|
||||
extern SortLinkAttribute g_swtmrSortLink;
|
||||
|
||||
#define OS_SORT_LINK_INVALID_TIME ((UINT64)-1)
|
||||
#define SET_SORTLIST_VALUE(sortList, value) (((SortLinkList *)(sortList))->responseTime = (value))
|
||||
#define GET_SORTLIST_VALUE(sortList) (((SortLinkList *)(sortList))->responseTime)
|
||||
|
||||
#define OS_SORT_LINK_UINT64_MAX ((UINT64)-1)
|
||||
|
||||
STATIC INLINE UINT64 OsSortLinkGetRemainTime(UINT64 currTime, const SortLinkList *targetSortList)
|
||||
{
|
||||
if (currTime >= targetSortList->responseTime) {
|
||||
@@ -67,14 +72,42 @@ STATIC INLINE UINT64 OsSortLinkGetRemainTime(UINT64 currTime, const SortLinkList
|
||||
return (targetSortList->responseTime - currTime);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsDeleteNodeSortLink(SortLinkList *sortList)
|
||||
{
|
||||
LOS_ListDelete(&sortList->sortLinkNode);
|
||||
SET_SORTLIST_VALUE(sortList, OS_SORT_LINK_INVALID_TIME);
|
||||
}
|
||||
|
||||
STATIC INLINE UINT64 GetSortLinkNextExpireTime(SortLinkAttribute *sortHeader, UINT64 startTime, UINT32 tickPrecision)
|
||||
{
|
||||
LOS_DL_LIST *head = &sortHeader->sortLink;
|
||||
LOS_DL_LIST *list = head->pstNext;
|
||||
|
||||
if (LOS_ListEmpty(head)) {
|
||||
return OS_SORT_LINK_UINT64_MAX - tickPrecision;
|
||||
}
|
||||
|
||||
SortLinkList *listSorted = LOS_DL_LIST_ENTRY(list, SortLinkList, sortLinkNode);
|
||||
if (listSorted->responseTime <= (startTime + tickPrecision)) {
|
||||
return (startTime + tickPrecision);
|
||||
}
|
||||
|
||||
return listSorted->responseTime;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT64 OsGetNextExpireTime(UINT64 startTime, UINT32 tickPrecision)
|
||||
{
|
||||
UINT64 taskExpireTime = GetSortLinkNextExpireTime(&g_taskSortLink, startTime, tickPrecision);
|
||||
UINT64 swtmrExpireTime = GetSortLinkNextExpireTime(&g_swtmrSortLink, startTime, tickPrecision);
|
||||
return (taskExpireTime < swtmrExpireTime) ? taskExpireTime : swtmrExpireTime;
|
||||
}
|
||||
|
||||
SortLinkAttribute *OsGetSortLinkAttribute(SortLinkType type);
|
||||
UINT64 OsGetNextExpireTime(UINT64 startTime);
|
||||
UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader);
|
||||
VOID OsDeleteNodeSortLink(SortLinkList *sortList);
|
||||
VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type);
|
||||
VOID OsDeleteSortLink(SortLinkList *node);
|
||||
UINT32 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList);
|
||||
UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader);
|
||||
UINT64 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList);
|
||||
UINT64 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -500,27 +500,7 @@ extern UINT32 OsSwtmrInit(VOID);
|
||||
*/
|
||||
extern UINT32 OsSwtmrGetNextTimeout(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Adjust software timer list.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to adjust software timer list.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param sleepTime [IN] UINT32 Sleep time.
|
||||
*
|
||||
* @retval UINT32 Sleep time.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsSwtmrAdjust(UINT32 sleepTime);
|
||||
extern VOID OsSwtmrResponseTimeReset(UINT64 startTime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -249,7 +249,7 @@ typedef struct TagSysTime {
|
||||
UINT8 ucWeek; /**< value 0 - 6 */
|
||||
} SYS_TIME_S;
|
||||
|
||||
VOID OsTickTimerReload(UINT64 responseTime);
|
||||
UINT64 OsTickTimerReload(UINT64 period);
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
VOID OsTickTimerBaseReset(UINT64 currTime);
|
||||
@@ -257,6 +257,8 @@ VOID OsTickTimerBaseReset(UINT64 currTime);
|
||||
|
||||
UINT32 OsTickTimerInit(VOID);
|
||||
|
||||
VOID OsTickSysTimerStartTimeSet(UINT64 currTime);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Obtain the number of Ticks.
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "los_sched.h"
|
||||
#include "los_task.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_swtmr.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_hook.h"
|
||||
#if (LOSCFG_KERNEL_PM == 1)
|
||||
@@ -49,6 +50,7 @@ extern "C" {
|
||||
#define OS_SCHED_TIME_SLICES ((LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT * OS_SYS_NS_PER_US) / OS_NS_PER_CYCLE)
|
||||
#define OS_TIME_SLICE_MIN (INT32)((50 * OS_SYS_NS_PER_US) / OS_NS_PER_CYCLE) /* 50us */
|
||||
#define OS_TICK_RESPONSE_TIME_MAX LOSCFG_BASE_CORE_TICK_RESPONSE_MAX
|
||||
#define OS_TICK_RESPONSE_PRECISION (UINT32)((OS_SCHED_MINI_PERIOD * 75) / 100)
|
||||
#if (LOSCFG_BASE_CORE_TICK_RESPONSE_MAX == 0)
|
||||
#error "Must specify the maximum value that tick timer counter supports!"
|
||||
#endif
|
||||
@@ -63,25 +65,7 @@ STATIC UINT32 g_queueBitmap;
|
||||
|
||||
STATIC UINT32 g_schedResponseID = 0;
|
||||
STATIC UINT16 g_tickIntLock = 0;
|
||||
STATIC UINT64 g_tickStartTime = 0;
|
||||
STATIC UINT64 g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
STATIC VOID (*SchedRealSleepTimeSet)(UINT64) = NULL;
|
||||
UINT64 g_sysSchedStartTime = OS_64BIT_MAX;
|
||||
|
||||
STATIC VOID OsSchedSetStartTime(UINT64 currCycle)
|
||||
{
|
||||
g_sysSchedStartTime = currCycle;
|
||||
}
|
||||
|
||||
UINT32 OsSchedRealSleepTimeSet(VOID (*func)(UINT64))
|
||||
{
|
||||
if (func == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
SchedRealSleepTimeSet = func;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsSchedResetSchedResponseTime(UINT64 responseTime)
|
||||
{
|
||||
@@ -101,27 +85,21 @@ STATIC INLINE VOID OsTimeSliceUpdate(LosTaskCB *taskCB, UINT64 currTime)
|
||||
taskCB->startTime = currTime;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedTickReload(UINT64 nextResponseTime, UINT32 responseID, BOOL isTimeSlice)
|
||||
STATIC INLINE VOID OsSchedSetNextExpireTime(UINT32 responseID, UINT64 taskEndTime)
|
||||
{
|
||||
UINT64 currTime, nextExpireTime;
|
||||
UINT32 usedTime;
|
||||
UINT64 nextResponseTime = 0;
|
||||
BOOL isTimeSlice = FALSE;
|
||||
|
||||
currTime = OsGetCurrSchedTimeCycle();
|
||||
if (g_tickStartTime != 0) {
|
||||
usedTime = currTime - g_tickStartTime;
|
||||
g_tickStartTime = 0;
|
||||
} else {
|
||||
usedTime = 0;
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
UINT64 nextExpireTime = OsGetNextExpireTime(currTime, OS_TICK_RESPONSE_PRECISION);
|
||||
/* The response time of the task time slice is aligned to the next response time in the delay queue */
|
||||
if ((nextExpireTime > taskEndTime) && ((nextExpireTime - taskEndTime) > OS_SCHED_MINI_PERIOD)) {
|
||||
nextExpireTime = taskEndTime;
|
||||
isTimeSlice = TRUE;
|
||||
}
|
||||
|
||||
if ((nextResponseTime > usedTime) && ((nextResponseTime - usedTime) > OS_TICK_RESPONSE_PRECISION)) {
|
||||
nextResponseTime -= usedTime;
|
||||
} else {
|
||||
nextResponseTime = OS_TICK_RESPONSE_PRECISION;
|
||||
}
|
||||
|
||||
nextExpireTime = currTime + nextResponseTime;
|
||||
if (nextExpireTime >= g_schedResponseTime) {
|
||||
if ((g_schedResponseTime <= nextExpireTime) ||
|
||||
((g_schedResponseTime - nextExpireTime) < OS_TICK_RESPONSE_PRECISION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -131,46 +109,15 @@ STATIC INLINE VOID OsSchedTickReload(UINT64 nextResponseTime, UINT32 responseID,
|
||||
} else {
|
||||
g_schedResponseID = OS_INVALID;
|
||||
}
|
||||
g_schedResponseTime = nextExpireTime;
|
||||
OsTickTimerReload(nextResponseTime);
|
||||
|
||||
nextResponseTime = nextExpireTime - currTime;
|
||||
if (nextResponseTime < OS_TICK_RESPONSE_PRECISION) {
|
||||
nextResponseTime = OS_TICK_RESPONSE_PRECISION;
|
||||
}
|
||||
g_schedResponseTime = currTime + OsTickTimerReload(nextResponseTime);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedSetNextExpireTime(UINT64 startTime, UINT32 responseID, UINT64 taskEndTime)
|
||||
{
|
||||
UINT64 nextExpireTime;
|
||||
UINT64 nextResponseTime = 0;
|
||||
BOOL isTimeSlice = FALSE;
|
||||
|
||||
nextExpireTime = OsGetNextExpireTime(startTime);
|
||||
/* The response time of the task time slice is aligned to the next response time in the delay queue */
|
||||
if ((nextExpireTime > taskEndTime) && ((nextExpireTime - taskEndTime) > OS_SCHED_MINI_PERIOD)) {
|
||||
nextExpireTime = taskEndTime;
|
||||
isTimeSlice = TRUE;
|
||||
}
|
||||
|
||||
if ((g_schedResponseTime > nextExpireTime) &&
|
||||
((g_schedResponseTime - nextExpireTime) >= OS_TICK_RESPONSE_PRECISION)) {
|
||||
nextResponseTime = nextExpireTime - startTime;
|
||||
if (nextResponseTime > OS_TICK_RESPONSE_TIME_MAX) {
|
||||
if (SchedRealSleepTimeSet != NULL) {
|
||||
SchedRealSleepTimeSet(nextResponseTime);
|
||||
}
|
||||
nextResponseTime = OS_TICK_RESPONSE_TIME_MAX;
|
||||
}
|
||||
|
||||
if (SchedRealSleepTimeSet != NULL) {
|
||||
SchedRealSleepTimeSet(0);
|
||||
}
|
||||
} else {
|
||||
/* There is no point earlier than the current expiration date */
|
||||
g_tickStartTime = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
OsSchedTickReload(nextResponseTime, responseID, isTimeSlice);
|
||||
}
|
||||
|
||||
VOID OsSchedUpdateExpireTime(UINT64 startTime)
|
||||
VOID OsSchedUpdateExpireTime(VOID)
|
||||
{
|
||||
UINT64 endTime;
|
||||
BOOL isPmMode = FALSE;
|
||||
@@ -185,11 +132,11 @@ VOID OsSchedUpdateExpireTime(UINT64 startTime)
|
||||
#endif
|
||||
if ((runTask->taskID != g_idleTaskID) && !isPmMode) {
|
||||
INT32 timeSlice = (runTask->timeSlice <= OS_TIME_SLICE_MIN) ? OS_SCHED_TIME_SLICES : runTask->timeSlice;
|
||||
endTime = startTime + timeSlice;
|
||||
endTime = runTask->startTime + timeSlice;
|
||||
} else {
|
||||
endTime = OS_SCHED_MAX_RESPONSE_TIME - OS_TICK_RESPONSE_PRECISION;
|
||||
}
|
||||
OsSchedSetNextExpireTime(startTime, runTask->taskID, endTime);
|
||||
OsSchedSetNextExpireTime(runTask->taskID, endTime);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedPriQueueEnHead(LOS_DL_LIST *priqueueItem, UINT32 priority)
|
||||
@@ -468,6 +415,11 @@ UINT32 OsTaskNextSwitchTimeGet(VOID)
|
||||
return ticks;
|
||||
}
|
||||
|
||||
UINT64 OsSchedGetNextExpireTime(UINT64 startTime)
|
||||
{
|
||||
return OsGetNextExpireTime(startTime, OS_TICK_RESPONSE_PRECISION);
|
||||
}
|
||||
|
||||
UINT32 OsSchedInit(VOID)
|
||||
{
|
||||
UINT16 pri;
|
||||
@@ -503,6 +455,8 @@ LosTaskCB *OsGetTopTask(VOID)
|
||||
|
||||
VOID OsSchedStart(VOID)
|
||||
{
|
||||
PRINTK("Entering scheduler\n");
|
||||
|
||||
(VOID)LOS_IntLock();
|
||||
LosTaskCB *newTask = OsGetTopTask();
|
||||
|
||||
@@ -510,18 +464,19 @@ VOID OsSchedStart(VOID)
|
||||
g_losTask.newTask = newTask;
|
||||
g_losTask.runTask = g_losTask.newTask;
|
||||
|
||||
/* Initialize the schedule timeline and enable scheduling */
|
||||
g_taskScheduled = TRUE;
|
||||
OsSchedSetStartTime(LOS_SysCycleGet());
|
||||
|
||||
newTask->startTime = OsGetCurrSchedTimeCycle();
|
||||
OsSchedTaskDeQueue(newTask);
|
||||
|
||||
OsTickSysTimerStartTimeSet(newTask->startTime);
|
||||
|
||||
OsSwtmrResponseTimeReset(newTask->startTime);
|
||||
|
||||
/* Initialize the schedule timeline and enable scheduling */
|
||||
g_taskScheduled = TRUE;
|
||||
|
||||
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
g_schedResponseID = OS_INVALID;
|
||||
OsSchedSetNextExpireTime(newTask->startTime, newTask->taskID, newTask->startTime + newTask->timeSlice);
|
||||
|
||||
PRINTK("Entering scheduler\n");
|
||||
OsSchedSetNextExpireTime(newTask->taskID, newTask->startTime + newTask->timeSlice);
|
||||
}
|
||||
|
||||
BOOL OsSchedTaskSwitch(VOID)
|
||||
@@ -563,7 +518,7 @@ BOOL OsSchedTaskSwitch(VOID)
|
||||
if (g_schedResponseID == runTask->taskID) {
|
||||
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
}
|
||||
OsSchedSetNextExpireTime(newTask->startTime, newTask->taskID, endTime);
|
||||
OsSchedSetNextExpireTime(newTask->taskID, endTime);
|
||||
|
||||
return isTaskSwitch;
|
||||
}
|
||||
@@ -595,7 +550,7 @@ VOID LOS_SchedTickHandler(VOID)
|
||||
}
|
||||
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
g_tickStartTime = OsGetCurrSchedTimeCycle();
|
||||
UINT64 tickStartTime = OsGetCurrSchedTimeCycle();
|
||||
if (g_schedResponseID == OS_INVALID) {
|
||||
g_tickIntLock++;
|
||||
if (g_swtmrScan != NULL) {
|
||||
@@ -606,14 +561,14 @@ VOID LOS_SchedTickHandler(VOID)
|
||||
g_tickIntLock--;
|
||||
}
|
||||
|
||||
OsTimeSliceUpdate(g_losTask.runTask, g_tickStartTime);
|
||||
OsTimeSliceUpdate(g_losTask.runTask, tickStartTime);
|
||||
g_losTask.runTask->startTime = OsGetCurrSchedTimeCycle();
|
||||
|
||||
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
if (LOS_CHECK_SCHEDULE) {
|
||||
ArchTaskSchedule();
|
||||
} else {
|
||||
OsSchedUpdateExpireTime(g_losTask.runTask->startTime);
|
||||
OsSchedUpdateExpireTime();
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
@@ -39,8 +39,8 @@ extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
STATIC SortLinkAttribute g_taskSortLink;
|
||||
STATIC SortLinkAttribute g_swtmrSortLink;
|
||||
SortLinkAttribute g_taskSortLink;
|
||||
SortLinkAttribute g_swtmrSortLink;
|
||||
|
||||
UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
|
||||
{
|
||||
@@ -78,29 +78,6 @@ STATIC INLINE VOID OsAddNode2SortLink(SortLinkAttribute *sortLinkHeader, SortLin
|
||||
} while (1);
|
||||
}
|
||||
|
||||
VOID OsDeleteNodeSortLink(SortLinkList *sortList)
|
||||
{
|
||||
LOS_ListDelete(&sortList->sortLinkNode);
|
||||
SET_SORTLIST_VALUE(sortList, OS_SORT_LINK_INVALID_TIME);
|
||||
}
|
||||
|
||||
STATIC INLINE UINT64 OsGetSortLinkNextExpireTime(SortLinkAttribute *sortHeader, UINT64 startTime)
|
||||
{
|
||||
LOS_DL_LIST *head = &sortHeader->sortLink;
|
||||
LOS_DL_LIST *list = head->pstNext;
|
||||
|
||||
if (LOS_ListEmpty(head)) {
|
||||
return OS_SCHED_MAX_RESPONSE_TIME - OS_TICK_RESPONSE_PRECISION;
|
||||
}
|
||||
|
||||
SortLinkList *listSorted = LOS_DL_LIST_ENTRY(list, SortLinkList, sortLinkNode);
|
||||
if (listSorted->responseTime <= (startTime + OS_TICK_RESPONSE_PRECISION)) {
|
||||
return startTime + OS_TICK_RESPONSE_PRECISION;
|
||||
}
|
||||
|
||||
return listSorted->responseTime;
|
||||
}
|
||||
|
||||
VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type)
|
||||
{
|
||||
UINT32 intSave;
|
||||
@@ -144,30 +121,16 @@ SortLinkAttribute *OsGetSortLinkAttribute(SortLinkType type)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UINT64 OsGetNextExpireTime(UINT64 startTime)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SortLinkAttribute *taskHeader = &g_taskSortLink;
|
||||
SortLinkAttribute *swtmrHeader = &g_swtmrSortLink;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
UINT64 taskExpirTime = OsGetSortLinkNextExpireTime(taskHeader, startTime);
|
||||
UINT64 swtmrExpirTime = OsGetSortLinkNextExpireTime(swtmrHeader, startTime);
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return (taskExpirTime < swtmrExpirTime) ? taskExpirTime : swtmrExpirTime;
|
||||
}
|
||||
|
||||
UINT32 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList)
|
||||
UINT64 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList)
|
||||
{
|
||||
if (currTime >= targetSortList->responseTime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (UINT32)(((targetSortList->responseTime - currTime) * LOSCFG_BASE_CORE_TICK_PER_SECOND) / g_sysClock);
|
||||
return (targetSortList->responseTime - currTime);
|
||||
}
|
||||
|
||||
UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
|
||||
UINT64 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
|
||||
{
|
||||
LOS_DL_LIST *head = (LOS_DL_LIST *)&sortLinkHeader->sortLink;
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ LITE_OS_SEC_TEXT VOID OsSwtmrStart(UINT64 currTime, SWTMR_CTRL_S *swtmr)
|
||||
}
|
||||
#endif
|
||||
OsAdd2SortLink(&swtmr->stSortList, swtmr->startTime, swtmr->uwInterval, OS_SORT_LINK_SWTMR);
|
||||
OsSchedUpdateExpireTime(currTime);
|
||||
OsSchedUpdateExpireTime();
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@@ -274,7 +274,7 @@ LITE_OS_SEC_TEXT VOID OsSwtmrStop(SWTMR_CTRL_S *swtmr)
|
||||
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
|
||||
|
||||
swtmr->ucOverrun = 0;
|
||||
OsSchedUpdateExpireTime(OsGetCurrSchedTimeCycle());
|
||||
OsSchedUpdateExpireTime();
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].isAligned = 0;
|
||||
#endif
|
||||
@@ -327,6 +327,24 @@ STATIC BOOL OsSwtmrScan(VOID)
|
||||
return needSchedule;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsSwtmrResponseTimeReset(UINT64 startTime)
|
||||
{
|
||||
LOS_DL_LIST *listHead = &g_swtmrSortLinkList->sortLink;
|
||||
LOS_DL_LIST *listNext = listHead->pstNext;
|
||||
|
||||
while (listNext != listHead) {
|
||||
SortLinkList *sortList = LOS_DL_LIST_ENTRY(listNext, SortLinkList, sortLinkNode);
|
||||
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
|
||||
OsDeleteNodeSortLink(sortList);
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].isAligned = 0;
|
||||
#endif
|
||||
swtmr->startTime = startTime;
|
||||
OsSwtmrStart(startTime, swtmr);
|
||||
listNext = listNext->pstNext;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrGetNextTimeout
|
||||
Description : Get next timeout
|
||||
@@ -337,14 +355,23 @@ Return : Count of the Timer list
|
||||
LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
|
||||
{
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
UINT32 ticks = OsSortLinkGetNextExpireTime(g_swtmrSortLinkList);
|
||||
UINT64 time = OsSortLinkGetNextExpireTime(g_swtmrSortLinkList);
|
||||
LOS_IntRestore(intSave);
|
||||
return ticks;
|
||||
time = time / OS_CYCLE_PER_TICK;
|
||||
if (time > OS_NULL_INT) {
|
||||
time = OS_NULL_INT;
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 OsSwtmrTimeGet(const SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
return OsSortLinkGetTargetExpireTime(OsGetCurrSchedTimeCycle(), &swtmr->stSortList);
|
||||
UINT64 time = OsSortLinkGetTargetExpireTime(OsGetCurrSchedTimeCycle(), &swtmr->stSortList);
|
||||
time = time / OS_CYCLE_PER_TICK;
|
||||
if (time > OS_NULL_INT) {
|
||||
time = OS_NULL_INT;
|
||||
}
|
||||
return (UINT32)time;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
@@ -42,7 +42,8 @@ LITE_OS_SEC_BSS UINT32 g_ticksPerSec;
|
||||
LITE_OS_SEC_BSS UINT32 g_uwCyclePerSec;
|
||||
LITE_OS_SEC_BSS UINT32 g_cyclesPerTick;
|
||||
LITE_OS_SEC_BSS UINT32 g_sysClock;
|
||||
LITE_OS_SEC_BSS BOOL g_sysTimerIsInit = FALSE;
|
||||
LITE_OS_SEC_BSS STATIC BOOL g_sysTimerIsInit = FALSE;
|
||||
LITE_OS_SEC_BSS STATIC UINT64 g_tickTimerStartTime;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
STATIC UINT64 g_tickTimerBase;
|
||||
@@ -72,12 +73,12 @@ LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
|
||||
LOS_SchedTickHandler();
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsTickTimerReload(UINT64 responseTime)
|
||||
LITE_OS_SEC_TEXT UINT64 OsTickTimerReload(UINT64 period)
|
||||
{
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
g_tickTimerBase = LOS_SysCycleGet();
|
||||
#endif
|
||||
g_sysTickTimer->reload(responseTime);
|
||||
return g_sysTickTimer->reload(period);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT64 LOS_SysCycleGet(VOID)
|
||||
@@ -120,6 +121,10 @@ STATIC UINT32 TickTimerCheck(const ArchTickTimer *tick)
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
|
||||
if (tick->periodMax == 0) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
|
||||
if ((tick->init == NULL) || (tick->reload == NULL) ||
|
||||
(tick->lock == NULL) || (tick->unlock == NULL) ||
|
||||
(tick->getCycle == NULL)) {
|
||||
@@ -172,6 +177,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTickTimerInit(VOID)
|
||||
g_sysTimerIsInit = TRUE;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -223,6 +229,11 @@ LITE_OS_SEC_TEXT UINT32 LOS_TickTimerRegister(const ArchTickTimer *timer, const
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTickSysTimerStartTimeSet(UINT64 currTime)
|
||||
{
|
||||
g_tickTimerStartTime = currTime;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_TickCountGet
|
||||
Description : get current tick
|
||||
@@ -232,7 +243,7 @@ Return : current tick
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
|
||||
{
|
||||
return LOS_SysCycleGet() / OS_CYCLE_PER_TICK;
|
||||
return (LOS_SysCycleGet() - g_tickTimerStartTime) / OS_CYCLE_PER_TICK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user