更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
time.c 文件参考

浏览源代码.

结构体

struct  swtmr_proc_arg
 

函数

STATIC INLINE BOOL ValidTimeval (const struct timeval *tv)
 
STATIC INLINE BOOL ValidTimeval64 (const struct timeval64 *tv)
 
STATIC INLINE BOOL ValidTimerID (UINT16 swtmrID)
 
STATIC SPIN_LOCK_INIT (g_timeSpin)
 
VOID OsAdjTime (VOID)
 
int adjtime (const struct timeval *delta, struct timeval *oldDelta)
 
STATIC INLINE struct timespec64 OsTimeSpecAdd (const struct timespec64 t1, const struct timespec64 t2)
 增加指定时间 更多...
 
STATIC INLINE struct timespec64 OsTimeSpecSub (const struct timespec64 t1, const struct timespec64 t2)
 减少指定时间 更多...
 
STATIC VOID OsGetHwTime (struct timespec64 *hwTime)
 获取硬件时间 更多...
 
STATIC INT32 OsSetTimeOfDay (const struct timeval64 *tv, const struct timezone *tz)
 设置日历 更多...
 
int settimeofday (const struct timeval *tv, const struct timezone *tz)
 
int settimeofday64 (const struct timeval64 *tv, const struct timezone *tz)
 
int setlocalseconds (int seconds)
 设置本地秒数 更多...
 
STATIC INT32 OsGetTimeOfDay (struct timeval64 *tv, struct timezone *tz)
 获取日历时间 更多...
 
int gettimeofday64 (struct timeval64 *tv, struct timezone *tz)
 
int gettimeofday (struct timeval *tv, void *_tz) int gettimeofday(struct timeval *tv
 gettimeofday
更多...
 
 if (tv==NULL)
 
 if (OsGetTimeOfDay(&stTimeVal64, tz)==-1)
 
 if (stTimeVal64.tv_sec >(long long) LONG_MAX)
 
int clock_settime (clockid_t clockID, const struct timespec *tp)
 
UINT32 GetTidFromClockID (clockid_t clockID)
 
const pid_t GetPidFromClockID (clockid_t clockID)
 
static int PthreadGetCputime (clockid_t clockID, struct timespec *ats)
 
static int ProcessGetCputime (clockid_t clockID, struct timespec *ats)
 
static int GetCputime (clockid_t clockID, struct timespec *tp)
 
static int CheckClock (const clockid_t clockID)
 
static int CpuClockGetres (const clockid_t clockID, struct timespec *tp)
 
int clock_gettime (clockid_t clockID, struct timespec *tp)
 当用户程序进行特定系统调用时(例如clock_gettime(CLOCK_REALTIME_COARSE, &ts)),VDSO代码页会将其拦截; 更多...
 
int clock_getres (clockid_t clockID, struct timespec *tp)
 
int clock_nanosleep (clockid_t clk, int flags, const struct timespec *req, struct timespec *rem)
 
static VOID SwtmrProc (UINTPTR tmrArg)
 
int timer_create (clockid_t clockID, struct sigevent *restrict evp, timer_t *restrict timerID)
 
int OsTimerCreate (clockid_t clockID, struct ksigevent *evp, timer_t *timerID)
 
int timer_delete (timer_t timerID)
 
int timer_settime (timer_t timerID, int flags, const struct itimerspec *value, struct itimerspec *oldValue)
 
int timer_gettime (timer_t timerID, struct itimerspec *value)
 
int timer_getoverrun (timer_t timerID)
 
STATIC INT32 DoNanoSleep (UINT64 nanoseconds)
 
int usleep (unsigned long useconds) int usleep(unsigned useconds)
 
int nanosleep (const struct timespec *rqtp, struct timespec *rmtp)
 
unsigned int sleep (unsigned int seconds)
 
double difftime (time_t time2, time_t time1)
 
clock_t clock (VOID)
 
clock_t times (struct tms *buf)
 
int setitimer (int which, const struct itimerval *value, struct itimerval *ovalue)
 
int getitimer (int which, struct itimerval *value)
 
VOID OsVdsoTimeGet (VdsoDataPage *vdsoDataPage)
 将最新的时间刷进数据页 更多...
 
time_t time (time_t *t)
 

变量

STATIC long long g_adjTimeLeft
 
STATIC INT32 g_adjDirection
 
STATIC const long long g_adjPacement
 
STATIC struct timespec64 g_accDeltaFromAdj
 
STATIC struct timespec64 g_accDeltaFromSet
 
int struct timezone * tz
 
tv tv_sec = stTimeVal64.tv_sec
 
tv tv_usec = stTimeVal64.tv_usec
 
 return
 

详细描述

 
版本
作者
weharmonyos.com | 鸿蒙研究站 | 每天死磕一点点
日期
2021-11-25

在文件 time.c 中定义.

函数说明

◆ adjtime()

int adjtime ( const struct timeval *  delta,
struct timeval *  oldDelta 
)

在文件 time.c208 行定义.

209{
210 UINT32 intSave;
211 LOS_SpinLockSave(&g_timeSpin, &intSave);
212 /* return the amount of time remaining from any previous adjustment that has not yet been completed. */
213 if (oldDelta != NULL) {
214 if (g_adjDirection == 1) {
215 oldDelta->tv_sec = g_adjTimeLeft / OS_SYS_NS_PER_SECOND;
216 oldDelta->tv_usec = (g_adjTimeLeft % OS_SYS_NS_PER_SECOND) / OS_SYS_NS_PER_US;
217 } else {
218 oldDelta->tv_sec = -(g_adjTimeLeft / OS_SYS_NS_PER_SECOND);
219 oldDelta->tv_usec = -((g_adjTimeLeft % OS_SYS_NS_PER_SECOND) / OS_SYS_NS_PER_US);
220 }
221 }
222
223 if ((delta == NULL) || ((delta->tv_sec == 0) && (delta->tv_usec == 0))) {
224 LOS_SpinUnlockRestore(&g_timeSpin, intSave);
225 return 0;
226 }
227
228 if ((delta->tv_usec > OS_SYS_US_PER_SECOND) || (delta->tv_usec < -OS_SYS_US_PER_SECOND)) {
229 LOS_SpinUnlockRestore(&g_timeSpin, intSave);
230 TIME_RETURN(EINVAL);
231 }
232
233 /*
234 * 2: in the glibc implementation, delta must be less than or equal to (INT_MAX / 1000000 - 2) and
235 * greater than or equal to (INT_MIN / 1000000 + 2)
236 */
237 if ((delta->tv_sec < (INT_MIN / OS_SYS_US_PER_SECOND + 2)) ||
238 (delta->tv_sec > (INT_MAX / OS_SYS_US_PER_SECOND + 2))) {
239 LOS_SpinUnlockRestore(&g_timeSpin, intSave);
240 TIME_RETURN(EINVAL);
241 }
242
243 g_adjTimeLeft = (INT64)delta->tv_sec * OS_SYS_NS_PER_SECOND + delta->tv_usec * OS_SYS_NS_PER_US;
244 if (g_adjTimeLeft > 0) {
245 g_adjDirection = 1;
246 } else {
247 g_adjDirection = 0;
249 }
250
251 LOS_SpinUnlockRestore(&g_timeSpin, intSave);
252 return 0;
253}
VOID LOS_SpinUnlockRestore(SPIN_LOCK_S *lock, UINT32 intSave)
Definition: los_spinlock.c:108
VOID LOS_SpinLockSave(SPIN_LOCK_S *lock, UINT32 *intSave)
Definition: los_spinlock.c:98
unsigned int UINT32
Definition: los_typedef.h:57
long signed int INT64
Definition: los_typedef.h:67
STATIC long long g_adjTimeLeft
Definition: time.c:138
STATIC INT32 g_adjDirection
Definition: time.c:139
if(tv==NULL)
Definition: time.c:430
函数调用图:

◆ CheckClock()

static int CheckClock ( const clockid_t  clockID)
static

在文件 time.c578 行定义.

579{
580 int error = 0;
581 const pid_t pid = GetPidFromClockID(clockID);
582
583 if (!((UINT32)clockID & CPUCLOCK_PERTHREAD_MASK)) {
584 LosProcessCB *spcb = NULL;
585 if (OsProcessIDUserCheckInvalid(pid) || pid < 0) {
586 return -EINVAL;
587 }
588 spcb = OS_PCB_FROM_PID(pid);
589 if (OsProcessIsUnused(spcb)) {
590 error = -EINVAL;
591 }
592 } else {
593 error = -EINVAL;
594 }
595
596 return error;
597}
STATIC INLINE BOOL OsProcessIsUnused(const LosProcessCB *processCB)
STATIC INLINE BOOL OsProcessIDUserCheckInvalid(UINT32 pid)
const pid_t GetPidFromClockID(clockid_t clockID)
Definition: time.c:498
函数调用图:
这是这个函数的调用关系图:

◆ clock()

clock_t clock ( VOID  )

在文件 time.c1096 行定义.

1097{
1098 clock_t clockMsec;
1099 UINT64 nowNsec;
1100
1101 nowNsec = LOS_CurrNanosec();
1102 clockMsec = (clock_t)(nowNsec / (OS_SYS_NS_PER_SECOND / CLOCKS_PER_SEC));
1103
1104 return clockMsec;
1105}
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID)
获取自系统启动以来的纳秒数
Definition: los_hw_tick.c:62
long unsigned int UINT64
Definition: los_typedef.h:66
函数调用图:

◆ clock_getres()

int clock_getres ( clockid_t  clockID,
struct timespec *  tp 
)

在文件 time.c676 行定义.

677{
678 if (tp == NULL) {
679 TIME_RETURN(EINVAL);
680 }
681
682 switch (clockID) {
683 case CLOCK_MONOTONIC_RAW:
684 case CLOCK_MONOTONIC:
685 case CLOCK_REALTIME:
686 /* the accessable rtc resolution */
687 tp->tv_nsec = OS_SYS_NS_PER_US; /* the precision of clock_gettime is 1us */
688 tp->tv_sec = 0;
689 break;
690 case CLOCK_MONOTONIC_COARSE:
691 case CLOCK_REALTIME_COARSE:
692 /* the clock coarse resolution, supported by vdso.
693 * the precision of clock_gettime is 1tick */
694 tp->tv_nsec = OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND;
695 tp->tv_sec = 0;
696 break;
697 case CLOCK_THREAD_CPUTIME_ID:
698 case CLOCK_PROCESS_CPUTIME_ID:
699 case CLOCK_BOOTTIME:
700 case CLOCK_REALTIME_ALARM:
701 case CLOCK_BOOTTIME_ALARM:
702 case CLOCK_TAI:
703 TIME_RETURN(ENOTSUP);
704 default:
705#ifdef LOSCFG_KERNEL_CPUP
706 {
707 int ret = CpuClockGetres(clockID, tp);
708 TIME_RETURN(-ret);
709 }
710#else
711 TIME_RETURN(EINVAL);
712#endif
713 }
714
715 TIME_RETURN(0);
716}
static int CpuClockGetres(const clockid_t clockID, struct timespec *tp)
Definition: time.c:599
函数调用图:
这是这个函数的调用关系图:

◆ clock_gettime()

int clock_gettime ( clockid_t  clockID,
struct timespec *  tp 
)

当用户程序进行特定系统调用时(例如clock_gettime(CLOCK_REALTIME_COARSE, &ts)),VDSO代码页会将其拦截;

在文件 time.c614 行定义.

615{
616 UINT32 intSave;
617 struct timespec64 tmp = {0};
618 struct timespec64 hwTime = {0};
619
620 if (clockID > MAX_CLOCKS) {
621 goto ERROUT;
622 }
623
624 if (tp == NULL) {
625 goto ERROUT;
626 }
627
628 OsGetHwTime(&hwTime);
629
630 switch (clockID) {
631 case CLOCK_MONOTONIC_RAW:
632 tp->tv_sec = hwTime.tv_sec;
633 tp->tv_nsec = hwTime.tv_nsec;
634 break;
635 case CLOCK_MONOTONIC:
636 LOS_SpinLockSave(&g_timeSpin, &intSave);
637 tmp = OsTimeSpecAdd(hwTime, g_accDeltaFromAdj);
638 LOS_SpinUnlockRestore(&g_timeSpin, intSave);
639 tp->tv_sec = tmp.tv_sec;
640 tp->tv_nsec = tmp.tv_nsec;
641 break;
642 case CLOCK_REALTIME:
643 LOS_SpinLockSave(&g_timeSpin, &intSave);
644 tmp = OsTimeSpecAdd(hwTime, g_accDeltaFromAdj);
646 LOS_SpinUnlockRestore(&g_timeSpin, intSave);
647 tp->tv_sec = tmp.tv_sec;
648 tp->tv_nsec = tmp.tv_nsec;
649 break;
650 case CLOCK_MONOTONIC_COARSE:
651 case CLOCK_REALTIME_COARSE:
652 case CLOCK_THREAD_CPUTIME_ID:
653 case CLOCK_PROCESS_CPUTIME_ID:
654 case CLOCK_BOOTTIME:
655 case CLOCK_REALTIME_ALARM:
656 case CLOCK_BOOTTIME_ALARM:
657 case CLOCK_TAI:
658 TIME_RETURN(ENOTSUP);
659 default:
660 {
661#ifdef LOSCFG_KERNEL_CPUP
662 int ret = GetCputime(clockID, tp);
663 TIME_RETURN(-ret);
664#else
665 TIME_RETURN(EINVAL);
666#endif
667 }
668 }
669
670 return 0;
671
672 ERROUT:
673 TIME_RETURN(EINVAL);
674}
STATIC VOID OsGetHwTime(struct timespec64 *hwTime)
获取硬件时间
Definition: time.c:287
STATIC struct timespec64 g_accDeltaFromAdj
Definition: time.c:146
static int GetCputime(clockid_t clockID, struct timespec *tp)
Definition: time.c:561
STATIC INLINE struct timespec64 OsTimeSpecAdd(const struct timespec64 t1, const struct timespec64 t2)
增加指定时间
Definition: time.c:255
STATIC struct timespec64 g_accDeltaFromSet
Definition: time.c:148
函数调用图:
这是这个函数的调用关系图:

◆ clock_nanosleep()

int clock_nanosleep ( clockid_t  clk,
int  flags,
const struct timespec *  req,
struct timespec *  rem 
)

在文件 time.c718 行定义.

719{
720 switch (clk) {
721 case CLOCK_REALTIME:
722 if (flags == 0) {
723 /* we only support the realtime clock currently */
724 return nanosleep(req, rem);
725 }
726 /* fallthrough */
727 case CLOCK_MONOTONIC_COARSE:
728 case CLOCK_REALTIME_COARSE:
729 case CLOCK_MONOTONIC_RAW:
730 case CLOCK_MONOTONIC:
731 case CLOCK_PROCESS_CPUTIME_ID:
732 case CLOCK_BOOTTIME:
733 case CLOCK_REALTIME_ALARM:
734 case CLOCK_BOOTTIME_ALARM:
735 case CLOCK_TAI:
736 if (flags == 0 || flags == TIMER_ABSTIME) {
737 TIME_RETURN(ENOTSUP);
738 }
739 /* fallthrough */
740 case CLOCK_THREAD_CPUTIME_ID:
741 default:
742 TIME_RETURN(EINVAL);
743 }
744
745 TIME_RETURN(0);
746}
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
Definition: time.c:1068
函数调用图:
这是这个函数的调用关系图:

◆ clock_settime()

int clock_settime ( clockid_t  clockID,
const struct timespec *  tp 
)

在文件 time.c452 行定义.

453{
454 struct timeval tv = {0};
455
456 switch (clockID) {
457 case CLOCK_REALTIME:
458 /* we only support the realtime clock currently */
459 break;
460 case CLOCK_MONOTONIC_COARSE:
461 case CLOCK_REALTIME_COARSE:
462 case CLOCK_MONOTONIC_RAW:
463 case CLOCK_PROCESS_CPUTIME_ID:
464 case CLOCK_BOOTTIME:
465 case CLOCK_REALTIME_ALARM:
466 case CLOCK_BOOTTIME_ALARM:
467 case CLOCK_TAI:
468 case CLOCK_THREAD_CPUTIME_ID:
469 TIME_RETURN(ENOTSUP);
470 case CLOCK_MONOTONIC:
471 default:
472 TIME_RETURN(EINVAL);
473 }
474
475 if (!ValidTimeSpec(tp)) {
476 TIME_RETURN(EINVAL);
477 }
478
479#ifdef LOSCFG_SECURITY_CAPABILITY
480 if (!IsCapPermit(CAP_CLOCK_SETTIME)) {
481 TIME_RETURN(EPERM);
482 }
483#endif
484
485 tv.tv_sec = tp->tv_sec;
486 tv.tv_usec = tp->tv_nsec / OS_SYS_NS_PER_US;
487 return settimeofday(&tv, NULL);
488}
BOOL IsCapPermit(UINT32 capIndex)
Definition: capability.c:43
int settimeofday(const struct timeval *tv, const struct timezone *tz)
Definition: time.c:331
STATIC INLINE BOOL ValidTimeSpec(const struct timespec *tp)
Definition: time_posix.h:53
函数调用图:
这是这个函数的调用关系图:

◆ CpuClockGetres()

static int CpuClockGetres ( const clockid_t  clockID,
struct timespec *  tp 
)
static

在文件 time.c599 行定义.

600{
601 if (clockID > 0) {
602 return -EINVAL;
603 }
604
605 int error = CheckClock(clockID);
606 if (!error) {
607 error = ProcessGetCputime(clockID, tp);
608 }
609
610 return error;
611}
static int ProcessGetCputime(clockid_t clockID, struct timespec *ats)
Definition: time.c:531
static int CheckClock(const clockid_t clockID)
Definition: time.c:578
函数调用图:
这是这个函数的调用关系图:

◆ difftime()

double difftime ( time_t  time2,
time_t  time1 
)

在文件 time.c1091 行定义.

1092{
1093 return (double)(time2 - time1);
1094}

◆ DoNanoSleep()

STATIC INT32 DoNanoSleep ( UINT64  nanoseconds)

在文件 time.c1048 行定义.

1049{
1050 UINT32 ret;
1051
1052 ret = LOS_TaskDelay(OsNS2Tick(nanoseconds));
1053 if (ret == LOS_OK || ret == LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK) {
1054 return 0;
1055 }
1056 return -1;
1057}
LITE_OS_SEC_TEXT_MINOR UINT32 OsNS2Tick(UINT64 nanoseconds)
纳秒转化成 tick
Definition: los_sys.c:125
LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick)
任务延时等待,释放CPU,等待时间到期后该任务会重新进入ready状态
Definition: los_task.c:1020
函数调用图:
这是这个函数的调用关系图:

◆ GetCputime()

static int GetCputime ( clockid_t  clockID,
struct timespec *  tp 
)
static

在文件 time.c561 行定义.

562{
563 int ret;
564
565 if (clockID >= 0) {
566 return -EINVAL;
567 }
568
569 if ((UINT32)clockID & CPUCLOCK_PERTHREAD_MASK) {
570 ret = PthreadGetCputime(clockID, tp);
571 } else {
572 ret = ProcessGetCputime(clockID, tp);
573 }
574
575 return ret;
576}
static int PthreadGetCputime(clockid_t clockID, struct timespec *ats)
Definition: time.c:505
函数调用图:
这是这个函数的调用关系图:

◆ getitimer()

int getitimer ( int  which,
struct itimerval *  value 
)

在文件 time.c1172 行定义.

1173{
1174 LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
1175 LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
1176 struct itimerspec spec = {};
1177
1178 int ret = LOS_OK;
1179
1180 /* we only support the realtime clock timer currently */
1181 if (which != ITIMER_REAL || !value) {
1182 set_errno(EINVAL);
1183 return -1;
1184 }
1185
1186 if (processCB->timerID != (timer_t)(UINTPTR)MAX_INVALID_TIMER_VID) {
1187 ret = timer_gettime(processCB->timerID, &spec);
1188 }
1189
1190 if (ret == LOS_OK) {
1191 TIMESPEC_TO_TIMEVAL(&value->it_value, &spec.it_value);
1192 TIMESPEC_TO_TIMEVAL(&value->it_interval, &spec.it_interval);
1193 }
1194
1195 return ret;
1196}
LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID)
Obtain current running task ID.
Definition: los_task.c:331
unsigned long UINTPTR
Definition: los_typedef.h:68
timer_t timerID
UINT32 processID
int timer_gettime(timer_t timerID, struct itimerspec *value)
Definition: time.c:995
函数调用图:
这是这个函数的调用关系图:

◆ GetPidFromClockID()

const pid_t GetPidFromClockID ( clockid_t  clockID)
inline

在文件 time.c498 行定义.

499{
500 // In musl/src/time/clock_getcpuclockid.c, we know 'clockid = (-pid - 1) * 8 + 2'
501 const pid_t pid = -(clockID - 2) / 8 - 1; // 2 8 1 inverse operation from clockID to pid
502 return pid;
503}
这是这个函数的调用关系图:

◆ GetTidFromClockID()

UINT32 GetTidFromClockID ( clockid_t  clockID)
inline

在文件 time.c491 行定义.

492{
493 // In musl/src/thread/pthread_getcpuclockid.c, we know 'clockid = (-tid - 1) * 8 + 6'
494 UINT32 tid = -(clockID - 6) / 8 - 1; // 6 8 1 inverse operation from clockID to tid
495 return tid;
496}
这是这个函数的调用关系图:

◆ gettimeofday()

int gettimeofday ( struct timeval *  tv,
void _tz 
)

gettimeofday

    gettimeofday 函数是一个符合 POSIX 标准的函数,它可以检索当前时间,精度达到纳秒级
    struct timeval{  
       long int tv_sec; // 秒数  
       long int tv_usec; // 微秒数  
    }
    其中time_t和suseconds_t都是long int类型。在32位下为4个字节,能够表示的最大正整数是2147483647,
    而这个表示的时间最大能到2038-01-19 03:14:07,超过了之后就变为-2147483648,这就是linux2038年的问题。
    而64位系统下的time_t类型即long类型长度为8个字节,可以用到几千亿年,这么长的时间完全不用担心溢出的问题。
参数
tv
tz
返回

参见
这是这个函数的调用关系图:

◆ gettimeofday64()

int gettimeofday64 ( struct timeval64 *  tv,
struct timezone *  tz 
)

在文件 time.c391 行定义.

392{
393 if (tv == NULL) {
394 TIME_RETURN(EINVAL);
395 }
396
397 return OsGetTimeOfDay(tv, tz);
398}
STATIC INT32 OsGetTimeOfDay(struct timeval64 *tv, struct timezone *tz)
获取日历时间
Definition: time.c:366
int struct timezone * tz
Definition: time.c:424
函数调用图:
这是这个函数的调用关系图:

◆ if() [1/3]

if ( OsGetTimeOfDay &,  tz = = -1)

在文件 time.c434 行定义.

434 {
435 return -1;
436 }

◆ if() [2/3]

if ( stTimeVal64.  tv_sec,
(long long LONG_MAX 
)

在文件 time.c442 行定义.

442 {
443 return -1;
444 }

◆ if() [3/3]

if ( tv  = = NULL)

在文件 time.c430 行定义.

430 {
431 TIME_RETURN(EINVAL);
432 }
这是这个函数的调用关系图:

◆ nanosleep()

int nanosleep ( const struct timespec *  rqtp,
struct timespec *  rmtp 
)

在文件 time.c1068 行定义.

1069{
1070 UINT64 nanoseconds;
1071 INT32 ret = -1;
1072
1073 (VOID)rmtp;
1074 /* expire time */
1075
1076 if (!ValidTimeSpec(rqtp)) {
1077 errno = EINVAL;
1078 return ret;
1079 }
1080
1081 nanoseconds = (UINT64)rqtp->tv_sec * OS_SYS_NS_PER_SECOND + rqtp->tv_nsec;
1082
1083 return DoNanoSleep(nanoseconds);
1084}
signed int INT32
Definition: los_typedef.h:60
STATIC INT32 DoNanoSleep(UINT64 nanoseconds)
Definition: time.c:1048
函数调用图:
这是这个函数的调用关系图:

◆ OsAdjTime()

VOID OsAdjTime ( VOID  )

在文件 time.c150 行定义.

151{
152 UINT32 intSave;
153
154 LOS_SpinLockSave(&g_timeSpin, &intSave);
155 if (!g_adjTimeLeft) {
156 LOS_SpinUnlockRestore(&g_timeSpin, intSave);
157 return;
158 }
159
161 if (g_adjDirection) {
162 if ((g_accDeltaFromAdj.tv_nsec + g_adjPacement) >= OS_SYS_NS_PER_SECOND) {
163 g_accDeltaFromAdj.tv_sec++;
164 g_accDeltaFromAdj.tv_nsec = (g_accDeltaFromAdj.tv_nsec + g_adjPacement) % OS_SYS_NS_PER_SECOND;
165 } else {
167 }
168 } else {
169 if ((g_accDeltaFromAdj.tv_nsec - g_adjPacement) < 0) {
170 g_accDeltaFromAdj.tv_sec--;
171 g_accDeltaFromAdj.tv_nsec = g_accDeltaFromAdj.tv_nsec - g_adjPacement + OS_SYS_NS_PER_SECOND;
172 } else {
174 }
175 }
176
178 } else {
179 if (g_adjDirection) {
180 if ((g_accDeltaFromAdj.tv_nsec + g_adjTimeLeft) >= OS_SYS_NS_PER_SECOND) {
181 g_accDeltaFromAdj.tv_sec++;
182 g_accDeltaFromAdj.tv_nsec = (g_accDeltaFromAdj.tv_nsec + g_adjTimeLeft) % OS_SYS_NS_PER_SECOND;
183 } else {
185 }
186 } else {
187 if ((g_accDeltaFromAdj.tv_nsec - g_adjTimeLeft) < 0) {
188 g_accDeltaFromAdj.tv_sec--;
189 g_accDeltaFromAdj.tv_nsec = g_accDeltaFromAdj.tv_nsec - g_adjTimeLeft + OS_SYS_NS_PER_SECOND;
190 } else {
192 }
193 }
194
195 g_adjTimeLeft = 0;
196 }
197 LOS_SpinUnlockRestore(&g_timeSpin, intSave);
198 return;
199}
STATIC const long long g_adjPacement
Definition: time.c:142
函数调用图:

◆ OsGetHwTime()

STATIC VOID OsGetHwTime ( struct timespec64 *  hwTime)

获取硬件时间

在文件 time.c287 行定义.

288{
289 UINT64 nowNsec;
290
291 nowNsec = LOS_CurrNanosec();//获取当前纳秒
292 hwTime->tv_sec = nowNsec / OS_SYS_NS_PER_SECOND;//当前秒数
293 hwTime->tv_nsec = nowNsec - hwTime->tv_sec * OS_SYS_NS_PER_SECOND;// @note_thinking 为啥要这样做? 不应该是直接 nowNsec ?
294}
函数调用图:
这是这个函数的调用关系图:

◆ OsGetTimeOfDay()

STATIC INT32 OsGetTimeOfDay ( struct timeval64 *  tv,
struct timezone *  tz 
)

获取日历时间

在文件 time.c366 行定义.

367{
368 UINT32 intSave;
369
370 (VOID)tz;
371 struct timespec64 hwTime = {0};
372 struct timespec64 realTime = {0};
373
374 OsGetHwTime(&hwTime);
375
376 LOS_SpinLockSave(&g_timeSpin, &intSave);
377 realTime = OsTimeSpecAdd(hwTime, g_accDeltaFromAdj);
378 realTime = OsTimeSpecAdd(realTime, g_accDeltaFromSet);
379 LOS_SpinUnlockRestore(&g_timeSpin, intSave);
380
381 tv->tv_sec = realTime.tv_sec;
382 tv->tv_usec = realTime.tv_nsec / OS_SYS_NS_PER_US;
383
384 if (tv->tv_sec < 0) {
385 TIME_RETURN(EINVAL);
386 }
387 return 0;
388}
函数调用图:
这是这个函数的调用关系图:

◆ OsSetTimeOfDay()

STATIC INT32 OsSetTimeOfDay ( const struct timeval64 *  tv,
const struct timezone *  tz 
)

设置日历

在文件 time.c296 行定义.

297{
298 UINT32 intSave;
299 struct timespec64 setTime = {0};
300 struct timespec64 hwTime = {0};
301 struct timespec64 realTime = {0};
302 struct timespec64 tmp = {0};
303
304#ifdef LOSCFG_SECURITY_CAPABILITY
305 if (!IsCapPermit(CAP_SET_TIMEOFDAY)) {
306 TIME_RETURN(EPERM);
307 }
308#endif
309
310 (VOID)tz;
311 OsGetHwTime(&hwTime);
312 setTime.tv_sec = tv->tv_sec;
313 setTime.tv_nsec = tv->tv_usec * OS_SYS_NS_PER_US;
314
315 LOS_SpinLockSave(&g_timeSpin, &intSave);
316 /* stop on-going continuous adjusement */
317 if (g_adjTimeLeft) {
318 g_adjTimeLeft = 0;
319 }
320 realTime = OsTimeSpecAdd(hwTime, g_accDeltaFromAdj);
321 realTime = OsTimeSpecAdd(realTime, g_accDeltaFromSet);
322
323 tmp = OsTimeSpecSub(setTime, realTime);
325
326 LOS_SpinUnlockRestore(&g_timeSpin, intSave);
327
328 return 0;
329}
STATIC INLINE struct timespec64 OsTimeSpecSub(const struct timespec64 t1, const struct timespec64 t2)
减少指定时间
Definition: time.c:273
函数调用图:
这是这个函数的调用关系图:

◆ OsTimerCreate()

int OsTimerCreate ( clockid_t  clockID,
struct ksigevent evp,
timer_t *  timerID 
)

在文件 time.c842 行定义.

843{
844 UINT32 ret;
845 UINT16 swtmrID;
846 swtmr_proc_arg *arg = NULL;
847 int signo;
848#ifdef LOSCFG_SECURITY_VID
849 UINT16 vid;
850#endif
851
852 if ((clockID != CLOCK_REALTIME) || (timerID == NULL)) {
853 errno = EINVAL;
854 return -1;
855 }
856
857 signo = evp ? evp->sigev_signo : SIGALRM;
858 if (signo > SIGRTMAX || signo < 1) {
859 errno = EINVAL;
860 return -1;
861 }
862 if (evp && (evp->sigev_notify != SIGEV_SIGNAL && evp->sigev_notify != SIGEV_THREAD_ID)) {
863 errno = ENOTSUP;
864 return -1;
865 }
866
867 arg = (swtmr_proc_arg *)malloc(sizeof(swtmr_proc_arg));
868 if (arg == NULL) {
869 errno = ENOMEM;
870 return -1;
871 }
872
873 arg->tid = evp ? evp->sigev_tid : 0;
874 arg->sigev_signo = signo;
875 arg->pid = LOS_GetCurrProcessID();
876 arg->sigev_value.sival_ptr = evp ? evp->sigev_value.sival_ptr : NULL;
877 ret = LOS_SwtmrCreate(1, LOS_SWTMR_MODE_ONCE, SwtmrProc, &swtmrID, (UINTPTR)arg);
878 if (ret != LOS_OK) {
879 errno = (ret == LOS_ERRNO_SWTMR_MAXSIZE) ? EAGAIN : EINVAL;
880 free(arg);
881 return -1;
882 }
883
884#ifdef LOSCFG_SECURITY_VID
885 vid = AddNodeByRid(swtmrID);
886 if (vid == MAX_INVALID_TIMER_VID) {
887 free(arg);
888 (VOID)LOS_SwtmrDelete(swtmrID);
889 return -1;
890 }
891 swtmrID = vid;
892#endif
893 *timerID = (timer_t)(UINTPTR)swtmrID;
894 return 0;
895}
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrID)
接口函数 删除定时器
Definition: los_swtmr.c:889
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval, UINT8 mode, SWTMR_PROC_FUNC handler, UINT16 *swtmrID, UINTPTR arg)
创建定时器,设置定时器的定时时长、定时器模式、回调函数,并返回定时器ID
Definition: los_swtmr.c:712
@ LOS_SWTMR_MODE_ONCE
Definition: los_swtmr.h:232
LITE_OS_SEC_TEXT UINT32 LOS_GetCurrProcessID(VOID)
获取当前进程的进程ID
Definition: los_process.c:2161
unsigned short UINT16
Definition: los_typedef.h:56
void * malloc(size_t size)
动态分配内存块大小
Definition: malloc.c:81
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
int sigev_tid
Definition: time_posix.h:49
int sigev_signo
Definition: time_posix.h:47
union sigval sigev_value
Definition: time_posix.h:46
int sigev_notify
Definition: time_posix.h:48
union sigval sigev_value
Definition: time.c:752
unsigned int tid
Definition: time.c:751
pid_t pid
Definition: time.c:750
int sigev_signo
Definition: time.c:749
static VOID SwtmrProc(UINTPTR tmrArg)
Definition: time.c:755
UINT16 AddNodeByRid(UINT16 rid)
Definition: vid.c:178
函数调用图:
这是这个函数的调用关系图:

◆ OsTimeSpecAdd()

STATIC INLINE struct timespec64 OsTimeSpecAdd ( const struct timespec64  t1,
const struct timespec64  t2 
)

增加指定时间

在文件 time.c255 行定义.

256{
257 struct timespec64 ret = {0};
258
259 ret.tv_sec = t1.tv_sec + t2.tv_sec;
260 ret.tv_nsec = t1.tv_nsec + t2.tv_nsec;
261 //用于校正精度
262 if (ret.tv_nsec >= OS_SYS_NS_PER_SECOND) {//超过1秒时的计算
263 ret.tv_sec += 1; //秒数加一
264 ret.tv_nsec -= OS_SYS_NS_PER_SECOND;//剩余纳秒数
265 } else if (ret.tv_nsec < 0L) {//介于 0 - 1秒之间的纳秒数
266 ret.tv_sec -= 1; //秒数减一
267 ret.tv_nsec += OS_SYS_NS_PER_SECOND;//纳秒数增加
268 }
269
270 return ret;
271}
这是这个函数的调用关系图:

◆ OsTimeSpecSub()

STATIC INLINE struct timespec64 OsTimeSpecSub ( const struct timespec64  t1,
const struct timespec64  t2 
)

减少指定时间

在文件 time.c273 行定义.

274{
275 struct timespec64 ret = {0};
276
277 ret.tv_sec = t1.tv_sec - t2.tv_sec;
278 ret.tv_nsec = t1.tv_nsec - t2.tv_nsec;
279 if (ret.tv_nsec < 0) {
280 ret.tv_sec -= 1;
281 ret.tv_nsec += OS_SYS_NS_PER_SECOND;
282 }
283
284 return ret;
285}
这是这个函数的调用关系图:

◆ OsVdsoTimeGet()

VOID OsVdsoTimeGet ( VdsoDataPage vdsoDataPage)

将最新的时间刷进数据页

在文件 time.c1200 行定义.

1201{
1202 UINT32 intSave;
1203 struct timespec64 tmp = {0};
1204 struct timespec64 hwTime = {0};
1205
1206 if (vdsoDataPage == NULL) {
1207 return;
1208 }
1209
1210 OsGetHwTime(&hwTime);//获取硬件时间
1211
1212 LOS_SpinLockSave(&g_timeSpin, &intSave);
1213 tmp = OsTimeSpecAdd(hwTime, g_accDeltaFromAdj);//
1214 vdsoDataPage->monoTimeSec = tmp.tv_sec;
1215 vdsoDataPage->monoTimeNsec = tmp.tv_nsec;
1216
1217 tmp = OsTimeSpecAdd(tmp, g_accDeltaFromSet);
1218 vdsoDataPage->realTimeSec = tmp.tv_sec;
1219 vdsoDataPage->realTimeNsec = tmp.tv_nsec;
1220 LOS_SpinUnlockRestore(&g_timeSpin, intSave);
1221}
INT64 monoTimeSec
系统运行时间,从系统启动时开始计时,速度更快精度更低,系统休眠时不再计时
INT64 realTimeNsec
单位纳秒: 系统实时时间
INT64 realTimeSec
单位秒: 系统实时时间
函数调用图:
这是这个函数的调用关系图:

◆ ProcessGetCputime()

static int ProcessGetCputime ( clockid_t  clockID,
struct timespec *  ats 
)
static

在文件 time.c531 行定义.

532{
533 UINT64 runtime;
534 UINT32 intSave;
535 const pid_t pid = GetPidFromClockID(clockID);
536 LosProcessCB *spcb = NULL;
537
538 if (OsProcessIDUserCheckInvalid(pid) || pid < 0) {
539 return -EINVAL;
540 }
541
542 spcb = OS_PCB_FROM_PID(pid);
543 if (OsProcessIsUnused(spcb)) {
544 return -EINVAL;
545 }
546
547 SCHEDULER_LOCK(intSave);
548 if (spcb->processCpup == NULL) {
549 SCHEDULER_UNLOCK(intSave);
550 return -EINVAL;
551 }
552 runtime = spcb->processCpup->allTime;
553 SCHEDULER_UNLOCK(intSave);
554
555 ats->tv_sec = runtime / OS_SYS_NS_PER_SECOND;
556 ats->tv_nsec = runtime % OS_SYS_NS_PER_SECOND;
557
558 return 0;
559}
UINT64 allTime
Definition: los_cpup_pri.h:50
OsCpupBase * processCpup
函数调用图:
这是这个函数的调用关系图:

◆ PthreadGetCputime()

static int PthreadGetCputime ( clockid_t  clockID,
struct timespec *  ats 
)
static

在文件 time.c505 行定义.

506{
507 uint64_t runtime;
508 UINT32 intSave;
509 UINT32 tid = GetTidFromClockID(clockID);
510
511 if (OS_TID_CHECK_INVALID(tid)) {
512 return -EINVAL;
513 }
514
515 LosTaskCB *task = OsGetTaskCB(tid);
516
517 if (OsCurrTaskGet()->processID != task->processID) {
518 return -EINVAL;
519 }
520
521 SCHEDULER_LOCK(intSave);
522 runtime = task->taskCpup.allTime;
523 SCHEDULER_UNLOCK(intSave);
524
525 ats->tv_sec = runtime / OS_SYS_NS_PER_SECOND;
526 ats->tv_nsec = runtime % OS_SYS_NS_PER_SECOND;
527
528 return 0;
529}
STATIC INLINE LosTaskCB * OsCurrTaskGet(VOID)
STATIC INLINE LosTaskCB * OsGetTaskCB(UINT32 taskID)
通过任务ID获取任务实体,task由任务池分配,本质是个数组,彼此都挨在一块
Definition: los_task_pri.h:250
OsCpupBase taskCpup
UINT32 GetTidFromClockID(clockid_t clockID)
Definition: time.c:491
函数调用图:
这是这个函数的调用关系图:

◆ setitimer()

int setitimer ( int  which,
const struct itimerval *  value,
struct itimerval *  ovalue 
)

在文件 time.c1117 行定义.

1118{
1119 UINT32 intSave;
1120 LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
1121 LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
1122 timer_t timerID = 0;
1123 struct itimerspec spec;
1124 struct itimerspec ospec;
1125 int ret = LOS_OK;
1126
1127 /* we only support the realtime clock timer currently */
1128 if (which != ITIMER_REAL || !value) {
1129 set_errno(EINVAL);
1130 return -1;
1131 }
1132
1133 /* To avoid creating an invalid timer after the timer has already been create */
1134 if (processCB->timerID == (timer_t)(UINTPTR)MAX_INVALID_TIMER_VID) {
1135 ret = OsTimerCreate(CLOCK_REALTIME, NULL, &timerID);
1136 if (ret != LOS_OK) {
1137 return ret;
1138 }
1139 }
1140
1141 /* The initialization of this global timer must be in spinlock
1142 * OsTimerCreate cannot be located in spinlock.
1143 */
1144 SCHEDULER_LOCK(intSave);
1145 if (processCB->timerID == (timer_t)(UINTPTR)MAX_INVALID_TIMER_VID) {
1146 processCB->timerID = timerID;
1147 SCHEDULER_UNLOCK(intSave);
1148 } else {
1149 SCHEDULER_UNLOCK(intSave);
1150 if (timerID) {
1151 timer_delete(timerID);
1152 }
1153 }
1154
1155 if (!ValidTimeval(&value->it_value) || !ValidTimeval(&value->it_interval)) {
1156 set_errno(EINVAL);
1157 return -1;
1158 }
1159
1160 TIMEVAL_TO_TIMESPEC(&value->it_value, &spec.it_value);
1161 TIMEVAL_TO_TIMESPEC(&value->it_interval, &spec.it_interval);
1162
1163 ret = timer_settime(processCB->timerID, 0, &spec, ovalue ? &ospec : NULL);
1164 if (ret == LOS_OK && ovalue) {
1165 TIMESPEC_TO_TIMEVAL(&ovalue->it_value, &ospec.it_value);
1166 TIMESPEC_TO_TIMEVAL(&ovalue->it_interval, &ospec.it_interval);
1167 }
1168
1169 return ret;
1170}
int timer_delete(timer_t timerID)
Definition: time.c:897
STATIC INLINE BOOL ValidTimeval(const struct timeval *tv)
Definition: time.c:92
int OsTimerCreate(clockid_t clockID, struct ksigevent *evp, timer_t *timerID)
Definition: time.c:842
int timer_settime(timer_t timerID, int flags, const struct itimerspec *value, struct itimerspec *oldValue)
Definition: time.c:929
函数调用图:
这是这个函数的调用关系图:

◆ setlocalseconds()

int setlocalseconds ( int  seconds)

设置本地秒数

在文件 time.c356 行定义.

357{
358 struct timeval tv = {0};
359
360 tv.tv_sec = seconds;
361 tv.tv_usec = 0;
362
363 return settimeofday(&tv, NULL);
364}
函数调用图:

◆ settimeofday()

int settimeofday ( const struct timeval *  tv,
const struct timezone *  tz 
)

在文件 time.c331 行定义.

332{
333 struct timeval64 stTimeVal64 = {0};
334
335 if (!ValidTimeval(tv)) {
336 TIME_RETURN(EINVAL);
337 }
338
339 stTimeVal64.tv_sec = tv->tv_sec;
340 stTimeVal64.tv_usec = tv->tv_usec;
341
342 return OsSetTimeOfDay(&stTimeVal64, tz);
343}
STATIC INT32 OsSetTimeOfDay(const struct timeval64 *tv, const struct timezone *tz)
设置日历
Definition: time.c:296
函数调用图:
这是这个函数的调用关系图:

◆ settimeofday64()

int settimeofday64 ( const struct timeval64 *  tv,
const struct timezone *  tz 
)

在文件 time.c346 行定义.

347{
348 if (!ValidTimeval64(tv)) {
349 TIME_RETURN(EINVAL);
350 }
351
352 return OsSetTimeOfDay(tv, tz);
353}
STATIC INLINE BOOL ValidTimeval64(const struct timeval64 *tv)
Definition: time.c:107
函数调用图:
这是这个函数的调用关系图:

◆ sleep()

unsigned int sleep ( unsigned int  seconds)

在文件 time.c1086 行定义.

1087{
1088 return DoNanoSleep((UINT64)seconds * OS_SYS_NS_PER_SECOND);
1089}
函数调用图:
这是这个函数的调用关系图:

◆ SPIN_LOCK_INIT()

STATIC SPIN_LOCK_INIT ( g_timeSpin  )

◆ SwtmrProc()

static VOID SwtmrProc ( UINTPTR  tmrArg)
static

在文件 time.c755 行定义.

756{
757#ifdef LOSCFG_KERNEL_VM
758 INT32 sig, ret;
759 UINT32 intSave;
760 pid_t pid;
761 siginfo_t info;
762 LosTaskCB *stcb = NULL;
763
764 swtmr_proc_arg *arg = (swtmr_proc_arg *)tmrArg;
765 OS_GOTO_EXIT_IF(arg == NULL, EINVAL);
766
767 sig = arg->sigev_signo;
768 pid = arg->pid;
769 OS_GOTO_EXIT_IF(!GOOD_SIGNO(sig), EINVAL);
770
771 /* Create the siginfo structure */
772 info.si_signo = sig;
773 info.si_code = SI_TIMER;
774 info.si_value.sival_ptr = arg->sigev_value.sival_ptr;
775
776 /* Send signals to threads or processes */
777 if (arg->tid > 0) {
778 /* Make sure that the para is valid */
779 OS_GOTO_EXIT_IF(OS_TID_CHECK_INVALID(arg->tid), EINVAL);
780 stcb = OsGetTaskCB(arg->tid);
782 OS_GOTO_EXIT_IF(ret != LOS_OK, -ret);
783
784 /* Dispatch the signal to thread, bypassing normal task group thread
785 * dispatch rules. */
786 SCHEDULER_LOCK(intSave);
787 ret = OsTcbDispatch(stcb, &info);
788 SCHEDULER_UNLOCK(intSave);
789 OS_GOTO_EXIT_IF(ret != LOS_OK, -ret);
790 } else {
791 /* Make sure that the para is valid */
792 OS_GOTO_EXIT_IF(pid <= 0 || OS_PID_CHECK_INVALID(pid), EINVAL);
793 /* Dispatch the signal to process */
794 SCHEDULER_LOCK(intSave);
795 OsDispatch(pid, &info, OS_USER_KILL_PERMISSION);
796 SCHEDULER_UNLOCK(intSave);
797 }
798 return;
799EXIT:
800 PRINT_ERR("Dispatch signals failed!, ret: %d\r\n", ret);
801#endif
802 return;
803}
int OsDispatch(pid_t pid, siginfo_t *info, int permission)
信号分发,发送信号权限/进程组过滤.
Definition: los_signal.c:412
static int GOOD_SIGNO(unsigned int sig)
信号ID是否有效
Definition: los_signal.h:158
INT32 OsUserProcessOperatePermissionsCheck(const LosTaskCB *taskCB, UINT32 processID)
Definition: los_task.c:1385
INT32 OsTcbDispatch(LosTaskCB *stcb, siginfo_t *info)
给任务(线程)发送一个信号
Definition: los_signal.c:182
函数调用图:
这是这个函数的调用关系图:

◆ time()

time_t time ( time_t *  t)

在文件 time.c1224 行定义.

1225{
1226 struct timeval tp;
1227 int ret;
1228
1229 /* Get the current time from the system */
1230 ret = gettimeofday(&tp, (struct timezone *)NULL);
1231 if (ret == LOS_OK) {
1232 /* Return the seconds since the epoch */
1233 if (t) {
1234 *t = tp.tv_sec;
1235 }
1236 return tp.tv_sec;
1237 }
1238 return (time_t)OS_ERROR;
1239}
int gettimeofday(struct timeval *tv, void *_tz) int gettimeofday(struct timeval *tv
gettimeofday
函数调用图:
这是这个函数的调用关系图:

◆ timer_create()

int timer_create ( clockid_t  clockID,
struct sigevent *restrict  evp,
timer_t *restrict  timerID 
)

在文件 time.c805 行定义.

806{
807 UINT32 ret;
808 UINT16 swtmrID;
809#ifdef LOSCFG_SECURITY_VID
810 UINT16 vid;
811#endif
812
813 if (!timerID || (clockID != CLOCK_REALTIME) || !evp) {
814 errno = EINVAL;
815 return -1;
816 }
817
818 if ((evp->sigev_notify != SIGEV_THREAD) || evp->sigev_notify_attributes) {
819 errno = ENOTSUP;
820 return -1;
821 }
822
823 ret = LOS_SwtmrCreate(1, LOS_SWTMR_MODE_ONCE, (SWTMR_PROC_FUNC)evp->sigev_notify_function,
824 &swtmrID, (UINTPTR)evp->sigev_value.sival_ptr);
825 if (ret != LOS_OK) {
826 errno = (ret == LOS_ERRNO_SWTMR_MAXSIZE) ? EAGAIN : EINVAL;
827 return -1;
828 }
829
830#ifdef LOSCFG_SECURITY_VID
831 vid = AddNodeByRid(swtmrID);
832 if (vid == MAX_INVALID_TIMER_VID) {
833 (VOID)LOS_SwtmrDelete(swtmrID);
834 return -1;
835 }
836 swtmrID = vid;
837#endif
838 *timerID = (timer_t)(UINTPTR)swtmrID;
839 return 0;
840}
VOID(* SWTMR_PROC_FUNC)(UINTPTR arg)
Define the type of a callback function that handles software timer timeout.
Definition: los_swtmr.h:260
函数调用图:

◆ timer_delete()

int timer_delete ( timer_t  timerID)

在文件 time.c897 行定义.

898{
899 UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
900 VOID *arg = NULL;
901 UINTPTR swtmrProc;
902
903#ifdef LOSCFG_SECURITY_VID
904 swtmrID = GetRidByVid(swtmrID);
905#endif
906 if (OS_INT_ACTIVE || !ValidTimerID(swtmrID)) {
907 goto ERROUT;
908 }
909
910 arg = (VOID *)OS_SWT_FROM_SID(swtmrID)->uwArg;
911 swtmrProc = (UINTPTR)OS_SWT_FROM_SID(swtmrID)->pfnHandler;
912 if (LOS_SwtmrDelete(swtmrID)) {
913 goto ERROUT;
914 }
915 if ((swtmrProc == (UINTPTR)SwtmrProc) && (arg != NULL)) {
916 free(arg);
917 }
918
919#ifdef LOSCFG_SECURITY_VID
920 RemoveNodeByVid((UINT16)(UINTPTR)timerID);
921#endif
922 return 0;
923
924ERROUT:
925 errno = EINVAL;
926 return -1;
927}
STATIC INLINE BOOL ValidTimerID(UINT16 swtmrID)
Definition: time.c:122
UINT16 GetRidByVid(UINT16 vid)
Definition: vid.c:212
void RemoveNodeByVid(UINT16 vid)
Definition: vid.c:221
函数调用图:
这是这个函数的调用关系图:

◆ timer_getoverrun()

int timer_getoverrun ( timer_t  timerID)

在文件 time.c1024 行定义.

1025{
1026 UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
1027 SWTMR_CTRL_S *swtmr = NULL;
1028 INT32 overRun;
1029
1030#ifdef LOSCFG_SECURITY_VID
1031 swtmrID = GetRidByVid(swtmrID);
1032#endif
1033 if (!ValidTimerID(swtmrID)) {
1034 errno = EINVAL;
1035 return -1;
1036 }
1037
1038 swtmr = OS_SWT_FROM_SID(swtmrID);
1039 if (swtmr->usTimerID >= OS_SWTMR_MAX_TIMERID) {
1040 errno = EINVAL;
1041 return -1;
1042 }
1043
1044 overRun = (INT32)(swtmr->uwOverrun);
1045 return (overRun > DELAYTIMER_MAX) ? DELAYTIMER_MAX : overRun;
1046}
UINT16 usTimerID
Definition: los_swtmr.h:271
UINT32 uwOverrun
Definition: los_swtmr.h:272
函数调用图:
这是这个函数的调用关系图:

◆ timer_gettime()

int timer_gettime ( timer_t  timerID,
struct itimerspec *  value 
)

在文件 time.c995 行定义.

996{
997 UINT32 tick = 0;
998 SWTMR_CTRL_S *swtmr = NULL;
999 UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
1000 UINT32 ret;
1001
1002#ifdef LOSCFG_SECURITY_VID
1003 swtmrID = GetRidByVid(swtmrID);
1004#endif
1005 if ((value == NULL) || !ValidTimerID(swtmrID)) {
1006 errno = EINVAL;
1007 return -1;
1008 }
1009
1010 swtmr = OS_SWT_FROM_SID(swtmrID);
1011
1012 /* get expire time */
1013 ret = LOS_SwtmrTimeGet(swtmr->usTimerID, &tick);
1014 if ((ret != LOS_OK) && (ret != LOS_ERRNO_SWTMR_NOT_STARTED)) {
1015 errno = EINVAL;
1016 return -1;
1017 }
1018
1019 OsTick2TimeSpec(&value->it_value, tick);
1020 OsTick2TimeSpec(&value->it_interval, (swtmr->ucMode == LOS_SWTMR_MODE_ONCE) ? 0 : swtmr->uwInterval);
1021 return 0;
1022}
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT16 swtmrID, UINT32 *tick)
接口函数 获得软件定时器剩余Tick数 通过 *tick 带走
Definition: los_swtmr.c:848
UINT8 ucMode
Definition: los_swtmr.h:270
UINT32 uwInterval
Definition: los_swtmr.h:274
STATIC INLINE VOID OsTick2TimeSpec(struct timespec *tp, UINT32 tick)
Definition: time_posix.h:81
函数调用图:
这是这个函数的调用关系图:

◆ timer_settime()

int timer_settime ( timer_t  timerID,
int  flags,
const struct itimerspec *  value,
struct itimerspec *  oldValue 
)

在文件 time.c929 行定义.

932{
933 UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
934 SWTMR_CTRL_S *swtmr = NULL;
935 UINT32 interval, expiry, ret;
936 UINT32 intSave;
937
938 if (flags != 0) {
939 /* flags not supported currently */
940 errno = ENOSYS;
941 return -1;
942 }
943
944#ifdef LOSCFG_SECURITY_VID
945 swtmrID = GetRidByVid(swtmrID);
946#endif
947 if ((value == NULL) || OS_INT_ACTIVE || !ValidTimerID(swtmrID)) {
948 errno = EINVAL;
949 return -1;
950 }
951
952 if (!ValidTimeSpec(&value->it_value) || !ValidTimeSpec(&value->it_interval)) {
953 errno = EINVAL;
954 return -1;
955 }
956
957 if (oldValue) {
958 (VOID)timer_gettime(timerID, oldValue);
959 }
960
961 swtmr = OS_SWT_FROM_SID(swtmrID);
962 ret = LOS_SwtmrStop(swtmr->usTimerID);
963 if ((ret != LOS_OK) && (ret != LOS_ERRNO_SWTMR_NOT_STARTED)) {
964 errno = EINVAL;
965 return -1;
966 }
967
968 expiry = OsTimeSpec2Tick(&value->it_value);
969 interval = OsTimeSpec2Tick(&value->it_interval);
970
971 LOS_SpinLockSave(&g_swtmrSpin, &intSave);
973 swtmr->uwExpiry = expiry + !!expiry; // PS: skip the first tick because it is NOT a full tick.
974 swtmr->uwInterval = interval;
975 swtmr->uwOverrun = 0;
977
978 if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0)) {
979 /*
980 * 1) when expiry is 0, means timer should be stopped.
981 * 2) If timer is ticking, stopping timer is already done before.
982 * 3) If timer is created but not ticking, return 0 as well.
983 */
984 return 0;
985 }
986
987 if (LOS_SwtmrStart(swtmr->usTimerID)) {
988 errno = EINVAL;
989 return -1;
990 }
991
992 return 0;
993}
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrID)
接口函数 停止定时器 参数定时任务ID
Definition: los_swtmr.c:808
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrID)
接口函数 启动定时器 参数定时任务ID
Definition: los_swtmr.c:764
@ LOS_SWTMR_MODE_OPP
Definition: los_swtmr.h:235
@ LOS_SWTMR_MODE_NO_SELFDELETE
Definition: los_swtmr.h:234
SPIN_LOCK_S g_swtmrSpin
UINT32 uwExpiry
Definition: los_swtmr.h:275
STATIC INLINE UINT32 OsTimeSpec2Tick(const struct timespec *tp)
Definition: time_posix.h:68
函数调用图:
这是这个函数的调用关系图:

◆ times()

clock_t times ( struct tms *  buf)

在文件 time.c1107 行定义.

1108{
1109 clock_t clockTick = -1;
1110
1111 (void)buf;
1112 set_errno(ENOSYS);
1113
1114 return clockTick;
1115}
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
这是这个函数的调用关系图:

◆ usleep()

int usleep ( unsigned long  useconds)

在文件 time.c1060 行定义.

1064{
1065 return DoNanoSleep((UINT64)useconds * OS_SYS_NS_PER_US);
1066}
函数调用图:
这是这个函数的调用关系图:

◆ ValidTimerID()

STATIC INLINE BOOL ValidTimerID ( UINT16  swtmrID)

在文件 time.c122 行定义.

123{
124 /* check timer id */
125 if (swtmrID >= OS_SWTMR_MAX_TIMERID) {
126 return FALSE;
127 }
128
129 /* check owner of this timer */
130 if (OS_SWT_FROM_SID(swtmrID)->uwOwnerPid != LOS_GetCurrProcessID()) {
131 return FALSE;
132 }
133
134 return TRUE;
135}
函数调用图:
这是这个函数的调用关系图:

◆ ValidTimeval()

STATIC INLINE BOOL ValidTimeval ( const struct timeval *  tv)

在文件 time.c92 行定义.

93{
94 /* Fail a NULL pointer */
95 if (tv == NULL) {
96 return FALSE;
97 }
98
99 /* Fail illegal microseconds values */
100 if ((tv->tv_usec < 0) || (tv->tv_usec >= OS_SYS_US_PER_SECOND) || (tv->tv_sec < 0)) {
101 return FALSE;
102 }
103
104 return TRUE;
105}
这是这个函数的调用关系图:

◆ ValidTimeval64()

STATIC INLINE BOOL ValidTimeval64 ( const struct timeval64 *  tv)

在文件 time.c107 行定义.

108{
109 /* Fail a NULL pointer */
110 if (tv == NULL) {
111 return FALSE;
112 }
113
114 /* Fail illegal microseconds values */
115 if ((tv->tv_usec < 0) || (tv->tv_usec >= OS_SYS_US_PER_SECOND) || (tv->tv_sec < 0)) {
116 return FALSE;
117 }
118
119 return TRUE;
120}
这是这个函数的调用关系图:

变量说明

◆ g_accDeltaFromAdj

STATIC struct timespec64 g_accDeltaFromAdj

在文件 time.c146 行定义.

◆ g_accDeltaFromSet

STATIC struct timespec64 g_accDeltaFromSet

在文件 time.c148 行定义.

◆ g_adjDirection

STATIC INT32 g_adjDirection

在文件 time.c139 行定义.

◆ g_adjPacement

STATIC const long long g_adjPacement
初始值:
= (((LOSCFG_BASE_CORE_ADJ_PER_SECOND * SCHED_CLOCK_INTETRVAL_TICKS) /
LOSCFG_BASE_CORE_TICK_PER_SECOND) * OS_SYS_NS_PER_US)

在文件 time.c142 行定义.

◆ g_adjTimeLeft

STATIC long long g_adjTimeLeft

在文件 time.c138 行定义.

◆ return

return

在文件 time.c449 行定义.

◆ tv_sec

tv tv_sec = stTimeVal64.tv_sec

在文件 time.c439 行定义.

◆ tv_usec

tv tv_usec = stTimeVal64.tv_usec

在文件 time.c440 行定义.

◆ tz

struct timezone * tz
初始值:
{
struct timeval64 stTimeVal64 = {0}

在文件 time.c422 行定义.