notes

time: measuring a command that holds no clock

The shell's second prefix word (milestone 86), after caps. time wc report.txt runs the command exactly as typed and says how long it took. The program is components/src/swish/, the arithmetic and every sentence are crates/swish, and the guest tests are kernel::user::time_tests.

$ time wc report.txt
       3      12      67
  time: real 4.213 ms

The one thing worth understanding: whose clock it is

The shell's. time reads a clock capability the shell was granted at boot, times the command around its own dispatch, and hands the command nothing. So wc, whose entire endowment is one endpoint and which has never been able to ask what time it is, gets timed anyway.

That is the Unix behavior, and it is also the capability-model answer, which is why the two agree here rather than needing a trade. A program does not consent to being timed and cannot tell that it is. A duration is observable to anybody who can watch a thing start and stop, and the shell is that observer by construction, because it is what started the thing and what noticed it finish.

The alternative was delegating a clock to the child, and it is rejected rather than deferred. It would make time a grant: time wc report.txt would run a differently endowed wc from the one wc report.txt runs. That breaks the property the whole command rests on, and it would put a readable clock in the hands of every program anybody thought to time. The design/decisions/ section for this is the integrator's to mint at merge (CLAUDE.md: a lane does not claim a number global to the tree); until it exists the argument is here and in design/roadmap/0086-time-command.md.

The consequence in the wiring is one bit. The shell holds the clock page with READ and not GRANT, so it can read the time and cannot hand a clock to anything it spawns. Which processes can read the time is still decided by the manifests the progenitor reads (Manifest::clock, today date and nothing else); the shell's own reading authority does not widen that set by one. caps prints the row, with the rights, because a reader who saw "clock" in that table and assumed it could be passed on would be wrong about the one thing the table exists to answer:

$ caps
  this shell holds, and nothing else:
    cap 0  endpoint  terminal   read lines, write text
    ...
    cap 5  frame     clock      READ only, NOT delegable: 'time' measures with
                                it and no command can be handed it

What you time is what you run

The tail of time is a whole command line, operators included, and the shell re-dispatches it through dispatch, the same function the prompt calls. So time date | wc times the pipeline, time echo hello times a builtin that spawns no process at all, and a line that would have been refused is refused identically.

This is caps's shape one milestone later, including the ordering bug behind it: swish::route answers both prefix words before it splits the line on its operators. Otherwise the tail would arrive as the single word date with everything after the pipe silently gone. One function, two arms, one host test each.

caps time <command> previews the command itself, for the same reason: time moves no authority, so the preview must be identical to the untimed one. The host test asserts equality of the whole table, not a substring, because "identical" is the claim.

What the number means, and three things it is not

It is wall clock, between the shell deciding to run the line and the line being over. The resolution is the ambient counter's (16 ns on the aarch64 board at 62.5 MHz, 100 ns on the RISC-V one at 10 MHz). real is Unix's word for it and it is the honest one.

It is not CPU time. There is no user row and no sys row, because nothing in this kernel is asked what a thread spent: that is the scheduler's knowledge and it is unqueried today. If it arrives it is another row printed by this command, not a rival command. Saying so at the prompt (the help line says "WALL clock, not CPU") is cheaper than a person inferring it from a number.

It is not a benchmark. os_primitives_benchmarker and script/bench measure spawn latency properly, with repetition and a stated methodology (notes/benchmarks.md). time measures one run of one line and includes the shell's own planning, spawning and draining, because there is no other vantage point from which the question has an answer.

It is not a promise that the clock stood still. A wall clock can be stepped by an authority the shell does not hold. The shell reads clock_contract's generation at both ends, and when it changed it says so rather than printing a number it cannot stand behind:

  time: real 4.213 ms
  time: the wall clock was stepped while that ran, so this is what the clock
        says elapsed rather than what did

The subtraction is saturating for the same reason: a backwards step would otherwise wrap a u64 into something enormous.

The refusals, two of which are date's

A shell that cannot read a clock does not run the command. time is a request to measure, and running the line unmeasured while saying nothing would be DECISIONS ยง42's silent degradation with a stopwatch on it; running it while complaining would leave a person unable to tell which half happened. So the refusal is at the prompt, before anything is spawned, like every other refusal in this shell.

time: name a command to time: time <command>
time: the time is unknown: this shell holds no clock capability
time: the time is unknown: the machine has no clock it believes

The last two are date's sentences with the name changed, deliberately (notes/date.md). They are the same two facts about the same page and they call for the same two fixes: nobody granted this process a clock, or the machine never learned the time. A person who has met one has met the other.

The probe for the first cannot read the page, which is date's finding applied unchanged: a process granted no clock has nothing mapped where a clock would be, so a read there would fault instead of answering. It invokes the capability with a method number no object type defines, and a refusal from an object is proof one is there.

The wiring, and the slot that moves

The progenitor grants the shell the clock last, after the filesystem pair, so a boot with no disk attached takes exactly the path it took before this existed. That means the slot is 4 on a boot with no filesystem and 5 on a boot with one, and the shell is told the number in x2 at _start rather than assuming it.

This was written twice when milestone 86 landed, once in each of the two inits, because milestone 96 had not merged yet. It is written once now, in crates/system_initializer, and the frame it hands over is BootEndowment::clock_page: the same capability the kernel granted the progenitor, handed on with READ and no GRANT. There is deliberately no second endowment field for the shell's copy, because the shell's clock is not a separate kernel grant. A field would ask each board to state the same slot number twice with nothing checking that the two agree.

Being told is the same shape as arg1 carrying the directory's rights (notes/shell-navigation.md), and here the argument is sharper. Nothing in this system reports what a process holds, and a shell that probed the wrong slot would find some other object and map a page that is not a clock. Zero means "no clock", which is unambiguous because slot 0 is the terminal in every wiring.

The page is mapped at 0x00d0_0000, which is not date's 0x00c0_0000: that address is where a child maps its clock, and the shell already has the terminal's output frame there. Two address spaces may agree on an address; one may not.

What the tests prove

Host (crates/swish, crates/grant_plan), in milliseconds and with no machine:

Guest (kernel::user::time_tests), one script run three times against three capability tables:

At a real prompt (script/swish-check, both ISAs), because only that gate runs the real inits: time wc gate.txt answers the same three numbers wc gate.txt answered, time date prints a time: real line, and caps shows the clock row with its rights. A boot where the progenitor never handed the shell a clock passes every guest test and fails here.

BUGS

Named here rather than in a tracker, next to the feature.