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/GraphicsEnv.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'libs/graphicsenv/GraphicsEnv.cpp') diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 24b6c2d6de..a411dd56f6 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -170,11 +170,11 @@ void GraphicsEnv::hintActivityLaunch() { std::lock_guard lock(mStatsLock); if (mGpuStats.glDriverToSend) { mGpuStats.glDriverToSend = false; - sendGpuStatsLocked(GraphicsEnv::Api::API_GL, true, mGpuStats.glDriverLoadingTime); + sendGpuStatsLocked(GpuStatsInfo::Api::API_GL, true, mGpuStats.glDriverLoadingTime); } if (mGpuStats.vkDriverToSend) { mGpuStats.vkDriverToSend = false; - sendGpuStatsLocked(GraphicsEnv::Api::API_VK, true, mGpuStats.vkDriverLoadingTime); + sendGpuStatsLocked(GpuStatsInfo::Api::API_VK, true, mGpuStats.vkDriverLoadingTime); } }); trySendGpuStatsThread.detach(); @@ -205,32 +205,32 @@ void GraphicsEnv::setGpuStats(const std::string& driverPackageName, mGpuStats.vulkanVersion = vulkanVersion; } -void GraphicsEnv::setDriverToLoad(GraphicsEnv::Driver driver) { +void GraphicsEnv::setDriverToLoad(GpuStatsInfo::Driver driver) { ATRACE_CALL(); std::lock_guard lock(mStatsLock); switch (driver) { - case GraphicsEnv::Driver::GL: - case GraphicsEnv::Driver::GL_UPDATED: - case GraphicsEnv::Driver::ANGLE: { - if (mGpuStats.glDriverToLoad == GraphicsEnv::Driver::NONE) { + case GpuStatsInfo::Driver::GL: + case GpuStatsInfo::Driver::GL_UPDATED: + case GpuStatsInfo::Driver::ANGLE: { + if (mGpuStats.glDriverToLoad == GpuStatsInfo::Driver::NONE) { mGpuStats.glDriverToLoad = driver; break; } - if (mGpuStats.glDriverFallback == GraphicsEnv::Driver::NONE) { + if (mGpuStats.glDriverFallback == GpuStatsInfo::Driver::NONE) { mGpuStats.glDriverFallback = driver; } break; } - case Driver::VULKAN: - case Driver::VULKAN_UPDATED: { - if (mGpuStats.vkDriverToLoad == GraphicsEnv::Driver::NONE) { + case GpuStatsInfo::Driver::VULKAN: + case GpuStatsInfo::Driver::VULKAN_UPDATED: { + if (mGpuStats.vkDriverToLoad == GpuStatsInfo::Driver::NONE) { mGpuStats.vkDriverToLoad = driver; break; } - if (mGpuStats.vkDriverFallback == GraphicsEnv::Driver::NONE) { + if (mGpuStats.vkDriverFallback == GpuStatsInfo::Driver::NONE) { mGpuStats.vkDriverFallback = driver; } break; @@ -240,13 +240,13 @@ void GraphicsEnv::setDriverToLoad(GraphicsEnv::Driver driver) { } } -void GraphicsEnv::setDriverLoaded(GraphicsEnv::Api api, bool isDriverLoaded, +void GraphicsEnv::setDriverLoaded(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime) { ATRACE_CALL(); std::lock_guard lock(mStatsLock); const bool doNotSend = mGpuStats.appPackageName.empty(); - if (api == GraphicsEnv::Api::API_GL) { + if (api == GpuStatsInfo::Api::API_GL) { if (doNotSend) mGpuStats.glDriverToSend = true; mGpuStats.glDriverLoadingTime = driverLoadingTime; } else { @@ -278,7 +278,7 @@ void GraphicsEnv::setCpuVulkanInUse() { } } -void GraphicsEnv::sendGpuStatsLocked(GraphicsEnv::Api api, bool isDriverLoaded, +void GraphicsEnv::sendGpuStatsLocked(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime) { ATRACE_CALL(); @@ -299,16 +299,16 @@ void GraphicsEnv::sendGpuStatsLocked(GraphicsEnv::Api api, bool isDriverLoaded, mGpuStats.driverVersionCode, mGpuStats.driverBuildTime, mGpuStats.appPackageName.c_str(), mGpuStats.vulkanVersion, static_cast(api), isDriverLoaded, driverLoadingTime); - GraphicsEnv::Driver driver = GraphicsEnv::Driver::NONE; + GpuStatsInfo::Driver driver = GpuStatsInfo::Driver::NONE; bool isIntendedDriverLoaded = false; - if (api == GraphicsEnv::Api::API_GL) { + if (api == GpuStatsInfo::Api::API_GL) { driver = mGpuStats.glDriverToLoad; isIntendedDriverLoaded = - isDriverLoaded && (mGpuStats.glDriverFallback == GraphicsEnv::Driver::NONE); + isDriverLoaded && (mGpuStats.glDriverFallback == GpuStatsInfo::Driver::NONE); } else { driver = mGpuStats.vkDriverToLoad; isIntendedDriverLoaded = - isDriverLoaded && (mGpuStats.vkDriverFallback == GraphicsEnv::Driver::NONE); + isDriverLoaded && (mGpuStats.vkDriverFallback == GpuStatsInfo::Driver::NONE); } const sp gpuService = getGpuService(); -- 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/GraphicsEnv.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 8e09730244a3fb935d5fdae94c572bb3946c5c6e Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Mon, 8 Jul 2019 16:11:12 -0700 Subject: GpuStats: Cache the gpu service binder Cache the gpu service binder in the app process so that sending stats pieces won't try to find gpu service every time. If gpu service accidentally restarts, just ignore the later stats from the app, since the memory that holds GpuStats for that app is gone already during the gpu service restart. Test: systrace while try killing gpu service Change-Id: Ib9c38a3592f509f18d146b6c6e8f14e9e997c994 --- libs/graphicsenv/GraphicsEnv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libs/graphicsenv/GraphicsEnv.cpp') diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index a411dd56f6..1eedac111a 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -258,7 +258,7 @@ void GraphicsEnv::setDriverLoaded(GpuStatsInfo::Api api, bool isDriverLoaded, } static sp getGpuService() { - const sp binder = defaultServiceManager()->checkService(String16("gpu")); + static const sp binder = defaultServiceManager()->checkService(String16("gpu")); if (!binder) { ALOGE("Failed to get gpu service"); return nullptr; -- cgit v1.2.3-59-g8ed1b From 49b9ac79f8ca475af1e98f098f803b593b0a02d6 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Mon, 5 Aug 2019 16:57:17 -0700 Subject: libgraphicsenv: get linker symbols from real header Test: build, flash and boot Change-Id: I181430f0f0caef6ee5590c2ed2bf3e7e90e4ed0d --- libs/graphicsenv/Android.bp | 4 ++++ libs/graphicsenv/GraphicsEnv.cpp | 17 +---------------- 2 files changed, 5 insertions(+), 16 deletions(-) (limited to 'libs/graphicsenv/GraphicsEnv.cpp') diff --git a/libs/graphicsenv/Android.bp b/libs/graphicsenv/Android.bp index 56521bf2b4..f11cf62e50 100644 --- a/libs/graphicsenv/Android.bp +++ b/libs/graphicsenv/Android.bp @@ -32,5 +32,9 @@ cc_library_shared { "libutils", ], + header_libs: [ + "libnativeloader-dummy-headers", + ], + export_include_dirs: ["include"], } diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 3e29e88b20..7f8d3a66b5 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -39,22 +40,6 @@ #include #include -// TODO(b/37049319) Get this from a header once one exists -extern "C" { -android_namespace_t* android_get_exported_namespace(const char*); -android_namespace_t* android_create_namespace(const char* name, const char* ld_library_path, - const char* default_library_path, uint64_t type, - const char* permitted_when_isolated_path, - android_namespace_t* parent); -bool android_link_namespaces(android_namespace_t* from, android_namespace_t* to, - const char* shared_libs_sonames); - -enum { - ANDROID_NAMESPACE_TYPE_ISOLATED = 1, - ANDROID_NAMESPACE_TYPE_SHARED = 2, -}; -} - // TODO(ianelliott@): Get the following from an ANGLE header: #define CURRENT_ANGLE_API_VERSION 2 // Current API verion we are targetting // Version-2 API: -- cgit v1.2.3-59-g8ed1b From 472cab0a611317cc2a8a50cb9897018cee8d79e3 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Mon, 5 Aug 2019 17:57:41 -0700 Subject: GpuStats: fix driver loading stats at driver unloading Bug: 138963614 Test: opt-in to GameDriver or ANGLE and test Change-Id: I1e74cf55dd00f6fd7cb65d278d4dbaf018c5f322 --- libs/graphicsenv/GraphicsEnv.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libs/graphicsenv/GraphicsEnv.cpp') diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 3e29e88b20..705a0a4b03 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -213,7 +213,8 @@ void GraphicsEnv::setDriverToLoad(GpuStatsInfo::Driver driver) { case GpuStatsInfo::Driver::GL: case GpuStatsInfo::Driver::GL_UPDATED: case GpuStatsInfo::Driver::ANGLE: { - if (mGpuStats.glDriverToLoad == GpuStatsInfo::Driver::NONE) { + if (mGpuStats.glDriverToLoad == GpuStatsInfo::Driver::NONE || + mGpuStats.glDriverToLoad == GpuStatsInfo::Driver::GL) { mGpuStats.glDriverToLoad = driver; break; } @@ -225,7 +226,8 @@ void GraphicsEnv::setDriverToLoad(GpuStatsInfo::Driver driver) { } case GpuStatsInfo::Driver::VULKAN: case GpuStatsInfo::Driver::VULKAN_UPDATED: { - if (mGpuStats.vkDriverToLoad == GpuStatsInfo::Driver::NONE) { + if (mGpuStats.vkDriverToLoad == GpuStatsInfo::Driver::NONE || + mGpuStats.vkDriverToLoad == GpuStatsInfo::Driver::VULKAN) { mGpuStats.vkDriverToLoad = driver; break; } -- cgit v1.2.3-59-g8ed1b From 0afcca0b295d50227439af6a555fcbabc80341b0 Mon Sep 17 00:00:00 2001 From: Adam Bodnar Date: Tue, 17 Sep 2019 13:23:17 -0700 Subject: [libgraphicsenv] Add an API to enable profiling features Set PR_SET_DUMPABLE for process that wishes to inject Vk/GL layers via metadata. This signals the graphics driver to enable profiling features. Bug: 138204026 Test: Add to the xml in the manifest of a GL/Vk app. Call prctl(PR_GET_DUMPABLE) in a native app to verify. Change-Id: Ife7d18f77775499629d830376a76c4599afd9c15 --- libs/graphicsenv/GraphicsEnv.cpp | 7 +++++++ libs/graphicsenv/include/graphicsenv/GraphicsEnv.h | 8 ++++++++ 2 files changed, 15 insertions(+) (limited to 'libs/graphicsenv/GraphicsEnv.cpp') diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 30f5f73c3a..28591110f0 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -307,6 +307,13 @@ void GraphicsEnv::sendGpuStatsLocked(GpuStatsInfo::Api api, bool isDriverLoaded, } } +bool GraphicsEnv::setInjectLayersPrSetDumpable() { + if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) { + return false; + } + return true; +} + void* GraphicsEnv::loadLibrary(std::string name) { const android_dlextinfo dlextinfo = { .flags = ANDROID_DLEXT_USE_NAMESPACE, diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h index a47f468e7a..83448d4ce7 100644 --- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h +++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h @@ -67,6 +67,14 @@ public: // Set which driver is actually loaded. void setDriverLoaded(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime); + /* + * Api for Vk/GL layer injection. Presently, drivers enable certain + * profiling features when prctl(PR_GET_DUMPABLE) returns true. + * Calling this when layer injection metadata is present allows the driver + * to enable profiling even when in a non-debuggable app + */ + bool setInjectLayersPrSetDumpable(); + /* * Apis for ANGLE */ -- cgit v1.2.3-59-g8ed1b From 6a674c9e105bdc5d736c06a4500dcdac1c6c4006 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Fri, 8 Nov 2019 11:55:36 -0800 Subject: GraphicsEnv: refactor to unify the debuggable logic By default, PR_SET_DUMPABLE is 0 for zygote spawned apps, except in the following circumstances: 1. ro.debuggable=1 (global debuggable enabled, i.e., userdebug or eng builds). 2. android:debuggable="true" in the manifest for an individual application. 3. An app which explicitly calls prctl(PR_SET_DUMPABLE, 1). 4. GraphicsEnv calls prctl(PR_SET_DUMPABLE, 1) in the presence of in the application manifest. So checking both ro.debuggable=1 and PR_GET_DUMPABLE is redundant. Bug: 144186877 Test: CtsAngleIntegrationHostTestCases Test: CtsRootlessGpuDebugHostTest Change-Id: I934f64315b67db77ee2c2a9dff50fb23bc0a546a --- libs/graphicsenv/GraphicsEnv.cpp | 8 ++------ libs/graphicsenv/include/graphicsenv/GraphicsEnv.h | 12 ++++++++++-- opengl/libs/EGL/egl_layers.cpp | 2 +- vulkan/libvulkan/api.cpp | 6 ++++-- vulkan/libvulkan/driver.cpp | 4 ---- vulkan/libvulkan/driver.h | 1 - vulkan/libvulkan/layers_extensions.cpp | 3 +-- 7 files changed, 18 insertions(+), 18 deletions(-) (limited to 'libs/graphicsenv/GraphicsEnv.cpp') diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 28591110f0..354703b9e4 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -124,12 +124,8 @@ static const std::string getSystemNativeLibraries(NativeLibrary type) { return env; } -int GraphicsEnv::getCanLoadSystemLibraries() { - if (property_get_bool("ro.debuggable", false) && prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) { - // Return an integer value since this crosses library boundaries - return 1; - } - return 0; +bool GraphicsEnv::isDebuggable() { + return prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) > 0; } void GraphicsEnv::setDriverPathAndSphalLibraries(const std::string path, diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h index 83448d4ce7..c6dc1f831a 100644 --- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h +++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h @@ -33,8 +33,16 @@ class GraphicsEnv { public: static GraphicsEnv& getInstance(); - // Check if device is debuggable. - int getCanLoadSystemLibraries(); + // Check if the process is debuggable. It returns false except in any of the + // following circumstances: + // 1. ro.debuggable=1 (global debuggable enabled). + // 2. android:debuggable="true" in the manifest for an individual app. + // 3. An app which explicitly calls prctl(PR_SET_DUMPABLE, 1). + // 4. GraphicsEnv calls prctl(PR_SET_DUMPABLE, 1) in the presence of + // + // in the application manifest. + bool isDebuggable(); /* * Apis for updatable driver diff --git a/opengl/libs/EGL/egl_layers.cpp b/opengl/libs/EGL/egl_layers.cpp index ac01dc8f96..ba7cacdbf2 100644 --- a/opengl/libs/EGL/egl_layers.cpp +++ b/opengl/libs/EGL/egl_layers.cpp @@ -337,7 +337,7 @@ void LayerLoader::LoadLayers() { // Only enable the system search path for non-user builds std::string system_path; - if (property_get_bool("ro.debuggable", false) && prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) { + if (android::GraphicsEnv::getInstance().isDebuggable()) { system_path = kSystemLayerLibraryDir; } diff --git a/vulkan/libvulkan/api.cpp b/vulkan/libvulkan/api.cpp index 24039b1fee..a1207d324f 100644 --- a/vulkan/libvulkan/api.cpp +++ b/vulkan/libvulkan/api.cpp @@ -124,7 +124,8 @@ class OverrideLayerNames { }; void AddImplicitLayers() { - if (!is_instance_ || !driver::Debuggable()) + if (!is_instance_ || + !android::GraphicsEnv::getInstance().isDebuggable()) return; GetLayersFromSettings(); @@ -370,7 +371,8 @@ class OverrideExtensionNames { private: bool EnableDebugCallback() const { - return (is_instance_ && driver::Debuggable() && + return (is_instance_ && + android::GraphicsEnv::getInstance().isDebuggable() && property_get_bool("debug.vulkan.enable_callback", false)); } diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 0b686f189a..c1994f9976 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -755,10 +755,6 @@ void FreeDeviceData(DeviceData* data, const VkAllocationCallbacks& allocator) { } // anonymous namespace -bool Debuggable() { - return prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) > 0; -} - bool OpenHAL() { return Hal::Open(); } diff --git a/vulkan/libvulkan/driver.h b/vulkan/libvulkan/driver.h index 7edadea09d..23c717cf5d 100644 --- a/vulkan/libvulkan/driver.h +++ b/vulkan/libvulkan/driver.h @@ -100,7 +100,6 @@ struct DeviceData { DeviceDriverTable driver; }; -bool Debuggable(); bool OpenHAL(); const VkAllocationCallbacks& GetDefaultAllocator(); diff --git a/vulkan/libvulkan/layers_extensions.cpp b/vulkan/libvulkan/layers_extensions.cpp index 2f33fee8ac..3ebfd7b629 100644 --- a/vulkan/libvulkan/layers_extensions.cpp +++ b/vulkan/libvulkan/layers_extensions.cpp @@ -475,8 +475,7 @@ void* GetLayerGetProcAddr(const Layer& layer, void DiscoverLayers() { ATRACE_CALL(); - if (property_get_bool("ro.debuggable", false) && - prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) { + if (android::GraphicsEnv::getInstance().isDebuggable()) { DiscoverLayersInPathList(kSystemLayerLibraryDir); } if (!android::GraphicsEnv::getInstance().getLayerPaths().empty()) -- cgit v1.2.3-59-g8ed1b From d381938b704b640dd58fbd0c2879617e6e3e512a Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Tue, 7 Jan 2020 19:53:56 -0800 Subject: GpuStats: tighten the triggers to send GPU stats to gpuservice Before: (1) Any driver gets loaded and GraphicsEnvironment setup (2) At least one activity launched and GraphicsEnvironment setup (3) Target stats collected After: General pre-condition: at least one activity has been launched and GraphicsEnvironment setup is not skipped. (1) Any driver gets loaded (2) At least one activity launched (3) Target stats collected Test: adb shell dumpsys gpu Change-Id: Iba714e6c98d90bf9a21abdbdc2067e834a306cc2 --- libs/graphicsenv/GraphicsEnv.cpp | 22 +++++++++++++++++----- libs/graphicsenv/include/graphicsenv/GraphicsEnv.h | 4 ++++ 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'libs/graphicsenv/GraphicsEnv.cpp') diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 354703b9e4..f07c23132d 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -145,6 +145,12 @@ void GraphicsEnv::setDriverPathAndSphalLibraries(const std::string path, void GraphicsEnv::hintActivityLaunch() { ATRACE_CALL(); + { + std::lock_guard lock(mStatsLock); + if (mActivityLaunched) return; + mActivityLaunched = true; + } + std::thread trySendGpuStatsThread([this]() { // If there's already graphics driver preloaded in the process, just send // the stats info to GpuStats directly through async binder. @@ -228,12 +234,11 @@ void GraphicsEnv::setDriverLoaded(GpuStatsInfo::Api api, bool isDriverLoaded, ATRACE_CALL(); std::lock_guard lock(mStatsLock); - const bool doNotSend = mGpuStats.appPackageName.empty(); if (api == GpuStatsInfo::Api::API_GL) { - if (doNotSend) mGpuStats.glDriverToSend = true; + mGpuStats.glDriverToSend = true; mGpuStats.glDriverLoadingTime = driverLoadingTime; } else { - if (doNotSend) mGpuStats.vkDriverToSend = true; + mGpuStats.vkDriverToSend = true; mGpuStats.vkDriverLoadingTime = driverLoadingTime; } @@ -250,10 +255,18 @@ static sp getGpuService() { return interface_cast(binder); } +bool GraphicsEnv::readyToSendGpuStatsLocked() { + // Only send stats for processes having at least one activity launched and that process doesn't + // skip the GraphicsEnvironment setup. + return mActivityLaunched && !mGpuStats.appPackageName.empty(); +} + void GraphicsEnv::setTargetStats(const GpuStatsInfo::Stats stats, const uint64_t value) { ATRACE_CALL(); std::lock_guard lock(mStatsLock); + if (!readyToSendGpuStatsLocked()) return; + const sp gpuService = getGpuService(); if (gpuService) { gpuService->setTargetStats(mGpuStats.appPackageName, mGpuStats.driverVersionCode, stats, @@ -265,8 +278,7 @@ void GraphicsEnv::sendGpuStatsLocked(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime) { ATRACE_CALL(); - // Do not sendGpuStats for those skipping the GraphicsEnvironment setup - if (mGpuStats.appPackageName.empty()) return; + if (!readyToSendGpuStatsLocked()) return; ALOGV("sendGpuStats:\n" "\tdriverPackageName[%s]\n" diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h index c6dc1f831a..2219074ec0 100644 --- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h +++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h @@ -131,6 +131,8 @@ private: void updateUseAngle(); // Link updatable driver namespace with llndk and vndk-sp libs. bool linkDriverNamespaceLocked(android_namespace_t* vndkNamespace); + // Check whether this process is ready to send stats. + bool readyToSendGpuStatsLocked(); // Send the initial complete GpuStats to GpuService. void sendGpuStatsLocked(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime); @@ -141,6 +143,8 @@ private: std::string mSphalLibraries; // This mutex protects mGpuStats and get gpuservice call. std::mutex mStatsLock; + // Cache the activity launch info + bool mActivityLaunched = false; // Information bookkept for GpuStats. GpuStatsInfo mGpuStats; // Path to ANGLE libs. -- cgit v1.2.3-59-g8ed1b From db3ed6e69797afa5735b5d7a3b0d0f788a522284 Mon Sep 17 00:00:00 2001 From: Peiyong Lin Date: Thu, 9 Jan 2020 18:43:27 -0800 Subject: Don't fall back to system driver when driver apk fails. Previously when driver apk fails to load, the loader falls back to load system driver. However, this provides no indication of driver apk failure and hence users that intend to use driver apk may end up working against the system driver. BUG: b/147459984 Test: Verified by forcing to use a dummy apk Change-Id: I3befc0d6c1f143dc53eab3762b7ff19c702e8cda --- libs/graphicsenv/GraphicsEnv.cpp | 4 ++++ libs/graphicsenv/include/graphicsenv/GraphicsEnv.h | 1 + opengl/libs/EGL/Loader.cpp | 5 +++++ 3 files changed, 10 insertions(+) (limited to 'libs/graphicsenv/GraphicsEnv.cpp') diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index f07c23132d..befabee66d 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -611,6 +611,10 @@ android_namespace_t* GraphicsEnv::getDriverNamespace() { return mDriverNamespace; } +std::string GraphicsEnv::getDriverPath() const { + return mDriverPath; +} + android_namespace_t* GraphicsEnv::getAngleNamespace() { std::lock_guard lock(mNamespaceMutex); diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h index 2219074ec0..22a2332589 100644 --- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h +++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h @@ -58,6 +58,7 @@ public: void setDriverPathAndSphalLibraries(const std::string path, const std::string sphalLibraries); // Get the updatable driver namespace. android_namespace_t* getDriverNamespace(); + std::string getDriverPath() const; /* * Apis for GpuStats diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp index e1432608c9..06944bb5c6 100644 --- a/opengl/libs/EGL/Loader.cpp +++ b/opengl/libs/EGL/Loader.cpp @@ -238,6 +238,11 @@ void* Loader::open(egl_connection_t* cnx) bool failToLoadFromDriverSuffixProperty = false; if (!hnd) { + // If updated driver apk is set but fail to load, abort here. + if (android::GraphicsEnv::getInstance().getDriverNamespace()) { + LOG_ALWAYS_FATAL("couldn't find an OpenGL ES implementation from %s", + android::GraphicsEnv::getInstance().getDriverPath().c_str()); + } // Finally, try to load system driver, start by searching for the library name appended by // the system properties of the GLES userspace driver in both locations. // i.e.: -- cgit v1.2.3-59-g8ed1b From 1f7c37f373068c41ba77413fc6dc4eb8bac28f0b Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Sun, 23 Feb 2020 03:02:43 +0900 Subject: Use {llndk,vndksp}.libraries.txt from VNDK APEX /system/etc/{llndk,vndksp}.libraries.txt files will be deprecated. These files can be read from VNDK APEX. Bug: 145184886 Test: build / boot Merged-In: Ic6f46033bd525325562e04ef9e8bcb8ebb5b5d41 Change-Id: Ic6f46033bd525325562e04ef9e8bcb8ebb5b5d41 (cherry picked from commit 78396804770bf3c3a1143f823a466cc0c6849104) --- libs/graphicsenv/GraphicsEnv.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'libs/graphicsenv/GraphicsEnv.cpp') diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index befabee66d..4809c1f0d8 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -61,26 +61,25 @@ enum NativeLibrary { VNDKSP = 1, }; -static constexpr const char* kNativeLibrariesSystemConfigPath[] = {"/etc/llndk.libraries.txt", - "/etc/vndksp.libraries.txt"}; +static constexpr const char* kNativeLibrariesSystemConfigPath[] = + {"/apex/com.android.vndk.v{}/etc/llndk.libraries.{}.txt", + "/apex/com.android.vndk.v{}/etc/vndksp.libraries.{}.txt"}; static std::string vndkVersionStr() { #ifdef __BIONIC__ - std::string version = android::base::GetProperty("ro.vndk.version", ""); - if (version != "" && version != "current") { - return "." + version; - } + return android::base::GetProperty("ro.vndk.version", ""); #endif return ""; } static void insertVndkVersionStr(std::string* fileName) { LOG_ALWAYS_FATAL_IF(!fileName, "fileName should never be nullptr"); - size_t insertPos = fileName->find_last_of("."); - if (insertPos == std::string::npos) { - insertPos = fileName->length(); + std::string version = vndkVersionStr(); + size_t pos = fileName->find("{}"); + while (pos != std::string::npos) { + fileName->replace(pos, 2, version); + pos = fileName->find("{}", pos + version.size()); } - fileName->insert(insertPos, vndkVersionStr()); } static bool readConfig(const std::string& configFile, std::vector* soNames) { @@ -103,11 +102,7 @@ static bool readConfig(const std::string& configFile, std::vector* } static const std::string getSystemNativeLibraries(NativeLibrary type) { - static const char* androidRootEnv = getenv("ANDROID_ROOT"); - static const std::string rootDir = androidRootEnv != nullptr ? androidRootEnv : "/system"; - - std::string nativeLibrariesSystemConfig = rootDir + kNativeLibrariesSystemConfigPath[type]; - + std::string nativeLibrariesSystemConfig = kNativeLibrariesSystemConfigPath[type]; insertVndkVersionStr(&nativeLibrariesSystemConfig); std::vector soNames; -- 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/GraphicsEnv.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