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

Commit 47e090c3 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by android-build-merger
Browse files

Boost thread priority when holding the WM lock am: 36db127e

am: b72e651f

Change-Id: Ib3ddb7622a3412ca71c5cb20dbcd844697f895c3
parents 364cd109 b72e651f
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ endif

LOCAL_JACK_FLAGS := \
 -D jack.transformations.boost-locked-region-priority=true \
 -D jack.transformations.boost-locked-region-priority.classname=com.android.server.am.ActivityManagerService \
 -D jack.transformations.boost-locked-region-priority.request=com.android.server.am.ActivityManagerService\#boostPriorityForLockedSection \
 -D jack.transformations.boost-locked-region-priority.reset=com.android.server.am.ActivityManagerService\#resetPriorityAfterLockedSection
 -D jack.transformations.boost-locked-region-priority.classname=com.android.server.am.ActivityManagerService,com.android.server.wm.WindowHashMap \
 -D jack.transformations.boost-locked-region-priority.request=com.android.server.am.ActivityManagerService\#boostPriorityForLockedSection,com.android.server.wm.WindowManagerService\#boostPriorityForLockedSection \
 -D jack.transformations.boost-locked-region-priority.reset=com.android.server.am.ActivityManagerService\#resetPriorityAfterLockedSection,com.android.server.wm.WindowManagerService\#resetPriorityAfterLockedSection

include $(BUILD_STATIC_JAVA_LIBRARY)
+76 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.server;

import android.os.Process;

/**
 * Utility class to boost threads in sections where important locks are held.
 */
public class ThreadPriorityBooster {

    private final int mBoostToPriority;
    private final int mLockGuardIndex;

    private final ThreadLocal<PriorityState> mThreadState = new ThreadLocal<PriorityState>() {
        @Override protected PriorityState initialValue() {
            return new PriorityState();
        }
    };

    public ThreadPriorityBooster(int boostToPriority, int lockGuardIndex) {
        mBoostToPriority = boostToPriority;
        mLockGuardIndex = lockGuardIndex;
    }

    public void boost() {
        final int tid = Process.myTid();
        final int prevPriority = Process.getThreadPriority(tid);
        PriorityState state = mThreadState.get();
        if (state.regionCounter == 0 && prevPriority > mBoostToPriority) {
            state.prevPriority = prevPriority;
            Process.setThreadPriority(tid, mBoostToPriority);
        }
        state.regionCounter++;
        if (LockGuard.ENABLED) {
            LockGuard.guard(mLockGuardIndex);
        }
    }

    public void reset() {
        PriorityState state = mThreadState.get();
        state.regionCounter--;
        if (state.regionCounter == 0 && state.prevPriority > mBoostToPriority) {
            Process.setThreadPriority(Process.myTid(), state.prevPriority);
        }
    }

    private static class PriorityState {

        /**
         * Acts as counter for number of synchronized region that needs to acquire 'this' as a lock
         * the current thread is currently in. When it drops down to zero, we will no longer boost
         * the thread's priority.
         */
        int regionCounter;

        /**
         * The thread's previous priority before boosting.
         */
        int prevPriority;
    }
}
 No newline at end of file
+158 −149

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ class WindowContainerController<E extends WindowContainer, I extends WindowConta

    final WindowManagerService mService;
    final RootWindowContainer mRoot;
    final HashMap<IBinder, WindowState> mWindowMap;
    final WindowHashMap mWindowMap;

    // The window container this controller owns.
    E mContainer;
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.server.wm;

import android.os.IBinder;

import java.util.HashMap;

/**
 * Subclass of HashMap such that we can instruct the compiler to boost our thread priority when
 * locking this class. See makefile.
 */
class WindowHashMap extends HashMap<IBinder, WindowState> {
}
Loading