diff options
author | 2018-11-01 10:34:57 -0700 | |
---|---|---|
committer | 2018-11-08 11:42:05 -0800 | |
commit | 2c37e20e8dd553b70601d09514ecdf5a8adf30a6 (patch) | |
tree | 262b643b87c0e9f75a9e1b0c8370ffe34858fc1d | |
parent | 5a9bcace84475fb8a2963fb1432b519de65b5f8b (diff) |
[GPU Service] Separate GPU Service out of SurfaceFlinger.
Historically GPU service lives in SurfaceFlinger because it's a convenient
hack. This patch separates GPU service out of SurfaceFlinger. The GPU service
is a service that accesses to GPU, queries GPU capabilities and reports back.
Minor: Replace Vector with std::vector.
BUG: 118347356
Test: Build, flash and boot, `adb shell cmd gpuservice vkjson` to verify
Change-Id: If8feedc0a58bcd3c2e4111f8997117a618f5a516
-rw-r--r-- | services/gpuservice/Android.bp | 74 | ||||
-rw-r--r-- | services/gpuservice/GpuService.cpp (renamed from services/surfaceflinger/GpuService.cpp) | 26 | ||||
-rw-r--r-- | services/gpuservice/GpuService.h (renamed from services/surfaceflinger/GpuService.h) | 13 | ||||
-rw-r--r-- | services/gpuservice/gpuservice.rc | 4 | ||||
-rw-r--r-- | services/gpuservice/main_gpuservice.cpp | 43 | ||||
-rw-r--r-- | services/surfaceflinger/Android.bp | 7 | ||||
-rw-r--r-- | services/surfaceflinger/main_surfaceflinger.cpp | 5 |
7 files changed, 135 insertions, 37 deletions
diff --git a/services/gpuservice/Android.bp b/services/gpuservice/Android.bp new file mode 100644 index 0000000000..250bbee350 --- /dev/null +++ b/services/gpuservice/Android.bp @@ -0,0 +1,74 @@ +filegroup { + name: "gpuservice_sources", + srcs: [ + "GpuService.cpp", + ], +} + +filegroup { + name: "gpuservice_binary_sources", + srcs: ["main_gpuservice.cpp"], +} + +cc_defaults { + name: "gpuservice_defaults", + cflags: [ + "-DLOG_TAG=\"GpuService\"", + "-Wall", + "-Werror", + "-Wformat", + "-Wthread-safety", + "-Wunused", + "-Wunreachable-code", + ], + cppflags: ["-std=c++1z"], + srcs: [ + ":gpuservice_sources", + ], + include_dirs: [ + "frameworks/native/vulkan/vkjson", + "frameworks/native/vulkan/include", + ], + shared_libs: [ + "libbinder", + "liblog", + "libutils", + "libvulkan", + ], + static_libs: [ + "libvkjson", + ], +} + +cc_defaults { + name: "gpuservice_production_defaults", + defaults: ["gpuservice_defaults"], + cflags: [ + "-fvisibility=hidden", + "-fwhole-program-vtables", // requires ThinLTO + ], + lto: { + thin: true, + }, +} + +cc_defaults { + name: "gpuservice_binary", + defaults: ["gpuservice_defaults"], + whole_static_libs: [ + "libsigchain", + ], + shared_libs: [ + "libbinder", + "liblog", + "libutils", + ], + ldflags: ["-Wl,--export-dynamic"], +} + +cc_binary { + name: "gpuservice", + defaults: ["gpuservice_binary"], + init_rc: ["gpuservice.rc"], + srcs: [":gpuservice_binary_sources"], +} diff --git a/services/surfaceflinger/GpuService.cpp b/services/gpuservice/GpuService.cpp index 71052fb563..e4ca6bcc47 100644 --- a/services/surfaceflinger/GpuService.cpp +++ b/services/gpuservice/GpuService.cpp @@ -23,10 +23,7 @@ namespace android { -// ---------------------------------------------------------------------------- - -class BpGpuService : public BpInterface<IGpuService> -{ +class BpGpuService : public BpInterface<IGpuService> { public: explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {} }; @@ -34,19 +31,15 @@ public: IMPLEMENT_META_INTERFACE(GpuService, "android.ui.IGpuService"); status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, - Parcel* reply, uint32_t flags) -{ + Parcel* reply, uint32_t flags) { status_t status; switch (code) { case SHELL_COMMAND_TRANSACTION: { int in = data.readFileDescriptor(); int out = data.readFileDescriptor(); int err = data.readFileDescriptor(); - int argc = data.readInt32(); - Vector<String16> args; - for (int i = 0; i < argc && data.dataAvail() > 0; i++) { - args.add(data.readString16()); - } + std::vector<String16> args; + data.readString16Vector(&args); sp<IBinder> unusedCallback; sp<IResultReceiver> resultReceiver; if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) @@ -64,20 +57,17 @@ status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, } } -// ---------------------------------------------------------------------------- - namespace { status_t cmd_help(int out); status_t cmd_vkjson(int out, int err); } -const char* const GpuService::SERVICE_NAME = "gpu"; +const char* const GpuService::SERVICE_NAME = "gpuservice"; -GpuService::GpuService() {} +GpuService::GpuService() = default; status_t GpuService::shellCommand(int /*in*/, int out, int err, - Vector<String16>& args) -{ + std::vector<String16>& args) { ALOGV("GpuService::shellCommand"); for (size_t i = 0, n = args.size(); i < n; i++) ALOGV(" arg[%zu]: '%s'", i, String8(args[i]).string()); @@ -93,8 +83,6 @@ status_t GpuService::shellCommand(int /*in*/, int out, int err, return BAD_VALUE; } -// ---------------------------------------------------------------------------- - namespace { status_t cmd_help(int out) { diff --git a/services/surfaceflinger/GpuService.h b/services/gpuservice/GpuService.h index b8c28d2495..e2b396ec7b 100644 --- a/services/surfaceflinger/GpuService.h +++ b/services/gpuservice/GpuService.h @@ -17,6 +17,8 @@ #ifndef ANDROID_GPUSERVICE_H #define ANDROID_GPUSERVICE_H +#include <vector> + #include <binder/IInterface.h> #include <cutils/compiler.h> @@ -34,22 +36,21 @@ public: class BnGpuService: public BnInterface<IGpuService> { protected: virtual status_t shellCommand(int in, int out, int err, - Vector<String16>& args) = 0; + std::vector<String16>& args) = 0; - virtual status_t onTransact(uint32_t code, const Parcel& data, + status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0) override; }; -class GpuService : public BnGpuService -{ +class GpuService : public BnGpuService { public: static const char* const SERVICE_NAME ANDROID_API; GpuService() ANDROID_API; protected: - virtual status_t shellCommand(int in, int out, int err, - Vector<String16>& args) override; + status_t shellCommand(int in, int out, int err, + std::vector<String16>& args) override; }; } // namespace android diff --git a/services/gpuservice/gpuservice.rc b/services/gpuservice/gpuservice.rc new file mode 100644 index 0000000000..d23cf461f8 --- /dev/null +++ b/services/gpuservice/gpuservice.rc @@ -0,0 +1,4 @@ +service gpuservice /system/bin/gpuservice + class core + user gpu_service + group graphics diff --git a/services/gpuservice/main_gpuservice.cpp b/services/gpuservice/main_gpuservice.cpp new file mode 100644 index 0000000000..64aafcab6a --- /dev/null +++ b/services/gpuservice/main_gpuservice.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <binder/IPCThreadState.h> +#include <binder/IServiceManager.h> +#include <binder/ProcessState.h> +#include <sys/resource.h> +#include "GpuService.h" + +using namespace android; + +int main(int /* argc */, char** /* argv */) { + signal(SIGPIPE, SIG_IGN); + + // publish GpuService + sp<GpuService> gpuservice = new GpuService(); + sp<IServiceManager> sm(defaultServiceManager()); + sm->addService(String16(GpuService::SERVICE_NAME), gpuservice, false); + + // limit the number of binder threads to 4. + ProcessState::self()->setThreadPoolMaxThreadCount(4); + + // start the thread pool + sp<ProcessState> ps(ProcessState::self()); + ps->startThreadPool(); + ps->giveThreadPoolName(); + IPCThreadState::self()->joinThreadPool(); + + return 0; +} diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp index 16003a258c..e8092a9e4a 100644 --- a/services/surfaceflinger/Android.bp +++ b/services/surfaceflinger/Android.bp @@ -19,10 +19,6 @@ cc_defaults { "-DGL_GLEXT_PROTOTYPES", "-DEGL_EGLEXT_PROTOTYPES", ], - include_dirs: [ - "frameworks/native/vulkan/vkjson", - "frameworks/native/vulkan/include", - ], shared_libs: [ "android.frameworks.vr.composer@1.0", "android.hardware.configstore-utils", @@ -59,13 +55,11 @@ cc_defaults { "libtimestats_proto", "libui", "libutils", - "libvulkan", ], static_libs: [ "librenderengine", "libserviceutils", "libtrace_proto", - "libvkjson", "libvr_manager", "libvrflinger", ], @@ -132,7 +126,6 @@ filegroup { "Effects/Daltonizer.cpp", "EventLog/EventLog.cpp", "FrameTracker.cpp", - "GpuService.cpp", "Layer.cpp", "LayerBE.cpp", "LayerProtoHelper.cpp", diff --git a/services/surfaceflinger/main_surfaceflinger.cpp b/services/surfaceflinger/main_surfaceflinger.cpp index 9c2edca43d..92ae87b5a8 100644 --- a/services/surfaceflinger/main_surfaceflinger.cpp +++ b/services/surfaceflinger/main_surfaceflinger.cpp @@ -28,7 +28,6 @@ #include <cutils/sched_policy.h> #include <displayservice/DisplayService.h> #include <hidl/LegacySupport.h> -#include "GpuService.h" #include "SurfaceFlinger.h" #include "SurfaceFlingerFactory.h" @@ -104,10 +103,6 @@ int main(int, char**) { sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false, IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL | IServiceManager::DUMP_FLAG_PROTO); - // publish GpuService - sp<GpuService> gpuservice = new GpuService(); - sm->addService(String16(GpuService::SERVICE_NAME), gpuservice, false); - startDisplayService(); // dependency on SF getting registered above struct sched_param param = {0}; |