13022591351 commented on PR #19982:
URL: https://github.com/apache/nuttx/pull/19982#issuecomment-5462726855

   I force-pushed the branch after applying the inline review feedback and
   rebasing the series onto current Apache NuttX master
   `5d2ed54d26e293a5eea870d9458e36d0d02083fb`.
   
   The updated commit series is:
   
   ```text
   c4ccf265d0 sched/wqueue: Harden custom queue lifecycle.
   19898d78d4 libc/wqueue: Support custom user work queues.
   917659e44b libc/wqueue: Use the uninterruptible wait helper.
   9fc4184667 Documentation/wqueue: Document custom user queues.
   ```
   
   ## Review fixes
   
   The updated series addresses all 16 inline review comments:
   
   - Reordered the local declarations in the scheduler cancellation path.
   - Configured the predefined pthread worker as detached through
     `pthread_attr_setdetachstate()` and removed the separate detach call.
   - Moved pthread attribute destruction after thread creation.
   - Kept the predefined queue and worker state in their static initializers and
     removed redundant runtime reinitialization.
   - Kept the predefined `USRWORK` queue at one worker; configurable 
multi-worker
     pools remain limited to queues created by `work_queue_create()`.
   - Renamed the worker argument consistently and merged the intermediate worker
     wrapper into `work_pthread()`.
   - Restored the removed source section headers.
   - Wrapped the delay validation conditions as requested in both scheduler 
queue
     entry points and the libc entry point.
   - Replaced direct list manipulation with `work_remove()`. Both the queue and
     cancel paths call it while holding the corresponding queue lock, so pending
     replacement remains atomic.
   - Documented the `work_remove()` lock and queue-ownership requirements in 
both
     backends.
   - Expanded the zero-delay wake comment: an immediately runnable item may be
     inserted behind another ready item, so another idle worker should be woken
     without waiting for the first worker to dequeue the current head.
   
   ## Additional changes beyond the literal inline suggestions
   
   I also included the following compatibility and robustness corrections found
   while validating the review changes:
   
   - Changed libc worker identifiers from `pthread_t` handling to NuttX `pid_t`
     handling with `gettid()` and `sched_getparam()`.
   - Preserved the predefined Protected `USRWORK` queue when
     `CONFIG_DISABLE_PTHREAD=y`. In this configuration, pthread-backed custom
     queue APIs are excluded while predefined queue-ID APIs remain available.
   - Updated Kconfig, public header comments, and the work queue documentation 
to
     describe that custom user queues require pthread support.
   - Added `pthread_attr_getschedparam()` before changing a custom worker's
     priority. This initializes the complete `struct sched_param` and avoids
     passing uninitialized sporadic-scheduling fields when
     `CONFIG_SCHED_SPORADIC=y`.
   - Kept the `nxsem_wait_uninterruptible()` cleanup in a separate commit so the
     functional commits remain independently backportable to an older branch
     where that helper is unavailable to Protected user space.
   
   The last scheduling-parameter initialization change is six lines in
   `work_thread_create()`. The Protected image was rebuilt after this change.
   The test target does not enable `CONFIG_SCHED_SPORADIC`, so its runtime
   scheduling behavior is unchanged.
   
   ## Test coverage
   
   All full work queue runs cover:
   
   - HPWORK and LPWORK where available;
   - custom queues with one and two workers;
   - invalid arguments and idle cancellation;
   - callback-driven periodic requeue;
   - pending work replacement;
   - synchronous cancellation;
   - two concurrent callbacks using one `work_s`;
   - four simultaneous queues with eight work items each and worker pools of
     one, two, three, and four threads;
   - callback self-destruction rejection;
   - pending and running queue teardown;
   - rejection of requeue attempts after teardown starts.
   
   ### 1. Flat
   
   Build output:
   
   ```text
   Flash:    143,956 B
   AXI SRAM:  34,468 B
   ```
   
   Three `ostest wqueue` runs:
   
   ```text
   30.1490 / 30.1480 / 30.1480 s
   ```
   
   After the first run, Umem remained stable at:
   
   ```text
   14,000 B used / 835,512 B free
   55 used / 6 free allocation nodes
   ```
   
   The first run retained 32 bytes of one-time process state. The following two
   runs showed no cumulative memory growth.
   
   ### 2. Protected
   
   Build output:
   
   ```text
   Kernel: 89,848 B kflash; 31,696 B ksram
   User:   80,816 B uflash; 4 KiB usram
   ```
   
   Three kernel backend runs:
   
   ```text
   30.1490 / 30.1480 / 30.1490 s
   ```
   
   Three libc custom user queue runs:
   
   ```text
   15.6540 / 15.6540 / 15.6540 s
   ```
   
   Steady state after the first executions:
   
   ```text
   Kernel test:
     Kmem 9,968 B used / 248,080 B free
     Umem 9,232 B used / 416,752 B free
   
   After starting the libc user test:
     Kmem 10,032 B used / 248,016 B free
     Umem  9,232 B used / 416,752 B free
   ```
   
   The remaining runs had identical current heap usage and allocation-node
   counts.
   
   ### 3. Protected Lite (`CONFIG_DISABLE_PTHREAD=y`)
   
   Build output:
   
   ```text
   Kernel: 87,232 B kflash; 31,644 B ksram
   User:   49,056 B uflash; 4 KiB usram
   ```
   
   Three kernel backend runs:
   
   ```text
   30.1490 / 30.1490 / 30.1490 s
   ```
   
   Three predefined libc `USRWORK` runs without pthread support:
   
   ```text
   0.2290 / 0.2290 / 0.2290 s
   ```
   
   Every user run reported:
   
   ```text
   wqueue_test: backend = predefined USRWORK (pthread disabled)
   wqueue_test: PASS
   ```
   
   The test queued real immediate and delayed work, pending replacement,
   pending cancellation, synchronous cancellation, and callback-driven periodic
   requeue. After the first kernel run, memory remained stable at:
   
   ```text
   Kmem 9,784 B used / 248,264 B free
   Umem 9,216 B used / 416,768 B free
   ```
   
   The three predefined USRWORK runs retained no additional memory.
   
   ### 4. PX4 Flat integration
   
   ```text
   nsh> ver all
   HW arch: PX4_FMU_V6C
   HW type: V6C002001
   HW version: 0x002
   HW revision: 0x001
   PX4 git-hash: ce0460fc83231d8b1e6d6e0233bf1f2795ae7c36
   PX4 version: 1.18.0 80 (17956992)
   PX4 git-branch: baseline/px4-nuttx-12.12-wqueue
   OS: NuttX
   OS version: Release 13.0.1 (218104319)
   OS git-hash: 571531fa019229bd61480f9ee5d2a52017bc1a9f
   Build datetime: Aug 29 2026 16:42:38
   Build uri: localhost
   Build variant: default
   Toolchain: GNU GCC, 10.3.1 20210824 (release)
   PX4GUID: 00060000000034373938303151090027001b
   MCU: STM32H7[4|5]xxx, rev. V
   
   nsh> top once
   
    PID COMMAND                   CPU(ms) CPU(%)  USED/STACK PRIO(BASE) STATE FD
      0 Idle_Task                   32406 77.543   272/  768   0 (  0)  READY  3
      1 hpwork                          0  0.000   336/ 1216 249 (249)  w:sem  3
      2 lpwork                          0  0.000   336/ 1568  50 ( 50)  w:sem  3
      3 nsh_main                        0  0.000  2224/ 3152 100 (100)  w:sem  3
      4 wq:manager                      0  0.000   592/ 1240 255 (255)  w:sem  3
      5 wq:lp_default                   2  0.172  1040/ 3424 205 (205)  w:sem  3
   1165 mavlink_shell                   0  0.000   808/ 2008 100 (100)  w:sem  3
    407 wq:hp_default                   7  0.648   920/ 2728 237 (237)  w:sem  3
    476 wq:SPI1                        51  4.270  1736/ 2328 253 (253)  w:sem  3
    486 wq:I2C4                         5  0.493   776/ 2272 243 (243)  w:sem  3
    671 wq:nav_and_controllers         24  2.052  1200/ 2160 242 (242)  w:sem  3
    680 wq:rate_ctrl                   27  2.326  2424/ 3072 255 (255)  w:sem  3
    681 wq:INS0                        14  1.190  1144/ 5936 241 (241)  w:sem  3
    682 wq:INS1                        13  1.154  1128/ 5936 240 (240)  w:sem  3
   1145 mavlink_rcv_if0                 2  0.195  1304/ 3984 175 (175)  w:sem  5
    734 wq:ttyS4                        2  0.188  1032/ 1664 230 (230)  w:sem  3
    876 commander                       4  0.412  1528/ 3200 140 (140)  w:sig  5
    989 gps                             0  0.062  1280/ 1944 205 (205)  w:sem  4
   1042 mavlink_if0                    21  1.751  1640/ 2712 100 (100)  w:sig  5
   1083 navigator                       0  0.006  1312/ 2176 105 (105)  w:sem 10
   1136 logger                          1  0.127  2512/ 3616 230 (230)  w:sem  3
   1137 log_writer_file                 0  0.000   392/ 1152  60 ( 60)  w:sem  3
   1163 mavlink_rcv_if1                 2  0.221  1728/ 3984 175 (175)  w:sem  8
   1159 mavlink_if1                    79  6.584  1808/ 2800 100 (100)  READY  8
   1167 top                             0  0.001  2232/ 4056 237 (237)  RUN    3
   
   Processes: 25 total, 3 running, 22 sleeping
   CPU usage: 21.85% tasks, 0.61% sched, 77.54% idle
   DMA Memory: 5120 total, 0 used 0 peak
   Uptime: 41.153s total, 32.407s idle
   
   nsh> work_queue status
   
   Work Queue: 9  threads                          RATE        INTERVAL
   |__ 1) wq:rate_ctrl
   |   |__ 1) control_allocator                400.8 Hz         2495 us
   |   |__ 2) pwm_out                          395.1 Hz         2531 us
   |   \__ 3) vehicle_angular_velocity         400.9 Hz         2495 us
   |__ 2) wq:SPI1
   |   |__ 1) bmi055_accel                     407.4 Hz         2454 us
   |   |__ 2) bmi055_gyro                      400.7 Hz         2496 us
   |   \__ 3) icm42688p                        401.6 Hz         2490 us
   |__ 3) wq:I2C4
   |   |__ 1) ist8310                           46.2 Hz        21623 us
   |   \__ 2) ms5611                            92.5 Hz        10812 us
   |__ 4) wq:nav_and_controllers
   |   |__ 1) airspeed_selector                 10.0 Hz        99928 us (100000 
us)
   |   |__ 2) ekf2_selector                     10.0 Hz        99627 us
   |   |__ 3) fw_att_control                     0.0 Hz            0 us
   |   |__ 4) fw_lat_lon_control                 0.0 Hz            0 us
   |   |__ 5) fw_mode_manager                    0.0 Hz            0 us
   |   |__ 6) fw_rate_control                  400.8 Hz         2495 us
   |   |__ 7) land_detector                     20.0 Hz        49992 us
   |   |__ 8) sensors                          200.4 Hz         4991 us
   |   |__ 9) vehicle_acceleration             204.0 Hz         4902 us
   |   |__10) vehicle_air_data                  69.5 Hz        14397 us
   |   |__11) vehicle_gps_position               3.3 Hz       299095 us
   |   \__12) vehicle_magnetometer              46.3 Hz        21600 us
   |__ 5) wq:INS0
   |   |__ 1) ekf2                             200.3 Hz         4991 us
   |   \__ 2) vehicle_imu                      200.4 Hz         4990 us
   |__ 6) wq:INS1
   |   |__ 1) ekf2                             200.9 Hz         4977 us
   |   \__ 2) vehicle_imu                      200.9 Hz         4977 us
   |__ 7) wq:hp_default
   |   |__ 1) battery_status                   100.0 Hz         9999 us
   |   |__ 2) board_adc                        100.0 Hz         9999 us (10000 
us)
   |   |__ 3) fw_autotune_attitude_control     400.8 Hz         2495 us
   |   |__ 4) manual_control                     5.0 Hz       199380 us
   |   |__ 5) rc_update                          0.0 Hz            0 us
   |   \__ 6) tone_alarm                         0.4 Hz      2473010 us
   |__ 8) wq:ttyS4
   |   \__ 1) px4io                             48.3 Hz        20708 us
   \__ 9) wq:lp_default
       |__ 1) cdcacm_autostart                   2.0 Hz       495727 us
       |__ 2) gyro_calibration                  50.0 Hz        19992 us (20000 
us)
       |__ 3) load_mon                           2.0 Hz       499734 us (500000 
us)
       |__ 4) mag_bias_estimator                50.0 Hz        19990 us (20000 
us)
       |__ 5) parameters                         0.0 Hz            0 us
       \__ 6) send_event                        30.0 Hz        33315 us (33333 
us)
   ```
   
   ### 5. PX4 Protected integration
   
   ```text
   nsh> ver all
   HW arch: PX4_FMU_V6C
   HW type: V6C002001
   HW version: 0x002
   HW revision: 0x001
   PX4 git-hash: f41aec1da254de4a0c2b23bc5bda2dd242d8bd90
   PX4 version: 1.18.0 80 (17956992)
   PX4 git-branch: baseline/px4-nuttx-12.12-wqueue
   OS: NuttX
   OS version: Release 13.0.1 (218104319)
   OS git-hash: 571531fa019229bd61480f9ee5d2a52017bc1a9f
   Build datetime: Aug 29 2026 16:51:50
   Build uri: localhost
   Build variant: protected
   Toolchain: GNU GCC, 10.3.1 20210824 (release)
   PX4GUID: 00060000000034373938303151090027001b
   MCU: STM32H7[4|5]xxx, rev. V
   
   nsh> top once
   
    PID COMMAND                   CPU(ms) CPU(%)  USED/STACK PRIO(BASE) STATE FD
      0 Idle_Task                   25238 33.287   272/  768   0 (  0)  READY  3
      1 hpwork                          0  0.000   336/ 1216 249 (249)  w:sem  3
      2 lpwork                          0  0.000   336/ 1568  50 ( 50)  w:sem  3
      3 uwork                           0  0.000   376/ 2016 100 (100)  w:sem  3
      5 kwq:manager                     0  0.000   560/ 1240 255 (255)  w:sem  3
      6 kwq:lp_default                  0  0.069   864/ 3424 205 (205)  w:sem  3
      7 usr_hrt                         5  0.417   416/  968 255 (255)  w:sem  3
      8 uwq:manager                     0  0.000   568/ 1240 255 (255)  w:sem  3
    976 mavlink_shell                   0  0.000   912/ 2008 100 (100)  w:sem  3
    207 kwq:hp_default                  5  0.446   864/ 2728 237 (237)  w:sem  3
    265 kwq:SPI1                       23  1.923  1728/ 2328 253 (253)  w:sem  3
    222 uwq:lp_default                  5  0.439  1072/ 3480 205 (205)  w:sem  3
    267 kwq:I2C4                        5  0.452   768/ 2272 243 (243)  w:sem  3
    554 kwq:nav_and_controllers        29  2.476  1192/ 2160 242 (242)  w:sem  3
    556 kwq:rate_ctrl                  19  1.606  1088/ 3072 255 (255)  w:sem  3
    557 kwq:INS0                       14  1.221  1128/ 5936 241 (241)  w:sem  3
    950 mavlink_rcv_if0                10  0.868  1280/ 3984 175 (175)  w:sem  5
    567 kwq:ttyS4                       2  0.199  1032/ 1664 230 (230)  w:sem  3
    570 uwq:hp_default                  0  0.000   352/ 2784 237 (237)  w:sem  3
    595 commander                      31  2.644  1624/ 3200 140 (140)  w:sig  5
    604 uwq:rate_ctrl                  63  5.327  2424/ 3128 255 (255)  w:sem  3
    622 uwq:nav_and_controllers         2  0.186   856/ 2224 242 (242)  w:sem  3
    725 gps                             9  0.751  1344/ 1944 205 (205)  w:sem  4
    761 mavlink_if0                   101  8.423  1696/ 2712 100 (100)  w:sig  5
    827 navigator                       0  0.049  1344/ 2176 105 (105)  w:sem 10
    914 logger                         12  1.070  2576/ 3616 230 (230)  w:sem  3
    916 log_writer_file                 0  0.000   424/ 1152  60 ( 60)  w:sem  3
    959 mavlink_rcv_if1                12  1.029  1728/ 3984 175 (175)  w:sem  8
    957 mavlink_if1                   264 22.044  1840/ 2800 100 (100)  READY  8
    984 top                             0  0.001  2304/ 4056 237 (237)  RUN    3
   
   Processes: 30 total, 3 running, 27 sleeping
   CPU usage: 51.64% tasks, 15.07% sched, 33.29% idle
   DMA Memory: 5120 total, 0 used 0 peak
   Uptime: 43.260s total, 25.239s idle
   
   nsh> work_queue status
   
   User Work Queue: 4  threads                          RATE        INTERVAL
   |__ 1) uwq:rate_ctrl
   |   \__ 1) control_allocator                401.8 Hz         2489 us
   |__ 2) uwq:nav_and_controllers
   |   \__ 1) land_detector                     20.0 Hz        49990 us
   |__ 3) uwq:hp_default
   |   \__ 1) rc_update                          0.0 Hz            0 us
   \__ 4) uwq:lp_default
       |__ 1) cdcacm_autostart                   2.0 Hz       492085 us
       |__ 2) gyro_calibration                  50.0 Hz        19999 us (20000 
us)
       \__ 3) send_event                        30.0 Hz        33321 us (33333 
us)
   
   Kernel Work Queue: 8  threads                          RATE        INTERVAL
   |__ 1) kwq:rate_ctrl
   |   |__ 1) pwm_out                          396.6 Hz         2521 us
   |   \__ 2) vehicle_angular_velocity         401.8 Hz         2489 us
   |__ 2) kwq:SPI1
   |   \__ 1) icm42688p                        401.6 Hz         2490 us
   |__ 3) kwq:I2C4
   |   |__ 1) ist8310                           46.3 Hz        21621 us
   |   \__ 2) ms5611                            92.5 Hz        10812 us
   |__ 4) kwq:nav_and_controllers
   |   |__ 1) ekf2_selector                     10.0 Hz        99878 us
   |   |__ 2) fw_rate_control                  401.8 Hz         2489 us
   |   |__ 3) sensors                          200.9 Hz         4978 us
   |   |__ 4) vehicle_acceleration             201.0 Hz         4976 us
   |   |__ 5) vehicle_air_data                  69.5 Hz        14398 us
   |   |__ 6) vehicle_gps_position               3.3 Hz       299757 us
   |   \__ 7) vehicle_magnetometer              46.3 Hz        21615 us
   |__ 5) kwq:INS0
   |   |__ 1) ekf2                             200.9 Hz         4978 us
   |   \__ 2) vehicle_imu                      200.9 Hz         4978 us
   |__ 6) kwq:hp_default
   |   |__ 1) battery_status                   100.0 Hz        10000 us
   |   |__ 2) board_adc                        100.0 Hz         9998 us (10000 
us)
   |   |__ 3) manual_control                     5.0 Hz       199789 us
   |   \__ 4) tone_alarm                         0.4 Hz      2654780 us
   |__ 7) kwq:ttyS4
   |   \__ 1) px4io                             48.2 Hz        20739 us
   \__ 8) kwq:lp_default
       |__ 1) load_mon                           2.0 Hz       496279 us (500000 
us)
       |__ 2) mag_bias_estimator                50.0 Hz        19990 us (20000 
us)
       \__ 3) parameters                         0.0 Hz            0 us
   ```
   
   ## Validation
   
   ```text
   NuttX commit-message checkpatch: pass
   NuttX complete patch checkpatch: pass
   git diff --check: pass
   Protected rebuild after the final attr initialization fix: pass
   Repeated runtime tests: no assertion, crash, reboot, or cumulative heap 
growth
   ```
   


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