|
19 | 19 | #include "Extensions.h" |
20 | 20 | #include "AuxRoutines.h" |
21 | 21 | #include "UrmPlatformAL.h" |
| 22 | +#include "SignalInternal.h" |
22 | 23 | #include "SignalRegistry.h" |
23 | 24 | #include "RestuneInternal.h" |
24 | 25 | #include "ContextualClassifier.h" |
@@ -97,67 +98,6 @@ static ResIterable* createMovePidResource(int32_t cGroupdId, pid_t pid) { |
97 | 98 | return resIterable; |
98 | 99 | } |
99 | 100 |
|
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 | | - |
161 | 101 | ContextualClassifier::~ContextualClassifier() { |
162 | 102 | this->Terminate(); |
163 | 103 | if(this->mInference) { |
@@ -242,8 +182,6 @@ void ContextualClassifier::ClassifierMain() { |
242 | 182 | std::string comm; |
243 | 183 | uint32_t sigId = URM_SIG_APP_OPEN; |
244 | 184 | uint32_t sigType = DEFAULT_SIGNAL_TYPE; |
245 | | - int32_t numArgs = 0; |
246 | | - int32_t* args = nullptr; |
247 | 185 | uint32_t ctxDetails = 0U; |
248 | 186 |
|
249 | 187 | if(ev.pid != -1) { |
@@ -294,19 +232,17 @@ void ContextualClassifier::ClassifierMain() { |
294 | 232 | .mPid = ev.pid, |
295 | 233 | .mSigId = sigId, |
296 | 234 | .mSigType = sigType, |
297 | | - .mNumArgs = numArgs, |
298 | | - .mArgs = args, |
| 235 | + .mNumArgs = 0, |
| 236 | + .mArgs = nullptr, |
| 237 | + .mHandleAcq = -1, |
299 | 238 | }; |
300 | 239 | postCb((void*)&postProcessData); |
301 | 240 |
|
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 | + } |
306 | 245 | } |
307 | | - |
308 | | - // Apply actions, call tuneSignal |
309 | | - this->ApplyActions(sigId, sigType, ev.pid, ev.tgid, numArgs, args); |
310 | 246 | } |
311 | 247 | } else if(ev.type == CC_APP_CLOSE) { |
312 | 248 | // No Action Needed, Pulse Monitor to take care of cleanup |
@@ -407,35 +343,6 @@ int32_t ContextualClassifier::ClassifyProcess(pid_t processPid, |
407 | 343 | return context; |
408 | 344 | } |
409 | 345 |
|
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 | | - |
439 | 346 | uint32_t ContextualClassifier::GetSignalIDForWorkload(int32_t contextType) { |
440 | 347 | switch(contextType) { |
441 | 348 | case CC_MULTIMEDIA: |
@@ -498,7 +405,7 @@ int8_t ContextualClassifier::shouldProcBeIgnored(int32_t evType, pid_t pid) { |
498 | 405 | } |
499 | 406 |
|
500 | 407 | std::string procName = ""; |
501 | | - if(!AuxRoutines::getProcName(pid, procName)) { |
| 408 | + if(AuxRoutines::fetchComm(pid, procName) != 0) { |
502 | 409 | return true; |
503 | 410 | } |
504 | 411 |
|
@@ -575,36 +482,22 @@ void ContextualClassifier::MoveAppThreadsToCGroup(pid_t incomingPID, |
575 | 482 | void ContextualClassifier::configureAppSignals(pid_t incomingPID, |
576 | 483 | pid_t incomingTID, |
577 | 484 | 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); |
603 | 499 | } |
604 | 500 | } |
605 | | - } catch(const std::exception& e) { |
606 | | - LOGE(CLASSIFIER_TAG, |
607 | | - "Failed to acquire per-app config signal, Error: " + std::string(e.what())); |
608 | 501 | } |
609 | 502 | } |
610 | 503 |
|
|
0 commit comments