yangsong8-a1 opened a new pull request, #21836:
URL: https://github.com/apache/nuttx/pull/21836

   ## Summary
   
   With CONFIG_ALARM_ARCH and no arch perf counter, up_perf_gettime() in
   arch_alarm.c reads the oneshot time as a timespec and converts it to
   nanoseconds on every call. With CONFIG_ONESHOT_COUNT the lower half
   already has a free-running counter, so return the raw count instead.
   up_perf_getfreq() returns the counter frequency, and up_perf_convert()
   converts counts with oneshot_cnt2sec()/oneshot_delta_cnt2nsec().
   
   ## Impact
   
   Only CONFIG_ALARM_ARCH + CONFIG_ONESHOT_COUNT builds without
   CONFIG_ARCH_HAVE_PERF_EVENTS (for example sim). perf_gettime() values are
   now in counter units and perf_getfreq() reports the counter frequency;
   callers that use perf_convert()/perf_getfreq() get the same times. Callers
   that assumed nanoseconds see a different scale unless the counter runs at
   1 GHz. With a 32-bit clock_t the count wraps sooner.
   
   ## Testing
   
   Ubuntu 22.04, gcc 13.1.
   
   sim:nsh (oneshot counter at 1 GHz), test program comparing perf_*() with
   CLOCK_MONOTONIC:
   
   | | apache/master | This PR |
   |---|---|---|
   | perf_getfreq() | 1000000000 | 1000000000 |
   | usleep(10000): perf_convert() / CLOCK_MONOTONIC | 19845572 / 19846425 ns | 
19811908 / 19812377 ns |
   | usleep(1000000): perf_convert() / CLOCK_MONOTONIC | 1010018644 / 
1010019100 ns | 1009988194 / 1009988907 ns |
   | perf_convert(5.5 s of counts) | 5.500000000 | 5.500000000 |
   | 1000000 perf_gettime() calls | 48.2 ms | 34.8 ms |
   
   Also built without new warnings: sim:ostest, qemu-armv7a:nsh,
   qemu-armv7r:nsh, qemu-armv8a:nsh, rv-virt:nsh, qemu-intel64:nsh,
   mps3-an547:nsh.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to