Skip to content

Commit b8daa45

Browse files
authored
[libc] Implement timespec_get (#116102)
`timespec_get` is C standard counterpart to POSIX `clock_gettime`. On Linux we simply use `clock_gettime`. On baremetal we introduce a new external API `__llvm_libc_timespec_get_utc` that should be implemented by the vendor.
1 parent 0c98776 commit b8daa45

File tree

18 files changed

+245
-0
lines changed

18 files changed

+245
-0
lines changed

libc/config/baremetal/arm/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ set(TARGET_LIBC_ENTRYPOINTS
209209
libc.src.time.gmtime
210210
libc.src.time.gmtime_r
211211
libc.src.time.mktime
212+
libc.src.time.timespec_get
212213

213214
# internal entrypoints
214215
libc.startup.baremetal.init

libc/config/baremetal/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ set(TARGET_LIBC_ENTRYPOINTS
205205
libc.src.time.gmtime
206206
libc.src.time.gmtime_r
207207
libc.src.time.mktime
208+
libc.src.time.timespec_get
208209

209210
# internal entrypoints
210211
libc.startup.baremetal.init

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ if(LLVM_LIBC_FULL_BUILD)
10001000
libc.src.time.mktime
10011001
libc.src.time.nanosleep
10021002
libc.src.time.time
1003+
libc.src.time.timespec_get
10031004

10041005
# unistd.h entrypoints
10051006
libc.src.unistd.__llvm_libc_syscall

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ if(LLVM_LIBC_FULL_BUILD)
939939
libc.src.time.mktime
940940
libc.src.time.nanosleep
941941
libc.src.time.time
942+
libc.src.time.timespec_get
942943

943944
# unistd.h entrypoints
944945
libc.src.unistd.__llvm_libc_syscall

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,7 @@ if(LLVM_LIBC_FULL_BUILD)
10831083
libc.src.time.mktime
10841084
libc.src.time.nanosleep
10851085
libc.src.time.time
1086+
libc.src.time.timespec_get
10861087

10871088
# locale.h entrypoints
10881089
libc.src.locale.localeconv

libc/include/llvm-libc-macros/time-macros.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@
77
#include "linux/time-macros.h"
88
#endif
99

10+
#define TIME_UTC 1
11+
#define TIME_MONOTONIC 2
12+
#define TIME_ACTIVE 3
13+
#define TIME_THREAD_ACTIVE 4
14+
1015
#endif // LLVM_LIBC_MACROS_TIME_MACROS_H

libc/newhdrgen/yaml/time.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,10 @@ functions:
9696
return_type: time_t
9797
arguments:
9898
- type: time_t *
99+
- name: timespec_get
100+
standard:
101+
- stdc
102+
return_type: int
103+
arguments:
104+
- type: struct timespec *
105+
- type: int

libc/spec/stdc.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,14 @@ def StdC : StandardSpec<"stdc"> {
16761676
RetValSpec<TimeTType>,
16771677
[ArgSpec<TimeTTypePtr>]
16781678
>,
1679+
FunctionSpec<
1680+
"timespec_get",
1681+
RetValSpec<IntType>,
1682+
[
1683+
ArgSpec<StructTimeSpecPtr>,
1684+
ArgSpec<IntType>,
1685+
]
1686+
>,
16791687
]
16801688
>;
16811689

libc/src/time/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ add_entrypoint_object(
111111
.${LIBC_TARGET_OS}.time
112112
)
113113

114+
add_entrypoint_object(
115+
timespec_get
116+
ALIAS
117+
DEPENDS
118+
.${LIBC_TARGET_OS}.timespec_get
119+
)
120+
114121
add_entrypoint_object(
115122
clock
116123
ALIAS
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
add_entrypoint_object(
2+
timespec_get
3+
SRCS
4+
timespec_get.cpp
5+
HDRS
6+
../timespec_get.h
7+
DEPENDS
8+
libc.hdr.time_macros
9+
libc.hdr.types.struct_timespec
10+
)

0 commit comments

Comments
 (0)