Matt Macy d9f1b8dbf2 hwpmc: Refactor sample ring buffer handling to fix races
Refactor sample ring buffer ring handling to make it more robust to
long running callchain collection handling

r338112 introduced a (now fixed) regression that exposed a number of race
conditions within the management of the sample buffers. This
simplifies the handling and moves the decision to overwrite a
callchain sample that has taken too long out of the NMI in to the
hardlock handler. With this change the problem no longer shows up as a
ring corruption but as the code spending all of its time in callchain
collection.

- Makes the producer / consumer index incrementing monotonic, making it
  easier (for me at least) to reason about.
- Moves the decision to overwrite a sample from NMI context to interrupt
  context where we can enforce serialization.
- Puts a time limit on waiting to collect a user callchain - putting a
  bound on head-of-line blocking causing samples to be dropped
- Removes the flush routine which was previously needed to purge
  dangling references to the pmc from the sample buffers but now is only
  a source of a race condition on unload.

Previously one could lock up or crash HEAD by running:
pmcstat -S inst_retired.any_p -T and then hitting ^C

After this change it is no longer possible.

PR:	231793
Reviewed by:	markj@
Approved by:	re (gjb@)
Differential Revision:	https://reviews.freebsd.org/D17011
2018-10-05 05:55:56 +00:00
..
2018-03-27 15:20:03 +00:00
2018-02-12 17:42:28 +00:00
2018-07-03 01:55:09 +00:00
2017-12-13 16:13:17 +00:00
2018-06-13 16:48:07 +00:00
2018-02-20 00:06:07 +00:00
2018-02-06 19:14:15 +00:00
2018-08-23 05:06:16 +00:00
2018-06-10 19:15:38 +00:00
2017-12-28 14:26:33 +00:00
2017-11-30 20:33:45 +00:00
2017-12-13 16:13:17 +00:00
2017-12-13 16:13:17 +00:00
2017-12-13 16:13:17 +00:00
2018-03-20 15:51:05 +00:00
2017-12-13 16:30:39 +00:00
2017-12-13 16:30:39 +00:00
2018-03-02 22:13:29 +00:00
2018-03-27 15:20:03 +00:00
2018-08-04 20:45:43 +00:00
2017-12-13 16:13:17 +00:00
2018-05-07 23:36:16 +00:00
2018-07-25 00:18:21 +00:00
2018-05-11 00:01:43 +00:00
2018-01-05 22:26:23 +00:00
2017-12-13 16:13:17 +00:00
2018-07-30 15:46:40 +00:00
2017-11-30 20:33:45 +00:00
2018-03-27 15:20:03 +00:00
2018-08-03 01:37:00 +00:00
2018-01-03 00:56:30 +00:00
2017-12-13 16:13:17 +00:00