-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix RR scheduler and mutex/cond #36
base: master
Are you sure you want to change the base?
Changes from all commits
857107f
8a956fc
eabe264
a9c1003
f5d69e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,74 +7,61 @@ | |
static LIST_HEAD(rr_runq); | ||
extern struct thread_info *thread_idle; | ||
|
||
int sched_rr_init(void) | ||
int sched_rr_init(struct thread_info *thread) | ||
{ | ||
if (thread) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we initialize without checking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not check about |
||
sched_rr_enqueue(thread); | ||
return 0; | ||
} | ||
|
||
static struct thread_info *find_next_thread(struct thread_info *thread) | ||
static struct thread_info *find_next_thread(void) | ||
{ | ||
if (list_is_last(&thread->ti_q, &rr_runq)) | ||
return list_first_entry(&rr_runq, struct thread_info, ti_q); | ||
|
||
return list_next_entry(thread, ti_q); | ||
return list_first_entry(&rr_runq, struct thread_info, ti_q); | ||
} | ||
|
||
int sched_rr_enqueue(struct thread_info *thread) | ||
{ | ||
list_add(&thread->ti_q, &rr_runq); | ||
if (thread->ti_queued) | ||
return -1; | ||
|
||
list_add_tail(&thread->ti_q, &rr_runq); | ||
thread->ti_queued = 1; | ||
|
||
return 0; | ||
} | ||
|
||
int sched_rr_dequeue(struct thread_info *thread) | ||
{ | ||
CURRENT_THREAD_INFO(current); | ||
if (!thread->ti_queued) | ||
return -1; | ||
|
||
if (current == thread) { | ||
struct thread_info *next = thread_idle; | ||
if (!list_is_singular(&rr_runq)) { | ||
next = find_next_thread(current); | ||
} | ||
list_del(&thread->ti_q); | ||
thread_restore(next); // FIXME: rename to switch_to_no_save | ||
} else { | ||
list_del(&thread->ti_q); | ||
} | ||
list_del(&thread->ti_q); | ||
thread->ti_queued = 0; | ||
|
||
return 0; | ||
} | ||
|
||
/* This function is used when the runqueue has been modified externally, and it | ||
is not possible to fetch the next thread. */ | ||
static int sched_rr_elect_reset(void) | ||
void sched_rr_requeue(struct thread_info *thread) | ||
{ | ||
CURRENT_THREAD_INFO(current); | ||
struct thread_info *next = thread_idle; | ||
|
||
if (!list_empty(&rr_runq)) | ||
next = list_first_entry(&rr_runq, struct thread_info, ti_q); | ||
switch_to(next, current); | ||
|
||
return 0; | ||
sched_rr_dequeue(thread); | ||
sched_rr_enqueue(thread); | ||
} | ||
|
||
int sched_rr_elect(int switch_type) | ||
int sched_rr_elect(__unused int switch_type) | ||
{ | ||
CURRENT_THREAD_INFO(current); | ||
struct thread_info *next; | ||
|
||
if (switch_type & SCHED_OPT_RESET) | ||
return sched_rr_elect_reset(); | ||
|
||
if (list_empty(&rr_runq)) { | ||
// go to thread idle. | ||
next = thread_idle; | ||
} else { | ||
next = find_next_thread(current); | ||
switch_to(thread_idle, current); | ||
return -1; | ||
} | ||
|
||
/* keep running the previous thread */ | ||
/* XXX: Will RR stuck inside the loop? */ | ||
while ((next = find_next_thread()) == current && !list_is_singular(&rr_runq)) | ||
sched_rr_requeue(next); | ||
|
||
/* Shortcut if next is current */ | ||
if (next == current) | ||
return -1; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make scheduler pluggable as Linux does instead of configuring it at build time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible to change scheduler in runtime using
sched_select
for now. But this is an easy step for running test and debugging.