The entry scheduler
The source src/modules/demonstrations/scheduler built with the setting DRAWING_THROUGH_MODULE=true. The text after this paragraph is the comment of that source.
The scheduling strategies of the kernel, side by side. A measure run measures them. The design: Scheduling strategies.
The process runs its cases under each strategy: two threads that wake each other while spinners keep each processor busy; a thread that sleeps 2 ms, many times, while 8 spinners run, with the delay of each wake (a measure run only: the delay is a measure); 8 spinners of one weight, their shares and their work; 12 spinners with the weights 1, 2 and 4, their shares; 12 spinners that start with the full weight and get the weights 1, 2 and 4 while they run, their shares. Then it changes the strategy 100 times while threads start, stop, wake each other and move, and while a thread writes the schedule of the spinners. The window shows the numbers and the strategy in use; the keys 1, 2 and 3, or a click on a strategy, change it.
A case of the check ends after a count, never after a time. The two threads go on until the first one did its rounds and, under EEVDF, the kernel counted the stints that a wake ended. The spinners go on until the thread report says that each one ran SHARE_TICKS_CHECKED ticks: the shares are the work of each spinner in that interval. A measure run gives each case a fixed time, and writes the wakes in one second, the late wakes and the work in one second.
The process checks what does not depend on the load of the host: no spinner starved, a wake ended stints under EEVDF and none under round robin (the counts of the kernel; the wakes in one second are measures), the weights order the shares under the strategies with weights, each thread runs after the changes, no wake was lost, the kernel refuses a change with no right Schedule and a weight above the full weight. For the schedule of a live thread: a thread reads and writes its own schedule, the weights written through the machine handle order the shares, the kernel refuses each write that it must refuse, and writes during the changes of strategy lose no thread; the schedule of a thread of another process is read and written through the machine handle; a weight limit that the machine handle wrote holds against the writes of the thread and against its new threads; a write of the process never raises a weight or a request; the lag that the kernel reports for a held thread stays the same after a write of the process, and is 0 after a raise through the machine handle. For the placement of a thread on the processors (placement.odin): a thread narrows its own set and then runs only there; the kernel refuses each write that it must refuse; a limit that the machine handle wrote holds against the writes of the thread and against its new threads; a thread that waits, that a stop holds, that is in a list or that runs moves into a new set; two groups of spinners with no common processor never run on a processor of the other group; a queue of threads that a processor cannot take does not stop the balance; writes of placements during the changes of strategy lose no thread.
For a share of the processors for each process (share.odin): after a round of the share policy, each thread of four processes with 1, 2, 4 and 8 spinning threads has the full weight divided by the threads of its process; a thread that asked a smaller weight, or lowered itself, keeps it; a process that starts more threads has no more weight in all; the part of the process with 8 threads against the process with 1 is smaller with the policy than without it; when the policy goes off, each thread has its weight back.
The process needs the machine with the rights Inspect and Schedule.
What it is for. The kernel has three scheduling strategies (round robin, fair, EEVDF) and changes from one to another at run time. This process shows what each one gives on the same load, and checks what each one must keep, whatever the speed of the host.
Start: start("scheduler") in the console, or the bar of the desktop. Its budget has room for 24 threads: 12 spinners, two threads that wake each other, one that sleeps, a changer, a thread that writes schedules, and a thread that starts threads; then the 15 threads of the four processes of the shares, which it starts from the boot image.
The share policy. scheduler.policy(1) in the console, the key P or the button of the view of the shares turns it on: each process then has one process weight, which the process divides between the threads of that process, so a process with many threads takes no more of the processors than a process with one. scheduler.share("paint", 256) gives the processes with a name another process weight. The policy is off when the process starts. The two commands are served after the checks.
Grants, as the root service gives them:
- Inspect: the machine with the right Inspect, for the counts of the scheduler in the system report.
- Schedule: the right to change the strategy of the whole machine, and the weight and the request of any thread. A change touches every process, so this right is rare.
- Serve: the process is a service. Its export
strategy_setsets the strategy for a caller that holds no right over the machine: the console runs it asstrategy("eevdf"), and the palette of the desktop for the entry "set strategy to eevdf". The calls run after the checks, in the loop of the window. Its exportsshareandpolicyare commands of the console too. - Image: the boot image, to start the four processes of the shares from its own file.
What a reader sees: one tile for each strategy with its numbers, and the strategy in use. The key S, or the button after the tiles, opens the view of the shares: one row for each process, with its threads that count, its process weight, the weight of each thread, and its share of the processors in the last period as a bar. The log has one line of results for each strategy, then "scheduler: ok, no spinner starved under 3 strategies, ..." or "scheduler: wrong: ..." with the first problem, and the time to draw the window. At the end the process sets the strategy that was in use at its start.
What it does not prove: the wakes in one second and the shares are measures of this host, printed and not checked.
See: Scheduling strategies: The schedule of a live thread, Scheduling strategies: The placement of a thread, Scheduling strategies: A share for each process
scheduler module with an entry
- Hash
703ac2bf5b231fb4d045c1e67233b98b19afd6bc5360bb0dceae9e735416fd2b- Size
424555 bytes- Exports
3- Imports
1- Imported by
0- License
- MIT
The scheduling strategies of the kernel, side by side
| Fact | Value |
|---|---|
| Kind | Modules with an entry |
| Source | src/modules/demonstrations/scheduler |
| Boot image | yes: in the boot image, 424555 bytes in this build |
| Build settings |
|
| Imports | |
| Imported by | none |
Neighbours
What it imports, at its left, and what imports it, at its right: the part of the module graph that touches it.
Exports
| Export | What it does |
|---|---|
strategy_set(name: Text) -> Integer | sets the scheduling strategy of the whole machine, by its name |
entry() | The entry of scheduler: the checks of the refusals, the four cases under each strategy, the stress of the changes, then a window where a key or a click chooses the strategy |
share(name: Text, weight: Integer) -> Integer | sets the process weight of the processes with a name: the part of the processors that the share policy gives them, against the other processes |
policy(on: Integer) -> Integer | turns the share policy on or off |
strategy_set
strategy_set(name: ) ->
strategy_set sets the scheduling strategy of the whole machine, by its name. The result is the number of the strategy that the machine used before (1 round robin, 2 fair, 3 EEVDF).
The process scheduler holds the right Schedule on the machine; a caller holds none. The console calls this export for its command strategy, and the palette of the desktop for an entry such as "set strategy to eevdf". The process serves its calls after its checks, in the loop of its window: the checks change the strategy themselves.
- name:
round_robin,fairoreevdf; 16 bytes at most. The case of the letters does not count, and a space is the same as_.
The caller must act for the principal (Acts_For_Principal): the console has that grant. The process uses its own right for a caller, so it serves only a caller whose requests are those of the principal; the root service gives that grant, shows it and revokes it.
It fails with -1 and an error record, and the strategy does not change:
No_Grant: the caller does not act for the principal;Too_Long: the name has more than 16 bytes;Bad_Value: the name is no strategy;Refused: the kernel refused the change; the record holds its status. A caller that loads the module as a library gets this error: it holds no machine handle with the right Schedule.
Example: scheduler.strategy_set("fair").
name:
- When it fails
- a negative result, and the error record
src/modules/demonstrations/scheduler/main.odin:1872
entry
entry()
The entry of scheduler: the checks of the refusals, the four cases under each strategy, the stress of the changes, then a window where a key or a click chooses the strategy.
With no window it stops with Failed. A failed check does not stop it: fail keeps the first problem, and the result line says it. After the measures it gives the machine back the strategy of its start. Then it draws every 500 ms; the keys 1, 2 and 3, or a click on a tile, change the strategy of the machine, and a call of strategy_set does the same for a caller.
- Form
- The entry of the module: one parameter, an address, fixed by the contract.
src/modules/demonstrations/scheduler/main.odin:1922
share
share(name: , weight: ) ->
share sets the process weight of the processes with a name: the part of the processors that the share policy gives them, against the other processes.
The policy divides the process weight between the threads of the process that count, so a process with 8 threads and a process with 1 thread of the same process weight have the same weight in all. The setting holds for each process with that name, also one that starts later, until the process scheduler stops. It has an effect while the policy is on (policy), under the fair strategy and EEVDF: the round robin reads no weight.
- name: the name of the processes, 31 bytes at most.
- weight: the process weight, from 32 to 1024. 1024 is the weight of a process with no setting. A process has at most 32 threads, so 32 is the least weight that gives each thread a weight of 1 or more.
The result is the process weight that the name had. It fails with -1 and an error record, and no setting changes:
No_Grant: the caller does not act for the principal;Empty: the name has no byte;Too_Long: the name has more than 31 bytes;Too_Small: the weight is under 32;Bad_Value: the weight is above 1024;Full: 16 names have a setting.
Example: scheduler.share("paint", 256) gives the process paint a quarter of the weight of another process.
name:weight:
- When it fails
- a negative result, and the error record
src/modules/demonstrations/scheduler/share.odin:506
policy
policy(on: ) ->
policy turns the share policy on or off.
With the policy on, the process scheduler reads the threads of each process each 100 ms, and writes the weight of each thread: the process weight (share) divided by the count of the threads of the process that are ready or that ran since the last round. It never gives a thread more than its process asked. With the policy off, each thread gets back the weight that its process asked and the full weight limit. The policy is off when the process starts.
- on: 1 turns the policy on, 0 turns it off.
The result is 1 when the policy was on before the call, else 0. It fails with -1 and an error record:
Example: scheduler.policy(1).
on:
- When it fails
- a negative result, and the error record
src/modules/demonstrations/scheduler/share.odin:579
Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).
What the root service gives it
| What | Value | As the root service says |
|---|---|---|
| Grants | It reads the counts of the scheduler, changes the strategy and writes the weight of each thread (the share policy). It starts the four processes of its case of the shares from the boot image, and serves strategy_set(), share() and policy() to the console. | |
| Other terms of its start grant set | none | |
| Budget that it asks for |
| Threads: 12 spinners, two threads that wake each other, one that sleeps, a changer, a thread that starts threads; later, with its first thread, the 15 threads of the four processes of the shares, or 8 spinners of its own. Processes: itself and those four. The tool counts its module, a stack and a thread area for each of the 24 threads, and its window. The working memory: 512 for each of the four processes of the shares, its own tables, and the rest of the 5632 pages that it had before the tool counted: 3659 pages. And the glyph memory of the copy of the text rendering of the drawing module, which draws its text: 354 pages (display.TEXT_MEMORY_PAGES). 3659 + 354 = 4013. |
The start grant set is read from start_grant_sets in src/modules/system/root/start_grant_sets.odin. The stated budget is read from the constant MODULE_BUDGET of the source of the module (its line); the build adds the counted parts and writes the sum in the module (tools/modustool/build/budget_count.odin); the root service accepts it up to the largest budget of a process, and adds the limits of processor time and of log records (src/modules/system/root/budgets.odin).
Text wire form
A wire form of the module contract: one word of a call. The address of a slice record {address, count} of UTF-8 bytes.
Integer wire form
A wire form of the module contract: one word of a call. A signed integer of 64 bits, in a register.
Error_Record record of a module
A record of the module scheduler: 56 bytes, aligned on 8 bytes, 0 bytes of padding.
kindi6408 bytesuniti6488 bytesoperationi64168 bytesargumenti64248 bytesvaluei64328 byteslimiti64408 bytesfoundi64488 bytes
