This repository has been archived by the owner on Jan 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
my_scheduler.c
79 lines (66 loc) · 1.52 KB
/
my_scheduler.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "vcpu.h"
#include "schedule.h"
#include "timer.h"
#include "logger.h"
#include "debug.h"
#include "port.h"
#include "gic.h"
#include "my_scheduler.h"
#include "timer_event.h"
#include "vcpu.h"
typedef struct t_queue {
QUEUE que;
T_VCPU *vcpu;
} queue_t;
static queue_t _que[16];
static QUEUE_LIST _wque;
static QUEUE_LIST _fque;
static void my_init(void) {
int i;
queue_list_init(&_wque);
queue_list_init(&_fque);
for(i=0;i<16;i++){
queue_list_enque(&_fque, &(_que[i].que));
}
}
static void *my_allocate(T_VCPU *vcpu){
if(queue_list_is_empty(&_fque)){
tv_abort("# canot allocate !");
return NULL;
}
queue_t *ret = (queue_t *)queue_list_pop(&_fque);
ret->vcpu = vcpu;
return ret;
}
static void my_enque(T_VCPU *vcpu){
queue_list_enque(&_wque, (QUEUE *)vcpu->sched_state);
if(vcpu_get_executing()==NULL) scheduler_set_flag();
}
static T_VCPU *my_schedule(void) {
if(queue_list_is_empty(&_wque)){
return vcpu_get_executing();
}
T_VCPU *ret = ((queue_t *)queue_list_pop(&_wque))->vcpu;
return ret;
}
static void my_yield(void){
scheduler_set_flag();
}
static void my_block(T_VCPU *vcpu){
my_enque(vcpu);
}
static void my_unblock(T_VCPU *vcpu){
if(vcpu->state==VCPU_STATE_SLEEP){
my_enque(vcpu);
if(vcpu_get_executing()==NULL) scheduler_set_flag();
}
}
schedule_operation_t my_scheduler = {
my_init,
my_schedule,
my_yield,
my_block,
my_unblock,
my_allocate,
my_enque,
};