scheduler: continue rework

This commit is contained in:
Matheus
2025-08-20 22:00:25 -03:00
parent 5098c09f26
commit 136c86354c
26 changed files with 348 additions and 154 deletions
+16
View File
@@ -0,0 +1,16 @@
#ifndef _BITMAP_H
#define _BITMAP_H
#include <stddef.h>
typedef struct {
long *data;
size_t size;
} bitmap_t;
int bitmap_init(bitmap_t *bitmap, size_t size);
void bitmap_set(bitmap_t *bitmap, long idx, int v);
long bitmap_find_first_set(bitmap_t *bitmap, long start_offset);
#endif
-1
View File
@@ -79,7 +79,6 @@ typedef struct proc_t {
} timer;
} proc_t;
#include <arch/cpu.h>
#define UMASK(mode) ((mode) & ~current_thread()->proc->umask)
#define PROC_HOLD(v) __atomic_add_fetch(&(v)->refcount, 1, __ATOMIC_SEQ_CST)
+25
View File
@@ -3,6 +3,7 @@
#include <kernel/proc.h>
#include <kernel/thread.h>
#include <bitmap.h>
#define SCHED_WAKEUP_REASON_NORMAL 0
#define SCHED_WAKEUP_REASON_INTERRUPTED -1
@@ -10,6 +11,27 @@
#define STACK_TOP (void *)0x0000800000000000
#define INTERP_BASE (void *)0x00000beef0000000
#define SCHED_RUN_QUEUE_SIZE 32
#define SCHED_MAX_INTERACTIVITY 100
typedef struct {
struct {
thread_t *ins;
thread_t *run;
} queues[SCHED_RUN_QUEUE_SIZE];
bitmap_t thread_bitmap;
} sched_run_queue_t;
typedef struct {
thread_t *queues[SCHED_RUN_QUEUE_SIZE];
int ins;
int run;
size_t thread_count;
} sched_calendar_queue_t;
extern bitmap_t sched_idle_cpu_bitmap;
extern spinlock_t sched_idle_cpu_bitmap_lock;
void sched_init();
void sched_ap_entry();
@@ -27,4 +49,7 @@ void sched_thread_running_callback(thread_t *thread);
void sched_thread_stopping_callback(thread_t *thread, bool sleeping);
void sched_thread_wakeup_callback(thread_t *thread);
thread_t *sched_select_next_thread(void);
void sched_insert_in_cpu_queue(struct cpu_t *cpu, thread_t *thread);
#endif
+5
View File
@@ -16,6 +16,10 @@
struct proc_t;
#define THREAD_CLASS_TIMESHARE 0
#define THREAD_CLASS_REAL_TIME 1
#define THREAD_CLASS_IDLE 2
typedef struct thread_t {
void *kernelstacktop;
struct thread_t *next;
@@ -40,6 +44,7 @@ typedef struct thread_t {
bool shouldexit;
void *kernelarg;
context_t *usercopyctx;
int class;
struct {
spinlock_t lock;
eventheader_t waitpendingevent;
+10 -1
View File
@@ -24,7 +24,8 @@ typedef struct cpu_t {
vmmcontext_t *vmmctx; // expected to be here by other code
long id; // expected to be here by other code
long hardware_id; // expected to be here by other code
long internal_id;
timekeeper_source_t *timekeeper_source;
timekeeper_source_info_t *timekeeper_source_info;
@@ -49,6 +50,14 @@ typedef struct cpu_t {
dpc_t reschedule_dpc;
isr_t *reschedule_isr;
sched_run_queue_t rt_queue;
sched_calendar_queue_t ts_queue;
sched_run_queue_t idle_queue;
spinlock_t sched_lock;
long calendar_ticks;
timerentry_t calendar_tick_timer_entry;
// architecture specific, does not need to be exposed
uint64_t gdt[7];
+3 -2
View File
@@ -11,8 +11,9 @@
extern size_t arch_smp_cpusawake;
extern cpu_t **smp_cpus;
void arch_smp_wakeup();
void arch_smp_wakeup(void);
void arch_smp_sendipi(cpu_t *targcpu, isr_t *isr, int target, bool nmi);
void arch_smp_haltallothers();
void arch_smp_haltallothers(void);
size_t arch_smp_get_cpu_count(void);
#endif