Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b417208c authored by Wei Wang's avatar Wei Wang
Browse files

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
parent d66babf9
Loading
Loading
Loading
Loading
+32 −4
Original line number Diff line number Diff line
@@ -1059,8 +1059,22 @@ public final class HintManagerService extends SystemService {
                    throw new SecurityException(errMsg);
                }
                if (resetOnForkEnabled()){
                    try {
                        for (int tid : tids) {
                        Process.setThreadScheduler(tid, Process.SCHED_RESET_ON_FORK, 0);
                            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()){
                            try {
                                for (int tid : tids) {
                                Process.setThreadScheduler(tid, Process.SCHED_RESET_ON_FORK, 0);
                                    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()) {