[libc] Add definitions to embedded AArch32/AArch64 (#142597)

Add `CLOCKS_PER_SEC` and the older `CLK_TCK`. Allows the user to define
a `__CLK_TCK` to override if necessary.

Also add an extra column for embedded AArch64 in `time.rst`
This commit is contained in:
William
2025-06-06 21:05:14 +01:00
committed by GitHub
parent 34e5d8ef16
commit a75fc765d3
4 changed files with 104 additions and 65 deletions

View File

@@ -42,72 +42,74 @@ Implementation Status
* To check date and time functions enabled for embedded system: * To check date and time functions enabled for embedded system:
- `barebone-aarch64 <https://github.com/llvm/llvm-project/tree/main/libc/config/baremetal/aarch64/entrypoints.txt>`_
- `barebone-aarch32 <https://github.com/llvm/llvm-project/tree/main/libc/config/baremetal/arm/entrypoints.txt>`_ - `barebone-aarch32 <https://github.com/llvm/llvm-project/tree/main/libc/config/baremetal/arm/entrypoints.txt>`_
- barebone-riscv32 - to be added - barebone-riscv32 - to be added
+---------------------+-----------------------------------------------+-------------------+-------------------+-------------------+-------------------+ +---------------------+-----------------------------------------------+-------------------+-------------------+-----------------------------+---------+---------+
| <Func> | Linux | Windows | MacOS | Embedded | GPU | | <Func> | Linux | Windows | MacOS | Embedded | GPU |
| +---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ | +---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| | x86_64 | aarch64 | aarch32 | riscv64/riscv32 | x86_64 | aarch64 | x86_64 | aarch64 | aarch32 | riscv32 | AMD | nVidia | | | x86_64 | aarch64 | aarch32 | riscv64/riscv32 | x86_64 | aarch64 | x86_64 | aarch64 | aarch64 | aarch32 | riscv32 | AMD | nVidia |
+=====================+=========+=========+=========+=================+=========+=========+=========+=========+=========+=========+=========+=========+ +=====================+=========+=========+=========+=================+=========+=========+=========+=========+=========+=========+=========+=========+=========+
| asctime | |check| | |check| | | |check| | | | | | | | | | | asctime | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| asctime_r | |check| | |check| | | |check| | | | | | | | | | | asctime_r | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| ctime | |check| | |check| | | |check| | | | | | | | | | | ctime | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| ctime_r | |check| | |check| | | |check| | | | | | | | | | | ctime_r | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| clock | |check| | |check| | | |check| | | | | | | | | | | clock | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| clock_getcpuclockid | | | | | | | | | | | | | | clock_getcpuclockid | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| clock_getres | | | | | | | | | | | | | | clock_getres | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| clock_gettime | |check| | |check| | | |check| | | | | | | | | | | clock_gettime | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| clock_nanosleep | | | | | | | | | | | | | | clock_nanosleep | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| clock_settime | | | | | | | | | | | | | | clock_settime | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| ctime | | | | | | | | | | | | | | ctime | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| ctime_r | | | | | | | | | | | | | | ctime_r | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| difftime | |check| | |check| | | |check| | | | | | | | | | | difftime | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| getdate | | | | | | | | | | | | | | getdate | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| gettimeofday | |check| | |check| | | |check| | | | | | | | | | | gettimeofday | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| gmtime | |check| | |check| | | |check| | | | | | | | | | | gmtime | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| gmtime_r | |check| | |check| | | |check| | | | | | | | | | | gmtime_r | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| localtime | | | | | | | | | | | | | | localtime | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| localtime_r | | | | | | | | | | | | | | localtime_r | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| mktime | |check| | |check| | | |check| | | | | | | | | | | mktime | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| nanosleep | |check| | |check| | | |check| | | | | | | | | | | nanosleep | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| strftime | | | | | | | | | | | | | | strftime | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| strptime | | | | | | | | | | | | | | strptime | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| time | |check| | |check| | | |check| | | | | | | | | | | time | |check| | |check| | | |check| | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| timer_create | | | | | | | | | | | | | | timer_create | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| timer_delete | | | | | | | | | | | | | | timer_delete | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| timer_gettime | | | | | | | | | | | | | | timer_gettime | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| timer_getoverrun | | | | | | | | | | | | | | timer_getoverrun | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| timer_settime | | | | | | | | | | | | | | timer_settime | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
| tzset | | | | | | | | | | | | | | tzset | | | | | | | | | | | | | |
+---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+ +---------------------+---------+---------+---------+-----------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+

View File

@@ -0,0 +1,5 @@
add_header(
time_macros
HDR
time-macros.h
)

View File

@@ -0,0 +1,26 @@
//===-- Definition of macros from time.h ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_MACROS_BAREMETAL_TIME_MACROS_H
#define LLVM_LIBC_MACROS_BAREMETAL_TIME_MACROS_H
#ifdef __CLK_TCK
#define CLOCKS_PER_SEC __CLK_TCK
#else
#if defined(__arm__) || defined(_M_ARM) || defined(__aarch64__) || \
defined(__arm64__) || defined(_M_ARM64)
// This default implementation of this function shall use semihosting
// Semihosting measures time in centiseconds
// https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst#sys-clock-0x10
#define CLOCKS_PER_SEC 100
#else
#define CLOCKS_PER_SEC 1000000
#endif
#endif
#endif // LLVM_LIBC_MACROS_BAREMETAL_TIME_MACROS_H

View File

@@ -5,8 +5,14 @@
#include "gpu/time-macros.h" #include "gpu/time-macros.h"
#elif defined(__linux__) #elif defined(__linux__)
#include "linux/time-macros.h" #include "linux/time-macros.h"
#elif defined(__ELF__)
#include "baremetal/time-macros.h"
#else
#define CLOCKS_PER_SEC 1000000
#endif #endif
#define CLK_TCK CLOCKS_PER_SEC
#define TIME_UTC 1 #define TIME_UTC 1
#define TIME_MONOTONIC 2 #define TIME_MONOTONIC 2
#define TIME_ACTIVE 3 #define TIME_ACTIVE 3