FreeCalypso > hg > fc-tourmaline
view src/gpf/osl/os_pro_ir.c @ 220:0ed36de51973
ABB semaphore protection overhaul
The ABB semaphone protection logic that came with TCS211 from TI
was broken in several ways:
* Some semaphore-protected functions were called from Application_Initialize()
context. NU_Obtain_Semaphore() called with NU_SUSPEND fails with
NU_INVALID_SUSPEND in this context, but the return value wasn't checked,
and NU_Release_Semaphore() would be called unconditionally at the end.
The latter call would increment the semaphore count past 1, making the
semaphore no longer binary and thus no longer effective for resource
protection. The fix is to check the return value from NU_Obtain_Semaphore()
and skip the NU_Release_Semaphore() call if the semaphore wasn't properly
obtained.
* Some SPI hardware manipulation was being done before entering the semaphore-
protected critical section. The fix is to reorder the code: first obtain
the semaphore, then do everything else.
* In the corner case of L1/DSP recovery, l1_abb_power_on() would call some
non-semaphore-protected ABB & SPI init functions. The fix is to skip those
calls in the case of recovery.
* A few additional corner cases existed, all of which are fixed by making
ABB semaphore protection 100% consistent for all ABB functions and code paths.
There is still one remaining problem of priority inversion: suppose a low-
priority task calls an ABB function, and some medium-priority task just happens
to preempt right in the middle of that semaphore-protected ABB operation. Then
the high-priority SPI task is locked out for a non-deterministic time until
that medium-priority task finishes its work and goes back to sleep. This
priority inversion problem remains outstanding for now.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 26 Apr 2021 20:55:25 +0000 |
parents | 4e78acac3d88 |
children |
line wrap: on
line source
/* * This C module is a reconstruction based on the disassembly of * os_pro.obj in frame_na7_db_ir.lib from the Leonardo package. */ /* set of included headers from COFF symtab: */ #include <stdio.h> #include <string.h> #include "nucleus.h" #include "typedefs.h" #include "os.h" #include "gdi.h" #include "os_types.h" #include "os_glob.h" extern VOID *TCD_Current_Thread; extern T_OS_TASK_TABLE_ENTRY TaskTable[]; extern unsigned os_time_to_tick_multiplier; #define OS_NU_TASK_MAGIC 0xdeafbeef VOID os_TaskEntry(UNSIGNED TaskHandle, VOID *argv) { TaskTable[TaskHandle].TaskEntry(TaskHandle, 0); } GLOBAL LONG os_SuspendTask(OS_HANDLE Caller, ULONG Time) { UNSIGNED SuspendTicks; SuspendTicks = TIME_TO_SYSTEM_TICKS(Time); if (!SuspendTicks) SuspendTicks = 1; NU_Sleep(SuspendTicks); return (OS_OK); } GLOBAL LONG os_ResumeTask(OS_HANDLE task_handle) { if (NU_Resume_Task(&TaskTable[task_handle].TaskCB.TCB) == NU_SUCCESS) return(OS_OK); else return(OS_ERROR); } GLOBAL LONG os_Relinquish(void) { NU_Relinquish(); return(OS_OK); } GLOBAL OS_HANDLE os_MyHandle(void) { OS_NU_TASK *os_nu_task = (OS_NU_TASK *) TCD_Current_Thread; if (os_nu_task && os_nu_task->magic_nr == OS_NU_TASK_MAGIC) return(os_nu_task->handle); else return(OS_NOTASK); } GLOBAL LONG os_GetTaskName(OS_HANDLE Caller, OS_HANDLE TaskHandle, char *Name) { if (TaskHandle) { if (TaskHandle > MaxTasks || !TaskTable[TaskHandle].Name[0]) return(OS_ERROR); strcpy(Name, TaskTable[TaskHandle].Name); } else if (TCD_Current_Thread) { NU_TASK *curtask = TCD_Current_Thread; strcpy(Name, curtask->tc_name); } else strcpy(Name, "ROOT"); return(OS_OK); } GLOBAL LONG os_DeferTask(OS_HANDLE task_handle, OS_TIME time) { if (NU_Suspend_Task(&TaskTable[task_handle].TaskCB.TCB) == NU_SUCCESS) return(OS_OK); else return(OS_ERROR); } GLOBAL LONG os_CheckTaskStack(OS_HANDLE Handle) { #ifdef __GNUC__ register void *sp asm("sp"); #endif if (*TaskTable[Handle].Stack != GUARD_PATTERN) return(OS_ERROR); #ifdef __GNUC__ if (TCD_Current_Thread) { NU_TASK *curtask = TCD_Current_Thread; if (sp < curtask->tc_stack_start) return(OS_ERROR); } #endif return(OS_OK); }