Crossing the kernel boundary Small writes, busy CPU Two encoders turn the same frame into the same bytes. One suddenly needs more processor time. Finn lays their output side by side and notices that every tiny metadata field is now written separately. One bounded buffer meant one kernel entry per frame in the reference version. The changed version makes sixty-four entries to send the same payload. The byte counter alone cannot show the repeated entry overhead. An application executes ordinary instructions directly on the processor. A privileged operation such as submitting device I O goes through a kernel entry point. Encoder in context A privileged operation such as submitting device input and output goes through a kernel entry point. The processor changes privilege, the kernel validates the arguments and eventually returns to the caller. A mode transition can take place on the same thread. A context switch means that a different execution context is scheduled. Switching tasks saves and restores execution state. Disrupted cache or translation locality can cost more than saving the registers. Compare switches per completed operation at equal load. A syscall enters privileged execution on behalf of the current thread. The thread can return directly without the scheduler choosing a different task. An interrupt can arrive asynchronously from a device. A synchronous exception is tied to the executing instruction. A page fault is one such exception and can be handled successfully. Imagine an encoder issuing a write for every small field in one frame. Each call crosses a privilege boundary and must validate arguments and the destination descriptor. On a ready buffer the calling thread can do the kernel work and return on the same processor. Seeing sixty-four calls is therefore different evidence from seeing sixty-four context switches. Count crossings for one video frame The driver maps the buffer for the device and supplies descriptors for the I O. The device moves data to or from mapped memory. The CPU can run other work during that transfer. A completion event tells the driver when the transfer has finished. Only reuse the buffer after the required completion and synchronization. Trace a small write twice. In one run there is immediately space in the output buffer, so the current thread returns directly. In another run the same call must wait for room and a different task gets scheduled. Both traces contain a system call. Only the second contains this particular sleep and task switch. Measure the entry and exit as well as scheduler events to distinguish the two paths. Read the measurements Build a comparison with equal frame count, equal bytes, and equal output requirements. Coalesce the fields into one buffer, measure entries and CPU per completed frame, then watch delivery delay. A queue that waits for more bytes can look wonderfully efficient while missing an interactive latency budget. Count entries per frame alongside frame size. If one variant processes a larger frame, bytes per entry may improve while total CPU per frame increases. Normalize by comparable output, and keep the latency of the first visible frame in view. A metric that only rewards batching can encourage holding work too long. Distinguish a syscall from a task switch If the thread enters the kernel sixty-four times, must the scheduler run another thread sixty-four times? A syscall can complete and return to the same running task. Sample syscall counts and task switches separately, normalized by equal completed frames. If both versions already issue one large write, look elsewhere for the CPU difference. If entries per frame remain constant, sample userspace encoding cost and compare bytes emitted. Check the competing explanation DMA lets a device transfer data to mapped memory. Zero-copy paths reduce data movement between software buffers. Page ownership, lifetimes and completion notifications still matter. A video encoder starts writing each metadata field separately. The new version spends more CPU per frame although it emits exactly the same bytes. Count kernel entries for equal-sized frames and compare CPU time on a matched core. A scheduler counter answers a different question because it measures changes of running task. Batch the writes and measure again A bounded batch brings the observed count to two entries per frame. On x eighty-six the kernel normally runs at ring zero and applications at ring three. The processor enforces privileged operations. Other architectures name their privilege levels differently. Finn checks frame latency as well as CPU cost, since waiting to fill a buffer can add delay. Count what crosses the boundary, then check what the user waited for. Apply the diagnosis Suppose entries fall but CPU per frame barely changes. Inspect the actual hot instructions next. Compression might dominate, or copies might still account for most time. Keep the privilege crossing on the drawing, then put the costs of validation, copying and scheduling on separate lines. Each line predicts a different benefit from batching.