diff options
author | 2019-05-09 14:34:19 -0700 | |
---|---|---|
committer | 2019-05-09 23:46:39 +0000 | |
commit | 8c5e3bde15a3d4c09d002a2d53de39c45528e2c9 (patch) | |
tree | 10b25a38af3d27017b966869f8fe24456d2501ac | |
parent | 6dec1db01247a00564e433ac2ff904e3d0ccac2c (diff) |
GpuStats: track CPU Vulkan implementation usage
Bug: 131927737
Test: test on both GPU and CPU Vulkan implementations
Change-Id: I36de47e14cd132a779d9f39fdc19325d4772bb9a
-rw-r--r-- | libs/graphicsenv/GpuStatsInfo.cpp | 3 | ||||
-rw-r--r-- | libs/graphicsenv/GraphicsEnv.cpp | 11 | ||||
-rw-r--r-- | libs/graphicsenv/IGpuService.cpp | 24 | ||||
-rw-r--r-- | libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h | 1 | ||||
-rw-r--r-- | libs/graphicsenv/include/graphicsenv/GraphicsEnv.h | 1 | ||||
-rw-r--r-- | libs/graphicsenv/include/graphicsenv/IGpuService.h | 5 | ||||
-rw-r--r-- | services/gpuservice/GpuService.cpp | 7 | ||||
-rw-r--r-- | services/gpuservice/GpuService.h | 2 | ||||
-rw-r--r-- | services/gpuservice/gpustats/GpuStats.cpp | 20 | ||||
-rw-r--r-- | services/gpuservice/gpustats/GpuStats.h | 2 | ||||
-rw-r--r-- | vulkan/libvulkan/driver.cpp | 5 |
11 files changed, 76 insertions, 5 deletions
diff --git a/libs/graphicsenv/GpuStatsInfo.cpp b/libs/graphicsenv/GpuStatsInfo.cpp index 047d6833fa..4a801bec38 100644 --- a/libs/graphicsenv/GpuStatsInfo.cpp +++ b/libs/graphicsenv/GpuStatsInfo.cpp @@ -85,6 +85,7 @@ status_t GpuStatsAppInfo::writeToParcel(Parcel* parcel) const { if ((status = parcel->writeInt64Vector(glDriverLoadingTime)) != OK) return status; if ((status = parcel->writeInt64Vector(vkDriverLoadingTime)) != OK) return status; if ((status = parcel->writeInt64Vector(angleDriverLoadingTime)) != OK) return status; + if ((status = parcel->writeBool(cpuVulkanInUse)) != OK) return status; return OK; } @@ -95,6 +96,7 @@ status_t GpuStatsAppInfo::readFromParcel(const Parcel* parcel) { if ((status = parcel->readInt64Vector(&glDriverLoadingTime)) != OK) return status; if ((status = parcel->readInt64Vector(&vkDriverLoadingTime)) != OK) return status; if ((status = parcel->readInt64Vector(&angleDriverLoadingTime)) != OK) return status; + if ((status = parcel->readBool(&cpuVulkanInUse)) != OK) return status; return OK; } @@ -102,6 +104,7 @@ std::string GpuStatsAppInfo::toString() const { std::string result; StringAppendF(&result, "appPackageName = %s\n", appPackageName.c_str()); StringAppendF(&result, "driverVersionCode = %" PRIu64 "\n", driverVersionCode); + StringAppendF(&result, "cpuVulkanInUse = %d\n", cpuVulkanInUse); result.append("glDriverLoadingTime:"); for (int32_t loadingTime : glDriverLoadingTime) { StringAppendF(&result, " %d", loadingTime); diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 2f84f86431..407f77d88b 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -263,6 +263,17 @@ static sp<IGpuService> getGpuService() { return interface_cast<IGpuService>(binder); } +void GraphicsEnv::setCpuVulkanInUse() { + ATRACE_CALL(); + + // Use the same stats lock to protect getGpuService() as well. + std::lock_guard<std::mutex> lock(mStatsLock); + const sp<IGpuService> gpuService = getGpuService(); + if (gpuService) { + gpuService->setCpuVulkanInUse(mGpuStats.appPackageName, mGpuStats.driverVersionCode); + } +} + void GraphicsEnv::sendGpuStatsLocked(GraphicsEnv::Api api, bool isDriverLoaded, int64_t driverLoadingTime) { ATRACE_CALL(); diff --git a/libs/graphicsenv/IGpuService.cpp b/libs/graphicsenv/IGpuService.cpp index 100dca598b..5f9624918f 100644 --- a/libs/graphicsenv/IGpuService.cpp +++ b/libs/graphicsenv/IGpuService.cpp @@ -91,6 +91,17 @@ public: outStats->clear(); return reply.readParcelableVector(outStats); } + + virtual void setCpuVulkanInUse(const std::string& appPackageName, + const uint64_t driverVersionCode) { + Parcel data, reply; + data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); + + data.writeUtf8AsUtf16(appPackageName); + data.writeUint64(driverVersionCode); + + remote()->transact(BnGpuService::SET_CPU_VULKAN_IN_USE, data, &reply, IBinder::FLAG_ONEWAY); + } }; IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService"); @@ -163,6 +174,19 @@ status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* rep return OK; } + case SET_CPU_VULKAN_IN_USE: { + CHECK_INTERFACE(IGpuService, data, reply); + + std::string appPackageName; + if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; + + uint64_t driverVersionCode; + if ((status = data.readUint64(&driverVersionCode)) != OK) return status; + + setCpuVulkanInUse(appPackageName, driverVersionCode); + + return OK; + } case SHELL_COMMAND_TRANSACTION: { int in = data.readFileDescriptor(); int out = data.readFileDescriptor(); diff --git a/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h b/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h index bdcf0d67f5..edcccfea4a 100644 --- a/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h +++ b/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h @@ -69,6 +69,7 @@ public: std::vector<int64_t> glDriverLoadingTime = {}; std::vector<int64_t> vkDriverLoadingTime = {}; std::vector<int64_t> angleDriverLoadingTime = {}; + bool cpuVulkanInUse = false; }; } // namespace android diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h index ca8f834b95..7d627500fd 100644 --- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h +++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h @@ -96,6 +96,7 @@ public: void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName, uint64_t versionCode, int64_t driverBuildTime, const std::string& appPackageName, const int32_t vulkanVersion); + void setCpuVulkanInUse(); void setDriverToLoad(Driver driver); void setDriverLoaded(Api api, bool isDriverLoaded, int64_t driverLoadingTime); void sendGpuStatsLocked(Api api, bool isDriverLoaded, int64_t driverLoadingTime); diff --git a/libs/graphicsenv/include/graphicsenv/IGpuService.h b/libs/graphicsenv/include/graphicsenv/IGpuService.h index 5bf0269430..34f1c7ee7e 100644 --- a/libs/graphicsenv/include/graphicsenv/IGpuService.h +++ b/libs/graphicsenv/include/graphicsenv/IGpuService.h @@ -40,6 +40,10 @@ public: const int32_t vulkanVersion, GraphicsEnv::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime) = 0; + // set CPU Vulkan in use signal from GraphicsEnvironment. + virtual void setCpuVulkanInUse(const std::string& appPackageName, + const uint64_t driverVersionCode) = 0; + // get GPU global stats from GpuStats module. virtual status_t getGpuStatsGlobalInfo(std::vector<GpuStatsGlobalInfo>* outStats) const = 0; @@ -53,6 +57,7 @@ public: SET_GPU_STATS = IBinder::FIRST_CALL_TRANSACTION, GET_GPU_STATS_GLOBAL_INFO, GET_GPU_STATS_APP_INFO, + SET_CPU_VULKAN_IN_USE, // Always append new enum to the end. }; diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp index b42884e139..8accf9d450 100644 --- a/services/gpuservice/GpuService.cpp +++ b/services/gpuservice/GpuService.cpp @@ -75,6 +75,13 @@ status_t GpuService::getGpuStatsAppInfo(std::vector<GpuStatsAppInfo>* outStats) return OK; } +void GpuService::setCpuVulkanInUse(const std::string& appPackageName, + const uint64_t driverVersionCode) { + ATRACE_CALL(); + + mGpuStats->setCpuVulkanInUse(appPackageName, driverVersionCode); +} + status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector<String16>& args) { ATRACE_CALL(); diff --git a/services/gpuservice/GpuService.h b/services/gpuservice/GpuService.h index 3e02b4a073..822690134a 100644 --- a/services/gpuservice/GpuService.h +++ b/services/gpuservice/GpuService.h @@ -50,6 +50,8 @@ private: int64_t driverLoadingTime) override; status_t getGpuStatsGlobalInfo(std::vector<GpuStatsGlobalInfo>* outStats) const override; status_t getGpuStatsAppInfo(std::vector<GpuStatsAppInfo>* outStats) const override; + void setCpuVulkanInUse(const std::string& appPackageName, + const uint64_t driverVersionCode) override; /* * IBinder interface diff --git a/services/gpuservice/gpustats/GpuStats.cpp b/services/gpuservice/gpustats/GpuStats.cpp index 8b01c282cc..37c6abc96b 100644 --- a/services/gpuservice/gpustats/GpuStats.cpp +++ b/services/gpuservice/gpustats/GpuStats.cpp @@ -108,13 +108,13 @@ void GpuStats::insert(const std::string& driverPackageName, const std::string& d addLoadingCount(driver, isDriverLoaded, &mGlobalStats[driverVersionCode]); } - if (mAppStats.size() >= MAX_NUM_APP_RECORDS) { - ALOGV("GpuStatsAppInfo has reached maximum size. Ignore new stats."); - return; - } - const std::string appStatsKey = appPackageName + std::to_string(driverVersionCode); if (!mAppStats.count(appStatsKey)) { + if (mAppStats.size() >= MAX_NUM_APP_RECORDS) { + ALOGV("GpuStatsAppInfo has reached maximum size. Ignore new stats."); + return; + } + GpuStatsAppInfo appInfo; addLoadingTime(driver, driverLoadingTime, &appInfo); appInfo.appPackageName = appPackageName; @@ -126,6 +126,16 @@ void GpuStats::insert(const std::string& driverPackageName, const std::string& d addLoadingTime(driver, driverLoadingTime, &mAppStats[appStatsKey]); } +void GpuStats::setCpuVulkanInUse(const std::string& appPackageName, + const uint64_t driverVersionCode) { + const std::string appStatsKey = appPackageName + std::to_string(driverVersionCode); + if (!mAppStats.count(appStatsKey)) { + return; + } + + mAppStats[appStatsKey].cpuVulkanInUse = true; +} + void GpuStats::interceptSystemDriverStatsLocked() { // Append cpuVulkanVersion and glesVersion to system driver stats if (!mGlobalStats.count(0) || mGlobalStats[0].glesVersion) { diff --git a/services/gpuservice/gpustats/GpuStats.h b/services/gpuservice/gpustats/GpuStats.h index 49699ee813..b293f5988d 100644 --- a/services/gpuservice/gpustats/GpuStats.h +++ b/services/gpuservice/gpustats/GpuStats.h @@ -37,6 +37,8 @@ public: uint64_t driverVersionCode, int64_t driverBuildTime, const std::string& appPackageName, const int32_t vulkanVersion, GraphicsEnv::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime); + // Set CPU Vulkan in use signal into app stats. + void setCpuVulkanInUse(const std::string& appPackageName, const uint64_t driverVersionCode); // dumpsys interface void dump(const Vector<String16>& args, std::string* result); // Pull gpu global stats diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 613fa1352a..23506bad54 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -1174,6 +1174,11 @@ VkResult CreateDevice(VkPhysicalDevice physicalDevice, &properties); ATRACE_END(); + if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU) { + // Log that the app is hitting software Vulkan implementation + android::GraphicsEnv::getInstance().setCpuVulkanInUse(); + } + data->driver_device = dev; data->driver_version = properties.driverVersion; |