Hi Guys - Sorry if this is a dumb question but I’m wondering about float support, and particularly context-switch efficiency. If I read the code correctly, FreeRTOS M4F is saving/restoring the floating point registers each context switch. I thought I understood from the ST example that float was even supported in ISRs, though I didn’t understand how this is implemented reading the FreeRTOS code.
First, my understanding (please correct if I’ve got this wrong) about M4F float support:
- processor will interrupt on attempt to use float if magic bit is set
- processsor will interrupt on leaving interrupt context if different magic bit is set
I naively expected no overhead if float only used in one task. Is the time to save/restore FP registers inconsequential and I’m worrying about nothing? In an OS I wrote donkeys years ago, the save/restore was so expensive I prohibited more than one task using FP, and trapped any offender to HCF. BTW a facility to enforce FP in only one task would be great in FreeRTOS…
Anyway, what I naively expected was:
- OS tracks which tasks use float,
- on context switch from task using float to task not using float, magic bit is set to disable float and cause interrupt if its used, and note is made of last task to use float
- on said interrupt, FP context saved to noted task’s TCB, current task is marked float-user, new float context initialized and float enabled, also note more than one task is using FP so for FP-users context save/restore is required on context switch.
- if float-used interrupt caused from ISR, save FP registers as required above, and restore on leaving ISR…
Sounds a bit complicated but isn’t much code, and makes average context switch less expensive.
Can you educate me? What am I missing?
Best Regards, Dave