Page 1 of 1

Unblocking a Task on the "Other" Core

Posted: Wed Jul 19, 2023 4:10 pm
by gfvalvo
Hello,

Suppose a task running on Core 0 posts some data to a FreeRTOS queue. Suppose further that a very high-priority task, that's pinned to Core 1, is currently blocked, pending on information to enter that queue.

Ideally, the high-priority task should very quickly become unblocked and preempt whatever task is currently running on Core 1 --- without needing to wait for that lower-priority task's tick time to expire. Does this happen and if so by what mechanism is Core 1 alerted to do an immediate context switch?

Thanks.

Re: Unblocking a Task on the "Other" Core

Posted: Wed Jul 19, 2023 10:51 pm
by esp_programmer
Hi gfvalvo,

I was wondering this myself. For what it's worth, it appears to me that one CPU sends an interrupt to the other when a yield is needed. See taskYIELD_OTHER_CORE in tasks.c. There are registers (in the System Registers block) that allow a CPU to trigger interrupts on the other.

esp_programmer

Re: Unblocking a Task on the "Other" Core

Posted: Thu Jul 20, 2023 12:37 am
by gfvalvo
esp_programmer wrote:
Wed Jul 19, 2023 10:51 pm
Hi gfvalvo,
... See taskYIELD_OTHER_CORE in tasks.c.


@esp_programmer, thanks for the reply. Where did you find task.c? It's not in my installation, only task.h. Also there is no mention of 'taskYIELD_OTHER_CORE' in any file of my ESP32 installation.

However, I did find the following in portmacro.h. I think it pretty much answers my question.

Code: Select all

/**
 * @brief Yields the other core
 *
 * - Send an interrupt to another core in order to make the task running on it yield for a higher-priority task.
 * - Can be used to yield current core as well
 *
 * @note [refactor-todo] Put this into private macros as its only called from task.c and is not public API
 * @param coreid ID of core to yield
 */
void vPortYieldOtherCore(BaseType_t coreid);

Re: Unblocking a Task on the "Other" Core

Posted: Thu Jul 20, 2023 1:21 am
by esp_programmer
Hi gfvalvo,

I am using an older version of the esp-idf (5.0). Looks like they have moved some things from tasks.c. As you noted, the function that is used is https://github.com/espressif/esp-idf/bl ... ort.c#L562 .

Thanks