| Mark Salyzyn | f089e14 | 2018-02-20 10:47:40 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2018 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 | #include "llkd.h" | 
 | 18 |  | 
 | 19 | #include <sched.h> | 
| Mark Salyzyn | 4832a8b | 2018-08-15 11:02:18 -0700 | [diff] [blame] | 20 | #include <sys/prctl.h> | 
| Mark Salyzyn | f089e14 | 2018-02-20 10:47:40 -0800 | [diff] [blame] | 21 | #include <unistd.h> | 
 | 22 |  | 
 | 23 | #include <chrono> | 
 | 24 |  | 
 | 25 | #include <android-base/logging.h> | 
 | 26 |  | 
 | 27 | using namespace std::chrono; | 
 | 28 |  | 
 | 29 | int main(int, char**) { | 
| Mark Salyzyn | 4832a8b | 2018-08-15 11:02:18 -0700 | [diff] [blame] | 30 |     prctl(PR_SET_DUMPABLE, 0); | 
 | 31 |  | 
| Mark Salyzyn | f089e14 | 2018-02-20 10:47:40 -0800 | [diff] [blame] | 32 |     LOG(INFO) << "started"; | 
 | 33 |  | 
 | 34 |     bool enabled = llkInit(); | 
 | 35 |  | 
 | 36 |     // Would like this policy to be automatic as part of libllkd, | 
 | 37 |     // but that would be presumptuous and bad side-effect. | 
 | 38 |     struct sched_param param; | 
 | 39 |     memset(¶m, 0, sizeof(param)); | 
 | 40 |     sched_setscheduler(0, SCHED_BATCH, ¶m); | 
 | 41 |  | 
 | 42 |     while (true) { | 
 | 43 |         if (enabled) { | 
 | 44 |             ::usleep(duration_cast<microseconds>(llkCheck()).count()); | 
 | 45 |         } else { | 
 | 46 |             ::pause(); | 
 | 47 |         } | 
 | 48 |     } | 
 | 49 |     // NOTREACHED | 
 | 50 |  | 
 | 51 |     LOG(INFO) << "exiting"; | 
 | 52 |     return 0; | 
 | 53 | } |