# Unequal CPU sampling intervals need time weights

Reviewed 2026-11-25. This is a continuation of the existing 3L-Cache
measurement note, not a new cache benchmark or a correction to the paper.

## What is actually averaged?

For adjacent intervals with elapsed durations d_i and cumulative CPU-time
increments c_i, the interval-average core usage is u_i = c_i / d_i.
Total CPU time is sum(c_i), so whole-window average cores is

    sum(c_i) / sum(d_i) = sum(d_i * u_i) / sum(d_i).

A plain average of u_i answers a different question: the average over recorded
intervals, with every interval assigned equal weight. Multiplying that average
by total elapsed time only works in special cases, such as equal durations.
Polling delays, dropped polls and a short final interval can change weights.

Our constructed ledger consumes four CPU seconds in its first elapsed second,
then zero in the next nine. The correct total is four CPU seconds and the
whole-window average is 0.4 cores. Averaging the two interval rates gives two
cores; multiplying by ten seconds invents twenty CPU seconds. Splitting the
idle interval into four and five seconds changes that plain mean to 4/3 cores,
although the work and elapsed window are unchanged. These exact values are
generated in cpu-interval-examples.json, not observations from 3L-Cache.

The counter method does not assume uniform usage within each interval.
It integrates the *interval average* exactly relative to the supplied counters.
Instantaneous gauge samples are different: their integral requires an explicit
interpolation or sampling model and is not made exact by rational arithmetic.

## A percentage needs a denominator

The psutil API distinguishes process CPU percentage from host-wide percentage:
a multithreaded process may exceed 100%, while the host-wide value is normalized
across logical CPUs. They are not interchangeable. The first nonblocking CPU
percentage call has no previous sample and must not be treated as measured
idle time. Keep a baseline and the actual elapsed boundaries. These API facts
do not establish that the paper used psutil or made either mistake.

Official contract, accessed 2026-11-25:
https://psutil.readthedocs.io/stable/#psutil.Process.cpu_percent

The FAST 2025 paper defines overhead using CPU load and time in section 2.1.
Our derivation clarifies the averaging needed for such a quantity; it does not
reconstruct the authors' sampling schedule or invalidate their measurements.
Source: Wenbin Zhou, Zhixiong Niu, Yongqiang Xiong, Juan Fang and Qian Wang,
3L-Cache: Low Overhead and Precise Learning-based Eviction Policy for Caches,
FAST 2025, pp. 237-254.
https://www.usenix.org/system/files/fast25-zhou-wenbin.pdf

## Reproduction and limits

Run Python 3 without third-party packages:

    python3 -B cpu_intervals.py
    python3 -B -m unittest test_cpu_intervals.py
    python3 -B -O -m unittest test_cpu_intervals.py

summarize_intervals accepts ordered adjacent intervals from one stable scope
and counter epoch. It rejects gaps, overlap, duplicate time ranges, decreasing
counters, discontinuous shared boundaries, changed labels and noninteger
counters. Positive multicore usage and idle intervals are valid. It uses
constant auxiliary memory and exact fractions, without sorting the input.

An epoch identifies the same counter lifetime, not merely a reused process ID.
Labels cannot verify process membership or detect a hidden reset that has
already overtaken the previous value. Sparse cumulative endpoints can retain
total work while losing short-lived peaks. Timestamp/counter reads may not be
atomic; nanosecond units do not imply nanosecond accuracy. No confidence
interval, energy result, observed cache efficiency or real-system speedup is
claimed. Earlier native parent/child observations remain a separate experiment.
