Skip to content

Commit 76a64f0

Browse files
committed
Merge branch 'main' of https://github.com/kartnema/resource-tuner into dev/classifier-app-persistence
2 parents d537977 + e136c60 commit 76a64f0

23 files changed

Lines changed: 974 additions & 290 deletions

configs/ResourcesConfig.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ ResourceConfigs:
142142
Policy: "lower_is_better"
143143
ApplyType: "cluster"
144144

145+
- ResType: "0x04"
146+
ResID: "0x0003"
147+
Name: "RES_CPU_ONLINE_PER_CORE"
148+
Path: "/sys/devices/system/cpu/cpu%d/online"
149+
Supported: true
150+
Permissions: "third_party"
151+
Modes: ["display_on", "doze"]
152+
Policy: "instant_apply"
153+
ApplyType: "core"
154+
145155
- ResType: "0x05"
146156
ResID: "0x0000"
147157
Name: "RES_DEVFREQ_GPU_MAX"

contextual-classifier/ContextualClassifier.cpp

Lines changed: 23 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "Extensions.h"
2020
#include "AuxRoutines.h"
2121
#include "UrmPlatformAL.h"
22+
#include "SignalInternal.h"
2223
#include "SignalRegistry.h"
2324
#include "RestuneInternal.h"
2425
#include "ContextualClassifier.h"
@@ -97,67 +98,6 @@ static ResIterable* createMovePidResource(int32_t cGroupdId, pid_t pid) {
9798
return resIterable;
9899
}
99100

100-
static Request* createTuneRequestFromSignal(uint32_t sigId,
101-
uint32_t sigType,
102-
pid_t incomingPID,
103-
pid_t incomingTID,
104-
int32_t numArgs,
105-
int32_t* args) {
106-
try {
107-
std::shared_ptr<SignalRegistry> sigRegistry = SignalRegistry::getInstance();
108-
109-
// Check if a Signal with the given ID exists in the Registry
110-
SignalInfo* signalInfo = sigRegistry->getSignalConfigById(sigId, sigType);
111-
112-
if(signalInfo == nullptr) return nullptr;
113-
114-
Request* request = MPLACED(Request);
115-
116-
int64_t handleGenerated = AuxRoutines::generateUniqueHandle();
117-
request->setHandle(handleGenerated);
118-
119-
request->setRequestType(REQ_RESOURCE_TUNING);
120-
request->setDuration(signalInfo->mTimeout);
121-
request->setProperties(SYSTEM_HIGH);
122-
request->setClientPID(incomingPID);
123-
request->setClientTID(incomingTID);
124-
125-
std::vector<Resource*>* signalLocks = signalInfo->mSignalResources;
126-
127-
for(int32_t i = 0; i < (int32_t)signalLocks->size(); i++) {
128-
if((*signalLocks)[i] == nullptr) {
129-
continue;
130-
}
131-
132-
// Copy
133-
Resource* resource = MPLACEV(Resource, (*((*signalLocks)[i])));
134-
135-
// fill placeholders if any
136-
int32_t listIndex = 0;
137-
for(int32_t j = 0; j < resource->getValuesCount(); j++) {
138-
if(resource->getValueAt(j) == -1) {
139-
if(args == nullptr) return nullptr;
140-
if(listIndex >= 0 && listIndex < numArgs) {
141-
resource->setValueAt(j, args[listIndex]);
142-
listIndex++;
143-
}
144-
}
145-
}
146-
147-
ResIterable* resIterable = MPLACED(ResIterable);
148-
resIterable->mData = resource;
149-
request->addResource(resIterable);
150-
}
151-
152-
return request;
153-
154-
} catch(const std::bad_alloc& e) {
155-
return nullptr;
156-
}
157-
158-
return nullptr;
159-
}
160-
161101
ContextualClassifier::~ContextualClassifier() {
162102
this->Terminate();
163103
if(this->mInference) {
@@ -242,8 +182,6 @@ void ContextualClassifier::ClassifierMain() {
242182
std::string comm;
243183
uint32_t sigId = URM_SIG_APP_OPEN;
244184
uint32_t sigType = DEFAULT_SIGNAL_TYPE;
245-
int32_t numArgs = 0;
246-
int32_t* args = nullptr;
247185
uint32_t ctxDetails = 0U;
248186

249187
if(ev.pid != -1) {
@@ -294,19 +232,17 @@ void ContextualClassifier::ClassifierMain() {
294232
.mPid = ev.pid,
295233
.mSigId = sigId,
296234
.mSigType = sigType,
297-
.mNumArgs = numArgs,
298-
.mArgs = args,
235+
.mNumArgs = 0,
236+
.mArgs = nullptr,
237+
.mHandleAcq = -1,
299238
};
300239
postCb((void*)&postProcessData);
301240

302-
sigId = postProcessData.mSigId;
303-
sigType = postProcessData.mSigType;
304-
numArgs = postProcessData.mNumArgs;
305-
args = postProcessData.mArgs;
241+
// Record any Configurations made
242+
if(postProcessData.mHandleAcq != - 1) {
243+
this->mCurrRestuneHandles.push_back(postProcessData.mHandleAcq);
244+
}
306245
}
307-
308-
// Apply actions, call tuneSignal
309-
this->ApplyActions(sigId, sigType, ev.pid, ev.tgid, numArgs, args);
310246
}
311247
} else if(ev.type == CC_APP_CLOSE) {
312248
// No Action Needed, Pulse Monitor to take care of cleanup
@@ -407,35 +343,6 @@ int32_t ContextualClassifier::ClassifyProcess(pid_t processPid,
407343
return context;
408344
}
409345

410-
void ContextualClassifier::ApplyActions(uint32_t sigId,
411-
uint32_t sigType,
412-
pid_t incomingPID,
413-
pid_t incomingTID,
414-
int32_t numArgs,
415-
int32_t* args) {
416-
Request* request =
417-
createTuneRequestFromSignal(sigId, sigType, incomingPID, incomingTID, numArgs, args);
418-
if(request != nullptr) {
419-
if(request->getResourcesCount() > 0) {
420-
// Record:
421-
this->mCurrRestuneHandles.push_back(request->getHandle());
422-
423-
// fast path to Request Queue
424-
submitResProvisionRequest(request, false);
425-
426-
} else {
427-
Request::cleanUpRequest(request);
428-
}
429-
}
430-
}
431-
432-
void ContextualClassifier::RemoveActions(pid_t processPid, pid_t processTgid) {
433-
(void)processPid;
434-
(void)processTgid;
435-
436-
return;
437-
}
438-
439346
uint32_t ContextualClassifier::GetSignalIDForWorkload(int32_t contextType) {
440347
switch(contextType) {
441348
case CC_MULTIMEDIA:
@@ -498,7 +405,7 @@ int8_t ContextualClassifier::shouldProcBeIgnored(int32_t evType, pid_t pid) {
498405
}
499406

500407
std::string procName = "";
501-
if(!AuxRoutines::getProcName(pid, procName)) {
408+
if(AuxRoutines::fetchComm(pid, procName) != 0) {
502409
return true;
503410
}
504411

@@ -575,36 +482,22 @@ void ContextualClassifier::MoveAppThreadsToCGroup(pid_t incomingPID,
575482
void ContextualClassifier::configureAppSignals(pid_t incomingPID,
576483
pid_t incomingTID,
577484
const std::string& comm) {
578-
try {
579-
// Configure any associated signal
580-
AppConfig* appConfig = AppConfigs::getInstance()->getAppConfig(comm);
581-
if(appConfig != nullptr && appConfig->mSignalCodes != nullptr) {
582-
int32_t numSignals = appConfig->mNumSignals;
583-
// Go over the list of proc names (comm) and get their pids
584-
for(int32_t i = 0; i < numSignals; i++) {
585-
Request* request = createTuneRequestFromSignal(
586-
appConfig->mSignalCodes[i],
587-
0,
588-
incomingPID,
589-
incomingTID,
590-
0,
591-
nullptr);
592-
593-
if(request != nullptr) {
594-
if(request->getResourcesCount() > 0) {
595-
// fast path to Request Queue
596-
this->mCurrRestuneHandles.push_back(request->getHandle());
597-
submitResProvisionRequest(request, false);
598-
599-
} else {
600-
Request::cleanUpRequest(request);
601-
}
602-
}
485+
// Configure any associated signal
486+
AppConfig* appConfig = AppConfigs::getInstance()->getAppConfig(comm);
487+
if(appConfig != nullptr && appConfig->mSignalCodes != nullptr) {
488+
// Go over the list of proc names (comm) and get their pids
489+
for(int32_t i = 0; i < appConfig->mNumSignals; i++) {
490+
int64_t handle = acquireSignal(
491+
appConfig->mSignalCodes[i],
492+
0,
493+
incomingPID,
494+
incomingTID
495+
);
496+
497+
if(handle != -1) {
498+
this->mCurrRestuneHandles.push_back(handle);
603499
}
604500
}
605-
} catch(const std::exception& e) {
606-
LOGE(CLASSIFIER_TAG,
607-
"Failed to acquire per-app config signal, Error: " + std::string(e.what()));
608501
}
609502
}
610503

contextual-classifier/Include/ContextualClassifier.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ class ContextualClassifier {
7474
// Fetch signal configuration info
7575
uint32_t GetSignalIDForWorkload(int32_t contextType);
7676

77-
// Methods for tuning / untuning signals based on the workload
78-
void ApplyActions(uint32_t sigId,
79-
uint32_t sigType,
80-
pid_t incomingPID,
81-
pid_t incomingTID,
82-
int32_t numArgs,
83-
int32_t* arg);
84-
void RemoveActions(pid_t pid, int32_t tgid);
85-
8677
// blacklisting mechanism
8778
void LoadIgnoredProcesses();
8879
int8_t shouldProcBeIgnored(int32_t evType, pid_t pid);

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ The following resource codes are supported resources or operations on upstream L
247247
| RES_SCALE_MIN_FREQ | 0x 00 04 0000 |
248248
| RES_SCALE_MAX_FREQ | 0x 00 04 0001 |
249249
| RES_RATE_LIMIT_US | 0x 00 04 0002 |
250+
| RES_CPU_ONLINE_PER_CORE | 0x 00 04 0003 |
250251
| RES_DEVFREQ_GPU_MAX | 0x 00 05 0000 |
251252
| RES_DEVFREQ_GPU_MIN | 0x 00 05 0001 |
252253
| RES_DEVFREQ_GPU_POLL_INTV | 0x 00 05 0002 |

extensions/Include/Extensions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ typedef struct {
2424
uint32_t mSigId;
2525
uint32_t mSigType;
2626
int32_t mNumArgs;
27-
int32_t* mArgs;
27+
uint32_t* mArgs;
28+
int64_t mHandleAcq;
2829
} PostProcessCBData;
2930

3031
/**

modula/Common/Include/UrmPlatformAL.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ enum Modes {
166166
X(RES_SCALE_MIN_FREQ, 0x00040000) \
167167
X(RES_SCALE_MAX_FREQ, 0x00040001) \
168168
X(RES_RATE_LIMIT_US, 0x00040002) \
169-
X(RES_CPU_IDLE_DISABLE_ST0, 0x00040003) \
170-
X(RES_CPU_IDLE_DISABLE_ST1, 0x00040004) \
171-
X(RES_CPU_IDLE_DISABLE_ST2, 0x00040005) \
169+
X(RES_CPU_ONLINE_PER_CORE, 0x00040003) \
170+
X(RES_CPU_IDLE_DISABLE_ST0, 0x00010002) \
171+
X(RES_CPU_IDLE_DISABLE_ST1, 0x00010003) \
172+
X(RES_CPU_IDLE_DISABLE_ST2, 0x00010004) \
172173
X(RES_SCHED_UTIL_CLAMP_MIN, 0x00030000) \
173174
X(RES_SCHED_UTIL_CLAMP_MAX, 0x00030001) \
174175
X(RES_SCHED_ENERGY_AWARE, 0x00030002) \

modula/CoreModules/AuxRoutines.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -131,50 +131,6 @@ pid_t AuxRoutines::fetchPid(const std::string& process_name) {
131131
return -1;
132132
}
133133

134-
int8_t AuxRoutines::getProcName(pid_t pid, std::string& procName) {
135-
std::string cmdlinePath = "/proc/" + std::to_string(pid) + "/cmdline";
136-
std::ifstream cmdlineFile(cmdlinePath);
137-
138-
if(cmdlineFile.is_open()) {
139-
std::string cmdline;
140-
std::getline(cmdlineFile, cmdline, '\0');
141-
142-
if(!cmdline.empty()) {
143-
size_t lastSlash = cmdline.find_last_of('/');
144-
if(lastSlash != std::string::npos) {
145-
procName = cmdline.substr(lastSlash + 1);
146-
} else {
147-
procName = cmdline;
148-
}
149-
150-
size_t first = procName.find_first_not_of(" \t\n\r");
151-
if(first != std::string::npos) {
152-
size_t last = procName.find_last_not_of(" \t\n\r");
153-
procName = procName.substr(first, (last - first + 1));
154-
}
155-
156-
return true;
157-
}
158-
}
159-
160-
std::string commPath = "/proc/" + std::to_string(pid) + "/comm";
161-
std::ifstream commFile(commPath);
162-
163-
if(commFile.is_open()) {
164-
std::string processName;
165-
std::getline(commFile, processName);
166-
167-
size_t first = processName.find_first_not_of(" \t\n\r");
168-
if(first != std::string::npos) {
169-
size_t last = processName.find_last_not_of(" \t\n\r");
170-
procName = processName.substr(first, (last - first + 1));
171-
return true;
172-
}
173-
}
174-
175-
return false;
176-
}
177-
178134
int32_t AuxRoutines::fetchComm(pid_t pid, std::string &comm) {
179135
std::string proc_path = "/proc/" + std::to_string(pid);
180136
if(!AuxRoutines::fileExists(proc_path)) {

modula/CoreModules/Include/AuxRoutines.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class AuxRoutines {
3838
static int8_t isNumericString(const std::string& str);
3939
static pid_t fetchPid(const std::string& processName);
4040
static int32_t fetchComm(pid_t pid, std::string &comm);
41-
static int8_t getProcName(pid_t pid, std::string& procName);
4241

4342
static int64_t generateUniqueHandle();
4443
static int64_t getCurrentTimeInMilliseconds();

resource-tuner/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ install(TARGETS RestuneCore LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
6464
set(HEADER_FILES "")
6565
list(APPEND HEADER_FILES
6666
${CMAKE_CURRENT_SOURCE_DIR}/core/Include/ResourceRegistry.h
67+
${CMAKE_CURRENT_SOURCE_DIR}/signals/Include/SignalInternal.h
6768
${CMAKE_CURRENT_SOURCE_DIR}/core/Include/TargetRegistry.h
6869
)
6970

resource-tuner/init/Include/RestuneParser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@
105105
#define SIGNAL_CONFIGS_ELEM_RESOURCE_CODE "ResCode"
106106
#define SIGNAL_CONFIGS_ELEM_RESOURCE_RESINFO "ResInfo"
107107
#define SIGNAL_CONFIGS_ELEM_RESOURCE_VALUES "Values"
108+
#define SIGNAL_CONFIGS_ELEM_EXTRA_ATTRS "ExtraAttrs"
109+
#define SIGNAL_CONFIGS_ELEM_FPS "Fps"
110+
#define SIGNAL_CONFIGS_ELEM_HEIGHT "Height"
111+
#define SIGNAL_CONFIGS_ELEM_WIDTH "Width"
108112

109113
// Ext-Features
110114
#define EXT_FEATURE_CONFIGS_ROOT "FeatureConfigs"

0 commit comments

Comments
 (0)