From 23034623f5f4ed6fb89794a43b309dc06aa25e5f Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Fri, 18 Mar 2022 14:39:53 -0700 Subject: Fixed free queue not initializing properly --- src/cpu/irq.c | 5 ++++- src/sys/schedule.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/cpu/irq.c b/src/cpu/irq.c index 6a5b43f..b2d9a71 100644 --- a/src/cpu/irq.c +++ b/src/cpu/irq.c @@ -31,8 +31,11 @@ void c_irq_handler(void) } // Handle the recieved data + // Ctrl+G to output scheduler debug info + if (data == 0x7) + uart_scheduler(); // Ctrl+T to toggle timer - if(data == 0x14) { + else if(data == 0x14) { unsigned long timer_status; asm volatile("mrc p15, 0, %0, c14, c3, 1" : "=r"(timer_status)); if(timer_status == 0) { diff --git a/src/sys/schedule.c b/src/sys/schedule.c index 4f8feff..00935c9 100644 --- a/src/sys/schedule.c +++ b/src/sys/schedule.c @@ -47,10 +47,6 @@ void init_scheduler(void) scheduler.swait[p].end.next = &scheduler.swait[p].start; scheduler.swait[p].end.entry_type = END_ENTRY; } - scheduler.free_threads.start.value = 0; - scheduler.free_threads.start.entry_type = START_ENTRY; - scheduler.free_threads.end.value = 0; - scheduler.free_threads.end.entry_type = END_ENTRY; // Initialize nextpid nextpid = FIRST_AVAIL_PID; @@ -60,13 +56,15 @@ void init_scheduler(void) struct Thread* t = &threads[i]; t->offset = i; t->sp_base = 0x20000000 - STACK_SIZE*i; - struct Entry* te = &thread_entries[i]; - te->value = t; - // Initialize To No Next Entry Initially - te->next = &thread_entries[(i+1)%MAX_THREADS]; - te->entry_type = VALUE_ENTRY; + thread_entries[i].value = t; + thread_entries[i].next = &thread_entries[(i+1)]; + thread_entries[i].entry_type = VALUE_ENTRY; } // Initialize the free queue + scheduler.free_threads.start.value = 0; + scheduler.free_threads.start.entry_type = START_ENTRY; + scheduler.free_threads.end.value = 0; + scheduler.free_threads.end.entry_type = END_ENTRY; scheduler.free_threads.start.next = &thread_entries[0]; scheduler.free_threads.end.next = &thread_entries[MAX_THREADS-1]; thread_entries[MAX_THREADS-1].next = &scheduler.free_threads.end; @@ -299,6 +297,7 @@ void uart_scheduler(void) uart_hex((unsigned long)scheduler.rthread); uart_char(' '); kmemshow32((void*)scheduler.rthread, 9); + unsigned long length; for(int p = 0; p < PRIORITIES; p++) { uart_string("Priority "); uart_10(p); @@ -309,33 +308,50 @@ void uart_scheduler(void) queue = &scheduler.ready[p]; uart_string("Ready Queue\n"); entry = queue->start.next; + length = 0; while (entry->entry_type != END_ENTRY) { uart_hex((unsigned long)entry->value); uart_char(' '); kmemshow32((void*)entry->value, 9); entry = entry->next; + length++; } + uart_hexn(length); queue = &scheduler.mwait[p]; uart_string("Mutex Wait Queue\n"); entry = queue->start.next; + length = 0; while (entry->entry_type != END_ENTRY) { uart_hex((unsigned long)entry->value); uart_char(' '); kmemshow32((void*)entry->value, 9); entry = entry->next; + length++; } + uart_hexn(length); queue = &scheduler.swait[p]; uart_string("Signal Wait Queue\n"); entry = queue->start.next; + length = 0; while (entry->entry_type != END_ENTRY) { uart_hex((unsigned long)entry->value); uart_char(' '); kmemshow32((void*)entry->value, 9); entry = entry->next; + length++; } + uart_hexn(length); + } + // Count number of free threads + struct Queue* queue = &scheduler.free_threads; + struct Entry* entry = queue->start.next; + while (entry->entry_type != END_ENTRY) { + entry = entry->next; + length++; } + uart_hexn(length); uart_string("==============\n"); } -- cgit v1.2.1