This is an archive of the discontinued LLVM Phabricator instance.

[libc][NFC] Simplifly inbox and outbox state handling
ClosedPublic

Authored by jhuber6 on May 11 2023, 7:06 AM.

Details

Summary

Currently we use a template parameter called InvertInbox to invert the
inbox when we load it. This is more easily understood as a static check
on whether or not the process running it is the server. Inverting the
inbox makes the states 1 0 and 0 1 own the buffer, so it's easier to
simply say that the server own the buffer if in != out. Also clean up some of
the comments.

Diff Detail

Event Timeline

jhuber6 created this revision.May 11 2023, 7:06 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 11 2023, 7:06 AM
jhuber6 requested review of this revision.May 11 2023, 7:06 AM
JonChesterfield added a comment.EditedMay 11 2023, 8:35 AM

Different definitions of simple in play here.

If

  • one reasons in terms of the values in the underlying memory
  • focuses on the differences between client and server
  • prefers code duplication

Then this is a reasonable way to go.

The direction I'm trying to take this in is different.

  • move atomic ops and fences out of client/server
  • concurrency logic in process is the same for either instance
  • client/server only work with concepts libc cares about

That has the advantage that the code in process covers all the subtle concurrency hazards and can be tested in isolation, notably stress tested under thread sanitisers with both sides running on x64. It also means the libc send/recv stuff can evolve over time more easily as it doesn't have to worry about breaking the concurrency model.

It also has the advantage that inbox and outbox always mean exactly the same thing, on client or server or process, which I find far easier to reason about than keeping track of which is the root of a given function call.

I'm ok with not thinking about whether a given block of memory underlying a mailbox has particular numbers written into it, in exchange for thinking about the states the machine is in.

jhuber6 updated this revision to Diff 522260.May 15 2023, 10:42 AM

Update to make this more obvious that we are simply moving the inversion from
the load to the condition. The inversion affects the condition so it is more
intuitive for the condition itself to be inverted. That is !a == b is the same
as !(a == b).

JonChesterfield accepted this revision.May 16 2023, 9:43 AM

I'm not convinced. This means reasoning in terms of the values in memory instead of in the abstract state of a process. However the change is localised and easy to reverse if it interacts badly with future patches and you seem to be especially passionate about this.

This revision is now accepted and ready to land.May 16 2023, 9:43 AM
This revision was automatically updated to reflect the committed changes.