From 27ab3ac610954ac01a18a1cf8559827cf7679f99 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Tue, 2 Jul 2019 18:10:55 -0700 Subject: GpuStats: move GpuStats related structs and enums away from GraphicsEnv Bug: 135210726 Test: build, flash and boot Test: adb shell dumpsys gpu Change-Id: I48c5c432aca916f923ab5674f8ec533d4f5aac0f --- libs/graphicsenv/IGpuService.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libs/graphicsenv/IGpuService.cpp') diff --git a/libs/graphicsenv/IGpuService.cpp b/libs/graphicsenv/IGpuService.cpp index 5f9624918f..30e5370650 100644 --- a/libs/graphicsenv/IGpuService.cpp +++ b/libs/graphicsenv/IGpuService.cpp @@ -30,7 +30,7 @@ public: virtual void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName, uint64_t driverVersionCode, int64_t driverBuildTime, const std::string& appPackageName, - const int32_t vulkanVersion, GraphicsEnv::Driver driver, + const int32_t vulkanVersion, GpuStatsInfo::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime) { Parcel data, reply; data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); @@ -143,7 +143,7 @@ status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* rep if ((status = data.readInt64(&driverLoadingTime)) != OK) return status; setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime, - appPackageName, vulkanVersion, static_cast(driver), + appPackageName, vulkanVersion, static_cast(driver), isDriverLoaded, driverLoadingTime); return OK; -- cgit v1.2.3-59-g8ed1b From bcba4117941a0506971654331d89961b6fbfd3c0 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 3 Jul 2019 13:39:32 -0700 Subject: GpuStats: refactor single stats pieces into a uniform way This change makes it easy for adding single stats pieces into GpuService without adding or modifying the binder interface each time. Bug: 135210726 Test: adb shell dumpsys gpu Change-Id: I2907065a55d03a6c1494737e6f0a77f6e94272eb --- libs/graphicsenv/GraphicsEnv.cpp | 6 +++--- libs/graphicsenv/IGpuService.cpp | 19 ++++++++++++++----- libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h | 4 ++++ libs/graphicsenv/include/graphicsenv/GraphicsEnv.h | 4 ++-- libs/graphicsenv/include/graphicsenv/IGpuService.h | 8 ++++---- services/gpuservice/GpuService.cpp | 16 +++------------- services/gpuservice/GpuService.h | 4 ++-- services/gpuservice/gpustats/GpuStats.cpp | 17 ++++++++++++++--- services/gpuservice/gpustats/GpuStats.h | 5 +++-- vulkan/libvulkan/driver.cpp | 3 ++- 10 files changed, 51 insertions(+), 35 deletions(-) (limited to 'libs/graphicsenv/IGpuService.cpp') diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index a411dd56f6..c5d5f71800 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -267,14 +267,14 @@ static sp getGpuService() { return interface_cast(binder); } -void GraphicsEnv::setCpuVulkanInUse() { +void GraphicsEnv::setTargetStats(const GpuStatsInfo::Stats stats, const uint64_t value) { ATRACE_CALL(); - // Use the same stats lock to protect getGpuService() as well. std::lock_guard lock(mStatsLock); const sp gpuService = getGpuService(); if (gpuService) { - gpuService->setCpuVulkanInUse(mGpuStats.appPackageName, mGpuStats.driverVersionCode); + gpuService->setTargetStats(mGpuStats.appPackageName, mGpuStats.driverVersionCode, stats, + value); } } diff --git a/libs/graphicsenv/IGpuService.cpp b/libs/graphicsenv/IGpuService.cpp index 30e5370650..9f5b0ff46f 100644 --- a/libs/graphicsenv/IGpuService.cpp +++ b/libs/graphicsenv/IGpuService.cpp @@ -92,15 +92,17 @@ public: return reply.readParcelableVector(outStats); } - virtual void setCpuVulkanInUse(const std::string& appPackageName, - const uint64_t driverVersionCode) { + virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, + const GpuStatsInfo::Stats stats, const uint64_t value) { Parcel data, reply; data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); data.writeUtf8AsUtf16(appPackageName); data.writeUint64(driverVersionCode); + data.writeInt32(static_cast(stats)); + data.writeUint64(value); - remote()->transact(BnGpuService::SET_CPU_VULKAN_IN_USE, data, &reply, IBinder::FLAG_ONEWAY); + remote()->transact(BnGpuService::SET_TARGET_STATS, data, &reply, IBinder::FLAG_ONEWAY); } }; @@ -174,7 +176,7 @@ status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* rep return OK; } - case SET_CPU_VULKAN_IN_USE: { + case SET_TARGET_STATS: { CHECK_INTERFACE(IGpuService, data, reply); std::string appPackageName; @@ -183,7 +185,14 @@ status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* rep uint64_t driverVersionCode; if ((status = data.readUint64(&driverVersionCode)) != OK) return status; - setCpuVulkanInUse(appPackageName, driverVersionCode); + int32_t stats; + if ((status = data.readInt32(&stats)) != OK) return status; + + uint64_t value; + if ((status = data.readUint64(&value)) != OK) return status; + + setTargetStats(appPackageName, driverVersionCode, + static_cast(stats), value); return OK; } diff --git a/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h b/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h index c2fd10ae63..711e8691ab 100644 --- a/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h +++ b/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h @@ -91,6 +91,10 @@ public: ANGLE = 5, }; + enum Stats { + CPU_VULKAN_IN_USE = 0, + }; + GpuStatsInfo() = default; GpuStatsInfo(const GpuStatsInfo&) = default; virtual ~GpuStatsInfo() = default; diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h index d0fc580fb6..a47f468e7a 100644 --- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h +++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h @@ -60,8 +60,8 @@ 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); - // Set that CPU type physical device is in use. - void setCpuVulkanInUse(); + // Set stats for target GpuStatsInfo::Stats type. + void setTargetStats(const GpuStatsInfo::Stats stats, const uint64_t value = 0); // Set which driver is intended to load. void setDriverToLoad(GpuStatsInfo::Driver driver); // Set which driver is actually loaded. diff --git a/libs/graphicsenv/include/graphicsenv/IGpuService.h b/libs/graphicsenv/include/graphicsenv/IGpuService.h index a47bbafcc4..f523d585be 100644 --- a/libs/graphicsenv/include/graphicsenv/IGpuService.h +++ b/libs/graphicsenv/include/graphicsenv/IGpuService.h @@ -40,9 +40,9 @@ public: const int32_t vulkanVersion, GpuStatsInfo::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; + // set target stats. + virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, + const GpuStatsInfo::Stats stats, const uint64_t value = 0) = 0; // get GPU global stats from GpuStats module. virtual status_t getGpuStatsGlobalInfo(std::vector* outStats) const = 0; @@ -57,7 +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, + SET_TARGET_STATS, // Always append new enum to the end. }; diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp index 72757dd02b..c81ab509c3 100644 --- a/services/gpuservice/GpuService.cpp +++ b/services/gpuservice/GpuService.cpp @@ -53,33 +53,23 @@ void GpuService::setGpuStats(const std::string& driverPackageName, int64_t driverBuildTime, const std::string& appPackageName, const int32_t vulkanVersion, GpuStatsInfo::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime) { - ATRACE_CALL(); - mGpuStats->insert(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime, appPackageName, vulkanVersion, driver, isDriverLoaded, driverLoadingTime); } status_t GpuService::getGpuStatsGlobalInfo(std::vector* outStats) const { - ATRACE_CALL(); - mGpuStats->pullGlobalStats(outStats); - return OK; } status_t GpuService::getGpuStatsAppInfo(std::vector* outStats) const { - ATRACE_CALL(); - mGpuStats->pullAppStats(outStats); - return OK; } -void GpuService::setCpuVulkanInUse(const std::string& appPackageName, - const uint64_t driverVersionCode) { - ATRACE_CALL(); - - mGpuStats->setCpuVulkanInUse(appPackageName, driverVersionCode); +void GpuService::setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, + const GpuStatsInfo::Stats stats, const uint64_t value) { + mGpuStats->insertTargetStats(appPackageName, driverVersionCode, stats, value); } status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector& args) { diff --git a/services/gpuservice/GpuService.h b/services/gpuservice/GpuService.h index 3e0e1b5f9b..525fb4fada 100644 --- a/services/gpuservice/GpuService.h +++ b/services/gpuservice/GpuService.h @@ -50,8 +50,8 @@ private: int64_t driverLoadingTime) override; status_t getGpuStatsGlobalInfo(std::vector* outStats) const override; status_t getGpuStatsAppInfo(std::vector* outStats) const override; - void setCpuVulkanInUse(const std::string& appPackageName, - const uint64_t driverVersionCode) override; + void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, + const GpuStatsInfo::Stats stats, const uint64_t value) override; /* * IBinder interface diff --git a/services/gpuservice/gpustats/GpuStats.cpp b/services/gpuservice/gpustats/GpuStats.cpp index 576c72cd3c..423c89f797 100644 --- a/services/gpuservice/gpustats/GpuStats.cpp +++ b/services/gpuservice/gpustats/GpuStats.cpp @@ -126,14 +126,25 @@ 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) { +void GpuStats::insertTargetStats(const std::string& appPackageName, + const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats, + const uint64_t /*value*/) { + ATRACE_CALL(); + const std::string appStatsKey = appPackageName + std::to_string(driverVersionCode); + + std::lock_guard lock(mLock); if (!mAppStats.count(appStatsKey)) { return; } - mAppStats[appStatsKey].cpuVulkanInUse = true; + switch (stats) { + case GpuStatsInfo::Stats::CPU_VULKAN_IN_USE: + mAppStats[appStatsKey].cpuVulkanInUse = true; + break; + default: + break; + } } void GpuStats::interceptSystemDriverStatsLocked() { diff --git a/services/gpuservice/gpustats/GpuStats.h b/services/gpuservice/gpustats/GpuStats.h index a79b2ba208..656b181464 100644 --- a/services/gpuservice/gpustats/GpuStats.h +++ b/services/gpuservice/gpustats/GpuStats.h @@ -37,8 +37,9 @@ public: uint64_t driverVersionCode, int64_t driverBuildTime, const std::string& appPackageName, const int32_t vulkanVersion, GpuStatsInfo::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); + // Insert target stats into app stats or potentially global stats as well. + void insertTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, + const GpuStatsInfo::Stats stats, const uint64_t value); // dumpsys interface void dump(const Vector& args, std::string* result); // Pull gpu global stats diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 680f94f42a..f596086ccf 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -1173,7 +1173,8 @@ VkResult CreateDevice(VkPhysicalDevice physicalDevice, if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU) { // Log that the app is hitting software Vulkan implementation - android::GraphicsEnv::getInstance().setCpuVulkanInUse(); + android::GraphicsEnv::getInstance().setTargetStats( + android::GpuStatsInfo::Stats::CPU_VULKAN_IN_USE); } data->driver_device = dev; -- cgit v1.2.3-59-g8ed1b From 6ee546d8808d1645fcc8fc2dbca82740fd0ac569 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Mon, 3 Feb 2020 18:13:23 -0800 Subject: GpuStats: migrate to new statsd native puller api (part 1) Bug: 148421389 Test: build, flash and boot. Change-Id: I44f0b5befd8f879ba0542cec50212ee274ce1adb --- libs/graphicsenv/IGpuService.cpp | 70 ---------------------- libs/graphicsenv/include/graphicsenv/IGpuService.h | 13 +--- services/gpuservice/GpuService.cpp | 10 ---- services/gpuservice/GpuService.h | 2 - services/gpuservice/gpustats/GpuStats.cpp | 30 ---------- .../gpustats/include/gpustats/GpuStats.h | 4 -- 6 files changed, 2 insertions(+), 127 deletions(-) (limited to 'libs/graphicsenv/IGpuService.cpp') diff --git a/libs/graphicsenv/IGpuService.cpp b/libs/graphicsenv/IGpuService.cpp index 9f5b0ff46f..de3503bcf0 100644 --- a/libs/graphicsenv/IGpuService.cpp +++ b/libs/graphicsenv/IGpuService.cpp @@ -48,50 +48,6 @@ public: remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply, IBinder::FLAG_ONEWAY); } - virtual status_t getGpuStatsGlobalInfo(std::vector* outStats) const { - if (!outStats) return UNEXPECTED_NULL; - - Parcel data, reply; - status_t status; - - if ((status = data.writeInterfaceToken(IGpuService::getInterfaceDescriptor())) != OK) - return status; - - if ((status = remote()->transact(BnGpuService::GET_GPU_STATS_GLOBAL_INFO, data, &reply)) != - OK) - return status; - - int32_t result = 0; - if ((status = reply.readInt32(&result)) != OK) return status; - if (result != OK) return result; - - outStats->clear(); - return reply.readParcelableVector(outStats); - } - - virtual status_t getGpuStatsAppInfo(std::vector* outStats) const { - if (!outStats) return UNEXPECTED_NULL; - - Parcel data, reply; - status_t status; - - if ((status = data.writeInterfaceToken(IGpuService::getInterfaceDescriptor())) != OK) { - return status; - } - - if ((status = remote()->transact(BnGpuService::GET_GPU_STATS_APP_INFO, data, &reply)) != - OK) { - return status; - } - - int32_t result = 0; - if ((status = reply.readInt32(&result)) != OK) return status; - if (result != OK) return result; - - outStats->clear(); - return reply.readParcelableVector(outStats); - } - virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats, const uint64_t value) { Parcel data, reply; @@ -150,32 +106,6 @@ status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* rep return OK; } - case GET_GPU_STATS_GLOBAL_INFO: { - CHECK_INTERFACE(IGpuService, data, reply); - - std::vector stats; - const status_t result = getGpuStatsGlobalInfo(&stats); - - if ((status = reply->writeInt32(result)) != OK) return status; - if (result != OK) return result; - - if ((status = reply->writeParcelableVector(stats)) != OK) return status; - - return OK; - } - case GET_GPU_STATS_APP_INFO: { - CHECK_INTERFACE(IGpuService, data, reply); - - std::vector stats; - const status_t result = getGpuStatsAppInfo(&stats); - - if ((status = reply->writeInt32(result)) != OK) return status; - if (result != OK) return result; - - if ((status = reply->writeParcelableVector(stats)) != OK) return status; - - return OK; - } case SET_TARGET_STATS: { CHECK_INTERFACE(IGpuService, data, reply); diff --git a/libs/graphicsenv/include/graphicsenv/IGpuService.h b/libs/graphicsenv/include/graphicsenv/IGpuService.h index f523d585be..c7c6d1e886 100644 --- a/libs/graphicsenv/include/graphicsenv/IGpuService.h +++ b/libs/graphicsenv/include/graphicsenv/IGpuService.h @@ -16,12 +16,11 @@ #pragma once -#include - #include #include #include -#include + +#include namespace android { @@ -43,20 +42,12 @@ public: // set target stats. virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats, const uint64_t value = 0) = 0; - - // get GPU global stats from GpuStats module. - virtual status_t getGpuStatsGlobalInfo(std::vector* outStats) const = 0; - - // get GPU app stats from GpuStats module. - virtual status_t getGpuStatsAppInfo(std::vector* outStats) const = 0; }; class BnGpuService : public BnInterface { public: enum IGpuServiceTag { SET_GPU_STATS = IBinder::FIRST_CALL_TRANSACTION, - GET_GPU_STATS_GLOBAL_INFO, - GET_GPU_STATS_APP_INFO, SET_TARGET_STATS, // Always append new enum to the end. }; diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp index 91a76f16eb..7bb0e4a751 100644 --- a/services/gpuservice/GpuService.cpp +++ b/services/gpuservice/GpuService.cpp @@ -57,16 +57,6 @@ void GpuService::setGpuStats(const std::string& driverPackageName, isDriverLoaded, driverLoadingTime); } -status_t GpuService::getGpuStatsGlobalInfo(std::vector* outStats) const { - mGpuStats->pullGlobalStats(outStats); - return OK; -} - -status_t GpuService::getGpuStatsAppInfo(std::vector* outStats) const { - mGpuStats->pullAppStats(outStats); - return OK; -} - void GpuService::setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats, const uint64_t value) { mGpuStats->insertTargetStats(appPackageName, driverVersionCode, stats, value); diff --git a/services/gpuservice/GpuService.h b/services/gpuservice/GpuService.h index b3dc2e2718..208a627f20 100644 --- a/services/gpuservice/GpuService.h +++ b/services/gpuservice/GpuService.h @@ -59,8 +59,6 @@ private: const std::string& appPackageName, const int32_t vulkanVersion, GpuStatsInfo::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime) override; - status_t getGpuStatsGlobalInfo(std::vector* outStats) const override; - status_t getGpuStatsAppInfo(std::vector* outStats) const override; void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats, const uint64_t value) override; diff --git a/services/gpuservice/gpustats/GpuStats.cpp b/services/gpuservice/gpustats/GpuStats.cpp index 71e6b973d4..58c6639916 100644 --- a/services/gpuservice/gpustats/GpuStats.cpp +++ b/services/gpuservice/gpustats/GpuStats.cpp @@ -233,34 +233,4 @@ void GpuStats::dumpAppLocked(std::string* result) { } } -void GpuStats::pullGlobalStats(std::vector* outStats) { - ATRACE_CALL(); - - std::lock_guard lock(mLock); - outStats->clear(); - outStats->reserve(mGlobalStats.size()); - - interceptSystemDriverStatsLocked(); - - for (const auto& ele : mGlobalStats) { - outStats->emplace_back(ele.second); - } - - mGlobalStats.clear(); -} - -void GpuStats::pullAppStats(std::vector* outStats) { - ATRACE_CALL(); - - std::lock_guard lock(mLock); - outStats->clear(); - outStats->reserve(mAppStats.size()); - - for (const auto& ele : mAppStats) { - outStats->emplace_back(ele.second); - } - - mAppStats.clear(); -} - } // namespace android diff --git a/services/gpuservice/gpustats/include/gpustats/GpuStats.h b/services/gpuservice/gpustats/include/gpustats/GpuStats.h index bcb9e0d7dd..bae4f9728f 100644 --- a/services/gpuservice/gpustats/include/gpustats/GpuStats.h +++ b/services/gpuservice/gpustats/include/gpustats/GpuStats.h @@ -43,10 +43,6 @@ public: const GpuStatsInfo::Stats stats, const uint64_t value); // dumpsys interface void dump(const Vector& args, std::string* result); - // Pull gpu global stats - void pullGlobalStats(std::vector* outStats); - // Pull gpu app stats - void pullAppStats(std::vector* outStats); // This limits the worst case number of loading times tracked. static const size_t MAX_NUM_LOADING_TIMES = 50; -- cgit v1.2.3-59-g8ed1b From 6b38825494997c3c2ab23e281956bb80558797d7 Mon Sep 17 00:00:00 2001 From: Peiyong Lin Date: Wed, 17 Jun 2020 18:47:12 -0700 Subject: Allow native process to load updatable driver. Previously an application process can be specified to load the updatable driver and the driver path will be set up correctly via GraphicsEnvironment.java. For a native process that is not an application process, there's no way for it to be specificed to load the updatable driver and hence the driver path is not set up. This patch provides a way for a native process that runs in an environment, for example shell, where environment variables can be set, to opt into using udpatable driver by setting UPDATABLE_GFX_DRIVER to 1. Bug: b/157832445, b/159240322 Test: ./gapit validate_gpu_profiling --os android Change-Id: I597535caa5ae0a033c2b8d581bb39b14875ac8fc Merged-In: I597535caa5ae0a033c2b8d581bb39b14875ac8fc --- libs/graphicsenv/GraphicsEnv.cpp | 30 ++++++++++++- libs/graphicsenv/IGpuService.cpp | 50 +++++++++++++++++++--- libs/graphicsenv/include/graphicsenv/IGpuService.h | 6 +++ services/gpuservice/GpuService.cpp | 8 ++++ services/gpuservice/GpuService.h | 3 ++ 5 files changed, 89 insertions(+), 8 deletions(-) (limited to 'libs/graphicsenv/IGpuService.cpp') diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 4809c1f0d8..3d0f8bbb11 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -40,6 +40,13 @@ #include #include +// TODO(b/159240322): Extend this to x86 ABI. +#if defined(__LP64__) +#define UPDATABLE_DRIVER_ABI "arm64-v8a" +#else +#define UPDATABLE_DRIVER_ABI "armeabi-v7a" +#endif // defined(__LP64__) + // TODO(ianelliott@): Get the following from an ANGLE header: #define CURRENT_ANGLE_API_VERSION 2 // Current API verion we are targetting // Version-2 API: @@ -584,7 +591,28 @@ android_namespace_t* GraphicsEnv::getDriverNamespace() { } if (mDriverPath.empty()) { - return nullptr; + // For an application process, driver path is empty means this application is not opted in + // to use updatable driver. Application process doesn't have the ability to set up + // environment variables and hence before `getenv` call will return. + // For a process that is not an application process, if it's run from an environment, + // for example shell, where environment variables can be set, then it can opt into using + // udpatable driver by setting UPDATABLE_GFX_DRIVER to 1. By setting to 1 the developer + // driver will be used currently. + // TODO(b/159240322) Support the production updatable driver. + const char* id = getenv("UPDATABLE_GFX_DRIVER"); + if (id == nullptr || std::strcmp(id, "1")) { + return nullptr; + } + const sp gpuService = getGpuService(); + if (!gpuService) { + return nullptr; + } + mDriverPath = gpuService->getUpdatableDriverPath(); + if (mDriverPath.empty()) { + return nullptr; + } + mDriverPath.append(UPDATABLE_DRIVER_ABI); + ALOGI("Driver path is setup via UPDATABLE_GFX_DRIVER: %s", mDriverPath.c_str()); } auto vndkNamespace = android_get_exported_namespace("vndk"); diff --git a/libs/graphicsenv/IGpuService.cpp b/libs/graphicsenv/IGpuService.cpp index de3503bcf0..fa25c5516d 100644 --- a/libs/graphicsenv/IGpuService.cpp +++ b/libs/graphicsenv/IGpuService.cpp @@ -27,11 +27,11 @@ class BpGpuService : public BpInterface { public: explicit BpGpuService(const sp& impl) : BpInterface(impl) {} - virtual void setGpuStats(const std::string& driverPackageName, - const std::string& driverVersionName, uint64_t driverVersionCode, - int64_t driverBuildTime, const std::string& appPackageName, - const int32_t vulkanVersion, GpuStatsInfo::Driver driver, - bool isDriverLoaded, int64_t driverLoadingTime) { + void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName, + uint64_t driverVersionCode, int64_t driverBuildTime, + const std::string& appPackageName, const int32_t vulkanVersion, + GpuStatsInfo::Driver driver, bool isDriverLoaded, + int64_t driverLoadingTime) override { Parcel data, reply; data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); @@ -48,8 +48,8 @@ public: remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply, IBinder::FLAG_ONEWAY); } - virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, - const GpuStatsInfo::Stats stats, const uint64_t value) { + void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, + const GpuStatsInfo::Stats stats, const uint64_t value) override { Parcel data, reply; data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); @@ -60,6 +60,27 @@ public: remote()->transact(BnGpuService::SET_TARGET_STATS, data, &reply, IBinder::FLAG_ONEWAY); } + + void setUpdatableDriverPath(const std::string& driverPath) override { + Parcel data, reply; + data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); + data.writeUtf8AsUtf16(driverPath); + + remote()->transact(BnGpuService::SET_UPDATABLE_DRIVER_PATH, data, &reply, + IBinder::FLAG_ONEWAY); + } + + std::string getUpdatableDriverPath() override { + Parcel data, reply; + data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); + + status_t error = remote()->transact(BnGpuService::GET_UPDATABLE_DRIVER_PATH, data, &reply); + std::string driverPath; + if (error == OK) { + error = reply.readUtf8FromUtf16(&driverPath); + } + return driverPath; + } }; IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService"); @@ -126,6 +147,21 @@ status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* rep return OK; } + case SET_UPDATABLE_DRIVER_PATH: { + CHECK_INTERFACE(IGpuService, data, reply); + + std::string driverPath; + if ((status = data.readUtf8FromUtf16(&driverPath)) != OK) return status; + + setUpdatableDriverPath(driverPath); + return OK; + } + case GET_UPDATABLE_DRIVER_PATH: { + CHECK_INTERFACE(IGpuService, data, reply); + + std::string driverPath = getUpdatableDriverPath(); + return reply->writeUtf8AsUtf16(driverPath); + } case SHELL_COMMAND_TRANSACTION: { int in = data.readFileDescriptor(); int out = data.readFileDescriptor(); diff --git a/libs/graphicsenv/include/graphicsenv/IGpuService.h b/libs/graphicsenv/include/graphicsenv/IGpuService.h index c7c6d1e886..2d59fa0165 100644 --- a/libs/graphicsenv/include/graphicsenv/IGpuService.h +++ b/libs/graphicsenv/include/graphicsenv/IGpuService.h @@ -42,6 +42,10 @@ public: // set target stats. virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats, const uint64_t value = 0) = 0; + + // setter and getter for updatable driver path. + virtual void setUpdatableDriverPath(const std::string& driverPath) = 0; + virtual std::string getUpdatableDriverPath() = 0; }; class BnGpuService : public BnInterface { @@ -49,6 +53,8 @@ public: enum IGpuServiceTag { SET_GPU_STATS = IBinder::FIRST_CALL_TRANSACTION, SET_TARGET_STATS, + SET_UPDATABLE_DRIVER_PATH, + GET_UPDATABLE_DRIVER_PATH, // Always append new enum to the end. }; diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp index f40ce71bda..304f1d059e 100644 --- a/services/gpuservice/GpuService.cpp +++ b/services/gpuservice/GpuService.cpp @@ -62,6 +62,14 @@ void GpuService::setTargetStats(const std::string& appPackageName, const uint64_ mGpuStats->insertTargetStats(appPackageName, driverVersionCode, stats, value); } +void GpuService::setUpdatableDriverPath(const std::string& driverPath) { + developerDriverPath = driverPath; +} + +std::string GpuService::getUpdatableDriverPath() { + return developerDriverPath; +} + status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector& args) { ATRACE_CALL(); diff --git a/services/gpuservice/GpuService.h b/services/gpuservice/GpuService.h index b3e34d559e..ba44fe04d4 100644 --- a/services/gpuservice/GpuService.h +++ b/services/gpuservice/GpuService.h @@ -50,6 +50,8 @@ private: int64_t driverLoadingTime) override; void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats, const uint64_t value) override; + void setUpdatableDriverPath(const std::string& driverPath) override; + std::string getUpdatableDriverPath() override; /* * IBinder interface @@ -73,6 +75,7 @@ private: * Attributes */ std::unique_ptr mGpuStats; + std::string developerDriverPath; }; } // namespace android -- cgit v1.2.3-59-g8ed1b