This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP][FIX] Ensure exclusive access to the HDTT map
ClosedPublic

Authored by jdoerfert on Mar 5 2022, 1:50 PM.

Details

Summary

This patch solves two problems with the HostDataToTargetMap (HDTT
map) which caused races and crashes before:

  1. Any access to the HDTT map needs to be exclusive access. This was not the case for the "dump table" traversals that could collide with updates by other threads. The new Accessor and ProtectedObject wrappers will ensure we have a hard time introducing similar races in the future. Note that we could allow multiple concurrent read-accesses but that feature can be added to the Accessor API later.
  2. The elements of the HDTT map were HostDataToTargetTy objects which meant that they could be copied/moved/deleted as the map was changed. However, we sometimes kept pointers to these elements around after we gave up the map lock which caused potential races again. The new indirection through HostDataToTargetMapKeyTy will allows us to modify the map while keeping the (interesting part of the) entries valid. To offset potential cost we duplicate the ordering key of the entry which avoids an additional indirect lookup.

We should replace more objects with "protected objects" as we go.

Diff Detail

Event Timeline

jdoerfert created this revision.Mar 5 2022, 1:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2022, 1:50 PM
jdoerfert requested review of this revision.Mar 5 2022, 1:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2022, 1:50 PM
Herald added a subscriber: sstefan1. · View Herald Transcript
jdoerfert updated this revision to Diff 413254.Mar 5 2022, 2:28 PM

Rename argument

Only comments on the helper type for now. I like the idea of a generic wrap-this-thing-in-mutex helper as a path to stepping on the remaining race conditions.

openmp/libomptarget/include/ExclusiveAccess.h
36

I don't see a way to give this thing ownership of a resource after constructing it with DoNotGetAccess. Perhaps replace that Boolean flag with a default constructor that sets the pointer to null.

42

Do we have multiple threads waiting to gain access to this thing? If not, asserting that it wasn't locked to begin with might be helpful for catching errors at the call site.

62

Null dereference looks likely here. Maybe an assert to get friendlier notice on the mistake.

84

Not sure we need the move here, it's already an R value. Also not sure we need the && on the return type.

jdoerfert updated this revision to Diff 413314.Mar 6 2022, 2:53 PM
jdoerfert marked 4 inline comments as done.

Addressed review comments

openmp/libomptarget/include/ExclusiveAccess.h
42

We do have multiple threads in play or this entire thing would be reasonably useless ;)

84

Because we don't want to copy it.

I'm ooo for a couple of days, @tianshilei1992 could you take a look?

This revision is now accepted and ready to land.Mar 8 2022, 5:29 PM
This revision was landed with ongoing or failed builds.Mar 25 2022, 9:39 AM
This revision was automatically updated to reflect the committed changes.