From 6e1cf1d50bca85f01b5f802b1a76f090e362bf05 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 28 May 2011 17:05:35 +0800 Subject: [PATCH] Kernel - Finally fixed that corruption bug (description follows) - Also fixed some logging bugs (Heap dump and VFS) - Fixed a bug in the AxWin2 shell include statement Bug Description: The last non-idle thread to be put to sleep didn't get the ->CurCPU field reset to -1. This probably caused the scheduler to think that the process was still in use, and hence it never got re-scheduled. The other VTs did not suffer this problem because they were not the last to sleep. --- .gitignore | 3 +- Kernel/arch/x86/proc.c | 31 +++++++++++-------- Kernel/heap.c | 8 +++-- Kernel/threads.c | 20 ++++++++---- Kernel/vfs/dir.c | 6 ++-- Modules/Storage/FDD/fdd.c | 2 +- .../Applications/axwin2_src/Shell_src/main.c | 2 +- 7 files changed, 45 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index e229ec91..c13c2551 100644 --- a/.gitignore +++ b/.gitignore @@ -26,9 +26,10 @@ serial.txt *.gz *.img SrcDoc/ -ApiDoc/ +APIDoc/ Usermode/Output/ gitstats/ .*.swp +.* obj-*/ diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index 6e944009..3ae79bf8 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -13,14 +13,19 @@ #endif // === FLAGS === -#define DEBUG_TRACE_SWITCH 1 +#define DEBUG_TRACE_SWITCH 0 #define DEBUG_DISABLE_DOUBLEFAULT 1 +#define DEBUG_VERY_SLOW_SWITCH 0 // === CONSTANTS === #define SWITCH_MAGIC 0xFF5317C8 // FF SWITCH - There is no code in this area // Base is 1193182 #define TIMER_BASE 1193182 -#define TIMER_DIVISOR 11932 //~100Hz +#if DEBUG_VERY_SLOW_PERIOD +# define TIMER_DIVISOR 1193 //~10Hz switch, with 10 quantum = 1s per thread +#else +# define TIMER_DIVISOR 11932 //~100Hz +#endif // === TYPES === #if USE_MP @@ -999,17 +1004,6 @@ void Proc_Scheduler(int CPU) thread = Threads_GetNextToRun(CPU, thread); - #if DEBUG_TRACE_SWITCH - if(thread) { - Log("Switching to task %i(%s), CR3 = 0x%x, EIP = %p", - thread->TID, - thread->ThreadName, - thread->MemState.CR3, - thread->SavedState.EIP - ); - } - #endif - // No avaliable tasks, just go into low power mode (idle thread) if(thread == NULL) { #if USE_MP @@ -1020,6 +1014,17 @@ void Proc_Scheduler(int CPU) #endif } + #if DEBUG_TRACE_SWITCH + if(thread && thread != Proc_GetCurThread() ) { + Log("Switching to task %i(%s), CR3 = 0x%x, EIP = %p", + thread->TID, + thread->ThreadName, + thread->MemState.CR3, + thread->SavedState.EIP + ); + } + #endif + // Set current thread #if USE_MP gaCPUs[CPU].Current = thread; diff --git a/Kernel/heap.c b/Kernel/heap.c index 07a3aad0..ea32436a 100644 --- a/Kernel/heap.c +++ b/Kernel/heap.c @@ -664,8 +664,12 @@ void Heap_Stats(void) // Print the block info? #if 1 - Log_Debug("Heap", "%p (0x%x) - 0x%x (%i) Owned by %s:%i", - head->Data, MM_GetPhysAddr((tVAddr)&head->Data), head->Size, head->ValidSize, head->File, head->Line); + if( head->Magic == MAGIC_FREE ) + Log_Debug("Heap", "%p (0x%llx) - 0x%x free", + head->Data, MM_GetPhysAddr((tVAddr)&head->Data), head->Size); + else + Log_Debug("Heap", "%p (0x%llx) - 0x%x (%i) Owned by %s:%i", + head->Data, MM_GetPhysAddr((tVAddr)&head->Data), head->Size, head->ValidSize, head->File, head->Line); #endif } diff --git a/Kernel/threads.c b/Kernel/threads.c index ecddf945..40e1729b 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -12,6 +12,7 @@ // Configuration #define DEBUG_TRACE_TICKETS 0 // Trace ticket counts #define DEBUG_TRACE_STATE 0 // Trace state changes (sleep/wake) +#define SEMAPHORE_DEBUG 0 // --- Schedulers --- #define SCHED_UNDEF 0 @@ -808,6 +809,7 @@ void Threads_AddActive(tThread *Thread) // Set state Thread->Status = THREAD_STAT_ACTIVE; +// Thread->CurCPU = -1; // Add to active list #if SCHEDULER_TYPE == SCHED_RR_PRI Thread->Next = gaActiveThreads[Thread->Priority]; @@ -1082,6 +1084,7 @@ tThread *Threads_GetNextToRun(int CPU, tThread *Last) // Clear Delete Queue // - I should probably put this in a worker thread to avoid calling free() in the scheduler // DEFINITELY - free() can deadlock in this case + // I'll do it when it becomes an issue while(gDeleteThreads) { thread = gDeleteThreads->Next; @@ -1102,7 +1105,10 @@ tThread *Threads_GetNextToRun(int CPU, tThread *Last) } gDeleteThreads = thread; } - + + // Make sure the current (well, old) thread is marked as de-scheduled + if(Last) Last->CurCPU = -1; + // No active threads, just take a nap if(giNumActiveThreads == 0) { SHORTREL( &glThreadListLock ); @@ -1441,14 +1447,14 @@ int Semaphore_Wait(tSemaphore *Sem, int MaxToTake) Sem->LastWaiting = us; } - #if DEBUG_TRACE_STATE + #if DEBUG_TRACE_STATE || SEMAPHORE_DEBUG Log("%p (%i %s) waiting on semaphore %p %s:%s", us, us->TID, us->ThreadName, Sem, Sem->ModName, Sem->Name); #endif + SHORTREL( &Sem->Protector ); // Release first to make sure it is released SHORTREL( &glThreadListLock ); - SHORTREL( &Sem->Protector ); while(us->Status == THREAD_STAT_SEMAPHORESLEEP) Threads_Yield(); // We're only woken when there's something avaliable us->WaitPointer = NULL; @@ -1479,7 +1485,7 @@ int Semaphore_Wait(tSemaphore *Sem, int MaxToTake) Sem->Value -= given; - #if DEBUG_TRACE_STATE + #if DEBUG_TRACE_STATE || SEMAPHORE_DEBUG Log("%p (%i %s) woken by wait on %p %s:%s", toWake, toWake->TID, toWake->ThreadName, Sem, Sem->ModName, Sem->Name); @@ -1541,7 +1547,7 @@ int Semaphore_Signal(tSemaphore *Sem, int AmmountToAdd) Sem->LastSignaling = us; } - #if DEBUG_TRACE_STATE + #if DEBUG_TRACE_STATE || SEMAPHORE_DEBUG Log("%p (%i %s) signaling semaphore %p %s:%s", us, us->TID, us->ThreadName, Sem, Sem->ModName, Sem->Name); @@ -1593,7 +1599,7 @@ int Semaphore_Signal(tSemaphore *Sem, int AmmountToAdd) if(toWake->bInstrTrace) Log("%s(%i) given %i from %p", toWake->ThreadName, toWake->TID, given, Sem); - #if DEBUG_TRACE_STATE + #if DEBUG_TRACE_STATE || SEMAPHORE_DEBUG Log("%p (%i %s) woken by signal on %p %s:%s", toWake, toWake->TID, toWake->ThreadName, Sem, Sem->ModName, Sem->Name); @@ -1603,6 +1609,8 @@ int Semaphore_Signal(tSemaphore *Sem, int AmmountToAdd) SHORTLOCK( &glThreadListLock ); if( toWake->Status != THREAD_STAT_ACTIVE ) Threads_AddActive(toWake); + else + Warning("Thread %p (%i %s) is already awake", toWake, toWake->TID, toWake->ThreadName); SHORTREL( &glThreadListLock ); } SHORTREL( &Sem->Protector ); diff --git a/Kernel/vfs/dir.c b/Kernel/vfs/dir.c index 43cc0b53..64c5d378 100644 --- a/Kernel/vfs/dir.c +++ b/Kernel/vfs/dir.c @@ -123,7 +123,7 @@ int VFS_Symlink(const char *Name, const char *Link) // Get absolue path name _link = VFS_GetAbsPath( Link ); if(!_link) { - Warning("Path '%s' is badly formed", Link); + Log_Warning("VFS", "Path '%s' is badly formed", Link); return -1; } @@ -134,7 +134,7 @@ int VFS_Symlink(const char *Name, const char *Link) // Check if destination exists if(!destNode) { - Warning("File '%s' does not exist, symlink not created", Link); + Log_Warning("VFS", "File '%s' does not exist, symlink not created", Link); return -1; } @@ -143,7 +143,7 @@ int VFS_Symlink(const char *Name, const char *Link) // Make node if( VFS_MkNod(Name, VFS_FFLAG_SYMLINK) != 0 ) { - Warning("Unable to create link node '%s'", Name); + Log_Warning("VFS", "Unable to create link node '%s'", Name); return -2; // Make link node } diff --git a/Modules/Storage/FDD/fdd.c b/Modules/Storage/FDD/fdd.c index 3b886e16..f8888105 100644 --- a/Modules/Storage/FDD/fdd.c +++ b/Modules/Storage/FDD/fdd.c @@ -111,7 +111,7 @@ void FDD_int_StartMotor(int Disk); int FDD_int_GetDims(int type, int lba, int *c, int *h, int *s, int *spt); // === GLOBALS === -MODULE_DEFINE(0, FDD_VERSION, FDD, FDD_Install, NULL, "ISADMA", NULL); +MODULE_DEFINE(0, FDD_VERSION, FDD, FDD_Install, NULL, "x86_ISADMA", NULL); t_floppyDevice gFDD_Devices[2]; tMutex glFDD; volatile int gbFDD_IrqFired = 0; diff --git a/Usermode/Applications/axwin2_src/Shell_src/main.c b/Usermode/Applications/axwin2_src/Shell_src/main.c index c0eeeec9..fbc63484 100644 --- a/Usermode/Applications/axwin2_src/Shell_src/main.c +++ b/Usermode/Applications/axwin2_src/Shell_src/main.c @@ -2,7 +2,7 @@ * Acess2 GUI Test App * - By John Hodge (thePowersGang) */ -#include +#include // === PROTOTYPES === int main(int argc, char *argv[]); -- 2.20.1