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
/
fp_scheduler.c
96 lines (78 loc) · 1.95 KB
/
fp_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "basic.h"
#include "fp_scheduler.h"
#include "timer.h"
#include "debug.h"
#include "logger.h"
#include "timer_event.h"
typedef struct t_queue {
QUEUE que;
T_VCPU *vcpu;
} queue_t;
static queue_t _que[16];
static QUEUE_LIST _ls[MAX_PRIORITY];
static QUEUE_LIST _fl;
static void my_init(void) {
int i;
queue_list_init(&_fl);
for(i=0;i<sizeof(_que)/sizeof(_que[0]);i++){
queue_list_enque(&_fl, &(_que[i].que));
}
for(i=0;i<MAX_PRIORITY;i++){
queue_list_init(&_ls[i]);
}
}
static void *my_allocate(T_VCPU *vcpu){
if(queue_list_is_empty(&_fl)){
tv_error_message("# fp sched: canot allocate !");
return NULL;
}
queue_t *que = (queue_t *)queue_list_pop(&_fl);
que->vcpu = vcpu;
return que;
}
static T_VCPU *my_schedule(void){
int i;
int max_pri = MAX_PRIORITY;
T_VCPU *exe = vcpu_get_executing();
if(exe!=NULL){
max_pri = ((fp_sched_param_t *)exe->sched_param)->priority;
if(max_pri >= MAX_PRIORITY) max_pri = MAX_PRIORITY-1;
}
for(i=0;i<=max_pri;i++) if(!queue_list_is_empty(&_ls[i])){
queue_t *que = (queue_t *)queue_list_pop(&_ls[i]);
return que->vcpu;
}
if(exe==NULL){
//tv_error_message("no vcpu!\n");
}
return exe;
}
static void my_enque(T_VCPU *vcpu){
queue_t *que = (queue_t *)vcpu->sched_state;
int pri = ((fp_sched_param_t *)vcpu->sched_param)->priority;
if(pri>=MAX_PRIORITY) pri = MAX_PRIORITY-1;
queue_list_enque(&_ls[pri], (QUEUE *)que);
return;
}
static void my_block(T_VCPU *vcpu){
my_enque(vcpu);
scheduler_set_flag();
}
static void my_unblock(T_VCPU *vcpu){
if(vcpu->state==VCPU_STATE_SLEEP){
my_enque(vcpu);
scheduler_set_flag();
}
}
static void my_yield(void){
scheduler_set_flag();
}
schedule_operation_t fp_scheduler = {
my_init,
my_schedule,
my_yield,
my_block,
my_unblock,
my_allocate,
my_enque,
};