Hi, thanks for the answers.
Brendan, with respect to the second case, i'm using a semaphores to unlock the threads locked for IO (in my kernel, threads blocked by semaphores has priority and more likely to be executed).
About the threads have a very short amount of CPU time, I do not know if this can be considered a problem, just like to distribute better the CPU time between threads.
Since we're talking about timers and task switch, has another thing I would ask about priorities. Several kernel projects using a time scheme. Ex.:
Code: Select all
// Thread initialization
THREAD.time = 20;
...
// Thread scheduler
CURRENT_THREAD.time--;
if (CURRENT_THREAD.time <= 0)
{
// ... TASK_SWITCH ...
}
This seems to work, but there seems to be something I say "fast". On each IRQ timer, the CPU push to stack the registers and jump to the handler of the timer. If it is not yet time for a task switch, the CPU pop registers of the stack and return to the same point where it stopped.
In this case, much time is wasted with push and pop of the registers, and call the timer handler unnecessarily (after all, is not it time for a task switch, then all that CPU time was wasted).
I thought in my kernel to implement a priority scheme based on number of TIMES that a thread would be executed, and not a TIME. For example, I have three threads (T1 = 1, T2 = 1, T3 = 2). In this case, the thread of priority 2 would run more 2x than a thread of the priority 1:
Code: Select all
+----------+
| Thread 3 |
+----------+
| Thread 1 |
+----------+
| Thread 3 |
+----------+
| Thread 2 |
+----------+
| Thread 3 |
+----------+
| Thread 1 |
+----------+
.
.
.
Although this system has a serious problem, if there are only one thread at a priority type, all have the same timeslice. It's just an initial idea... I would like suggestions about this or another priority scheme.
Bye