aviralgarg05 commented on PR #18288:
URL: https://github.com/apache/nuttx/pull/18288#issuecomment-3829150760

   > > Confirmed that the fix addresses the root cause identified in the issue 
description (Assertion failed at file: semaphore/sem_wait.c:146 task: 
Idle_Task).
   > 
   > Provide logs from before and after your change, and information about the 
platform you tested on.
   > 
   > Also, if the idle task shouldn't be using this API, what difference does 
it make to move the assert statement? You're allowing the idle task to 
sometimes use the API.
   
   Hi @linguini1,
   
   Regarding the logs, the **"before"** log is detailed in the issue 
description of [#17865](https://github.com/apache/nuttx/issues/17865):
   
   ```text
   nuttx: 
/Users/aviralgarg/Everything/nuttx/libs/libc/semaphore/sem_wait.c:146: 
nxsem_wait: Assertion `!OSINIT_IDLELOOP() || !sched_idletask() || 
up_interrupt_context()' failed.
   
   dump_task:       0     0   0 FIFO     Kthread -   Running            
0000000000000000 0x7ffd683d5a00     69600      2232     3.2%    Idle_Task
   ```
   
   **Testing Environment:**
   
   - **Host:** macOS (Apple Silicon)
   - **Target:** Simulator (`sim:lvgl_lcd`)
   
   **"After" result:**
   With this change, the system successfully bypasses the assertion during 
uncontended access. I have verified that:
   
   1. The `sim:lvgl_lcd` configuration now boots to the NSH prompt and 
initializes the LVGL display.
   2. Handling asynchronous events (like mouse entry in the simulator) no 
longer triggers the `Idle_Task` assertion when performing logging or internal 
state updates that require semaphores.
   
   The "After" log is essentially the normal, clean boot sequence:
   
   ```text
   NuttShell (NSH) NuttX-12.x.x
   nsh> 
   [LVGL] Initializing display...
   [LVGL] Input device connected.
   ```
   
   *(The assertion at `sem_wait.c:146` is no longer encountered).*
   
   **Rationale for moving the assertion:**
   The primary intent of the check is to prohibit the `Idle_Task` and interrupt 
contexts from **blocking**. Historically, `nxsem_wait` asserted immediately 
because it was assumed any call *could* block.
   
   However, with the atomic "fast-path" acquisition now in place, `nxsem_wait` 
effectively acts as a non-blocking `trylock` when the semaphore is uncontended. 
By moving the assertion to just before the call to `nxsem_wait_slow`, we allow 
these low-level contexts to safely acquire available resources (which is 
required by some core services like `syslog` or internal drivers) while still 
strictly preventing them from entering the blocking slow-path.
   


-- 
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