82 lines
1.6 KiB
C
82 lines
1.6 KiB
C
#include <socks/object.h>
|
|
#include <socks/sched.h>
|
|
#include <socks/cpu.h>
|
|
#include <socks/printk.h>
|
|
|
|
extern kern_status_t setup_kernel_task(void);
|
|
extern kern_status_t task_object_type_init(void);
|
|
extern kern_status_t thread_object_type_init(void);
|
|
|
|
static cycles_t __default_quantum = 0;
|
|
|
|
kern_status_t sched_init(void)
|
|
{
|
|
kern_status_t status = KERN_OK;
|
|
|
|
status = task_object_type_init();
|
|
if (status != KERN_OK) {
|
|
return status;
|
|
}
|
|
|
|
status = thread_object_type_init();
|
|
if (status != KERN_OK) {
|
|
return status;
|
|
}
|
|
|
|
status = setup_kernel_task();
|
|
if (status != KERN_OK) {
|
|
return status;
|
|
}
|
|
|
|
struct thread *this_thread = QUEUE_CONTAINER(struct thread, tr_threads, queue_first(&kernel_task()->t_threads));
|
|
|
|
struct cpu_data *this_cpu = get_this_cpu();
|
|
runqueue_init(&this_cpu->c_rq);
|
|
this_cpu->c_current_thread = this_thread;
|
|
put_cpu(this_cpu);
|
|
|
|
start_charge_period();
|
|
|
|
return status;
|
|
}
|
|
|
|
void start_charge_period(void)
|
|
{
|
|
struct thread *self = current_thread();
|
|
if (!self) {
|
|
return;
|
|
}
|
|
|
|
self->tr_charge_period_start = get_cycles();
|
|
}
|
|
|
|
void end_charge_period(void)
|
|
{
|
|
preempt_disable();
|
|
struct thread *self = current_thread();
|
|
if (!self) {
|
|
return;
|
|
}
|
|
|
|
cycles_t end = get_cycles();
|
|
preempt_enable();
|
|
|
|
cycles_t charge = cycles_diff(self->tr_charge_period_start, end);
|
|
|
|
self->tr_quantum_cycles += charge;
|
|
self->tr_total_cycles += charge;
|
|
|
|
if (self->tr_quantum_cycles >= self->tr_quantum_target) {
|
|
self->tr_flags |= THREAD_F_NEED_RESCHED;
|
|
}
|
|
|
|
self->tr_charge_period_start = 0;
|
|
|
|
//printk("%llu cycles charged to %s/%u", charge, self->tr_parent->t_name, self->tr_parent->t_id);
|
|
}
|
|
|
|
cycles_t default_quantum(void)
|
|
{
|
|
return __default_quantum;
|
|
}
|