diff options
author | 2024-10-07 05:45:42 +0000 | |
---|---|---|
committer | 2024-10-07 05:45:42 +0000 | |
commit | 6ff9d1eaa40d0f901da45ed943ee474ba759ea2c (patch) | |
tree | 8c962c74cad9bbcb2befe99e4a8c93f87460fb40 | |
parent | f370ad3a0ff4a8cf6703e0c02cca1172475cf836 (diff) | |
parent | b417208cecdf01f7ae7b8ca63f2da6a917202ea5 (diff) |
Merge "Only set SCHED_RESET_ON_FORK flag if the thread is using the default scheduling policy." into main
-rw-r--r-- | services/core/java/com/android/server/power/hint/HintManagerService.java | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/power/hint/HintManagerService.java b/services/core/java/com/android/server/power/hint/HintManagerService.java index c969eff32f8e..2c0ce252df18 100644 --- a/services/core/java/com/android/server/power/hint/HintManagerService.java +++ b/services/core/java/com/android/server/power/hint/HintManagerService.java @@ -1059,8 +1059,22 @@ public final class HintManagerService extends SystemService { throw new SecurityException(errMsg); } if (resetOnForkEnabled()){ - for (int tid : tids) { - Process.setThreadScheduler(tid, Process.SCHED_RESET_ON_FORK, 0); + try { + for (int tid : tids) { + int policy = Process.getThreadScheduler(tid); + // If the thread is not using the default scheduling policy (SCHED_OTHER), + // we don't change it. + if (policy != Process.SCHED_OTHER) { + continue; + } + // set the SCHED_RESET_ON_FORK flag. + int prio = Process.getThreadPriority(tid); + Process.setThreadScheduler(tid, Process.SCHED_OTHER | Process.SCHED_RESET_ON_FORK, 0); + Process.setThreadPriority(tid, prio); + } + } catch (Exception e) { + Slog.e(TAG, "Failed to set SCHED_RESET_ON_FORK for tids " + + Arrays.toString(tids), e); } } @@ -1454,8 +1468,22 @@ public final class HintManagerService extends SystemService { throw new SecurityException(errMsg); } if (resetOnForkEnabled()){ - for (int tid : tids) { - Process.setThreadScheduler(tid, Process.SCHED_RESET_ON_FORK, 0); + try { + for (int tid : tids) { + int policy = Process.getThreadScheduler(tid); + // If the thread is not using the default scheduling policy (SCHED_OTHER), + // we don't change it. + if (policy != Process.SCHED_OTHER) { + continue; + } + // set the SCHED_RESET_ON_FORK flag. + int prio = Process.getThreadPriority(tid); + Process.setThreadScheduler(tid, Process.SCHED_OTHER | Process.SCHED_RESET_ON_FORK, 0); + Process.setThreadPriority(tid, prio); + } + } catch (Exception e) { + Slog.e(TAG, "Failed to set SCHED_RESET_ON_FORK for tids " + + Arrays.toString(tids), e); } } if (powerhintThreadCleanup()) { |