Skip to content

Commit f0f442d

Browse files
committed
[libc] Implement timespec_get
`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_time_utc_get` that should be implemented by the vendor.
1 parent 39b2979 commit f0f442d

File tree

18 files changed

+208
-0
lines changed

18 files changed

+208
-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
@@ -999,6 +999,7 @@ if(LLVM_LIBC_FULL_BUILD)
999999
libc.src.time.mktime
10001000
libc.src.time.nanosleep
10011001
libc.src.time.time
1002+
libc.src.time.timespec_get
10021003

10031004
# unistd.h entrypoints
10041005
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
@@ -937,6 +937,7 @@ if(LLVM_LIBC_FULL_BUILD)
937937
libc.src.time.mktime
938938
libc.src.time.nanosleep
939939
libc.src.time.time
940+
libc.src.time.timespec_get
940941

941942
# unistd.h entrypoints
942943
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
@@ -1082,6 +1082,7 @@ if(LLVM_LIBC_FULL_BUILD)
10821082
libc.src.time.mktime
10831083
libc.src.time.nanosleep
10841084
libc.src.time.time
1085+
libc.src.time.timespec_get
10851086

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

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

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

10+
#define TIME_UTC 1
11+
1012
#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/src/__support/OSUtil/baremetal/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ add_object_library(
33
SRCS
44
io.cpp
55
exit.cpp
6+
time.cpp
67
HDRS
78
io.h
9+
time.h
810
DEPENDS
911
libc.src.__support.common
1012
libc.src.__support.CPP.string_view
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===---------- Baremetal implementation of time utils ----------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "time.h"
10+
11+
#include "src/__support/macros/config.h"
12+
13+
namespace LIBC_NAMESPACE_DECL {
14+
15+
extern "C" int __llvm_libc_time_utc_get(struct timespec *ts);
16+
17+
int time_utc_get(struct timespec *ts) {
18+
return __llvm_libc_time_utc_get(ts);
19+
}
20+
21+
} // namespace LIBC_NAMESPACE_DECL
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===---------- Baremetal implementation of time utils ----------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_BAREMETAL_TIME_H
10+
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_BAREMETAL_TIME_H
11+
12+
#include "include/llvm-libc-types/struct_timespec.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
int time_utc_get(struct timespec *ts);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_BAREMETAL_IO_H

0 commit comments

Comments
 (0)