Skip to content

Commit

Permalink
[Wisp] Exited coroutine should not be re-wakeuped
Browse files Browse the repository at this point in the history
Summary: re-wakeup a exited coroutine can waste a lot of CPU

Test Plan: Verify on a reproducible environment

Reviewed-by: joeylee, zhenxiaolinX

Issue: dragonwell-project/dragonwell8#262
  • Loading branch information
yuleil committed Sep 26, 2021
1 parent b321801 commit dae4180
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/linux/classes/com/alibaba/wisp/engine/WispCarrier.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ void destroy() {
/**
* Block current coroutine and do scheduling.
* Typically called when resource is not ready.
*
* @param terminal indicate terminal current coroutine.
*/
final void schedule(boolean terminal) {
Expand All @@ -264,9 +265,9 @@ final void schedule(boolean terminal) {
assert current.resumeEntry != null && current != threadTask
: "call `schedule()` in scheduler";
if (current.controlGroup != null) {
current.totalTs += current.controlGroup.calcCpuTicks(current);
current.totalTs += current.controlGroup.calcCpuTicks(current);
} else {
current.totalTs += System.nanoTime() - current.enterTs;
current.totalTs += System.nanoTime() - current.enterTs;
current.enterTs = 0;
}
current.resumeEntry.setStealEnable(true);
Expand Down Expand Up @@ -352,7 +353,7 @@ public void run() {
}
if (current.yieldTo(task, false)) {
current.runWispTaskEpilog();
} else { // switch failure
} else if (task.isAlive()) { // switch failure
// this is unexpected, record in counter to help troubleshooting.
// The actual behavior of switch failure is similar to unpark lost,
// so we re-enqueue the entry for compensation.
Expand Down Expand Up @@ -532,8 +533,8 @@ private void unregisterEvent(WispTask target) {
* Add a timer for current {@link WispTask},
* used for implementing timed IO operation / sleep etc...
*
* @param deadlineNano deadline of the timer
* @param action JVM_UNPARK/JDK_UNPARK/RESUME
* @param deadlineNano deadline of the timer
* @param action JVM_UNPARK/JDK_UNPARK/RESUME
*/
void addTimer(long deadlineNano, TimeOut.Action action) {
WispTask task = current;
Expand Down

0 comments on commit dae4180

Please sign in to comment.