diff options
| author | 2024-10-06 07:18:13 +0000 | |
|---|---|---|
| committer | 2024-10-06 07:18:13 +0000 | |
| commit | b417208cecdf01f7ae7b8ca63f2da6a917202ea5 (patch) | |
| tree | 27d1c20fb82e68412f8f7a02da95b5a0b54ed02e | |
| parent | d66babf9261e40319816eb5f19f5b67e885275a0 (diff) | |
Only set SCHED_RESET_ON_FORK flag if the thread is using the default scheduling policy.
Keep nice and policy same as well to reduce the overhead in syscall.
Bug: 370988407
Change-Id: I4d9ef914905da6807339cf2c55650b8188787b43
Test: Build
Flag: com.android.server.power.hint.reset_on_fork_enabled
| -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()) { |