aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-03-18 14:39:53 -0700
committerChristian Cunningham <cc@localhost>2022-03-18 14:39:53 -0700
commit23034623f5f4ed6fb89794a43b309dc06aa25e5f (patch)
tree2ec3e5fcdfe0fe0262f17575bd5300964fb1eb2f
parent3068d3d536ef4b1887f67f14ef853ef967504730 (diff)
Fixed free queue not initializing properly
-rw-r--r--include/sys/schedule.h2
-rw-r--r--src/cpu/irq.c5
-rw-r--r--src/sys/schedule.c34
3 files changed, 30 insertions, 11 deletions
diff --git a/include/sys/schedule.h b/include/sys/schedule.h
index 18b2f7f..3c0b2bb 100644
--- a/include/sys/schedule.h
+++ b/include/sys/schedule.h
@@ -2,7 +2,7 @@
#define SYS_SCHEDULE_H
#include <lib/queue.h>
-#define TQUEUE_MAX 0x800
+#define TQUEUE_MAX 0x80
#define STACK_SIZE 0x4000
#define TQUEUE_CNT 3
#define PRIORITIES 8
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");
}