mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
scheduler: continue work
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <kernel/proc.h>
|
||||
#include <kernel/thread.h>
|
||||
#include <util.h>
|
||||
#include <bitmap.h>
|
||||
|
||||
#define SCHED_WAKEUP_REASON_NORMAL 0
|
||||
@@ -13,8 +14,10 @@
|
||||
|
||||
#define SCHED_RUN_QUEUE_SIZE 32
|
||||
#define SCHED_MAX_INTERACTIVITY 100
|
||||
#define SCHED_INTERACTIVITY_LIMIT 30
|
||||
#define SCHED_NICE_MAX 19
|
||||
#define SCHED_NICE_MIN -20
|
||||
#define SCHED_SLEEP_TIME_LIMIT_CPU_US 1000
|
||||
|
||||
typedef struct {
|
||||
struct {
|
||||
@@ -53,5 +56,25 @@ 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);
|
||||
void sched_preempt_cpu(struct cpu_t *cpu);
|
||||
|
||||
static inline int sched_thread_run_queue_index(int interactivity) {
|
||||
return min(interactivity * SCHED_RUN_QUEUE_SIZE / SCHED_MAX_INTERACTIVITY, SCHED_RUN_QUEUE_SIZE - 1);
|
||||
}
|
||||
|
||||
static inline bool sched_thread_can_run_in_cpu(thread_t *thread, int cpu_queue, int cpu_interactivity) {
|
||||
int current_queue = 0;
|
||||
if (thread->class == THREAD_CLASS_TIMESHARE && thread->metrics.interactivity_score > SCHED_INTERACTIVITY_LIMIT)
|
||||
current_queue = 1;
|
||||
else if (thread->class == THREAD_CLASS_IDLE)
|
||||
current_queue = 2;
|
||||
|
||||
// if thread is timeshare, can only immediatelly run when cpu queue is running idle threads,
|
||||
if (current_queue == 1)
|
||||
return cpu_queue == 2;
|
||||
|
||||
// otherwise, realtime > idle and if a tie the index in the queue
|
||||
return current_queue < cpu_queue || sched_thread_run_queue_index(thread->metrics.interactivity_score) < sched_thread_run_queue_index(cpu_interactivity);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,6 +30,7 @@ typedef struct thread_t {
|
||||
struct proc_t *proc;
|
||||
struct cpu_t *cpu;
|
||||
struct cpu_t *cputarget;
|
||||
struct cpu_t *last_cpu;
|
||||
context_t context;
|
||||
extracontext_t extracontext;
|
||||
void *kernelstack;
|
||||
@@ -63,6 +64,7 @@ typedef struct thread_t {
|
||||
time_t run_time_avg_us;
|
||||
timespec_t sleep_start;
|
||||
timespec_t run_start;
|
||||
time_t last_sleep_duration_us;
|
||||
} metrics;
|
||||
} thread_t;
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ extern topology_node_t topology_root;
|
||||
|
||||
topology_node_t *topology_create_node(void);
|
||||
void topology_insert(topology_node_t *node, topology_node_t *parent, int id, cpu_t *cpu);
|
||||
cpu_t *topology_find_next_cpu_to_run(topology_node_t *last_cpu, thread_t *thread, time_t sleep_time);
|
||||
topology_node_t *topology_find_child_by_id(topology_node_t *node, int id);
|
||||
|
||||
static inline topology_node_t *topology_get_root(void) {
|
||||
return &topology_root;
|
||||
|
||||
@@ -53,10 +53,15 @@ typedef struct cpu_t {
|
||||
sched_run_queue_t rt_queue;
|
||||
sched_calendar_queue_t ts_queue;
|
||||
sched_run_queue_t idle_queue;
|
||||
int last_interactivity;
|
||||
int last_queue;
|
||||
size_t thread_count;
|
||||
spinlock_t sched_lock;
|
||||
|
||||
timerentry_t calendar_tick_timer_entry;
|
||||
|
||||
void *topology_node;
|
||||
|
||||
// architecture specific, does not need to be exposed
|
||||
|
||||
uint64_t gdt[7];
|
||||
|
||||
@@ -12,7 +12,7 @@ extern size_t arch_smp_cpusawake;
|
||||
extern cpu_t **smp_cpus;
|
||||
|
||||
void arch_smp_wakeup(void);
|
||||
void arch_smp_sendipi(cpu_t *targcpu, isr_t *isr, int target, bool nmi);
|
||||
void arch_smp_send_ipi(cpu_t *targcpu, isr_t *isr, int target, bool nmi);
|
||||
void arch_smp_haltallothers(void);
|
||||
size_t arch_smp_get_cpu_count(void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user