| 50 | | }}} |
| | 55 | == Phase 2 == |
| | 56 | |
| | 57 | Kaya OS provides a system call which offers to the caller the |
| | 58 | possibility to wait until the next pseudo-clock tick. This clock |
| | 59 | wakes up sleeping process every 100 milliseconds. |
| | 60 | The best way to make this clock accurate is to use the interval |
| | 61 | timer, which is therefore used in two different manners. So we |
| | 62 | had to distinguish between the pseudo-clock use and the classic |
| | 63 | preemption trigger use. Moreover we had to guarantee the |
| | 64 | accuracy of length of time-quantum assigned to scheduled |
| | 65 | processes. The answer to both issues is a time-credit system. |
| | 66 | [[BR]] |
| | 67 | Time credits, as you can easily see, solves the problem about |
| | 68 | time slices. And the problem about the distinction of |
| | 69 | interval-timer uses, too. If there are some credits, it means |
| | 70 | that the current process was dispatched for a time lesser than |
| | 71 | the quantum that was assigned by the scheduler. The dispatcher |
| | 72 | is conscious of time-credit system and restores time losses. |
| | 73 | |
| | 74 | There is another situation where our implementation differs from |
| | 75 | the expected one. The classic implementation of |
| | 76 | '''semaphores''', need a value adjustment when terminating a |
| | 77 | waiting process. Instead of this, we opted to change the value |
| | 78 | only if needed, that means the `passeren()` subtracts only if |
| | 79 | non-blocking and the `verhogen()` adds only when no process is |
| | 80 | blocked. |
| | 81 | There are several little optimization limiting wastes of cpu |
| | 82 | time and memory usage. They do not deserve a deep explanation |
| | 83 | but they must be mentioned: |
| | 84 | * '''Direct passup''': external exception-handlers (loaded by |
| | 85 | internal ones) returns the control directly to the process |
| | 86 | which raised the exception. |
| | 87 | * '''Iterative `TERMTHREAD`''': process termination means |
| | 88 | termination of its progeny. Instead of a recursive call, we |
| | 89 | preferred to first breadth-visit the whole sub-tree and then |
| | 90 | kill generation after generation.... muahuahuahuah! |
| | 91 | <pedice>Search for the mortuary among the code.</pedice> |
| | 92 | * '''Exception handler functions''': An unexpected benefit of |
| | 93 | modularization avoided exceptions raising after errors or |
| | 94 | abnormal situations. We opted for a direct function-call |
| | 95 | strategy, which clearly minimizes the over-head caused by |
| | 96 | these recursion, reducing the number of context switches. |
| | 97 | * '''Idle''': thumbs twiddling it is implemented without waste |
| | 98 | a whole process control block. A dummy-loop function is more |
| | 99 | than enough, so we automagically set the interval timer up in |
| | 100 | order to ring when it is time to pseudo-tick. |