public inbox for newlib-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] RISC-V: Using SYS_clock_gettime64 for rv32 libgloss. Date: Tue, 13 Apr 2021 10:55:00 +0000 (GMT) [thread overview] Message-ID: <20210413105500.2576B3943541@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=20d00819984058e439cfe40818f81d7315c89201 commit 20d00819984058e439cfe40818f81d7315c89201 Author: Kito Cheng <kito.cheng@sifive.com> Date: Tue Apr 13 17:33:03 2021 +0800 RISC-V: Using SYS_clock_gettime64 for rv32 libgloss. - RISC-V 32 bits linux/glibc didn't provide gettimeofday anymore after upstream, because RV32 didn't have backward compatible issue, so RV32 only support 64 bits time related system call. - So using clock_gettime64 call instead for rv32 libgloss. Diff: --- libgloss/riscv/machine/syscall.h | 1 + libgloss/riscv/sys_gettimeofday.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/libgloss/riscv/machine/syscall.h b/libgloss/riscv/machine/syscall.h index 88b9fdfda..1ac8b1a4b 100644 --- a/libgloss/riscv/machine/syscall.h +++ b/libgloss/riscv/machine/syscall.h @@ -44,6 +44,7 @@ #define SYS_munmap 215 #define SYS_mremap 216 #define SYS_mmap 222 +#define SYS_clock_gettime64 403 #define SYS_open 1024 #define SYS_link 1025 #define SYS_unlink 1026 diff --git a/libgloss/riscv/sys_gettimeofday.c b/libgloss/riscv/sys_gettimeofday.c index daa14e475..81bea8e55 100644 --- a/libgloss/riscv/sys_gettimeofday.c +++ b/libgloss/riscv/sys_gettimeofday.c @@ -1,10 +1,31 @@ #include <machine/syscall.h> #include <sys/time.h> +#include <stdint.h> #include "internal_syscall.h" /* Get the current time. Only relatively correct. */ int _gettimeofday(struct timeval *tp, void *tzp) { +#if __riscv_xlen == 32 + struct __timespec64 + { + int64_t tv_sec; /* Seconds */ +# if BYTE_ORDER == BIG_ENDIAN + int32_t __padding; /* Padding */ + int32_t tv_nsec; /* Nanoseconds */ +# else + int32_t tv_nsec; /* Nanoseconds */ + int32_t __padding; /* Padding */ +# endif + }; + struct __timespec64 ts64; + int rv; + rv = syscall_errno (SYS_clock_gettime64, 2, 0, (long)&ts64, 0, 0, 0, 0); + tp->tv_sec = ts64.tv_sec; + tp->tv_usec = ts64.tv_nsec * 1000; + return rv; +#else return syscall_errno (SYS_gettimeofday, 1, tp, 0, 0, 0, 0, 0); +#endif }
reply other threads:[~2021-04-13 10:55 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210413105500.2576B3943541@sourceware.org \ --to=corinna@sourceware.org \ --cc=newlib-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).