@@ -1047,6 +1047,7 @@ static void swift_task_cancelImpl(AsyncTask *task) {
1047
1047
1048
1048
// / Perform any escalation actions required by the given record.
1049
1049
static void performEscalationAction (TaskStatusRecord *record,
1050
+ JobPriority oldPriority,
1050
1051
JobPriority newPriority) {
1051
1052
switch (record->getKind ()) {
1052
1053
// Child tasks need to be recursively escalated.
@@ -1067,15 +1068,17 @@ static void performEscalationAction(TaskStatusRecord *record,
1067
1068
case TaskStatusRecordKind::EscalationNotification: {
1068
1069
auto notification =
1069
1070
cast<EscalationNotificationStatusRecord>(record);
1070
- notification->run (newPriority);
1071
+ SWIFT_TASK_DEBUG_LOG (" [Dependency] Trigger task escalation handler record %p, escalate from %#x to %#x" ,
1072
+ record, oldPriority, newPriority);
1073
+ notification->run (oldPriority, newPriority);
1071
1074
return ;
1072
1075
}
1073
1076
1074
1077
case TaskStatusRecordKind::TaskDependency: {
1075
1078
auto dependencyRecord = cast<TaskDependencyStatusRecord>(record);
1076
- SWIFT_TASK_DEBUG_LOG (" [Dependency] Escalating a task dependency record %p to %#x" ,
1077
- record, newPriority);
1078
- dependencyRecord->performEscalationAction (newPriority);
1079
+ SWIFT_TASK_DEBUG_LOG (" [Dependency] Escalating a task dependency record %p from %#x to %#x" ,
1080
+ record, oldPriority, newPriority);
1081
+ dependencyRecord->performEscalationAction (oldPriority, newPriority);
1079
1082
return ;
1080
1083
}
1081
1084
@@ -1101,17 +1104,17 @@ static void performEscalationAction(TaskStatusRecord *record,
1101
1104
SWIFT_CC (swift)
1102
1105
JobPriority
1103
1106
static swift_task_escalateImpl(AsyncTask *task, JobPriority newPriority) {
1104
-
1105
1107
SWIFT_TASK_DEBUG_LOG (" Escalating %p to %#zx priority" , task, newPriority);
1106
1108
auto oldStatus = task->_private ()._status ().load (std::memory_order_relaxed);
1109
+ auto oldPriority = oldStatus.getStoredPriority ();
1107
1110
auto newStatus = oldStatus;
1108
1111
1109
1112
while (true ) {
1110
1113
// Fast path: check that the stored priority is already at least
1111
1114
// as high as the desired priority.
1112
- if (oldStatus. getStoredPriority () >= newPriority) {
1113
- SWIFT_TASK_DEBUG_LOG (" Task is already at %#zx priority" , oldStatus. getStoredPriority () );
1114
- return oldStatus. getStoredPriority () ;
1115
+ if (oldPriority >= newPriority) {
1116
+ SWIFT_TASK_DEBUG_LOG (" Task is already at %#zx priority" , oldPriority );
1117
+ return oldPriority ;
1115
1118
}
1116
1119
1117
1120
if (oldStatus.isRunning () || oldStatus.isEnqueued ()) {
@@ -1145,8 +1148,11 @@ static swift_task_escalateImpl(AsyncTask *task, JobPriority newPriority) {
1145
1148
taskStatus = (ActiveTaskStatus *) &task->_private ()._status ();
1146
1149
executionLock = (dispatch_lock_t *) ((char *)taskStatus + ActiveTaskStatus::executionLockOffset ());
1147
1150
1148
- SWIFT_TASK_DEBUG_LOG (" [Override] Escalating %p which is running on %#x to %#x" , task, newStatus.currentExecutionLockOwner (), newPriority);
1149
- swift_dispatch_lock_override_start_with_debounce (executionLock, newStatus.currentExecutionLockOwner (), (qos_class_t ) newPriority);
1151
+ SWIFT_TASK_DEBUG_LOG (" [Override] Escalating %p which is running on %#x from %#x to %#x" ,
1152
+ task, newStatus.currentExecutionLockOwner (),
1153
+ oldPriority, newPriority);
1154
+ swift_dispatch_lock_override_start_with_debounce (
1155
+ executionLock, newStatus.currentExecutionLockOwner (), (qos_class_t ) newPriority);
1150
1156
#endif
1151
1157
} else if (newStatus.isEnqueued ()) {
1152
1158
// Task is not running, it's enqueued somewhere waiting to be run
@@ -1165,22 +1171,24 @@ static swift_task_escalateImpl(AsyncTask *task, JobPriority newPriority) {
1165
1171
return newStatus.getStoredPriority ();
1166
1172
}
1167
1173
1168
- SWIFT_TASK_DEBUG_LOG (" [Override] Escalating %p which is suspended to %#x" , task, newPriority);
1174
+ SWIFT_TASK_DEBUG_LOG (" [Override] Escalating %p which is suspended from %#x to %#x" ,
1175
+ task, oldPriority, newPriority);
1169
1176
// We must have at least one record - the task dependency one.
1170
1177
assert (newStatus.getInnermostRecord () != NULL );
1171
1178
1172
1179
withStatusRecordLock (task, newStatus, [&](ActiveTaskStatus status) {
1173
1180
// We know that none of the escalation actions will recursively
1174
1181
// modify the task status record list by adding or removing task records
1175
1182
for (auto cur: status.records ()) {
1176
- performEscalationAction (cur, newPriority);
1183
+ performEscalationAction (cur, oldPriority, newPriority);
1177
1184
}
1178
1185
});
1179
1186
1180
1187
return newStatus.getStoredPriority ();
1181
1188
}
1182
1189
1183
- void TaskDependencyStatusRecord::performEscalationAction (JobPriority newPriority) {
1190
+ void TaskDependencyStatusRecord::performEscalationAction (
1191
+ JobPriority oldPriority, JobPriority newPriority) {
1184
1192
switch (this ->DependencyKind ) {
1185
1193
case WaitingOnTask:
1186
1194
SWIFT_TASK_DEBUG_LOG (" [Dependency] Escalate dependent task %p noted in %p record" ,
@@ -1202,8 +1210,8 @@ void TaskDependencyStatusRecord::performEscalationAction(JobPriority newPriority
1202
1210
this ->DependentOn .TaskGroup , this );
1203
1211
break ;
1204
1212
case EnqueuedOnExecutor:
1205
- SWIFT_TASK_DEBUG_LOG (" [Dependency] Escalate dependent executor %p noted in %p record" ,
1206
- this ->DependentOn .Executor , this );
1213
+ SWIFT_TASK_DEBUG_LOG (" [Dependency] Escalate dependent executor %p noted in %p record from %#x to %#x " ,
1214
+ this ->DependentOn .Executor , this , oldPriority, newPriority );
1207
1215
swift_executor_escalate (this ->DependentOn .Executor , this ->WaitingTask , newPriority);
1208
1216
break ;
1209
1217
}
0 commit comments