@@ -1047,6 +1047,7 @@ static void swift_task_cancelImpl(AsyncTask *task) {
10471047
10481048// / Perform any escalation actions required by the given record.
10491049static void performEscalationAction (TaskStatusRecord *record,
1050+ JobPriority oldPriority,
10501051 JobPriority newPriority) {
10511052 switch (record->getKind ()) {
10521053 // Child tasks need to be recursively escalated.
@@ -1067,15 +1068,17 @@ static void performEscalationAction(TaskStatusRecord *record,
10671068 case TaskStatusRecordKind::EscalationNotification: {
10681069 auto notification =
10691070 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);
10711074 return ;
10721075 }
10731076
10741077 case TaskStatusRecordKind::TaskDependency: {
10751078 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);
10791082 return ;
10801083 }
10811084
@@ -1101,17 +1104,17 @@ static void performEscalationAction(TaskStatusRecord *record,
11011104SWIFT_CC (swift)
11021105JobPriority
11031106static swift_task_escalateImpl(AsyncTask *task, JobPriority newPriority) {
1104-
11051107 SWIFT_TASK_DEBUG_LOG (" Escalating %p to %#zx priority" , task, newPriority);
11061108 auto oldStatus = task->_private ()._status ().load (std::memory_order_relaxed);
1109+ auto oldPriority = oldStatus.getStoredPriority ();
11071110 auto newStatus = oldStatus;
11081111
11091112 while (true ) {
11101113 // Fast path: check that the stored priority is already at least
11111114 // 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 ;
11151118 }
11161119
11171120 if (oldStatus.isRunning () || oldStatus.isEnqueued ()) {
@@ -1145,8 +1148,11 @@ static swift_task_escalateImpl(AsyncTask *task, JobPriority newPriority) {
11451148 taskStatus = (ActiveTaskStatus *) &task->_private ()._status ();
11461149 executionLock = (dispatch_lock_t *) ((char *)taskStatus + ActiveTaskStatus::executionLockOffset ());
11471150
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);
11501156#endif
11511157 } else if (newStatus.isEnqueued ()) {
11521158 // Task is not running, it's enqueued somewhere waiting to be run
@@ -1165,22 +1171,24 @@ static swift_task_escalateImpl(AsyncTask *task, JobPriority newPriority) {
11651171 return newStatus.getStoredPriority ();
11661172 }
11671173
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);
11691176 // We must have at least one record - the task dependency one.
11701177 assert (newStatus.getInnermostRecord () != NULL );
11711178
11721179 withStatusRecordLock (task, newStatus, [&](ActiveTaskStatus status) {
11731180 // We know that none of the escalation actions will recursively
11741181 // modify the task status record list by adding or removing task records
11751182 for (auto cur: status.records ()) {
1176- performEscalationAction (cur, newPriority);
1183+ performEscalationAction (cur, oldPriority, newPriority);
11771184 }
11781185 });
11791186
11801187 return newStatus.getStoredPriority ();
11811188}
11821189
1183- void TaskDependencyStatusRecord::performEscalationAction (JobPriority newPriority) {
1190+ void TaskDependencyStatusRecord::performEscalationAction (
1191+ JobPriority oldPriority, JobPriority newPriority) {
11841192 switch (this ->DependencyKind ) {
11851193 case WaitingOnTask:
11861194 SWIFT_TASK_DEBUG_LOG (" [Dependency] Escalate dependent task %p noted in %p record" ,
@@ -1202,8 +1210,8 @@ void TaskDependencyStatusRecord::performEscalationAction(JobPriority newPriority
12021210 this ->DependentOn .TaskGroup , this );
12031211 break ;
12041212 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 );
12071215 swift_executor_escalate (this ->DependentOn .Executor , this ->WaitingTask , newPriority);
12081216 break ;
12091217 }
0 commit comments