Context switch delay from idle

My processor is a pic32mz2064DAH176 from microchip and I am using 10.0.1 with + tcp. The issue at hand is a delay in switching to a ready thread. There is an external interrupt routine that gets fired and looks like this. ~~~ void chipisrext4(void) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (gpfIsr) {
gpfIsr();
}
IFS0CLR = _IFS0_INT4IF_MASK;
if (gpfIsr) {
vTaskNotifyGiveFromISR(xNetworkTaskHandle, &xHigherPriorityTaskWoken);
}
} ~~~ The task looks like ~~~ //Priority 2 void NetworkTasks(void){ while(1){ ulTaskNotifyTake(pdTRUE, 10 / portTICKPERIODMS); (void) xSemaphoreTake(HifMutex, portMAXDELAY); m2mwifihandleevents(NULL); (void) xSemaphoreGive(HifMutex); }
} ~~~ I am trying to understand why there is a 0.5ms delay in a trace capture before the network task is switched to. I’m not sure how to ask this question exactly, so I’ll post the traces, see at 7.58.226.534 vTaskNotiveGiveFromISR(Network) where the isr fires, then the context switches to idle, then there are a number of Actor Readys with a delay I don’t understand, and Network doesn’t get switched to until 7.58.227.015. So I’m trying to understand what FreeRTOS and or the CPU is doing in this time, and wondering how I can get this to switch quicker? aercon.net/Public/trace.bin

Context switch delay from idle

Not looked at the trace yet – but from a quick squizz at the code I see you are not requesting the context switch from the ISR. If xHigherPriorityTaskWoken is set to a non zero value inside vTaskNotifyGiveFromISR() then a task that has a priority above that of the currently executing task was unblocked and a context switch should be performed. It is not done automatically to give you finer control (consider not wanting to perform a context switch each time a character in a stream was received). See the “Interrupt Service Routines” section on this page: https://www.freertos.org/portPIC32MIPS_MK4.html

Context switch delay from idle

I don’t quite follow here, so are you saying that if I set xHigherPriorityTaskWoken = pdTRUE; that it will switch immediately?

Context switch delay from idle

I still would like to understand why it would be sitting idle, or what it is waiting on. From the docs I have seen, xHigherPriorityTaskWoken wouldn’t apply against it running idle?

Context switch delay from idle

The page I linked to before shows two methods of implementing an interrupt that can cause a context switch. Which one are you using? Also, now I have looked at the trace, I cannot see what is actually executing, although I know you state it is the idle task. Are you using an idle hook function?

Context switch delay from idle

I am using the wrapper, not exactly like the one you have, but copied from the Microchip harmony stack. So for the ISR above , I have this in the .S file ~~~ //void __ISR(EXTERNAL4VECTOR, ipl?AUTO) chipisrext4(void) ********************* .extern chipisrext4 .section .vector23,code, keep .equ __vectordispatch23, IntVectorchipisrext4 .global __vectordispatch23 .set nomicromips .set noreorder .set nomips16 .set noat .ent IntVectorchipisrext4 IntVectorchipisrext4: portSAVECONTEXT la s6, chipisrext4 jalr s6 nop portRESTORECONTEXT .end IntVectorchipisrext4 ~~~ I do have configUSEIDLEHOOK to 1, but vApplicationIdleHook() is empty. I really don’t know that the idle task is running.

Context switch delay from idle

Ok – so the first thing to see is which task is actually running, as if you are using this wrapper than the context switch should happen as you come out of the interrupt handler. If you scroll to the left on the trace you provided you should be able to see what is using the CPU time. Then we can look into that task to see why it is preventing a context switch.

Context switch delay from idle

Ok, it is the idle. So in this case, I suppose that xHigherPriorityTaskWoken should do right. I’ll do some more looking. It may be just me, but xHigherPriorityTaskWoken documentation isn’t real clear.

Context switch delay from idle

Note, that xHignerPriorityTaskWoken is just a variable. The ISR needs to DO something with it to make anything happen. Unfortuanatly, it is somewhat port dependant on what this is. I suppose it would be nice if all the port supported something like portENDSWITCHINGISR( xYieldRequired ); so it could be in the main documentation, but as far as I know that hasn’t been added to all of them.

Context switch delay from idle

portENDSWITCHINGISR( xYieldRequired ); so it could be in the main documentation, but as far as I know that hasn’t been added to all of them.
Yes – I have referenced the page on the FreeRTOS.org website that has examples of how to do this on a PIC32 in a couple of previous posts on this thread – and there are examples in the download too.

Context switch delay from idle

Richard, my comment was that if ALL ports had portEND_SWITCHING_ISR(), then the main documentation, like for vTaskNotifyFromISR() could reference it, As it is, many example use it, but the main documentation tree doesn't have documentation for it, you need to look into the documentation for the port, which seems to trip up many people.

Is there any port that couldn't define the way to end an ISR to be that way?