Skip to content

Commit 1493941

Browse files
committed
[sched] fix scheduler crash, refactored to dynamic types
1 parent d583063 commit 1493941

8 files changed

Lines changed: 293 additions & 162 deletions

File tree

kernel/bin/monitor_processes.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ uint64_t calc_heap(uintptr_t ptr){
4141
char *procname;
4242

4343
void print_process_info(){
44-
process_t *processes = get_all_processes();
45-
for (int i = 0; i < MAX_PROCS; i++){
46-
process_t *proc = &processes[i];
44+
process_t *proc = get_all_processes();
45+
while (proc){
4746
if (proc->id != 0 && proc->state != STOPPED && (!procname || strcmp_case(procname,proc->name,true) == 0)){
48-
print("Process [%i]: %s [pid = %i | status = %s]",i,(uintptr_t)proc->name,proc->id,(uintptr_t)parse_proc_state(proc->state));
47+
print("Process %s [pid = %i | status = %s]",(uintptr_t)proc->name,proc->id,(uintptr_t)parse_proc_state(proc->state));
4948
print("Stack: %x (%x). SP: %x",proc->stack, proc->stack_size, proc->sp);
5049
print("Heap: %x (%x)",proc->mm.mmap_bottom, calc_heap(proc->heap_phys));
5150
print("Flags: %x", proc->spsr);
5251
print("PC: %x",proc->pc);
5352
}
53+
proc = proc->process_next;
5454
}
5555
}
5656

@@ -79,7 +79,6 @@ void draw_memory(char *name,int x, int y, int width, int full_height, int used,
7979

8080
void draw_process_view(){
8181
fb_clear(&ctx,system_theme.bg_color+0x112211);
82-
process_t *processes = get_all_processes();
8382
gpu_size screen_size = (gpu_size){ctx.width,ctx.height};
8483
gpu_point screen_middle = {screen_size.width / 2, screen_size.height / 2};
8584

@@ -90,26 +89,25 @@ void draw_process_view(){
9089
if (ev.key == KEY_LEFT)
9190
scroll_index = max(scroll_index - 1, 0);
9291
if (ev.key == KEY_RIGHT)
93-
scroll_index = min(scroll_index + 1,MAX_PROCS);
92+
scroll_index++;
9493
}
9594

9695
for (int i = 0; i < PROCS_PER_SCREEN; i++) {
97-
int index = scroll_index;
98-
int valid_count = 0;
96+
uint16_t index = scroll_index+i;
97+
uint16_t valid_count = 0;
98+
process_t *proc = get_all_processes();
9999

100-
process_t *proc = NULL;
101-
while (index < MAX_PROCS) {
102-
proc = &processes[index];
100+
while (proc) {
103101
if (proc->id != 0 && proc->state != STOPPED) {
104-
if (valid_count == i + scroll_index) {
102+
if (valid_count == index) {
105103
break;
106104
}
107105
valid_count++;
108106
}
109-
index++;
107+
proc = proc->process_next;
110108
}
111109

112-
if (proc == NULL || proc->id == 0 || valid_count < i || proc->state == STOPPED) break;
110+
if (proc == NULL || proc->id == 0 || proc->state == STOPPED) break;
113111

114112
string name = string_from_literal((const char*)(uintptr_t)proc->name);
115113
string state = string_from_literal(parse_proc_state(proc->state));

kernel/exceptions/timer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ static inline void timer_enable() {
3434
void permanent_disable_timer(){
3535
uint64_t ctl = 0;
3636
asm volatile ("msr cntp_ctl_el0, %0" :: "r"(ctl));
37+
asm volatile ("msr cntv_ctl_el0, %0" :: "r"(ctl));
38+
asm volatile ("isb");
3739
}
3840

3941
void timer_init(uint64_t msecs) {
@@ -58,6 +60,11 @@ void virtual_timer_enable() {
5860
asm volatile ("msr cntv_ctl_el0, %0" :: "r"(val));
5961
}
6062

63+
void virtual_timer_disable() {
64+
uint64_t val = 0;
65+
asm volatile ("msr cntv_ctl_el0, %0" :: "r"(val));
66+
}
67+
6168
uint64_t virtual_timer_remaining_msec() {
6269
uint64_t ticks;
6370
uint64_t freq = rd_cntfrq_el0();

kernel/exceptions/timer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ void timer_reset(uint64_t time);
1111

1212
void virtual_timer_reset(uint64_t smsecs);
1313
void virtual_timer_enable();
14+
void virtual_timer_disable();
1415
uint64_t virtual_timer_remaining_msec();
1516

1617
uint64_t timer_now();

kernel/input/input_dispatch.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ bool register_keypress(keypress kp) {
4545
if (buf->write_index == buf->read_index)
4646
buf->read_index = (buf->read_index + 1) % INPUT_BUFFER_CAPACITY;
4747

48+
if (focused_proc->sleeping) wake_process(focused_proc);
4849
return false;
4950
}
5051

@@ -59,6 +60,7 @@ void register_event(kbd_event event){
5960

6061
if (buf->write_index == buf->read_index)
6162
buf->read_index = (buf->read_index + 1) % INPUT_BUFFER_CAPACITY;
63+
if (focused_proc->sleeping) wake_process(focused_proc);
6264
}
6365

6466
void mouse_config(gpu_point point, gpu_size size){
@@ -91,6 +93,7 @@ void register_mouse_input(mouse_input *rat){
9193
gpu_set_cursor_pressed(last_cursor_state);
9294
gpu_update_cursor(mouse_loc, true);
9395
}
96+
if (focused_proc && focused_proc->sleeping) wake_process(focused_proc);
9497
}
9598

9699
gpu_point get_mouse_pos(){

kernel/process/process.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ typedef struct process {
4242
uint64_t spsr;
4343
//Not used in process saving
4444
uint16_t id;
45+
bool in_ready_queue;
46+
bool sleeping;
47+
uint64_t wake_at_msec;
4548
uintptr_t stack;
4649
paddr_t stack_phys;
4750
uint64_t stack_size;
@@ -70,6 +73,7 @@ typedef struct process {
7073
sizedptr debug_line_str;
7174
system_module exposed_fs;
7275
mm_struct mm;
76+
struct process *process_next;
7377
} process_t;
7478

7579
//Helper functions for accessing registers mapped to scratch regs

0 commit comments

Comments
 (0)