Skip to content

Commit

Permalink
sched: Clarify init and policy selection routine
Browse files Browse the repository at this point in the history
`sched_select()` explicitly work as a scheduler initialization routine.
It does the following tasks 1) select scheduler policy 2) initialize
relative scheduler structure for specified policy. However, we seperate
it into two funcs. The one is `sched_init()` and the other one is still
`sched_select`.

It would also meet the expected behavior within `start_kernel`. We expect
a function to initialize the scheduler relative structure and then select
the specified policy via `sched_select()`. `start_kernel()`.

closed #43
  • Loading branch information
iankuan committed Oct 19, 2017
1 parent c3b0bef commit 1d1a84a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/kernel/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct sched {
int (*elect)(int switch_type);
};

int sched_init();
int sched_select(int sched_type);
int sched_enqueue(struct thread_info *thread);
int sched_dequeue(struct thread_info *thread);
Expand Down
4 changes: 3 additions & 1 deletion kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ struct thread_info *start_kernel(void)
show_page_bitmap(); // init_pages();
kmem_cache_init();

/* select a scheduling policy */
/* initialize the scheduler internels */
sched_init();
/* select giving scheduling policy */
sched_select(SCHED_CLASS_BITMAP);

/* idle_thread is not added to the runqueue */
Expand Down
12 changes: 11 additions & 1 deletion kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ extern const struct sched sched_bitmap;

static const struct sched *sched;

int sched_init()
{
int ret;

ret = sched_rr.init();
ret = sched_bitmap.init();

return ret;
}

int sched_select(int sched_type)
{
switch (sched_type) {
Expand All @@ -19,7 +29,7 @@ int sched_select(int sched_type)
return -1;
}

return sched->init();
return 0;
}

int sched_enqueue(struct thread_info *thread)
Expand Down

0 comments on commit 1d1a84a

Please sign in to comment.