Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 1 | #include <sched.h> |
Fan Xu | 74df490 | 2018-09-20 16:40:51 -0700 | [diff] [blame] | 2 | #include <sys/resource.h> |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 3 | #include <unistd.h> |
| 4 | |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 5 | #include <dvr/performance_client_api.h> |
Fan Xu | 74df490 | 2018-09-20 16:40:51 -0700 | [diff] [blame] | 6 | #include <log/log.h> |
Alex Vakulenko | 5a244ed | 2017-06-09 16:29:04 -0700 | [diff] [blame] | 7 | #include <pdx/service_dispatcher.h> |
Fan Xu | 74df490 | 2018-09-20 16:40:51 -0700 | [diff] [blame] | 8 | #include <private/dvr/buffer_hub.h> |
Fan Xu | cfd1274 | 2018-09-14 13:23:52 -0700 | [diff] [blame] | 9 | #include <private/dvr/buffer_hub_binder.h> |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 10 | |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 11 | int main(int, char**) { |
| 12 | int ret = -1; |
Fan Xu | 7a0f33e | 2018-09-20 16:21:35 -0700 | [diff] [blame^] | 13 | std::shared_ptr<android::dvr::BufferHubService> pdx_service; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 14 | std::unique_ptr<android::pdx::ServiceDispatcher> dispatcher; |
| 15 | |
| 16 | // We need to be able to create endpoints with full perms. |
| 17 | umask(0000); |
| 18 | |
Corey Tabaka | 52ea25c | 2017-09-13 18:02:48 -0700 | [diff] [blame] | 19 | // Bump up the soft limit of open fd to the hard limit. |
| 20 | struct rlimit64 rlim; |
| 21 | ret = getrlimit64(RLIMIT_NOFILE, &rlim); |
| 22 | LOG_ALWAYS_FATAL_IF(ret != 0, "Failed to get nofile limit."); |
| 23 | |
| 24 | ALOGI("Current nofile limit is %llu/%llu.", rlim.rlim_cur, rlim.rlim_max); |
| 25 | rlim.rlim_cur = rlim.rlim_max; |
| 26 | ret = setrlimit64(RLIMIT_NOFILE, &rlim); |
| 27 | ALOGE_IF(ret < 0, "Failed to set nofile limit, error=%s", strerror(errno)); |
| 28 | |
| 29 | rlim.rlim_cur = -1; |
| 30 | rlim.rlim_max = -1; |
| 31 | if (getrlimit64(RLIMIT_NOFILE, &rlim) < 0) |
| 32 | ALOGE("Failed to get nofile limit."); |
| 33 | else |
| 34 | ALOGI("New nofile limit is %llu/%llu.", rlim.rlim_cur, rlim.rlim_max); |
| 35 | |
Alex Vakulenko | 5a244ed | 2017-06-09 16:29:04 -0700 | [diff] [blame] | 36 | dispatcher = android::pdx::ServiceDispatcher::Create(); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 37 | CHECK_ERROR(!dispatcher, error, "Failed to create service dispatcher\n"); |
| 38 | |
Fan Xu | 7a0f33e | 2018-09-20 16:21:35 -0700 | [diff] [blame^] | 39 | pdx_service = android::dvr::BufferHubService::Create(); |
| 40 | CHECK_ERROR(!pdx_service, error, "Failed to create bufferhub pdx service\n"); |
| 41 | dispatcher->AddService(pdx_service); |
| 42 | |
| 43 | ret = android::dvr::BufferHubBinderService::start(pdx_service); |
| 44 | CHECK_ERROR(ret != android::NO_ERROR, error, |
| 45 | "Failed to create bufferhub binder service\n"); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 46 | |
| 47 | ret = dvrSetSchedulerClass(0, "graphics"); |
| 48 | CHECK_ERROR(ret < 0, error, "Failed to set thread priority"); |
| 49 | |
| 50 | ALOGI("Entering message loop."); |
| 51 | |
| 52 | ret = dispatcher->EnterDispatchLoop(); |
| 53 | CHECK_ERROR(ret < 0, error, "Dispatch loop exited because: %s\n", |
| 54 | strerror(-ret)); |
| 55 | |
| 56 | error: |
| 57 | return -ret; |
| 58 | } |