xref: /DragonOS/kernel/src/common/time.h (revision fb6c29d01d4cf92368efec08c01e419c2a941f7d)
1 #pragma once
2 
3 #include "stddef.h"
4 
5 // 操作系统定义时间以ns为单位
6 #define CLOCKS_PER_SEC 1000000
7 
8 struct tm
9 {
10     int tm_sec;   /* Seconds.	[0-60] (1 leap second) */
11     int tm_min;   /* Minutes.	[0-59] */
12     int tm_hour;  /* Hours.	[0-23] */
13     int tm_mday;  /* Day.		[1-31] */
14     int tm_mon;   /* Month.	[0-11] */
15     int tm_year;  /* Year	- 1900.  */
16     int tm_wday;  /* Day of week.	[0-6] */
17     int tm_yday;  /* Days in year.[0-365]	*/
18     int tm_isdst; /* DST.		[-1/0/1]*/
19 
20     long int __tm_gmtoff;  /* Seconds east of UTC.  */
21     const char *__tm_zone; /* Timezone abbreviation.  */
22 };
23 
24 
25 struct timespec
26 {
27     long int tv_sec;    // 秒
28     long long tv_nsec;   // 纳秒
29 };
30 
31 /**
32  * @brief 休眠指定时间
33  *
34  * @param rqtp 指定休眠的时间
35  * @param rmtp 返回的剩余休眠时间
36  * @return int
37  */
38 extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
39 
40 /**
41  * @brief 睡眠指定时间
42  *
43  * @param usec 微秒
44  * @return int
45  */
46 extern int usleep(useconds_t usec);
47 
48 /**
49  * @brief 获取当前的CPU时间
50  *
51  * @return uint64_t timer_jiffies
52  */
53 extern uint64_t clock();