Using RTOS tasks with or without cpu core affinity

dejan.ns
Posts: 5
Joined: Fri Dec 15, 2017 11:03 pm

Using RTOS tasks with or without cpu core affinity

Postby dejan.ns » Fri Dec 15, 2017 11:43 pm

I am quite new to ESP32, coming from PIC32 MCUs which are all single core. So I would like to check if I'm right when it comes to running FreeRTOS scheduler on two cores. It seems to me that if a task is pinned to one core, than this task could be skipped by scheduler in round robin scheme (same priority tasks run in turn triggered by ticks) since both cores are using the same pointer to a task list of that specific priority, but looking only for tasks with no affinity or pinned to that specific core. So when one core skips the task pinned to the other core, it moves the pointer forward and the other core will continue traversing the task list from that point on, which means the skipped task won't be run.

If I'm right, then it seems a better strategy would be to create all application tasks with no cpu affinity. By doing that, all tasks can be run by both cores which guarantees no task would be ever skipped like in the above scenario.

I would appreciate a comment from someone with more experience in this matter.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Using RTOS tasks with or without cpu core affinity

Postby ESP_Sprite » Sat Dec 16, 2017 3:30 am

You actually are right, and this is explained in the documentation: http://esp-idf.readthedocs.io/en/latest ... scheduling

You could indeed get around this by un-pinning all tasks. As an alternative, if you have multiple tasks of the exact same priority pinned to both cores, I'd suggest moving the tasks on one core to a level higher or lower; that solves the problem without the need to un-pin tasks.

dejan.ns
Posts: 5
Joined: Fri Dec 15, 2017 11:03 pm

Re: Using RTOS tasks with or without cpu core affinity

Postby dejan.ns » Sat Dec 16, 2017 7:03 am

Yes, you could just use a specific set of priority levels for each core, not mixing them together and that solves the problem. This then leads to the next question - are the API tasks pinned to a specific core, which one (I guess the PRO core) and what priority levels do they use?

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Using RTOS tasks with or without cpu core affinity

Postby ESP_Sprite » Mon Dec 18, 2017 2:29 am

From memory, most tasks are either pinned to core 0 (WiFi, BT) or unpinned (lwip).

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: Using RTOS tasks with or without cpu core affinity

Postby chegewara » Mon Dec 18, 2017 7:51 am

System tasks priority list (all but acceptTask and HttpServerTask are system tasks):
Attachments
ble.jpg
ble.jpg (65.78 KiB) Viewed 8535 times

jtchitty
Posts: 1
Joined: Fri Jul 10, 2020 9:14 pm

Re: Using RTOS tasks with or without cpu core affinity

Postby jtchitty » Fri Jul 10, 2020 9:27 pm

Keep in mind that if an unpinned task executes a single-precision floating point (`float`) operation, it will be automatically pinned to the core that happens to be executing that task at that time.

Who is online

Users browsing this forum: Baidu [Spider], ESP_rrtandler, Google [Bot] and 113 guests