arch/sim: Handle Darwin clock IDs in clock_gettime()#18962
Conversation
Add a sim/macOS-specific clock_gettime() override that translates Darwin monotonic clock IDs to NuttX CLOCK_MONOTONIC before delegating to nxclock_gettime(). Make the common clock_gettime() weak so the simulator override can replace it. This fixes a Rust tokio panic on macOS when running hello_rust_cargo. Signed-off-by: Shoji Tokunaga <toku@mac.com>
195a3bc to
c49d064
Compare
is it expected to work at all? |
| ****************************************************************************/ | ||
|
|
||
| int clock_gettime(clockid_t clock_id, FAR struct timespec *tp) | ||
| int weak_function clock_gettime(clockid_t clock_id, FAR struct timespec *tp) |
There was a problem hiding this comment.
it's wrong to expose the host clock_gettime to nuttx. We should use the same approach as Linux, which do the conversion in arch/sim/posix. what's problem do you hit on macOS?
There was a problem hiding this comment.
is it expected to work at all?
it's wrong to expose the host clock_gettime to nuttx. We should use the same approach as Linux, which do the conversion in arch/sim/posix. what's problem do you hit on macOS?
I'll reconsider the implementation method.
There was a problem hiding this comment.
- Add
ARCH_HAVE_CLOCKID_TRANSLATEto Kconfig. - Reference this in
sched/clock/clock_gettime.candinclude/nuttx/arch.h. - Add
arch/sim/src/sim/posix/sim_clockid.c.
What do you think about this approach?
|
Since the summary has changed, I'll move this to #18978. |
Summary
This PR fixes
clock_gettime()compatibility for the macOS simulator whenDarwin-targeted code is linked into NuttX.
The fix adds a sim/macOS-specific
clock_gettime()override that translatesDarwin monotonic clock IDs to NuttX
CLOCK_MONOTONICbefore callingnxclock_gettime().clock_gettime()weak.arch/sim/src/sim/macos/sim_clock_gettime.c.REQUIREDOBJSso the override is included in the final simulator link.Impact
Running
hello_rust_cargowith nsh on macOS should no longer cause a panic.Testing
I confirm that changes are verified on local setup and works as intended:
make, you need apps PR #3501 .Configuration and Build:
Testing logs before change:
Testing logs after change:
PR verification Self-Check