Commit Graph

1608 Commits

Author SHA1 Message Date
Rokhini Prabhu
ac4fab89f1 Priority escalation support when actors run into contention
Radar-Id: rdar://problem/86100521
2022-02-16 10:22:18 -08:00
Rokhini Prabhu
b318f651c0 Track the identity of the task draining the actor in the
ActiveActorStatus

Radar-Id: rdar://problem/86100521
2022-02-16 10:22:17 -08:00
Rokhini Prabhu
4c736b0507 Create the notion of an ActiveActorStatus which captures the atomic
state of the actor similar to the ActiveTaskStatus. Refactor the default
actor runtime implementation to set us up for priority escalation
support

Radar-Id: rdar://problem/86100521
2022-02-16 10:21:40 -08:00
John McCall
84c74941dc Make with*Continuation inherit the caller's executor.
Not inheriting the caller's executor is a major problem for
these functions.  Under SE-0338, treating them as non-isolated
means that it's illegal to pass them anytthing non-Sendable
from a different isolation context; since the function is
declared to take a non-sendable function parameter, effectively,
SE-0338 means that these functions can only be safely called
from non-isolated contexts.  That's not really acceptable, but
it gets worse: since we haven't implemented the sendability
rule for that yet, we're immediately bypassing isolation safety
when using these functions with no warning.

The `withCheckedContinuation` functions are not
`@_alwaysEmitIntoClient` (an oversight in the initial release),
and so we need to use the unsafe attribute on them.  When we
eventually implement a safe mechanism for this, we should make
`@_alwaysEmitIntoClient` variants of these functions which use
the new feature, and we can demote the existing functions to
`internal @availableFromInline`.

I've gone ahead and made `withChecked*Continuation` `@inlinable`.
2022-02-14 20:46:03 -05:00
Alex Martini
4d99516174 Merge pull request #41309 from amartini51/typo_80335638
Match verb to its subject.
2022-02-11 11:41:59 -08:00
Rokhini Prabhu
a5fa349f88 Merge pull request #41281 from apple/rokhinip/88600541-task-priority-escalation-arm64_32
Task Escalation support on arm64_32 Apple platforms
2022-02-10 17:02:38 -08:00
Rokhini Prabhu
6beb11ed7d Rename flagAsEnqueuedOnExecutor to flagAsAndEnqueueOnExecutor to reflect
what it actually does.

Radar-Id: rdar://problem/88600541
2022-02-10 11:50:31 -08:00
Rokhini Prabhu
98a8bdbd38 Task Escalation support on arm64_32 Apple platforms
Radar-Id: rdar://problem/88600541
2022-02-10 11:50:31 -08:00
Mike Ash
8c61e4c063 Merge pull request #41210 from mikeash/clear-async-slab-metadatas
[Concurrency] Clear Slab's fake metadata pointer before freeing it.
2022-02-10 10:48:43 -05:00
Arnold Schwaighofer
e2bd75d622 Merge pull request #41304 from apple/rokhinip/88700717-workaround
Workaround clang backend bug
2022-02-10 06:51:17 -08:00
swift-ci
cddb08ab2c Merge pull request #40631 from sjavora/checked-continuation-docs-fix 2022-02-10 03:56:54 -08:00
swift-ci
24674d102b Merge pull request #41181 from ktoso/wip-dont-store-tasks 2022-02-09 21:30:53 -08:00
Konrad `ktoso` Malawski
083afff45a Update stdlib/public/Concurrency/Task.swift
Co-authored-by: Alex Martini <amartini@apple.com>
2022-02-10 10:54:16 +09:00
Alex Martini
4ad006e35c Match verb to its subject. 2022-02-09 17:22:52 -08:00
Rokhini Prabhu
c07aa9c425 PR #41088 triggered a machine verifier failure in optimized mode for
arm64 causing Actor.cpp to fail to compile. Workaround this bug (88700717) for now.
2022-02-09 15:47:49 -08:00
Kuba (Brecka) Mracek
a395db680a [Concurrency] Avoid #include-ing dlfcn.h when not available (#41276) 2022-02-09 09:41:04 -08:00
Kuba (Brecka) Mracek
ffb1cacac3 [Concurrency] Avoid using asl_log when not available (#41277) 2022-02-09 09:40:53 -08:00
Kuba (Brecka) Mracek
c54dccbeff [Concurrency] Move debug-only pthread code into the debug-only #ifdef (#41278) 2022-02-09 09:40:39 -08:00
Kuba (Brecka) Mracek
c2581aef76 Use the SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT macro guard in magic-symbols-for-install-name.c (#41280) 2022-02-09 09:40:08 -08:00
Mike Ash
1020a1a9c8 [Concurrency] Clear Slab's fake metadata pointer before freeing it.
This helps ensure that memory analysis tools don't get confused by leftover metadata pointers in reallocated memory that hasn't been initialized yet.

rdar://88494373
2022-02-09 11:41:32 -05:00
Rokhini Prabhu
d77edf6cd9 Merge pull request #41088 from apple/rokhinip/76127624-task-priority-escalation
Task Priority Escalation
2022-02-08 10:00:55 -08:00
Rokhini Prabhu
66d4af0b01 Task priority escalation on Apple platforms
A task can be in one of 4 states over its lifetime:

    (a) suspended
    (b) enqueued
    (c) running
    (d) completed

This change provides priority inversion avoidance support if a task gets
escalated when it is in state (a), (c), (d).

Radar-Id: rdar://problem/76127624
2022-02-07 16:34:46 -08:00
Rokhini Prabhu
519e60c43e Allow concurrent modifications to the ActiveTaskStatus while another
thread has the task status record lock.

Today, if a thread is holding the StatusRecordLock, then no other
modification of the task status is possible - including a thread
starting to execute the task or stopping execution of the task.
However, the TaskStatusRecordLock is really about protecting the linked
list that is maintained in the ActiveTaskStatus. As such, other
operations which don't need to look at that linked list of us records
really shouldn't have to block on the StatusRecordLock.

This change allows for concurrent modification of the veTaskStatus while
the TaskStatusRecordLock is held. In particular, a task can cancelled,
escalated, start and stop running, all while another ad is holding onto
the task's StatusRecordLock. In the event of cancellation and
escalation, the task's StatusRecordLock must be n in order to propagate
cancellation and escalation to its child tasks is not needed to cancel
or escalate the task itself.

Radar-Id: rdar://problem/76127624
2022-02-07 16:34:46 -08:00
Rokhini Prabhu
ff10907a8e Change ActiveTaskStatus layout in order to be able to track the identity
of the thread that is executing the task.

Radar-Id: rdar://problem/76127624
2022-02-07 16:34:46 -08:00
Mike Ash
4eb26ae952 [Concurrency] Fix two cases where tasks were signposted with %p.
Task pointers are not very useful for sigpost consumers. Send them task IDs instead, which are unique during a run. We mostly do this, but missed two places where we were still sending pointers.
2022-02-07 16:57:55 -05:00
Rokhini Prabhu
90bf37784c NFC: Rename isLocked to isStatusRecordLocked to more explicitly
distinguish from the drain lock of the task that will be added next

Radar-Id: rdar://problem/76127624
2022-02-04 13:45:40 -08:00
Mike Ash
bd434d4a56 Merge pull request #41160 from mikeash/swift-inspect-concurrency
[RemoteMirror][swift-inspect] Add a command to inspect the state of the concurrency runtime.
2022-02-04 12:41:20 -05:00
Mike Ash
a82ea120a4 [RemoteMirror][swift-inspect] Add a command to inspect the state of the concurrency runtime.
Most of the new inspection logic is in Remote Mirror. New code in swift-inspect calls the new Remote Mirror functions and formats the resulting information for display.

Specific Remote Mirror changes:

* Add a call to check if a given metadata is an actor.
* Add calls to get information about actors and tasks.
* Add a `readObj` call to MemoryReader that combines the read and the cast, greatly simplifying code chasing pointers in the remote process.
* Add a generalized facility to the C shims that can allocate a temporary object that remains valid until at least the next call, which is used to return various temporary arrays from the new calls. Remove the existing `lastString` and `lastChunks` member variables in favor of this new facility.

Swift-inspect changes:

* Add a new dump-concurrency command.
* Add a new `ConcurrencyDumper.swift` file with the implementation. The dumper needs to do some additional work with the results from Remote Mirror to build up the task tree and this keeps it all organized.
* Extend `Inspector` to query the target's threads and fetch each thread's current task.

Concurrency runtime changes:

* Add `_swift_concurrency_debug` variables pointing to the various future adapters. Remote Mirror uses these to provide a better view of a tasks's resume pointer.

rdar://85231338
2022-02-04 09:28:32 -05:00
Konrad `ktoso` Malawski
6691dcff81 Update stdlib/public/Concurrency/Task.swift
Co-authored-by: Kavon Farvardin <kfarvardin@apple.com>
2022-02-04 06:57:19 +09:00
Konrad `ktoso` Malawski
259c37c4ca [Concurrency] Fix docs which suggested outdated patterns; can't store "current" task safely 2022-02-03 20:57:37 +09:00
Ole Begemann
b32ae80e0c Remove Task.CancellationError in doc comments
Task.CancellationError has been renamed to CancellationError. Fix two doc comments that still used the old name.
2022-01-30 20:17:36 +01:00
Karoy Lorentey
61268aa259 [stdlib] Define placeholder version numbers for SwiftStdlib 5.7
Also update existing declarations with SwiftStdlib 9999 availability to use the 5.7 name.
2022-01-27 14:41:07 -08:00
Pavel Yaskevich
ac875d00f0 Merge pull request #40947 from xedin/generic-dist-funcs
[Distributed] Augment accessor to support calling generic distributed thunks
2022-01-25 22:51:23 -08:00
Pavel Yaskevich
624b27257a [Distributed] Move some of the swift_distributed_* accessors to a dedicated file
Add a new `DistributedActor.cpp` and move some of the logic related to
swift_distributed_execute_target there to avoid exporting it from Concurrency.
2022-01-24 18:22:37 -08:00
Pavel Yaskevich
59ff689f28 [Distributed] IRGen: Teach distributed thunk accessor to load witness tables (when needed) 2022-01-24 10:18:00 -08:00
Pavel Yaskevich
406af83329 [Distributed] Runtime/IRGen: Allow passing substitutions to distributed accessor
Accept an optional list of substitutions which are required to form
a call to a generic distributed thunk.
2022-01-24 10:18:00 -08:00
Pavel Yaskevich
925b59826d [Distributed] IRGen: Drop result type for accessor parameters 2022-01-24 10:18:00 -08:00
Pavel Yaskevich
e7ceddc564 [Distributed] IRGen: Provide argument/result types to the accessor 2022-01-24 10:17:59 -08:00
Pavel Yaskevich
d54e3294c3 [Distributed] Runtime: Implement a way to access generic env of distributed target 2022-01-24 10:17:59 -08:00
Rokhini Prabhu
a2a5c64d4b Change task's base and escalated priority propagation rules for
detached, unstructured and structured concurrency child tasks

Radar-Id: rdar://problem/86100376
2022-01-24 07:50:28 -08:00
Rokhini Prabhu
9df1c9a135 Track base priority separately from max priority whereby base priority
is set at creation time. Create a new API for accessing this state

Radar-Id: rdar://problem/86100376
2022-01-24 07:50:27 -08:00
Rokhini Prabhu
6d5c7b5797 NFC: Rename priority set during task creation to be RequestedPriority
Radar-Id: rdar://problem/86100376
2022-01-21 12:12:12 -08:00
Rokhini Prabhu
8f2ac188fb Make sure that currentPriority actually reads the max QoS in the active
task status instead of the Job priority which is not necessarily in sync

Radar-Id: rdar://problem/86100376
2022-01-21 12:12:12 -08:00
Mike Ash
17ac26903d [Concurrency] Adjust the task allocator slab size to 984 bytes.
A slab capacity of 1000 bytes was overflowing the 1024 byte malloc bucket when adding in the slab header. Adjust it down to 984 bytes. Calculate this by subtracting the slab header size from 1024, plus a little slop for malloc stack logging, to ensure we don't overflow the bucket again.

rdar://87612288
2022-01-19 16:50:15 -05:00
Max Desiatov
372ada0e24 test: add handling for Wasm/WASI (#39519)
This change adds support for WASI in stdlib tests. Some tests that expect a crash to happen had to be disabled, since there's currently no way to observe such crash from a WASI host.
2022-01-12 14:24:50 +00:00
Pavel Yaskevich
680698e099 [Distributed] Fix _executeDistributedFunction resume and result buffer (#40814)
* [Distributed] Adjust interface of `swift_distributed_execute_target`

Since this is a special function, `calleeContext` doesn't point to
a direct parent but instead both parent context (uninitialized)
and resume function are passed as last arguments which means that
`callContext` has to act as an intermediate context in call to accessor.

* [Distributed] Drop optionality from result buffer in `_executeDistributedTarget`

`RawPointer?` is lowered into a two arguments since it's a struct,
to make it easy let's just allocate an empty pointer for `Void` result.

* [Distributed] NFC: Update _remoteCall test-case to check multiple different result types
2022-01-12 23:18:40 +09:00
Rokhini Prabhu
a4fe57f230 Merge pull request #40606 from apple/rokhinip/86347801-task-creation-escalation-race
Resolve race between task creation and concurrent escalation and cancellation.
2022-01-12 12:14:09 +08:00
Mike Ash
e9356928d6 Merge pull request #40070 from mikeash/concurrency-tracing
[Concurrency] Add tracing for major operations in the concurrency runtime.
2022-01-11 14:42:45 -05:00
Saleem Abdulrasool
7972139464 Merge pull request #40740 from compnerd/unsupported
Concurrency: avoid unnecessary dependency on LLVMSupport
2022-01-10 08:31:20 -08:00
Konrad `ktoso` Malawski
9438cf6b2e [Distributed] Func metadata operations and implement executeDistributedTarget entry (#40605)
* [Distributed] Implement func metadata and executeDistributedTarget

dont expose new entrypoints

able to get all the way to calling _execute

* [Distributed] reimplement distributed get type info impls

* [Distributed] comment out distributed_actor_remoteCall for now

* [Distributed] disable test on linux for now
2022-01-09 23:55:06 +09:00