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

Commit 63f7c023 authored by Varad Gautam's avatar Varad Gautam Committed by Android (Google) Code Review
Browse files

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
parents 812dcabf 1d80be21
Loading
Loading
Loading
Loading
+14 −12
Original line number Diff line number Diff line
@@ -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 =
    int32_t duration =
            static_cast<int32_t>(
                std::chrono::duration_cast<std::chrono::seconds>(now - mPreviousMapClearTimePoint)
                    .count();
    if (duration > std::numeric_limits<int32_t>::max() || duration < 0) {
                    .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();
+1 −1
Original line number Diff line number Diff line
@@ -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);