cederom commented on PR #4111:
URL: https://github.com/apache/nuttx-apps/pull/4111#issuecomment-7089171566
Thanks, this test does reproduce the inversion fixed by apache/nuttx#22164:
- Threads with `incsection` set hold the critical section and then take the
queue lock in `work_queue_wq()`/`work_cancel_wq()`.
- The other threads and the queue's workers take the queue lock and then
enter the critical section in `wd_start()`, `wd_cancel()` and `nxsem_post()`.
The guards look right. The code is under `!CONFIG_DISABLE_PTHREAD` from the
enclosing block, and `CONFIG_BUILD_FLAT` covers `enter_critical_section()` and
the kernel `work_queue_wq()`. In protected and kernel builds, the custom queues
are the libc user implementation, which has no such inversion.
**Comments:**
1. **Merge order.** On current master, this test makes SMP ostest hang
rather than fail. It needs to land together with or after apache/nuttx#22164,
otherwise the nuttx-apps CI for SMP sim/qemu configs will time out. Please
cross-link the two PRs and say so in the description.
2. **CPU placement isn't enforced.** The commit message says "two threads
per CPU" and the comment says "the threads on some CPUs ... the threads on the
other CPUs". But the threads are created without affinity, so nothing
guarantees that a thread inside the critical section and one outside it run on
different CPUs at the same time. On SMP, pinning would make the test
deterministic about what it claims:
#ifdef CONFIG_SMP
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET((i / 2) % CONFIG_SMP_NCPUS, &cpuset);
pthread_attr_setaffinity_np(&attr, sizeof(cpuset), &cpuset);
#endif
Alternatively, change the wording to "half of the threads".
3. **Failure mode.** If it regresses, the result is a silent hang, not an
`ASSERT`. That's acceptable for ostest, but a one-line comment above
`csection_test()` saying "a deadlock here hangs ostest" would save the next
person some time.
4. Nit: `struct csection_s` and `CSECTION_LOOPS`/`CSECTION_THREADS` are only
used under `CONFIG_BUILD_FLAT`. They could move inside that guard, next to
`csection_thread()`.
The rest looks good: the final `work_cancel_sync_wq()` plus the
`work_available()` checks, the cleanup with `work_queue_free()`, and the loop
count. nxstyle is clean.
--
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]