PREVIOUS

Meters, Resources, and Charge Sets

Meters measure and control the quantity of resources that domains use. Meters may be used to prevent domains from proceeding. Cutting off a meter does not destroy data. The meter may be turned back on in such a way that affected domains restart from where they left off. Meters are organized into trees with the primordial meter at the root, domains at the leaves, and meters at the nodes of the tree.

A meter key is a specific type of key that designates a node. A meter is a node viewed through a meter key.

A node key may be used to obtain a meter key, which permits the node to be used as a meter. A meter key only allows the holder to use the node as a meter, or to create subsidiary meters.

Meter Hierarchies
Slot 1 of a meter node designates another meter node by a meter key. The first meter is said to depend on the second meter. If meter A depends on meter B, A is said to be inferior to B and to all meters to which B is inferior. Any resource measured by a meter is measured by the meter that it depends on (and by all meters to which it is inferior).

A domain which depends on a meter node causes the counters in that node to count the use of resources by the domain.

The primordial meter key is a valid level 0 meter key. B is a valid meter of level n+1 if:

In other words, a valid meter key must (among other things) point to the head of a chain of nodes, via slot 1 of those nodes, that leads to the primordial meter key. This chain may involve only meter keys and may have at most 20 keys.

Kinds of Resources
The counters in a meter node (each of which is a data key) are decremented as the resources are used. Programming note: When constructing meters, the data keys in slots 4 and 5 should be initialized with data keys that are all ones. This action will provide for compatibility with future versions of KeyKOS by preventing meter traps for these resources.

Meter Keepers
When the CPU time counter in a meter node is zero and a domain tries to decrement it, the counter remains zero and the key in slot 2 of that meter node is implicitly invoked. The key must be a gate key or the Error Key as described in the section in this chapter entitled, "How a Domain Invokes a Key".
Meter Format

Figure 2-7

Programming note: There is a programming convention for slot 14. When the CPU counter is zeroed to stop domains that depend on the meter, the old value of the counter is saved in Slot 14. This convention allows a single meter to be used for both measuring elapsed CPU time and for stopping the domains that depend on the meter.

Programming note: Whenever a domain's meter is invalid (malformed) the kernel causes the domain to trap to its domain keeper.

Charge Sets
A charge set is used to determine how many pages are referenced by domains running under one or more meters. Charge sets may be either active or inactive. Inactive charge sets have no pages in them. Active charge sets have zero or more pages and a 64-bit TOD value that is set whenever the charge set is activated.

When a domain, running under a meter that holds a a charge set key, references a page that is not already in the set, that page is added to the set. If the set was inactive it is activated and its TOD value is set to the current TOD value.

Implementations may arbitrarily inactivate a charge set when its space is needed or for other reasons.

NEXT