~samhsmith/AstraOS

f281fb5b93073b269157c07e22330ee7a66b21f5 — Sam H Smith 2 years ago 0c60950
solved kernel freeze problem
3 files changed, 10 insertions(+), 7 deletions(-)

M src/kernel.c
M src/process_run.c
M src/syscall.c
M src/kernel.c => src/kernel.c +1 -0
@@ 344,6 344,7 @@ void trap_hang_kernel(
        }
        else
        {
            printf("CPU#%llu is without a user thread to run\n", i);
        }
    }
    while(1) {}

M src/process_run.c => src/process_run.c +4 -3
@@ 73,8 73,8 @@ u64 current_thread_runtimes[KERNEL_MAX_HART_COUNT];
u64 last_mtimes[KERNEL_MAX_HART_COUNT];

/*
 * The following function only changes kernel_current_thread_pid/tid.
 * You the callee have to make sure you are not using an invalid pointer
 * Make sure you do not have a lock on THREAD_RUNTIME_ARRAY_LOCK
 * when calling kernel_choose_new_thread
 */

struct xoshiro256ss_state kernel_choose_new_thread_rando_state[KERNEL_MAX_HART_COUNT];


@@ 91,6 91,8 @@ void kernel_choose_new_thread(u64 new_mtime, u64 hart)
                        "hart has abandoned thread");
    }

    kernel_current_thread_has_thread[hart] = 0;

    u8 found_new_thread = 0;

    u64 thread_counter = 0;


@@ 225,7 227,6 @@ void kernel_choose_new_thread(u64 new_mtime, u64 hart)
    if(!found_new_thread)
    {
        // Causes the KERNEL nop thread to be loaded
        kernel_current_thread_has_thread[hart] = 0;
        return;
    }


M src/syscall.c => src/syscall.c +5 -4
@@ 230,8 230,8 @@ void syscall_thread_sleep(u64 hart, u64 mtime)
    }
    // go to sleep
    frame->regs[10] = 1;
    kernel_choose_new_thread(mtime, hart);
    rwlock_release_read(&KERNEL_PROCESS_ARRAY_RWLOCK);
    kernel_choose_new_thread(mtime, hart);
}

void syscall_thread_awake_on_keyboard(u64 hart)


@@ 1738,8 1738,8 @@ void syscall_process_exit(u64 hart, u64 mtime)
    process_flag_all_threads_for_destruction(process);
    rwlock_release_write(&process->process_lock);

    kernel_choose_new_thread(mtime, hart);
    rwlock_release_read(&KERNEL_PROCESS_ARRAY_RWLOCK);
    kernel_choose_new_thread(mtime, hart);
}

void syscall_process_is_alive(u64 hart)


@@ 2163,8 2163,8 @@ void syscall_IPFC_call(u64 hart, u64 mtime)
    current_thread->IPFC_handler_index = handler_index;
    current_thread->is_running = 0;

    kernel_choose_new_thread(mtime, hart);
    rwlock_release_write(&KERNEL_PROCESS_ARRAY_RWLOCK);
    kernel_choose_new_thread(mtime, hart);
}

void syscall_IPFC_return(u64 hart, u64 mtime)


@@ 2245,8 2245,9 @@ void syscall_IPFC_return(u64 hart, u64 mtime)
    }
    else
    { rwlock_release_write(&process->process_lock); }
    kernel_choose_new_thread(mtime, hart);

    rwlock_release_read(&KERNEL_PROCESS_ARRAY_RWLOCK);
    kernel_choose_new_thread(mtime, hart);
}

void do_syscall(TrapFrame* frame, u64 mtime, u64 hart)