Confused about built-in worker thread priorities

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
JeGu_2199941
Level 5
Level 5
25 likes received 10 likes received 10 likes given

In WICED/RTOS/<ThreadX or FreeRTOS>/WICED/rtos.h there are such comments :

/* Configuration of Built-in Worker Threads

*

* 1. wiced_hardware_io_worker_thread is designed to handle deferred execution of quick, non-blocking hardware I/O operations.

*    - priority         : higher than that of wiced_networking_worker_thread

*    - stack size       : small. Consequently, no printf is allowed here.

*    - event queue size : the events are quick; therefore, large queue isn't required.

*

* 2. wiced_networking_worker_thread is designed to handle deferred execution of networking operations

*    - priority         : lower to allow wiced_hardware_io_worker_thread to preempt and run

*    - stack size       : considerably larger than that of wiced_hardware_io_worker_thread because of the networking functions.

*    - event queue size : larger than that of wiced_hardware_io_worker_thread because networking operation may block

*/

But in WICED/RTOS/wiced_rtos_common.c, wiced_result_t wiced_rtos_init( void ) creates those worker threads as this :

    result = wiced_rtos_create_worker_thread( WICED_HARDWARE_IO_WORKER_THREAD, WICED_DEFAULT_WORKER_PRIORITY, HARDWARE_IO_WORKER_THREAD_STACK_SIZE, HARDWARE_IO_WORKER_THREAD_QUEUE_SIZE );

    result = wiced_rtos_create_worker_thread( WICED_NETWORKING_WORKER_THREAD, WICED_NETWORK_WORKER_PRIORITY, NETWORKING_WORKER_THREAD_STACK_SIZE, NETWORKING_WORKER_THREAD_QUEUE_SIZE );

And the priority macros are defined in include/wiced_defaults.h

#define WICED_NETWORK_WORKER_PRIORITY      (3)

#define WICED_DEFAULT_WORKER_PRIORITY      (5)

All above are the same for both SDK-3.5.2 & 3.7.0, (also both for ThreadX & FreeRTOS).

Got confused about those RED sections above, they doesn't look consistent to me.

To follow the "design" I think it should be modified that WICED_HARDWARE_IO_WORKER_THREAD is created with priority < 3.

Or the comments should be modified so people are not misled and can use them correctly.

(It's interesting that this is not mentioned in this old post : Worker IO Thread Priority is lower than Network IO thread priority ? .
  Iis a bug introduced in recent SDK versions?)

3 Replies
AxLi_1746341
Level 7
Level 7
10 comments on KBA 5 comments on KBA First comment on KBA

Hi xavier@candyhouse

I agree with your comment, it's really confusing.

Either the comment or the code is wrong.

Note, there is a thread priority bug fix in wiced_rtos_create_worker_thread() which is not mentioned in ChangeLog.

You can compare the implementation of wiced_rtos_create_worker_thread() between 3.5.2 and 3.7.0.

But after reading your post, I suspect the old code happens to be correct.

Really needs the official WICED team to clarify.

Axel

0 Likes

Hi axel.lin

I agree with you that the implementation of wiced_rtos_create_worker_thread() is different between versions.

But I think the new one in SDK-3.7.0 is correct.

In SDK-3.5.2 : worker thread priority is reversed twice for FreeRTOS

     RTOS/wiced_rtos_common.c => wiced_result_t wiced_rtos_create_worker_thread() :

           ...

          wiced_rtos_create_thread(..., WICED_PRIORITY_TO_NATIVE_PRIORITY( priority ), ...);

          ...

     RTOS/FreeRTOS/WICED/wiced_rtos.c => wiced_result_t wiced_rtos_create_thread) :

          ...

          return host_rtos_create_thread_with_arg(..., WICED_PRIORITY_TO_NATIVE_PRIORITY( priority ), ...);

     RTOS/ThreadX/WICED/wiced_rtos.c

          ...

          result = (wiced_result_t) host_rtos_create_thread_with_arg(..., priority, ...);

          ...

In SDK 3.7.0 : worker thread priority is only reversed for FreeRTOS & NuttX as expected

    

mwf_mmfae

Could you drop some comment about the original problem (about WICED_HARDWARE_IO_WORKER_THREAD) ?

0 Likes