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