diff options
| author | 2024-09-10 09:30:39 +0000 | |
|---|---|---|
| committer | 2024-09-10 09:30:39 +0000 | |
| commit | 63f7c0239d6b11a8c230a1c54cf7f3d2e63c7838 (patch) | |
| tree | 1e434164a40b34c14fa5e08033bc3233f78e1da8 | |
| parent | 812dcabff8b4ff8cdc9efa0414001be6d44a7df8 (diff) | |
| parent | 1d80be21e49852772c9ecf664ced8e8351da44ce (diff) | |
Merge changes from topic "b347657694-gpuwork-fixes" into main
* changes:
gpuwork: Simplify checks to avoid uploading negative timestamps
gpuwork: Fix msec to nsec time divisor
gpuwork: Fix GPU time threshold overflow due to bad literals
| -rw-r--r-- | services/gpuservice/gpuwork/GpuWork.cpp | 26 | ||||
| -rw-r--r-- | services/gpuservice/gpuwork/include/gpuwork/GpuWork.h | 2 |
2 files changed, 15 insertions, 13 deletions
diff --git a/services/gpuservice/gpuwork/GpuWork.cpp b/services/gpuservice/gpuwork/GpuWork.cpp index 00161e6f4c..7628745537 100644 --- a/services/gpuservice/gpuwork/GpuWork.cpp +++ b/services/gpuservice/gpuwork/GpuWork.cpp @@ -44,7 +44,7 @@ #include "gpuwork/gpuWork.h" -#define ONE_MS_IN_NS (10000000) +#define MSEC_PER_NSEC (1000LU * 1000LU) namespace android { namespace gpuwork { @@ -385,10 +385,11 @@ AStatsManager_PullAtomCallbackReturn GpuWork::pullWorkAtoms(AStatsEventList* dat ALOGI("pullWorkAtoms: after random selection: uids.size() == %zu", uids.size()); auto now = std::chrono::steady_clock::now(); - long long duration = - std::chrono::duration_cast<std::chrono::seconds>(now - mPreviousMapClearTimePoint) - .count(); - if (duration > std::numeric_limits<int32_t>::max() || duration < 0) { + int32_t duration = + static_cast<int32_t>( + std::chrono::duration_cast<std::chrono::seconds>(now - mPreviousMapClearTimePoint) + .count()); + if (duration < 0) { // This is essentially impossible. If it does somehow happen, give up, // but still clear the map. clearMap(); @@ -404,13 +405,14 @@ AStatsManager_PullAtomCallbackReturn GpuWork::pullWorkAtoms(AStatsEventList* dat } const UidTrackingInfo& info = it->second; - uint64_t total_active_duration_ms = info.total_active_duration_ns / ONE_MS_IN_NS; - uint64_t total_inactive_duration_ms = info.total_inactive_duration_ns / ONE_MS_IN_NS; + int32_t total_active_duration_ms = + static_cast<int32_t>(info.total_active_duration_ns / MSEC_PER_NSEC); + int32_t total_inactive_duration_ms = + static_cast<int32_t>(info.total_inactive_duration_ns / MSEC_PER_NSEC); // Skip this atom if any numbers are out of range. |duration| is // already checked above. - if (total_active_duration_ms > std::numeric_limits<int32_t>::max() || - total_inactive_duration_ms > std::numeric_limits<int32_t>::max()) { + if (total_active_duration_ms < 0 || total_inactive_duration_ms < 0) { continue; } @@ -421,11 +423,11 @@ AStatsManager_PullAtomCallbackReturn GpuWork::pullWorkAtoms(AStatsEventList* dat // gpu_id bitcast_int32(gpuId), // time_duration_seconds - static_cast<int32_t>(duration), + duration, // total_active_duration_millis - static_cast<int32_t>(total_active_duration_ms), + total_active_duration_ms, // total_inactive_duration_millis - static_cast<int32_t>(total_inactive_duration_ms)); + total_inactive_duration_ms); } } clearMap(); diff --git a/services/gpuservice/gpuwork/include/gpuwork/GpuWork.h b/services/gpuservice/gpuwork/include/gpuwork/GpuWork.h index e70da540b9..60cd2c703e 100644 --- a/services/gpuservice/gpuwork/include/gpuwork/GpuWork.h +++ b/services/gpuservice/gpuwork/include/gpuwork/GpuWork.h @@ -125,7 +125,7 @@ private: static constexpr size_t kNumGpusHardLimit = 32; // The minimum GPU time needed to actually log stats for a UID. - static constexpr uint64_t kMinGpuTimeNanoseconds = 30U * 1000000000U; // 30 seconds. + static constexpr uint64_t kMinGpuTimeNanoseconds = 10LLU * 1000000000LLU; // 10 seconds. // The previous time point at which |mGpuWorkMap| was cleared. std::chrono::steady_clock::time_point mPreviousMapClearTimePoint GUARDED_BY(mMutex); |