summaryrefslogtreecommitdiff
path: root/libs/binder/IPCThreadState.cpp
diff options
context:
space:
mode:
author Tomasz Wasilczyk <twasilczyk@google.com> 2024-05-21 15:06:29 -0700
committer Tomasz Wasilczyk <twasilczyk@google.com> 2024-06-27 12:04:32 -0700
commit1d46f58320055b7aad551b92827bf3405258f25e (patch)
treec32caea58d088c49f3a1a51d8b880717fb9694d1 /libs/binder/IPCThreadState.cpp
parent5e1cbe06681051d7e121364b36469acbdb24fdbe (diff)
Migrate from libutils SystemClock.h to std::chrono
Bug: 341997808 Test: mma Change-Id: Ib4d60eeaaac73566cc79d473f6551e9abd20e69a
Diffstat (limited to 'libs/binder/IPCThreadState.cpp')
-rw-r--r--libs/binder/IPCThreadState.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
index c3bbdbadaa..61d0dbad31 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -25,7 +25,6 @@
#include <cutils/sched_policy.h>
#include <utils/CallStack.h>
#include <utils/Log.h>
-#include <utils/SystemClock.h>
#include <atomic>
#include <errno.h>
@@ -38,6 +37,7 @@
#include <sys/resource.h>
#include <unistd.h>
+#include "Utils.h"
#include "binder_module.h"
#if LOG_NDEBUG
@@ -65,6 +65,8 @@
namespace android {
+using namespace std::chrono_literals;
+
// Static const and functions will be optimized out if not used,
// when LOG_NDEBUG and references in IF_LOG_COMMANDS() are optimized out.
static const char* kReturnStrings[] = {
@@ -647,8 +649,9 @@ status_t IPCThreadState::getAndExecuteCommand()
size_t newThreadsCount = mProcess->mExecutingThreadsCount.fetch_add(1) + 1;
if (newThreadsCount >= mProcess->mMaxThreads) {
- int64_t expected = 0;
- mProcess->mStarvationStartTimeMs.compare_exchange_strong(expected, uptimeMillis());
+ auto expected = ProcessState::never();
+ mProcess->mStarvationStartTime
+ .compare_exchange_strong(expected, std::chrono::steady_clock::now());
}
result = executeCommand(cmd);
@@ -656,12 +659,13 @@ status_t IPCThreadState::getAndExecuteCommand()
size_t maxThreads = mProcess->mMaxThreads;
newThreadsCount = mProcess->mExecutingThreadsCount.fetch_sub(1) - 1;
if (newThreadsCount < maxThreads) {
- size_t starvationStartTimeMs = mProcess->mStarvationStartTimeMs.exchange(0);
- if (starvationStartTimeMs != 0) {
- int64_t starvationTimeMs = uptimeMillis() - starvationStartTimeMs;
- if (starvationTimeMs > 100) {
+ auto starvationStartTime =
+ mProcess->mStarvationStartTime.exchange(ProcessState::never());
+ if (starvationStartTime != ProcessState::never()) {
+ auto starvationTime = std::chrono::steady_clock::now() - starvationStartTime;
+ if (starvationTime > 100ms) {
ALOGE("binder thread pool (%zu threads) starved for %" PRId64 " ms", maxThreads,
- starvationTimeMs);
+ to_ms(starvationTime));
}
}
}