From 7cc053be5c1e36c6f5326ac4ea5a99c0031f981d Mon Sep 17 00:00:00 2001 From: antifallobst Date: Fri, 3 Mar 2023 21:49:11 +0100 Subject: [PATCH] docs: documented processes --- .wiki/Kernel-documentation.md | 87 +++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 14 deletions(-) diff --git a/.wiki/Kernel-documentation.md b/.wiki/Kernel-documentation.md index f63b2c0..a8d708c 100644 --- a/.wiki/Kernel-documentation.md +++ b/.wiki/Kernel-documentation.md @@ -1090,14 +1090,17 @@ This function fills all the interrupt gates (handlers) into the IDT and loads it ### thread.h #### `thread_T` - struct -| Name | Type | Description | -|------------|-------------|--------------------------------------------------------------------------------------------------| -| state | cpu_state_T | The last saved state of the thread. ( -> _context switching_) | -| cpu_time | uint64_t | The amount of cpu time the thread had. (currently the amount of context switches the thread had) | -| stack | void* | The bottom of the threads stack | -| stack_size | uint32_t | The size of the threads stack (in bytes) | -| prev | thread_T* | The previous thread in the scheduling queue (**should only be accessed by the scheduler!**) | -| next | thread_T* | The next thread in the scheduling queue (**should only be accessed by the scheduler!**) | +| Name | Type | Description | +|-------------|-------------|--------------------------------------------------------------------------------------------------| +| state | cpu_state_T | The last saved state of the thread. ( -> _context switching_) | +| cpu_time | uint64_t | The amount of cpu time the thread had. (currently the amount of context switches the thread had) | +| stack | void* | The bottom of the threads stack | +| stack_size | uint32_t | The size of the threads stack (in bytes) | +| process | process_T* | The process, to which the thread belongs to | +| global_prev | thread_T* | The previous thread in the scheduling queue (**should only be accessed by the scheduler!**) | +| global_next | thread_T* | The next thread in the scheduling queue (**should only be accessed by the scheduler!**) | +| local_prev | thread_T* | The previous thread of _process_ (**should only be accessed by the scheduler!**) | +| local_next | thread_T* | The next thread of _process_ (**should only be accessed by the scheduler!**) | #### `thread_spawn(function)` - function (thread_T*) @@ -1125,15 +1128,59 @@ Pauses **_thread_**. Kills **_thread_**. The threads stack and `thread_T` structure will be freed. +### process.h + +#### `pid_t` - typedef +A typedef for `uint32_t`, used for process identification. +Such an identification number is also called `pid`. + +#### `processes_standard_E` - enum +These are standard pids + - **None** - This pid is invalid, like `NULL` is an invalid pointer + - **Kernel** - The kernels' main process + +#### `process_T` - struct + +| Name | Type | Description | +|----------|------------|--------------------------------------------------------| +| name | char[128] | The processes' name | +| id | pid_t | The process-identification number | +| chunk | void* | A pointer to the chunk, where the process is stored in | +| chunk_id | uint32_t | The processes id inside of its chunk | +| parent | process_T* | The process, that spawned this process | +| threads | void* | A pointer to the processes' first thread | + + +#### `process_spawn(parent, name)` - function (pid_t) +Spawns a process named **_name_** as child of **_parent_** and returns its pid. + +#### `process_kill(process)` - function (void) +Kills **_process_** and all of its threads and child processes. + ### scheduler.h +#### `scheduler_processes_chunk_T` - struct +These chunks are a combination of static array and linked list. +They store the `process_T` pointer for each valid `pid_T`. + +| Name | Type | Description | +|------------------|------------------------------|------------------------------------------------------------------------------------| +| processes | process_T** | The array of process pointers | +| processes_bitmap | bitmap_T | If a bit in this bitmap is set, the _processes_ entry with the same index is valid | +| num_free_pids | uint32_t | The amount of free slots in this chunk | +| prev | scheduler_processes_chunk_T* | The previous chunk | +| next | scheduler_processes_chunk_T* | The next chunk | + + #### `scheduler_T` - struct -| Name | Type | Description | -|----------------|-----------|--------------------------------------------------------------------| -| num_threads | uint32_t | Total amount of currently spawned threads | -| running_thread | thread_T* | A pointer to the currently running thread. | -| blocked | bool | Set to true, while switching the context. Thread safety mechanism. | -| initialized | bool | Set to true, if the scheduler is initialized and started. | +| Name | Type | Description | +|----------------|------------------------------|--------------------------------------------------------------------| +| num_threads | uint32_t | Total amount of currently spawned threads | +| num_processes | uint32_t | Total amount of currently spawned processes | +| running_thread | thread_T* | A pointer to the currently running thread. | +| processes | scheduler_processes_chunk_T* | The first processes store chunk | +| blocked | bool | Set to true, while switching the context. Thread safety mechanism. | +| initialized | bool | Set to true, if the scheduler is initialized and started. | #### `scheduler_init()` - function (void) Initializes the scheduler and performs a `scheduler_start` kernel syscall. @@ -1162,9 +1209,21 @@ Starts **_thread_**, by linking it into the scheduling queue. #### `scheduler_kill_thread(thread)` - function (void) Pauses and unregisters **_thread_**. +#### `scheduler_register_process(process)` - function (pid_t) +Reqisters **_process_** and returns its pid. + +#### `scheduler_kill_process(process)` - function (void) +Kills **_process_** and its threads and childs. + +#### `scheduler_get_process(pid)` - function (process_T*) +Returns the `process_T` pointer that is associated with **_pid_**. + #### `scheduler_get_current_thread()` - function (thread_T*) Returns a pointer to the currently running thread. +#### `scheduler_get_current_process()` - function (process_T*) +Returns a pointer to the currently running threads process. + #### `scheduler_switch_context(state)` - function (cpu_state_T*) Saves **_state_** in the running threads _state_ value and increments their _cpu_time_ value. Then it sets the next thread as the running thread and returns its _state_.