Skip to content

Commit

Permalink
Synced watchdog fixes from dev/1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHua269 committed Jul 1, 2024
1 parent db740bd commit 5c631a2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
71 changes: 44 additions & 27 deletions patches/server/0014-Add-a-simple-watchdog-for-tick-regions.patch
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,23 @@ index fc3d332aa1c1d469cedfe2aaa7102dcd78e25642..1ae61bc6603dd3ac290e3ead20416f9c
/*
if (false) {
io.papermc.paper.threadedregions.ThreadedTicketLevelPropagator.main(null);
diff --git a/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java b/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java
index 531aa50f2c84e13358e8918bb0c15ea3cd036cb5..fd0053369eb68f0fd596d8acfba4a5247ef8105a 100644
--- a/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java
+++ b/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java
@@ -167,6 +167,8 @@ public final class ThreadedRegionizer<R extends ThreadedRegionizer.ThreadedRegio
if (removed != region) {
throw new IllegalStateException("Expected to remove " + region + ", but removed " + removed);
}
+
+ me.earthme.luminol.utils.LuminolWatchDog.onRegionDeath(region); //Luminol - Simple watchdog
}

public int getSectionCoordinate(final int chunkCoordinate) {
diff --git a/src/main/java/io/papermc/paper/threadedregions/TickRegions.java b/src/main/java/io/papermc/paper/threadedregions/TickRegions.java
index 2ad25dd345ab42125d456f2b9cf67d8c4515c8b7..78c50292fb25e8703e9c91db892f05456f07d72f 100644
index 2ad25dd345ab42125d456f2b9cf67d8c4515c8b7..183fede965c3d227bbcc7e54781869e09796081f 100644
--- a/src/main/java/io/papermc/paper/threadedregions/TickRegions.java
+++ b/src/main/java/io/papermc/paper/threadedregions/TickRegions.java
@@ -402,6 +402,7 @@ public final class TickRegions implements ThreadedRegionizer.RegionCallbacks<Tic
@@ -402,10 +402,11 @@ public final class TickRegions implements ThreadedRegionizer.RegionCallbacks<Tic

@Override
protected void tickRegion(final int tickCount, final long startTime, final long scheduledEnd) {
+ me.earthme.luminol.utils.LuminolWatchDog.tickRegionHeartBeat(); //Luminol - Simple watchdog
final ca.spottedleaf.leafprofiler.RegionizedProfiler.Handle profiler = io.papermc.paper.threadedregions.TickRegionScheduler.getProfiler(); // Folia - profiler
profiler.startTick(); try { // Folia - profiler
MinecraftServer.getServer().tickServer(startTime, scheduledEnd, TimeUnit.MILLISECONDS.toMillis(10L), this.region);
- } finally { profiler.stopTick(); } // Folia - profiler
+ } finally { profiler.stopTick(); me.earthme.luminol.utils.LuminolWatchDog.releaseTickRegion(); } // Folia - profiler //Luminol - Simple watchdog
}

@Override
diff --git a/src/main/java/me/earthme/luminol/config/modules/misc/WatchdogConfig.java b/src/main/java/me/earthme/luminol/config/modules/misc/WatchdogConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..71d80b401470db777a86274d32f178bb2aa023d5
Expand Down Expand Up @@ -76,10 +68,10 @@ index 0000000000000000000000000000000000000000..71d80b401470db777a86274d32f178bb
+}
diff --git a/src/main/java/me/earthme/luminol/utils/LuminolWatchDog.java b/src/main/java/me/earthme/luminol/utils/LuminolWatchDog.java
new file mode 100644
index 0000000000000000000000000000000000000000..6b4368cdf9762ad981345fef0f26cd008a4236ee
index 0000000000000000000000000000000000000000..e19c6330a48cee402b1a999ca71cb2329d530356
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/utils/LuminolWatchDog.java
@@ -0,0 +1,161 @@
@@ -0,0 +1,178 @@
+package me.earthme.luminol.utils;
+
+import com.google.common.collect.Maps;
Expand All @@ -100,25 +92,34 @@ index 0000000000000000000000000000000000000000..6b4368cdf9762ad981345fef0f26cd00
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+public class LuminolWatchDog {
+ private static final Object keepaliveDataLock = new Object();
+ private static Pair<Thread,Long> globalRegionLastKeepalive = null;
+ private static final Map<Thread,Pair<ThreadedRegionizer.ThreadedRegion<?,?>,Long>> otherTickRegionKeepalive = Maps.newHashMap();
+ private static final Executor checkTimer = CompletableFuture.delayedExecutor(50, TimeUnit.MILLISECONDS);
+ private static final Executor checkTimer = CompletableFuture.delayedExecutor(50, TimeUnit.MILLISECONDS,Executors.newSingleThreadExecutor());
+ private static final Logger logger = MinecraftServer.LOGGER;
+ private static int tickCount = 0;
+ private static boolean runScheduleNext = true;
+ private static volatile boolean runScheduleNext = true;
+
+ public static void boot(){
+ if (!WatchdogConfig.enabled){
+ return;
+ }
+
+ runCheck();
+ }
+
+ private static void scheduleCheck(){
+ checkTimer.execute(LuminolWatchDog::runCheck);
+ }
+
+ public static void stopTicking(){
+ runScheduleNext = false;
+ }
+
+ private static void runCheck(){
+ try {
+ if (MinecraftServer.getServer().isStopped() || !runScheduleNext){
Expand All @@ -143,15 +144,23 @@ index 0000000000000000000000000000000000000000..6b4368cdf9762ad981345fef0f26cd00
+ }
+ }
+
+ for (Map.Entry<Thread,Pair<ThreadedRegionizer.ThreadedRegion<?,?>,Long>> tickData : otherTickRegionKeepalive.entrySet()){
+ final Thread targetThread = tickData.getKey();
+ final Pair<ThreadedRegionizer.ThreadedRegion<?, ?>, Long> keepaliveData = tickData.getValue();
+ final long lastKeepalive = keepaliveData.getRight();
+
+ final long timeEscaped = currentTimeNano - lastKeepalive;
+
+ if (timeEscaped >= WatchdogConfig.warnPeriodTicks * 50 * 1000 * 1000){
+ threadsToWarn.add(Pair.of(targetThread,timeEscaped));
+ }
+ }
+
+ for(Pair<Thread,Long> warnInfo : threadsToWarn){
+ final Thread targetThread = warnInfo.getLeft();
+ final long timeEscaped = warnInfo.getRight();
+
+ final ThreadedRegionizer.ThreadedRegion<?,?> targetRegion;
+
+ synchronized (keepaliveDataLock){
+ targetRegion = otherTickRegionKeepalive.get(targetThread).getLeft();
+ }
+ final ThreadedRegionizer.ThreadedRegion<?,?> targetRegion = targetThread == globalRegionLastKeepalive.getKey() ? null : otherTickRegionKeepalive.get(targetThread).getLeft();
+
+ if (tickCount % WatchdogConfig.warnPeriodTicks == 0){
+ dumpSingleRegion(targetThread,targetRegion,timeEscaped);
Expand Down Expand Up @@ -231,7 +240,7 @@ index 0000000000000000000000000000000000000000..6b4368cdf9762ad981345fef0f26cd00
+ }
+ }
+
+ public static void onRegionDeath(ThreadedRegionizer.ThreadedRegion<?,?> currentRegion){
+ public static void releaseTickRegion(){
+ if (!WatchdogConfig.enabled){
+ return;
+ }
Expand All @@ -243,10 +252,18 @@ index 0000000000000000000000000000000000000000..6b4368cdf9762ad981345fef0f26cd00
+}
\ No newline at end of file
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index cb3ae17634dfc753dec75c7e2385a4ccdcba40d3..08b0d3b970a7c86f577d20487d5fe3930b8eae6e 100644
index cb3ae17634dfc753dec75c7e2385a4ccdcba40d3..90fa6634dd1e426ba2469d366b3226a077c10f0e 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1222,6 +1222,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1003,6 +1003,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Folia end - region threading

public void stopServer() {
+ me.earthme.luminol.utils.LuminolWatchDog.stopTicking(); // Luminol - Watchdog
// Folia start - region threading
// halt scheduler
// don't wait, we may be on a scheduler thread
@@ -1222,6 +1223,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse(null); // CraftBukkit - decompile error
this.status = this.buildServerStatus();

Expand Down
4 changes: 2 additions & 2 deletions patches/server/0055-Leaves-Replay-Mod-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ index 936f8663b23908ac5de2076401a5d508f88a0376..0e8e57c291539e50f61e8178fc355fa6
super.channelActive(channelhandlercontext);
this.channel = channelhandlercontext.channel();
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 08b0d3b970a7c86f577d20487d5fe3930b8eae6e..8ea86315e09a6b182bab03ee902ef92c5e18d962 100644
index 90fa6634dd1e426ba2469d366b3226a077c10f0e..2ed097054d18919ad570a0fa990876285279f921 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1727,7 +1727,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1728,7 +1728,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}

private ServerStatus.Players buildPlayerStatus() {
Expand Down
6 changes: 3 additions & 3 deletions patches/server/0058-KioCG-Chunk-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ index 0000000000000000000000000000000000000000..53b4397997bc9b9b9d88e48304b37a25
+ }
+}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 8ea86315e09a6b182bab03ee902ef92c5e18d962..d933895e833bea1720cc32256e98e0fe3638f4eb 100644
index 2ed097054d18919ad570a0fa990876285279f921..37e7e88fa75dda6c2b59ed610ec3ae2136c653a5 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1654,6 +1654,17 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1655,6 +1655,17 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// Folia end - region threading

Expand All @@ -122,7 +122,7 @@ index 8ea86315e09a6b182bab03ee902ef92c5e18d962..d933895e833bea1720cc32256e98e0fe
// Folia - region threading
if (region == null) this.tickRateManager.tick(); // Folia - region threading
this.tickChildren(shouldKeepTicking, region); // Folia - region threading
@@ -1663,6 +1674,20 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1664,6 +1675,20 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}

// Folia - region threading
Expand Down

0 comments on commit 5c631a2

Please sign in to comment.