Page 1 of 1

about xTaskIncrementTick context switch?

Posted: Mon May 07, 2018 8:15 am
by daiyinger
anyone understand the comments below ? in function BaseType_t xTaskIncrementTick( void )
/* ToDo: This doesn't really play nice with the logic below: it means when core 1 is
running a low-priority task, it will keep running it until there is a context
switch, even when this routine (running on core 0) unblocks a bunch of high-priority
tasks... this is less than optimal -- JD. */

Re: about xTaskIncrementTick context switch?

Posted: Mon May 07, 2018 12:57 pm
by ESP_igrr
The situation is like this:

1. High priority task T1, pinned to CPU1 is in blocked state (e.g. waiting on a xQueueReceive)
2. Lower priority task T2 is running on CPU1
3. Tick interrupt on CPU0 calls xTaskIncrementTick, which unblocks T1 (by making xQueueReceive timeout expire).

Result (with the current logic in xTaskIncrementTick) is that T1 does not start running immediately, and T2 continues to run. T1 will start running when either of the following happens:

a) Tick interrupt occurs on CPU1 (tick interrupts on the two CPUs are not synchronized, so anywhere between 0 and portTICK_PERIOD_MS can pass until then)
b) T2 blocks or otherwise yields
c) Interrupt happens on CPU1, and interrupt handler calls portYIELD_FROM_ISR()

Re: about xTaskIncrementTick context switch?

Posted: Tue May 08, 2018 3:20 am
by ESP_Sprite

Re: about xTaskIncrementTick context switch?

Posted: Tue May 08, 2018 9:20 am
by daiyinger
thanks, I get it.