onlyonemac wrote:
I believe modulus to be a somewhat slow operation and you could replace instance where _secs is used with a call to get_secs(), which returns _ticks / 100.
It's worth a try.
The code for get_current_task() is one line, returning a pointer to the current task's struct:
Code: Select all
task_t *get_current_task()
{
return _task;
}
It is merely a convenience function. The code for get_next_runnable() is:
Code: Select all
task_t *get_next_runnable()
{
task_t *next = ready_queue;
/* Running queue is empty? run idle task */
if(!next) next = idle_task;
return next;
}
where read_queue is a linked list containing the ready-to-run processes.
onlyonemac wrote:
If I'm understanding your code correctly, that line is to prevent a crash if your scheduler isn't initialised yet. In that case, remove the line and only enable the timer once your scheduler has been initialised.
Hmmm. Sounds quite reasonable. I guess I actually don't need the timer before tasking is init'ed.
Code: Select all
if(current == idle_task && get_next_runnable() == idle_task) goto finish;
This was a desperate move, I was trying to check if there is no runnable task other than idle, so as to bypass the rest of the handler function and head out. It turned out it added nothing and still the processor is busy.
onlyonemac wrote:
What is current->time_left initialised to? Because that's how many ticks you're going to process before another task gets scheduled, and if that's too high for your idle task then your idle task isn't going to keep the CPU very idle.
Here is how I initialize timeslices for new processes (in order of timer ticks):
Code: Select all
void reset_task_timeslice(task_t *task)
{
switch(task->priority)
{
case PRIO_NORMAL: task->time_left = 20; break;
case PRIO_LO: task->time_left = 10; break;
case PRIO_HI: task->time_left = 50; break;
case PRIO_IDLE: task->time_left = 1; break;
case PRIO_ZOMBIE: task->time_left = 0; break;
default: task->time_left = 20; break;
}
}
The timeslice for the idle process is only 1, this shouldn't keep the processor busy, right?. But on the other hand, this means the scheduler will be called on each and every timer tick (if the idle task is the running task). This will add to the overhead of the timer handler and compound my problem further, right?