This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 7d1ef2107fcb3e1fa3cc826d45443676e85e57e2 Author: Lingao Meng <[email protected]> AuthorDate: Thu Oct 22 11:48:52 2026 +0800 arch/sim: Deliver sleep-driven oneshot ticks in interrupt context The sleep-driven timer path calls sim_timer_handler() directly from IDLE, so POSIX timer expiry runs in task context. Since e65ca9912808 ("sched/timer: a timer handle works only in its own process"), the owner check in timer_gethandle() rejects application timers in this path and timer_timeout() silently skips their expiry notifications. Dispatch idle-driven ticks through sim_doirq() and register the timer IRQ handler in both sleep and signal modes. This establishes interrupt context for the callbacks while keeping host signal delivery limited to signal mode. Found while running the stock NimBLE central/peripheral examples against a Python Controller with BSWorld. Both images compiled successfully, but the HCI receive callout stopped firing and initialization repeatedly reset. The same context error also affects ordinary sim without BabbleSim. Testing: Host: Ubuntu 22.04 x86_64 Board/config: sim:nimble, ONESHOT=y, SIM_WALLTIME_SLEEP=y With SIM_BSIM_TIME disabled, a standalone POSIX SIGEV_THREAD timer with a 10 ms period delivered 0 callbacks before the fix and 14 callbacks during a 150 ms wait after the fix. With SIM_BSIM_TIME enabled, ran the existing BSWorld test: python -m pytest tests/integration/nuttx/nimble/test_central_peripheral.py \ -k bscontroller -v The original oneshot implementation failed. Reversing only e65ca9912808 restored the test, as did this fix with the owner check retained. Discovery, connection, GATT discovery and subscription all passed. git diff --check and tools/checkpatch.sh -f passed. Assisted-by: OpenAI Codex Signed-off-by: Lingao Meng <[email protected]> --- arch/sim/src/sim/sim_oneshot.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/sim/src/sim/sim_oneshot.c b/arch/sim/src/sim/sim_oneshot.c index 34478b783ab..d3ca4fe3c70 100644 --- a/arch/sim/src/sim/sim_oneshot.c +++ b/arch/sim/src/sim/sim_oneshot.c @@ -276,16 +276,15 @@ void up_timer_initialize(void) */ struct oneshot_lowerhalf_s *priv = oneshot_initialize(1, 0); + int timer_irq = host_timerirq(); VERIFY(host_inittimer()); up_alarm_set_lowerhalf(priv); -#ifdef CONFIG_SIM_WALLTIME_SIGNAL - int timer_irq = host_timerirq(); - - /* Attach the interrupt to the NuttX logic and enable the alarm handler. */ + /* Register the handler for both signal and idle-driven timer interrupts. */ irq_attach(timer_irq, sim_timer_handler, NULL); +#ifdef CONFIG_SIM_WALLTIME_SIGNAL up_enable_irq(timer_irq); #endif } @@ -314,6 +313,8 @@ void sim_timer_update(void) host_sleepuntil(until); #ifdef CONFIG_SIM_WALLTIME_SLEEP - sim_timer_handler(0, NULL, NULL); + /* Timer callbacks must run in interrupt context, including idle ticks. */ + + sim_doirq(host_timerirq(), NULL); #endif }
