Fix page-migration background thread on fork (#31)

* Fix page-migration background thread on fork

After falling off main in the forked child, all the children
try to join on on the parent's monitoring thread. This results
in a deadlock. Parent is waiting for the child to exit, but
the child is trying to join the parent's thread which is
signaled from the parent's static destructors.

Even with just one parent and child, due to copy-on-write
semantics, a child signalling the background thread to join
will still block (thread's updated state is not visible
in the child).

This fix creates background treads on fork per-child with a
pthread_atfork handler, ensuring that each child has its own
monitoring thread.

* Formatting fixes

* Detach page-migration background thread and update test timeout

* Attach files with ctest

* Update corr-id assert

* Tweak on-fork, simplify background thread

* Revert thread detach
Este commit está contenido en:
Kuricheti, Mythreya
2024-12-05 17:58:38 -08:00
cometido por GitHub
padre fc2513888f
commit e7d45624d0
Se han modificado 3 ficheros con 95 adiciones y 78 borrados
+7 -3
Ver fichero
@@ -28,7 +28,7 @@ set(page-migration-env
set_tests_properties(
test-page-migration-execute
PROPERTIES TIMEOUT
45
60
LABELS
"integration-tests"
ENVIRONMENT
@@ -38,7 +38,9 @@ set_tests_properties(
SKIP_REGULAR_EXPRESSION
"KFD does not support SVM event reporting"
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR})
${CMAKE_CURRENT_BINARY_DIR}
ATTACHED_FILES
${CMAKE_CURRENT_BINARY_DIR}/page-migration-test.json)
# copy to binary directory
rocprofiler_configure_pytest_files(COPY validate.py conftest.py CONFIG pytest.ini)
@@ -60,4 +62,6 @@ set_tests_properties(
SKIP_REGULAR_EXPRESSION
"KFD does not support SVM event reporting"
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR})
${CMAKE_CURRENT_BINARY_DIR}
ATTACHED_FILES
${CMAKE_CURRENT_BINARY_DIR}/page-migration-test.json)
+13 -6
Ver fichero
@@ -243,16 +243,23 @@ def test_retired_correlation_ids(input_data):
api_corr_ids = _sort_dict(api_corr_ids)
async_corr_ids = _sort_dict(async_corr_ids)
retired_corr_ids = _sort_dict(retired_corr_ids)
missing_corr_ids = {}
for cid, itr in async_corr_ids.items():
assert cid in retired_corr_ids.keys()
ts = retired_corr_ids[cid]["timestamp"]
assert (ts - itr["end_timestamp"]) > 0, f"correlation-id: {cid}, data: {itr}"
if cid not in retired_corr_ids.keys():
missing_corr_ids[cid] = itr
else:
ts = retired_corr_ids[cid]["timestamp"]
assert (ts - itr["end_timestamp"]) > 0, f"correlation-id: {cid}, data: {itr}"
for cid, itr in api_corr_ids.items():
assert cid in retired_corr_ids.keys()
ts = retired_corr_ids[cid]["timestamp"]
assert (ts - itr["end_timestamp"]) > 0, f"correlation-id: {cid}, data: {itr}"
if cid not in retired_corr_ids.keys():
missing_corr_ids[cid] = itr
else:
ts = retired_corr_ids[cid]["timestamp"]
assert (ts - itr["end_timestamp"]) > 0, f"correlation-id: {cid}, data: {itr}"
assert len(missing_corr_ids) == 0, f"{missing_corr_ids}"
assert len(api_corr_ids.keys()) == (len(retired_corr_ids.keys()))