Skip to content

[Concurrency] Propagate Darwin vouchers across async tasks. #39115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2021

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented Aug 31, 2021

Darwin OSes support vouchers, which are key/value sets that can be adopted on a thread to influence its execution, or sent to another process. APIs like Dispatch propagate vouchers to worker threads when running async code. This change makes Swift Concurrency do the same.

The change consists of a few different parts:

  1. A set of shims (in VoucherShims.h) which provides declarations for the necessary calls when they're not available from the SDK, and stub implementations for non-Darwin platforms.
  2. One of Job's reserved fields is now used to store the voucher associated with a job.
  3. Jobs grab the current thread's voucher when they're created.
  4. A VoucherManager class manages adoption of vouchers when running a Job, and replacing vouchers in suspended tasks.
  5. A VoucherManager instance is maintained in ExecutionTrackingInfo, and is updated as necessary throughout a Job/Task's lifecycle.

rdar://76080222

@mikeash mikeash force-pushed the voucher-propagation branch from 9015584 to 6e22423 Compare September 1, 2021 21:01
@mikeash
Copy link
Contributor Author

mikeash commented Sep 1, 2021

Updated with naming feedback, less nasal-demon-y access to JobStorage's metadata, some refinement to the conditionals in VoucherShims.h, a more accurate declaration of voucher_t, and a switch to os_release.

@mikeash mikeash force-pushed the voucher-propagation branch from 6e22423 to c04c587 Compare September 2, 2021 16:15
Copy link

@das das left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm from an interaction with the OS voucher API perspective, thanks!

@mikeash
Copy link
Contributor Author

mikeash commented Sep 2, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Sep 2, 2021

Build failed
Swift Test Linux Platform
Git Sha - c04c5870a7116b490b4ac274ea3bd98b9388d5eb

@mikeash mikeash force-pushed the voucher-propagation branch from c04c587 to c6c3dc6 Compare September 2, 2021 17:50
@mikeash
Copy link
Contributor Author

mikeash commented Sep 2, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Sep 2, 2021

Build failed
Swift Test Linux Platform
Git Sha - c6c3dc675c4d8b845ebc887b51d5fcb3cf366bb6

@mikeash mikeash force-pushed the voucher-propagation branch from c6c3dc6 to c55c85b Compare September 2, 2021 18:19
@mikeash
Copy link
Contributor Author

mikeash commented Sep 2, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Sep 2, 2021

Build failed
Swift Test Linux Platform
Git Sha - c55c85b84de9f0dd7b2c3d666a83a030faf30a5d

@mikeash mikeash force-pushed the voucher-propagation branch from c55c85b to e35e05b Compare September 2, 2021 19:48
@mikeash
Copy link
Contributor Author

mikeash commented Sep 2, 2021

@swift-ci please test

Darwin OSes support vouchers, which are key/value sets that can be adopted on a thread to influence its execution, or sent to another process. APIs like Dispatch propagate vouchers to worker threads when running async code. This change makes Swift Concurrency do the same.

The change consists of a few different parts:

1. A set of shims (in VoucherShims.h) which provides declarations for the necessary calls when they're not available from the SDK, and stub implementations for non-Darwin platforms.
2. One of Job's reserved fields is now used to store the voucher associated with a job.
3. Jobs grab the current thread's voucher when they're created.
4. A VoucherManager class manages adoption of vouchers when running a Job, and replacing vouchers in suspended tasks.
5. A VoucherManager instance is maintained in ExecutionTrackingInfo, and is updated as necessary throughout a Job/Task's lifecycle.

rdar://76080222
@mikeash mikeash force-pushed the voucher-propagation branch from e35e05b to a80a19b Compare September 2, 2021 21:45
@mikeash
Copy link
Contributor Author

mikeash commented Sep 2, 2021

@swift-ci please test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants