This is an archive of the discontinued LLVM Phabricator instance.

[libc] Support suspending threads during RPC spin loops
ClosedPublic

Authored by jhuber6 on Mar 30 2023, 7:58 AM.

Details

Summary

The RPC interface relies on waiting on atomic signals to coordinate
which side of the protocol is in control of the shared buffer. The GPU client
supports briefly suspending the executing thread group. This is used by the
thread scheduler to identify which thread groups can be switched out so that
others may execute. This allows us to ensure that other threads get a chance
to make forward progress while these threads wait on the atomic signal.

This is currently only relevant on the client-side. We could use an
alternative implementation on the server that uses the standard
nanosleep on supported hosts.

Diff Detail

Event Timeline

jhuber6 created this revision.Mar 30 2023, 7:58 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 30 2023, 7:58 AM
jhuber6 requested review of this revision.Mar 30 2023, 7:58 AM
tianshilei1992 accepted this revision.Mar 30 2023, 8:00 AM

It looks like the two platforms are using different sleep duration? Other than that, LGTM.

This revision is now accepted and ready to land.Mar 30 2023, 8:00 AM

It looks like the two platforms are using different sleep duration? Other than that, LGTM.

The documentation is a little different. The AMDGCN implementation states that a value of 2 will sleep between 64 and 128 cycles so assuming a 2 GHz clock it'll sleep ~60 ns in the worst case. These numbers are just guesses, we could probably refine them. I think PCI(e) atomic access is in the order of microseconds.

jhuber6 edited the summary of this revision. (Show Details)Mar 30 2023, 8:06 AM
jhuber6 edited the summary of this revision. (Show Details)Mar 30 2023, 8:55 AM
JonChesterfield accepted this revision.Mar 30 2023, 9:26 AM

Thanks. Couple of nits above.

libc/src/__support/RPC/rpc.h
105–106

this probably gets rotated, might be better written do_while

sleep before or after load? the fence above probably takes time

libc/src/__support/RPC/rpc_util.h
21

probably worth leaving a comment here about how the magic numbers were chosen

This revision was automatically updated to reflect the committed changes.