modus
Menu
On this page

The entry budget

The source src/modules/demonstrations/budget built with the setting DRAWING_THROUGH_MODULE=true. The text after this paragraph is the comment of that source.

A demonstration of budgets: a process holds only what it was given, and each resource has a limit.

No operation creates an object from nothing: a budget pays for each memory object, each process and each thread. The root service gave this process a budget. The process creates objects until the kernel refuses, then frees them: each page returns. Then it takes a part of its budget for a new budget, and closes it: what the new budget held returns, and this budget pays for the objects that live.

What it is for. It shows that memory is supplied by the caller: a budget is a handle that pays for each page, each process and each thread, and the kernel refuses with No_Budget, never with a hidden allocation, when it cannot pay. It also shows that a process can split its budget, and that a closed budget gives back what it held.

What a reader sees. Start it from the start menu, or with start("budget") in the console. The window has one row for each step, with its answer: the pages of the budget from the root service; memory objects of 64 pages until No_Budget, then all of them closed; threads until No_Budget; a part of the budget given to a new budget, then that budget closed. The log gets budget: ok, <count> memory objects then no budget, <count> threads then no budget, each page returned, or budget: wrong answer: ... for a step that gave another answer.

Its grants: none. Its budget from the root service holds 1280 pages, 1 process and 4 threads: the limits that the steps reach.

budget module with an entry

Hash
3310a3f0d5ea73d81deebf74458409fa065fec4976073e15da3fa226aba7eb2a
Size
149015 bytes
Exports
0
Imports
1
Imported by
0
License
MIT

A demonstration of budgets: a process holds only what it was given, and each resource has a limit

FactValue
KindModules with an entry
Sourcesrc/modules/demonstrations/budget
Boot imageyes: in the boot image, 149015 bytes in this build
Build settings
  • DRAWING_THROUGH_MODULE=true
Imports
Imported bynone

Neighbours

What it imports, at its left, and what imports it, at its right: the part of the module graph that touches it.

budget drawing

Exports

ExportWhat it does
entry()runs each step of the demonstration once, writes the summary line, then keeps the window open until the process is stopped

entry

entry()

entry runs each step of the demonstration once, writes the summary line, then keeps the window open until the process is stopped. Each step checks its answer against the budget that it read before (system.budget_read): the count of objects that the pages pay for, the pages left, and each page back after the close. With no window, it stops with Failed.

Form
The entry of the module: one parameter, an address, fixed by the contract.
Source
src/modules/demonstrations/budget/main.odin:109

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

WhatValueAs the root service says
GrantsnoneThe budget of its own children.
Other terms of its start grant setnone
Budget that it asks for
  • working memory pages 952
  • pages of its threads 129
  • pages of the pictures of its window 2008
  • pages of the module and its imports from the files of the build
  • processes 1
  • threads 4
The pages that its cases spend: 598. 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). 598 + 354 = 952.

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).

Error_Record struct

A struct of the package errors: 56 bytes, aligned on 8 bytes, 0 bytes of padding. The error record: what a call that failed says about why, as seven integers.

  • kindi6408 bytes
  • uniti6488 bytes
  • operationi64168 bytes
  • argumenti64248 bytes
  • valuei64328 bytes
  • limiti64408 bytes
  • foundi64488 bytes

budget_read procedure of the package system

budget_read :: proc "contextless" (budget: Handle = 0, error: ^errors. = nil) -> (amounts: Budget_Amounts, status: Status)

budget_read gives what a budget (0: the budget of this process) can still pay.

src/library/modus/system/system.odin:417