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

Commit f512145d authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Reduce lock contention when starting process (1/N)"

parents 397065c0 8cd71201
Loading
Loading
Loading
Loading
+7 −7
Original line number Original line Diff line number Diff line
@@ -6344,7 +6344,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                int wakefulness) {
                int wakefulness) {
            synchronized (mGlobalLock) {
            synchronized (mGlobalLock) {
                if (mHomeProcess != null && (dumpPackage == null
                if (mHomeProcess != null && (dumpPackage == null
                        || mHomeProcess.mPkgList.contains(dumpPackage))) {
                        || mHomeProcess.containsPackage(dumpPackage))) {
                    if (needSep) {
                    if (needSep) {
                        pw.println();
                        pw.println();
                        needSep = false;
                        needSep = false;
@@ -6352,7 +6352,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                    pw.println("  mHomeProcess: " + mHomeProcess);
                    pw.println("  mHomeProcess: " + mHomeProcess);
                }
                }
                if (mPreviousProcess != null && (dumpPackage == null
                if (mPreviousProcess != null && (dumpPackage == null
                        || mPreviousProcess.mPkgList.contains(dumpPackage))) {
                        || mPreviousProcess.containsPackage(dumpPackage))) {
                    if (needSep) {
                    if (needSep) {
                        pw.println();
                        pw.println();
                        needSep = false;
                        needSep = false;
@@ -6360,14 +6360,14 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                    pw.println("  mPreviousProcess: " + mPreviousProcess);
                    pw.println("  mPreviousProcess: " + mPreviousProcess);
                }
                }
                if (dumpAll && (mPreviousProcess == null || dumpPackage == null
                if (dumpAll && (mPreviousProcess == null || dumpPackage == null
                        || mPreviousProcess.mPkgList.contains(dumpPackage))) {
                        || mPreviousProcess.containsPackage(dumpPackage))) {
                    StringBuilder sb = new StringBuilder(128);
                    StringBuilder sb = new StringBuilder(128);
                    sb.append("  mPreviousProcessVisibleTime: ");
                    sb.append("  mPreviousProcessVisibleTime: ");
                    TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb);
                    TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb);
                    pw.println(sb);
                    pw.println(sb);
                }
                }
                if (mHeavyWeightProcess != null && (dumpPackage == null
                if (mHeavyWeightProcess != null && (dumpPackage == null
                        || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) {
                        || mHeavyWeightProcess.containsPackage(dumpPackage))) {
                    if (needSep) {
                    if (needSep) {
                        pw.println();
                        pw.println();
                        needSep = false;
                        needSep = false;
@@ -6491,18 +6491,18 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                }
                }


                if (mHomeProcess != null && (dumpPackage == null
                if (mHomeProcess != null && (dumpPackage == null
                        || mHomeProcess.mPkgList.contains(dumpPackage))) {
                        || mHomeProcess.containsPackage(dumpPackage))) {
                    mHomeProcess.dumpDebug(proto, HOME_PROC);
                    mHomeProcess.dumpDebug(proto, HOME_PROC);
                }
                }


                if (mPreviousProcess != null && (dumpPackage == null
                if (mPreviousProcess != null && (dumpPackage == null
                        || mPreviousProcess.mPkgList.contains(dumpPackage))) {
                        || mPreviousProcess.containsPackage(dumpPackage))) {
                    mPreviousProcess.dumpDebug(proto, PREVIOUS_PROC);
                    mPreviousProcess.dumpDebug(proto, PREVIOUS_PROC);
                    proto.write(PREVIOUS_PROC_VISIBLE_TIME_MS, mPreviousProcessVisibleTime);
                    proto.write(PREVIOUS_PROC_VISIBLE_TIME_MS, mPreviousProcessVisibleTime);
                }
                }


                if (mHeavyWeightProcess != null && (dumpPackage == null
                if (mHeavyWeightProcess != null && (dumpPackage == null
                        || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) {
                        || mHeavyWeightProcess.containsPackage(dumpPackage))) {
                    mHeavyWeightProcess.dumpDebug(proto, HEAVY_WEIGHT_PROC);
                    mHeavyWeightProcess.dumpDebug(proto, HEAVY_WEIGHT_PROC);
                }
                }


+1 −1
Original line number Original line Diff line number Diff line
@@ -1714,7 +1714,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
                    // Don't kill the home process along with tasks from the same package.
                    // Don't kill the home process along with tasks from the same package.
                    continue;
                    continue;
                }
                }
                if (!proc.mPkgList.contains(pkg)) {
                if (!proc.containsPackage(pkg)) {
                    // Don't kill process that is not associated with this task.
                    // Don't kill process that is not associated with this task.
                    continue;
                    continue;
                }
                }
+1 −1
Original line number Original line Diff line number Diff line
@@ -566,7 +566,7 @@ public final class CompatModePackages {
            SparseArray<WindowProcessController> pidMap = mService.mProcessMap.getPidMap();
            SparseArray<WindowProcessController> pidMap = mService.mProcessMap.getPidMap();
            for (int i = pidMap.size() - 1; i >= 0; i--) {
            for (int i = pidMap.size() - 1; i >= 0; i--) {
                final WindowProcessController app = pidMap.valueAt(i);
                final WindowProcessController app = pidMap.valueAt(i);
                if (!app.mPkgList.contains(packageName)) {
                if (!app.containsPackage(packageName)) {
                    continue;
                    continue;
                }
                }
                try {
                try {
+14 −4
Original line number Original line Diff line number Diff line
@@ -76,6 +76,7 @@ import android.util.Slog;
import android.util.proto.ProtoOutputStream;
import android.util.proto.ProtoOutputStream;
import android.view.IRemoteAnimationRunner;
import android.view.IRemoteAnimationRunner;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.HeavyWeightSwitcherActivity;
import com.android.internal.app.HeavyWeightSwitcherActivity;
import com.android.internal.protolog.common.ProtoLog;
import com.android.internal.protolog.common.ProtoLog;
@@ -118,7 +119,8 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    // communicate back to the activity manager side.
    // communicate back to the activity manager side.
    public final Object mOwner;
    public final Object mOwner;
    // List of packages running in the process
    // List of packages running in the process
    final ArraySet<String> mPkgList = new ArraySet<>();
    @GuardedBy("itself")
    private final ArrayList<String> mPkgList = new ArrayList<>(1);
    private final WindowProcessListener mListener;
    private final WindowProcessListener mListener;
    private final ActivityTaskManagerService mAtm;
    private final ActivityTaskManagerService mAtm;
    private final BackgroundLaunchProcessController mBgLaunchController;
    private final BackgroundLaunchProcessController mBgLaunchController;
@@ -645,18 +647,26 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio


    @HotPath(caller = HotPath.PROCESS_CHANGE)
    @HotPath(caller = HotPath.PROCESS_CHANGE)
    public void addPackage(String packageName) {
    public void addPackage(String packageName) {
        synchronized (mAtm.mGlobalLockWithoutBoost) {
        synchronized (mPkgList) {
            if (!mPkgList.contains(packageName)) {
                mPkgList.add(packageName);
                mPkgList.add(packageName);
            }
            }
        }
        }
    }


    @HotPath(caller = HotPath.PROCESS_CHANGE)
    @HotPath(caller = HotPath.PROCESS_CHANGE)
    public void clearPackageList() {
    public void clearPackageList() {
        synchronized (mAtm.mGlobalLockWithoutBoost) {
        synchronized (mPkgList) {
            mPkgList.clear();
            mPkgList.clear();
        }
        }
    }
    }


    boolean containsPackage(String packageName) {
        synchronized (mPkgList) {
            return mPkgList.contains(packageName);
        }
    }

    void addActivityIfNeeded(ActivityRecord r) {
    void addActivityIfNeeded(ActivityRecord r) {
        // even if we already track this activity, note down that it has been launched
        // even if we already track this activity, note down that it has been launched
        setLastActivityLaunchTime(r.lastLaunchTime);
        setLastActivityLaunchTime(r.lastLaunchTime);