Kernel - Finally fixed that corruption bug (description follows)
authorJohn Hodge <[email protected]>
Sat, 28 May 2011 09:05:35 +0000 (17:05 +0800)
committerJohn Hodge <[email protected]>
Sat, 28 May 2011 09:05:35 +0000 (17:05 +0800)
- 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
Kernel/arch/x86/proc.c
Kernel/heap.c
Kernel/threads.c
Kernel/vfs/dir.c
Modules/Storage/FDD/fdd.c
Usermode/Applications/axwin2_src/Shell_src/main.c

index e229ec9..c13c255 100644 (file)
@@ -26,9 +26,10 @@ serial.txt
 *.gz
 *.img
 SrcDoc/
-ApiDoc/
+APIDoc/
 Usermode/Output/
 gitstats/
 .*.swp
+.*
 
 obj-*/
index 6e94400..3ae79bf 100644 (file)
 #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;
index 07a3aad..ea32436 100644 (file)
@@ -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
        }
 
index ecddf94..40e1729 100644 (file)
@@ -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 );
index 43cc0b5..64c5d37 100644 (file)
@@ -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
        }
        
index 3b886e1..f888810 100644 (file)
@@ -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;
index c0eeeec..fbc6348 100644 (file)
@@ -2,7 +2,7 @@
  * Acess2 GUI Test App
  * - By John Hodge (thePowersGang)
  */
-#include <axwin/axwin.h>
+#include <axwin2/axwin.h>
 
 // === PROTOTYPES ===
  int   main(int argc, char *argv[]);

UCC git Repository :: git.ucc.asn.au