From d44f3904cf1fcb245b03a239071c684be4a9a13f Mon Sep 17 00:00:00 2001 From: zhushengle Date: Tue, 20 Apr 2021 09:25:36 +0800 Subject: [PATCH 1/2] fix:the setitimer signals the process to be locked at a fixed time. There is a static problem. Close #I3H7TO Change-Id: Iccfb458ed43f761fde1f943e0005f4ac1bf425bc --- compat/posix/src/time.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compat/posix/src/time.c b/compat/posix/src/time.c index 462ea7c0..ce5ca456 100755 --- a/compat/posix/src/time.c +++ b/compat/posix/src/time.c @@ -586,6 +586,7 @@ typedef struct { static VOID SwtmrProc(UINTPTR tmrArg) { + unsigned int intSave; int sig; pid_t pid; siginfo_t info; @@ -610,7 +611,10 @@ static VOID SwtmrProc(UINTPTR tmrArg) info.si_value.sival_ptr = arg->sigev_value.sival_ptr; /* Send the signal */ + SCHEDULER_LOCK(intSave); OsDispatch(pid, &info, OS_USER_KILL_PERMISSION); + SCHEDULER_UNLOCK(intSave); + return; } From 1c0bbb66de0d721b747153c5e448e62619e03bb1 Mon Sep 17 00:00:00 2001 From: zhushengle Date: Tue, 20 Apr 2021 09:54:00 +0800 Subject: [PATCH 2/2] fix:setitimer are downregulated for multicore scenarios, and are static, resulting in inconsistent behavior. Close #I3EBOI Change-Id: I71a86b8f2b7451e886a08dfc7f274287107df916 --- compat/posix/src/time.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/compat/posix/src/time.c b/compat/posix/src/time.c index ce5ca456..2e6972b5 100755 --- a/compat/posix/src/time.c +++ b/compat/posix/src/time.c @@ -887,8 +887,10 @@ clock_t times(struct tms *buf) int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue) { + UINT32 intSave; LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet()); LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID); + timer_t timerID = 0; struct itimerspec spec; struct itimerspec ospec; int ret = LOS_OK; @@ -898,15 +900,27 @@ int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue set_errno(EINVAL); return -1; } - LOS_TaskLock(); + if (processCB->timerID == (timer_t)(UINTPTR)MAX_INVALID_TIMER_VID) { - ret = timer_create(CLOCK_REALTIME, NULL, &processCB->timerID); + ret = timer_create(CLOCK_REALTIME, NULL, &timerID); if (ret != LOS_OK) { - LOS_TaskUnlock(); return ret; } } - LOS_TaskUnlock(); + + /* The initialization of this global timer must be in spinlock + * timer_create cannot be located in spinlock. + */ + SCHEDULER_LOCK(intSave); + if (processCB->timerID == (timer_t)(UINTPTR)MAX_INVALID_TIMER_VID) { + processCB->timerID = timerID; + SCHEDULER_UNLOCK(intSave); + } else { + SCHEDULER_UNLOCK(intSave); + if (timerID) { + timer_delete(timerID); + } + } if (!ValidTimeval(&value->it_value) || !ValidTimeval(&value->it_interval)) { set_errno(EINVAL);