LF OS
Hobby operating system for amd64 with high ambitions
|
#include <scheduler.h>
#include <string.h>
#include <errno.h>
#include <mm.h>
#include <sc.h>
#include <bitmap.h>
#include <panic.h>
#include <log.h>
#include <mutex.h>
#include <mq.h>
#include <signal.h>
#include <sd.h>
#include <unused_param.h>
Go to the source code of this file.
Data Structures | |
struct | process_t |
Macros | |
#define | MAX_PROCS 4096 |
Enumerations | |
enum | process_state { process_state_empty = 0 , process_state_waiting , process_state_runnable , process_state_running , process_state_exited , process_state_killed } |
Variables | |
volatile pid_t | scheduler_current_process = -1 |
static process_t | processes [MAX_PROCS] |
struct process_t |
Definition at line 26 of file scheduler.c.
Data Fields | ||
---|---|---|
size_t | allocatedMemory | |
allocator_t | allocator | |
struct vm_table * | context | |
cpu_state | cpu | |
uint8_t | exit_code | |
region_t | heap | |
region_t | hw | |
ptr_t | iopb | Physical address of the first of two IOPB pages, 0 if no IO privilege granted. |
mq_id_t | mq | |
char | name[1024] | |
pid_t | parent | |
region_t | stack | |
process_state | state | |
union wait_data | waiting_data | |
enum wait_reason | waiting_for |
#define MAX_PROCS 4096 |
Definition at line 53 of file scheduler.c.
enum process_state |
Enumerator | |
---|---|
process_state_empty | |
process_state_waiting | |
process_state_runnable | |
process_state_running | |
process_state_exited | |
process_state_killed |
Definition at line 17 of file scheduler.c.
__attribute__ | ( | (naked) | ) |
Definition at line 83 of file scheduler.c.
pid_t free_pid | ( | void | ) |
Definition at line 91 of file scheduler.c.
References MAX_PROCS, process_state_empty, processes, and state.
void init_scheduler | ( | void | ) |
Definition at line 87 of file scheduler.c.
References MAX_PROCS, memset(), and processes.
void * process_alloc | ( | allocator_t * | alloc, |
size_t | size | ||
) |
Definition at line 56 of file scheduler.c.
References alloc, process_t::allocatedMemory, logw, process_state_empty, process_state_exited, process_state_killed, processes, size, process_t::state, allocator::tag, and vm_alloc().
void process_dealloc | ( | allocator_t * | alloc, |
void * | ptr | ||
) |
Definition at line 71 of file scheduler.c.
References alloc, process_t::allocatedMemory, logw, process_state_empty, processes, size, process_t::state, allocator::tag, and vm_free().
|
extern |
void sc_handle_hardware_interrupt_notify | ( | uint8_t | interrupt, |
bool | enable, | ||
uint64_t | mq, | ||
uint64_t * | error | ||
) |
Definition at line 478 of file scheduler.c.
References ENOENT, error, interrupt_add_queue(), interrupt_del_queue(), mq, process_t::mq, processes, and scheduler_current_process.
Definition at line 436 of file scheduler.c.
References ALLOCATOR_REGION_DIRECT_MAPPING, bitmap_clear(), bitmap_set(), error, process_t::iopb, KiB, memset(), mm_alloc_pages(), MM_FREE, mm_mark_physical_pages(), num, process, processes, scheduler_current_process, set_iopb(), and turn_on.
void sc_handle_ipc_mq_create | ( | bool | global_read, |
bool | global_write, | ||
size_t | msg_limit, | ||
size_t | data_limit, | ||
uint64_t * | mq, | ||
uint64_t * | error | ||
) |
Definition at line 498 of file scheduler.c.
References data_limit, ENOSYS, error, global_write, mq, and UNUSED_PARAM.
Definition at line 508 of file scheduler.c.
References ENOSYS, error, mq, and UNUSED_PARAM.
Definition at line 514 of file scheduler.c.
References EAGAIN, EMSGSIZE, ENOMSG, error, wait_data::message_queue, mq, process_t::mq, mq_peek(), mq_pop(), MT_Invalid, processes, scheduler_current_process, scheduler_wait_for(), Message::size, Message::type, wait, and wait_reason_message.
Definition at line 549 of file scheduler.c.
References error, MAX_PROCS, mq, process_t::mq, mq_push(), pid, process_state_empty, processes, scheduler_current_process, Message::sender, and state.
void sc_handle_ipc_service_discover | ( | uuid_t * | uuid, |
uint64_t | mq, | ||
struct Message * | msg, | ||
uint64_t * | error | ||
) |
Definition at line 576 of file scheduler.c.
References uuid_t::data, EINVAL, error, memcpy(), mq, Message::UserData::ServiceDiscoveryData::mq, process_t::mq, MT_ServiceDiscovery, processes, scheduler_current_process, sd_send(), Message::sender, Message::UserData::ServiceDiscovery, Message::UserData::ServiceDiscoveryData::serviceIdentifier, Message::type, and Message::user_data.
Definition at line 568 of file scheduler.c.
References error, mq, process_t::mq, processes, scheduler_current_process, and sd_register().
Definition at line 396 of file scheduler.c.
References ALLOCATOR_REGION_DIRECT_MAPPING, data_end, region_t::end, process_t::heap, memset(), mm_alloc_pages(), MM_FREE, mm_mark_physical_pages(), processes, scheduler_current_process, vm_context_get_physical_for_virtual(), vm_context_map(), and vm_context_unmap().
Definition at line 277 of file scheduler.c.
References process_t::context, process_t::cpu, region_t::end, ENOMEM, entry, process_t::heap, process_t::hw, memcpy(), process_t::name, pid, processes, scheduler_current_process, setup_process(), process_t::stack, region_t::start, strncpy(), vm_context_get_physical_for_virtual(), vm_context_map(), vm_context_new(), and vm_copy_range().
void sc_handle_scheduler_exit | ( | uint64_t | exit_code | ) |
Definition at line 269 of file scheduler.c.
References process_t::exit_code, logd, name, process_state_exited, processes, scheduler_current_process, scheduler_process_cleanup(), and process_t::state.
Definition at line 600 of file scheduler.c.
References process_t::parent, pid, processes, and scheduler_current_process.
void sc_handle_scheduler_sleep | ( | uint64_t | nanoseconds | ) |
Definition at line 422 of file scheduler.c.
References sc_handle_clock_read(), scheduler_current_process, scheduler_wait_for(), wait_data::timestamp_ns_since_boot, and wait_reason_time.
Definition at line 181 of file scheduler.c.
References process_t::context, process_t::cpu, MAX_PROCS, pid, process, process_state_runnable, process_state_running, process_state_waiting, processes, sc_handle_clock_read(), scheduler_current_process, scheduler_idle_if_needed(), process_t::state, state, and wait_reason_time.
Definition at line 221 of file scheduler.c.
References process_state_runnable, process_state_running, processes, schedule_next(), scheduler_current_process, and state.
Definition at line 334 of file scheduler.c.
References ALLOCATOR_REGION_DIRECT_MAPPING, ALLOCATOR_REGION_USER_STACK, logw, memset(), mm_alloc_pages(), name, processes, scheduler_current_process, process_t::stack, region_t::start, and vm_context_map().
Definition at line 164 of file scheduler.c.
References process_state_runnable, process_state_running, processes, scheduler_current_process, state, and VM_KERNEL_CONTEXT.
void scheduler_kill_current | ( | enum kill_reason | reason | ) |
Definition at line 261 of file scheduler.c.
References process_t::exit_code, logd, name, process_state_killed, processes, scheduler_current_process, scheduler_process_cleanup(), and process_t::state.
Map a given memory area in the currently running userspace process at a random location.
Definition at line 605 of file scheduler.c.
References region_t::end, process_t::hw, processes, scheduler_current_process, and vm_map_hardware().
void scheduler_process_cleanup | ( | pid_t | pid | ) |
Definition at line 232 of file scheduler.c.
References mq, process_t::mq, mq_destroy(), mq_push(), MT_Signal, mutex_unlock_holder(), process_t::parent, pid, process_state_empty, process_state_exited, process_state_killed, processes, Message::sender, SIGCHLD, Message::UserData::SignalUserData::signal, Message::UserData::Signal, size, Message::size, process_t::state, Message::type, Message::user_data, user_size, Message::user_size, vm_alloc(), and vm_free().
void scheduler_process_save | ( | cpu_state * | cpu | ) |
Definition at line 155 of file scheduler.c.
References memcpy(), process_state_running, process_state_waiting, processes, scheduler_current_process, and state.
void scheduler_wait_for | ( | pid_t | pid, |
enum wait_reason | reason, | ||
union wait_data | data | ||
) |
Definition at line 353 of file scheduler.c.
References pid, process_state_waiting, processes, scheduler_current_process, process_t::state, process_t::waiting_data, and process_t::waiting_for.
void scheduler_waitable_done | ( | enum wait_reason | reason, |
union wait_data | data, | ||
size_t | max_amount | ||
) |
Definition at line 363 of file scheduler.c.
References wait_data::condvar, MAX_PROCS, wait_data::message_queue, wait_data::mutex, mutex_lock(), pid, process_state_runnable, process_state_waiting, processes, scheduler_current_process, process_t::state, wait_reason_condvar, wait_reason_message, wait_reason_mutex, wait_reason_time, process_t::waiting_data, and process_t::waiting_for.
pid_t setup_process | ( | void | ) |
Definition at line 102 of file scheduler.c.
References ALLOCATOR_REGION_USER_HARDWARE, ALLOCATOR_REGION_USER_STACK, free_pid(), memset(), mq_create(), panic_message(), pid, process, process_alloc(), process_dealloc(), process_state_runnable, and processes.
void start_task | ( | struct vm_table * | context, |
ptr_t | entry, | ||
ptr_t | data_start, | ||
ptr_t | data_end, | ||
const char * | name | ||
) |
Definition at line 136 of file scheduler.c.
References ALLOCATOR_REGION_USER_STACK, data_end, entry, name, panic_message(), process_t::parent, pid, process, processes, setup_process(), and strncpy().
Definition at line 54 of file scheduler.c.
volatile pid_t scheduler_current_process = -1 |
Definition at line 50 of file scheduler.c.