X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fthreads.c;h=d5e1b4c3de6c1890315e20cc8c54a1f198555ff8;hb=0b24cbc2f18942b3d1d74efa025ecfa318ab35ec;hp=3ebc4dc6aa3428820b4f1d6e488520608e8d46f8;hpb=f79073d5ab322eef0813f7b05af0d31174d2c9d6;p=tpg%2Facess2.git diff --git a/Kernel/threads.c b/Kernel/threads.c index 3ebc4dc6..d5e1b4c3 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -7,7 +7,9 @@ #include #include #include +#include #include +#include // Configuration #define DEBUG_TRACE_TICKETS 0 // Trace ticket counts @@ -20,10 +22,10 @@ #define SCHED_RR_SIM 2 // Single Queue Round Robin #define SCHED_RR_PRI 3 // Multi Queue Round Robin // Set scheduler type -#define SCHEDULER_TYPE SCHED_LOTTERY +#define SCHEDULER_TYPE SCHED_RR_PRI // === CONSTANTS === -#define DEFAULT_QUANTUM 10 +#define DEFAULT_QUANTUM 5 #define DEFAULT_PRIORITY 5 #define MIN_PRIORITY 10 const enum eConfigTypes cCONFIG_TYPES[] = { @@ -33,10 +35,6 @@ const enum eConfigTypes cCONFIG_TYPES[] = { }; // === IMPORTS === -extern void ArchThreads_Init(void); -extern void Proc_CallFaultHandler(tThread *Thread); -extern void Proc_DumpThreadCPUState(tThread *Thread); -extern int GetCPUNum(void); // === PROTOTYPES === void Threads_Init(void); @@ -851,7 +849,7 @@ void Threads_AddActive(tThread *Thread) if( Thread->Status == THREAD_STAT_ACTIVE ) { tThread *cur = Proc_GetCurThread(); - Warning("WTF, CPU%i %p (%i %s) is adding %p (%i %s) when it is active", + Log_Warning("Threads", "WTF, CPU%i %p (%i %s) is adding %p (%i %s) when it is active", GetCPUNum(), cur, cur->TID, cur->ThreadName, Thread, Thread->TID, Thread->ThreadName); SHORTREL( &glThreadListLock ); return ; @@ -861,13 +859,23 @@ void Threads_AddActive(tThread *Thread) Thread->Status = THREAD_STAT_ACTIVE; // Thread->CurCPU = -1; // Add to active list - #if SCHEDULER_TYPE == SCHED_RR_PRI - Thread->Next = gaActiveThreads[Thread->Priority]; - gaActiveThreads[Thread->Priority] = Thread; - #else - Thread->Next = gActiveThreads; - gActiveThreads = Thread; - #endif + { + tThread *tmp, *prev = NULL; + #if SCHEDULER_TYPE == SCHED_RR_PRI + for( tmp = gaActiveThreads[Thread->Priority]; tmp; prev = tmp, tmp = tmp->Next ); + if(prev) + prev->Next = Thread; + else + gaActiveThreads[Thread->Priority] = Thread; + #else + for( tmp = gActiveThreads; tmp; prev = tmp, tmp = tmp->Next ); + if(prev) + prev->Next = Thread; + else + gActiveThreads = Thread; + #endif + Thread->Next = NULL; + } // Update bookkeeping giNumActiveThreads ++; @@ -971,6 +979,7 @@ void Threads_Fault(int Num) // Double Fault? Oh, F**k if(thread->CurFaultNum != 0) { + Log_Warning("Threads", "Threads_Fault: Double fault on %i", thread->TID); Threads_Kill(thread, -1); // For now, just kill HALT(); } @@ -986,7 +995,10 @@ void Threads_Fault(int Num) */ void Threads_SegFault(tVAddr Addr) { - Warning("Thread #%i committed a segfault at address %p", Proc_GetCurThread()->TID, Addr); + tThread *cur = Proc_GetCurThread(); + cur->bInstrTrace = 0; + Log_Warning("Threads", "Thread #%i committed a segfault at address %p", cur->TID, Addr); + MM_DumpTables(0, KERNEL_BASE); Threads_Fault( 1 ); //Threads_Exit( 0, -1 ); } @@ -1280,7 +1292,7 @@ tThread *Threads_GetNextToRun(int CPU, tThread *Last) } // If we fall onto the same queue again, special handling is // needed - if( i == Last->Priority ) { + if( Last && i == Last->Priority ) { tThread *savedThread = thread; // Find the next unscheduled thread in the list @@ -1474,7 +1486,6 @@ int Semaphore_Wait(tSemaphore *Sem, int MaxToTake) else taken = Sem->Value; Sem->Value -= taken; - SHORTREL( &Sem->Protector ); } else {