Handling of clock() for RISC-V
"Christian Herber (OSS)" <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <GV1PR04MB951346F26519298362C0C1A886542@GV1PR04MB9513.eurprd04.prod.outlook.com> |
Hi all, I have a question regarding the current implementation libc for RISC-V. There is no machine specific implementation of clock(). A call to the clock() function will call times() eventually lead to a syscall requesting the time, and converting that back to clock cycles. I see such a machine specific port has been done for few architectures only (in fact, I only see nvptx). I am sure more architectures have instructions to obtain cycles, why is this not used more? RISC-V defines a register called cycle (and cycleh for RV32), which provides and easy access to clock cycles. It is part of the Zicntr extension, which nearly all implementations support, and that should be possible to check through a marco __riscv_zicsr (did not test if the compilers actually do that, but they should). I cannot imagine many benefits for preferring the syscall (which will likely involve converting cycles to seconds / ns and back) rather than using the register, so I wanted to check if there is something I am missing. Christian