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