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

Commit 66a495a4 authored by Jing Ji's avatar Jing Ji Committed by Automerger Merge Worker
Browse files

Move the binder proxy accounting to libbinder am: 4c4ac063 am: 069a3fdd...

Move the binder proxy accounting to libbinder am: 4c4ac063 am: 069a3fdd am: 34e9b49d am: dfd30d32

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2754869



Change-Id: I383370c11284331dca7cd666e6c910d0c41a7c78
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 04fa3065 dfd30d32
Loading
Loading
Loading
Loading
+23 −0
Original line number Original line Diff line number Diff line
@@ -54,6 +54,11 @@ uint32_t BpBinder::sBinderProxyCountHighWatermark = 2500;
// Another arbitrary value a binder count needs to drop below before another callback will be called
// Another arbitrary value a binder count needs to drop below before another callback will be called
uint32_t BpBinder::sBinderProxyCountLowWatermark = 2000;
uint32_t BpBinder::sBinderProxyCountLowWatermark = 2000;


std::atomic<uint32_t> BpBinder::sBinderProxyCount(0);
std::atomic<uint32_t> BpBinder::sBinderProxyCountWarned(0);

static constexpr uint32_t kBinderProxyCountWarnInterval = 5000;

// Log any transactions for which the data exceeds this size
// Log any transactions for which the data exceeds this size
#define LOG_TRANSACTIONS_OVER_SIZE (300 * 1024)
#define LOG_TRANSACTIONS_OVER_SIZE (300 * 1024)


@@ -193,6 +198,18 @@ sp<BpBinder> BpBinder::create(int32_t handle) {
        }
        }
        sTrackingMap[trackedUid]++;
        sTrackingMap[trackedUid]++;
    }
    }
    uint32_t numProxies = sBinderProxyCount.fetch_add(1, std::memory_order_relaxed);
    uint32_t numLastWarned = sBinderProxyCountWarned.load(std::memory_order_relaxed);
    uint32_t numNextWarn = numLastWarned + kBinderProxyCountWarnInterval;
    if (numProxies >= numNextWarn) {
        // Multiple threads can get here, make sure only one of them gets to
        // update the warn counter.
        if (sBinderProxyCountWarned.compare_exchange_strong(numLastWarned,
                                                            numNextWarn,
                                                            std::memory_order_relaxed)) {
            ALOGW("Unexpectedly many live BinderProxies: %d\n", numProxies);
        }
    }
    return sp<BpBinder>::make(BinderHandle{handle}, trackedUid);
    return sp<BpBinder>::make(BinderHandle{handle}, trackedUid);
}
}


@@ -604,6 +621,7 @@ BpBinder::~BpBinder() {
            }
            }
        }
        }
    }
    }
    --sBinderProxyCount;


    if (ipc) {
    if (ipc) {
        ipc->expungeHandle(binderHandle(), this);
        ipc->expungeHandle(binderHandle(), this);
@@ -688,6 +706,11 @@ uint32_t BpBinder::getBinderProxyCount(uint32_t uid)
    return 0;
    return 0;
}
}


uint32_t BpBinder::getBinderProxyCount()
{
    return sBinderProxyCount.load();
}

void BpBinder::getCountByUid(Vector<uint32_t>& uids, Vector<uint32_t>& counts)
void BpBinder::getCountByUid(Vector<uint32_t>& uids, Vector<uint32_t>& counts)
{
{
    AutoMutex _l(sTrackingLock);
    AutoMutex _l(sTrackingLock);
+3 −0
Original line number Original line Diff line number Diff line
@@ -88,6 +88,7 @@ public:
    static void         setCountByUidEnabled(bool enable);
    static void         setCountByUidEnabled(bool enable);
    static void         setLimitCallback(binder_proxy_limit_callback cb);
    static void         setLimitCallback(binder_proxy_limit_callback cb);
    static void         setBinderProxyCountWatermarks(int high, int low);
    static void         setBinderProxyCountWatermarks(int high, int low);
    static uint32_t     getBinderProxyCount();


    std::optional<int32_t> getDebugBinderHandle() const;
    std::optional<int32_t> getDebugBinderHandle() const;


@@ -209,6 +210,8 @@ private:
    static uint32_t                             sBinderProxyCountLowWatermark;
    static uint32_t                             sBinderProxyCountLowWatermark;
    static bool                                 sBinderProxyThrottleCreate;
    static bool                                 sBinderProxyThrottleCreate;
    static std::unordered_map<int32_t,uint32_t> sLastLimitCallbackMap;
    static std::unordered_map<int32_t,uint32_t> sLastLimitCallbackMap;
    static std::atomic<uint32_t>                sBinderProxyCount;
    static std::atomic<uint32_t>                sBinderProxyCountWarned;
};
};


} // namespace android
} // namespace android