A sampling log could lose most of its samples at close, and
pmcstat -R then read few or none, with no error.
- pmclog_close() wrote the close record before it queued the buffers of the other CPUs. Their samples came after the close record, where pmclog_read() stops.
- pmclog_stop_kthread() cleared PMC_PO_OWNS_LOGFILE before the helper wrote its queue. The helper exited, and pmclog_deconfigure_log() freed the queued buffers.
Queue all buffers, set PMC_PO_SHUTDOWN, queue again, and write the
close record last. After a close, let the helper write its queue
before it exits. Stop waiting after 500 ms without progress, e.g.
when nobody reads a pipe.
Add a test: write records on one CPU, close the log on another, and
check that no record follows the close record.
Sponsored by: AMD