# CPU cost needs a measured boundary

Review date: 2026-11-25. Continuation of issue #7632.

## What the paper says

3L-Cache defines overhead as CPU load multiplied by time in section 2.1,
and describes simulator stress replay separately from HTTP-prototype
monitoring in section 5.1. A later plotting helper is not the complete
measurement method. The existing isolated artifact review does not
invalidate or reproduce the original paper's CPU measurements.

Source: Zhou et al., FAST 2025, pp. 237-254, sections 2.1, 5.1 and 5.3.
https://www.usenix.org/system/files/fast25-zhou-wenbin.pdf

## Exact counter arithmetic

Let n be completed requests, t elapsed seconds and c the CPU seconds charged
to the declared scope over the same work. Then q = n/t, mean CPU cores
u = c/t, and CPU seconds per request = c/n. For equal work:

    c_candidate / c_baseline
      = (t_candidate / t_baseline) * (u_candidate / u_baseline)

This is accounting, not a causal model. In a constructed case, 1,000 requests
take 10 elapsed and 10 CPU seconds for the baseline, but 5 elapsed and
20 CPU seconds for the candidate. The candidate is twice as fast in elapsed
time while consuming twice the CPU time. Its mean usage is four cores,
not a fraction that must be clamped to one. Another constructed candidate
can match baseline throughput while using half its CPU time.

cpu_accounting.py calculates directly from integer completed-work and time
counters; it does not round through QPS or infer absent CPU counters.
Its counter units are nanoseconds, not a precision guarantee. An observed
zero baseline CPU counter makes the ratio undefined, reported as null
with an explicit status. It is not replaced by infinity or an invented epsilon.
A zero candidate counter yields a zero counter ratio, not proof of free work.
Matching workload/scope labels is necessary within this helper but cannot
verify instrumentation, warm-up, worker inclusion, equivalent requests,
hardware, frequency, quota, or co-tenancy. These remain external evidence.

The helper is original Hesela code. cpu-examples.json is synthetic arithmetic,
not a model of 3L-Cache, an estimate from the paper, or a confidence interval.
Eight tests include 4,096 exact raw-counter controls, invalid inputs,
zero resolution, multicore accounting and large integer precision.

## A real process-boundary observation

probe_cpu_scope.py launches only its own bounded worker and waits for it,
three times. Each worker checks a fixed sum-of-squares calculation.
The parent records elapsed and process clocks, plus before/after resource
counters for itself and waited children. The worker separately records its
inner loop. cpu-observation.json is captured from this run, not invented data.

Python's process_time measures user plus system CPU time of the current
process and excludes sleeping time. perf_counter includes elapsed sleep.
getrusage(RUSAGE_SELF) covers the calling process's threads; RUSAGE_CHILDREN
covers terminated children that have been waited for. It is not a live
worker-tree counter. The parent CPU clock therefore cannot substitute for
the worker accounting. A harness reaping unrelated children would also
contaminate an aggregate child-counter delta.

The worker's inner interval excludes interpreter startup and shutdown.
Waited-child usage covers its lifetime; parent readings are not simultaneous.
Float resource counters and integer clocks have different resolution.
Do not require bit-identical timings, exact equality of the counters,
or a fixed parent/child ratio. The three observations diagnose this local
measurement boundary; they establish no general performance distribution,
CPU efficiency, energy saving, or cache-policy ranking.

Official contracts, accessed 2026-11-25:
- https://docs.python.org/3.12/library/time.html#time.process_time
- https://docs.python.org/3.12/library/time.html#time.perf_counter
- https://docs.python.org/3.12/library/resource.html#resource.getrusage

## Reproduce

Run the packet tests with Python 3, without extra packages:

    python3 -B -m unittest discover -s . -p 'test_*.py'
    python3 -B cpu_accounting.py
    python3 -B probe_cpu_scope.py

The final command requires Unix resource accounting and spawns a local worker
with a 15-second timeout. Repeated observations should retain their own date,
runtime and source digest. Do not overwrite the retained publication observation
during an ordinary deterministic example regeneration.
