blob: 1920198a3e1ca1299275bd040bd6195ed83079a5 [file] [log] [blame]
Mark Salyzynf089e142018-02-20 10:47:40 -08001/*
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 Salyzyn4832a8b2018-08-15 11:02:18 -070020#include <sys/prctl.h>
Mark Salyzynf089e142018-02-20 10:47:40 -080021#include <unistd.h>
22
23#include <chrono>
24
25#include <android-base/logging.h>
26
27using namespace std::chrono;
28
29int main(int, char**) {
Mark Salyzyn4832a8b2018-08-15 11:02:18 -070030 prctl(PR_SET_DUMPABLE, 0);
31
Mark Salyzynf089e142018-02-20 10:47:40 -080032 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(&param, 0, sizeof(param));
40 sched_setscheduler(0, SCHED_BATCH, &param);
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}