[SDK] Fix double buffer data race (#394)

* Fix double buffer data race

- fixes relatively rare data race in double buffering scheme

In `rocprofiler::buffer::instance::emplace`, the `container::record_header_buffer::get_record_headers()` function returned a `std::vector<rocprofiler_record_header_t*>` and then invoked callback to tool. It was possible for that callback to still be executing while the buffer was being updated. This potentially introduced a scenario where the rocprofiler_record_header_t* was modified (or corrupted) before the tool processed the record. In rocprofv3, this would result in a "future" buffer record showing up among "past" buffer records. E.g., correlation id sequence of 1-15 where the buffer flushes after five values, could result in this during processing:
|     |     |     |     |      |
|:---:|:---:|:---:|:---:|:---:|
|  1 |  2 |  3 |  4 | 15 |
|  6 |  7 |  8 |  9 | 10 |
| 11 | 12 | 13 | 14 | 15 |

Because buffer A (of double buffering scheme) originally containing corr ids 1-5 stalled after process corr id 4 (e.g. write to disk), buffer B filled up with 6-10 and started flushing, causing a switch back to buffer A, and buffer A was filled with 11-15 by the time callback accessed what was originally corr id 5 but was now updated to corr id 15.

* Update CHANGELOG

* misc minor cleanup

---------

Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
Cette révision appartient à :
Madsen, Jonathan
2025-05-14 13:19:22 -05:00
révisé par GitHub
Parent 6ec9526475
révision 8a1ee46e47
8 fichiers modifiés avec 144 ajouts et 66 suppressions
+6 -1
Voir le fichier
@@ -212,6 +212,11 @@ TEST(buffering, parallel)
// wait for all the threads to complete
pthread_barrier_wait(&_emplaced_barrier);
// designates that buffer should be cleared after invoking functor
using clear_buffer_t = std::true_type;
// verify the data pulled out the buffer matches the data put in by the threads
validate(_buffer.get_record_headers(), test_data_types{}, test_data_sizes);
_buffer.process_record_headers(clear_buffer_t{}, [](auto&& _records) {
validate(_records, test_data_types{}, test_data_sizes);
});
}