Re: Building newlib with clock_gettime()

Brian Inglis <[email protected]>
Newsgroups gmane.comp.lib.newlib
Organization Systematic Software
Message-ID <[email protected]>
Depending how your specific RISC-V CPU and support chips implement which 
architectural timing features with the specific timing facilities your RISC-V 
board supports determine what definitions you have to change or provide for your 
drivers and syscalls.

See the Platform and Supervisor Binary interface specifications information on 
timing and timers under:

	https://wiki.freebsd.org/riscv

and you could consider initially targeting the Spike simulator or QEMU emulator 
platforms.

For some timer implemenatation considerations see:

https://www.freertos.org/FreeRTOS_Support_Forum_Archive/August_2019/freertos_CLINT_vs_mtime_in_FreeRTOS_RISC-V_port_2e8d6a0c4fj.html

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to cut
                                 -- Antoine de Saint-Exupéry


On 2025-01-08 17:01, Joel Sherrill wrote:
> RTEMS has a robust set of clock services and its own clock_gettime 
> implementation. We do use some FreeBSD kernel level time code which reduces 
> contention for time in SMP systems and integrates well with NTP and PTP. Both of 
> which we have solid support for.
> 
> https://gitlab.rtems.org/rtems/rtos/rtems/-/blob/main/cpukit/posix/src/ 
> clockgettime.c?ref_type=heads <https://gitlab.rtems.org/rtems/rtos/rtems/-/blob/ 
> main/cpukit/posix/src/clockgettime.c?ref_type=heads>
> 
> I checked and the symbol clock_gettime isn't in the built libc.a .
> 
> Not that any of this impacts your explanation. clock_gettime is just one of the 
> methods that may need to be implemented in a target specific way. RTEMS adds a 
> lot ofPOSIX not in newlib and has its own Malloc family implementation, for example.
> 
> --joel
> 
> On Wed, Jan 8, 2025 at 3:43 PM Jeff Johnston <[email protected] 
> <mailto:[email protected]>> wrote:
> 
>     Hello,
> 
>     Newlib does not provide an implementation for clock_gettime().  In glibc,
>     for example, the source code uses syscalls to implement this which are not
>     part of the standard newlib syscall set.  Some platforms may define
>     clock_gettime() stubs that simply fail (RTEMS for example).  If you just
>     need to satisfy a link requirement, you can easily create such a stub that
>     fails, otherwise, you will have to implement the function yourself or try to
>     port an implementation from another library (e.g. FreeBSD).
> 
>     -- Jeff J.
> 
>     On Mon, Jan 6, 2025 at 5:32 PM Caden <[email protected]
>     <mailto:[email protected]>> wrote:
> 
>         Hi!
> 
>         I'm trying to build a RISC-V GNU compiler with /clock_gettime()/
>         provided by newlib. It seems that building the toolchain by default
>         does /not/ enable this function -- looking at the libstdc++ library
>         config settings shows that any symbols regarding /clock_gettime()/ are
>         disabled/./
>         /
>         /
>         I'm wondering if there's anything specific that can be done to have this
>         function provided by newlib.
>         Here's the command that newlib was built with:
> 
>         $ /nobackup/build/riscv-gnu-toolchain/newlib/configure --target=riscv64-
>         unknown-elf --prefix=/nobackup/build/riscv64-unknown-elf --enable-
>         newlib-io-long-double --enable-newlib-io-long-long --enable-newlib-io-
>         c99-formats --enable-newlib-reigster-fini CFLAGS_FOR_TARGET=-O2 -
>         D_POSIX_MODE -ffunction-sections -fdata-sections    -mcmodel=medlow
>         CXXFLAGS_FOR_TARGET=-O2 -D_POSIX_MODE -ffunction-sections -fdata-
>         sections    -mcmodel=medlow
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.