forked from qualcomm/userspace-resource-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurm.cpp
More file actions
104 lines (83 loc) · 2.8 KB
/
urm.cpp
File metadata and controls
104 lines (83 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// SPDX-License-Identifier: BSD-3-Clause-Clear
#include <csignal>
#include <thread>
#include "Utils.h"
#include "Logger.h"
#include "UrmSettings.h"
#include "UrmPlatformAL.h"
#include "ComponentRegistry.h"
static int8_t terminateServer = false;
static void handleSIGINT(int32_t sig) {
(void)sig;
terminateServer = true;
}
static void handleSIGTERM(int32_t sig) {
(void)sig;
terminateServer = true;
}
static ErrCode initModuleIfPresent(ModuleID moduleId) {
// Check if the module is plugged in and Initialize it
ModuleInfo modInfo = ComponentRegistry::getModuleInfo(moduleId);
if(modInfo.mInit == nullptr) {
// Module not enabled
return RC_SUCCESS;
}
return modInfo.mInit(nullptr);
}
static ErrCode cleanupModule(ModuleID moduleId) {
// Check if the module is plugged in and Initialize it
ModuleInfo modInfo = ComponentRegistry::getModuleInfo(moduleId);
if(modInfo.mTear == nullptr) {
// Module not enabled
return RC_SUCCESS;
}
return modInfo.mTear(nullptr);
}
static void serverCleanup() {
LOGI("RESTUNE_SERVER_INIT", "Server Stopped, Cleanup Initiated");
UrmSettings::setServerOnlineStatus(false);
}
int32_t main(int32_t argc, char *argv[]) {
(void)argc;
(void)argv;
// Initialize syslog
openlog(URM_IDENTIFIER, LOG_PID | LOG_CONS | LOG_NDELAY, LOG_DAEMON);
setlogmask(LOG_UPTO(LOG_DEBUG));
ErrCode opStatus = RC_SUCCESS;
std::signal(SIGINT, handleSIGINT);
std::signal(SIGTERM, handleSIGTERM);
TYPELOGV(NOTIFY_RESOURCE_TUNER_INIT_START, getpid());
// Ready for requests
if(RC_IS_OK(opStatus)) {
UrmSettings::setServerOnlineStatus(true);
UrmSettings::targetConfigs.currMode = MODE_RESUME;
}
if(RC_IS_OK(opStatus)) {
opStatus = initModuleIfPresent(ModuleID::MOD_RESTUNE);
if(RC_IS_NOTOK(opStatus)) {
TYPELOGV(MODULE_INIT_FAILED, "resource-tuner");
}
}
if(RC_IS_OK(opStatus)) {
opStatus = initModuleIfPresent(ModuleID::MOD_CLASSIFIER);
if(RC_IS_NOTOK(opStatus)) {
TYPELOGV(MODULE_INIT_FAILED, "classifier");
}
}
if(RC_IS_OK(opStatus)) {
// Listen for Terminal prompts
while(!terminateServer) {
std::this_thread::sleep_for(std::chrono::seconds(2));
}
}
// Cleanup the Server, so that it boots up correctly the next time
// - This includes Closing the Server Communication Endpoints
// - Resetting all the Sysfs nodes to their original values
// - Terminating the different listener and Processor threads created to handle Requests.
serverCleanup();
cleanupModule(ModuleID::MOD_RESTUNE);
cleanupModule(ModuleID::MOD_CLASSIFIER);
closelog();
return 0;
}