Skip to content

Commit 92ddea6

Browse files
authored
Persist multiple App-Configurations at once (#252)
Signed-off-by: Kartik Nema <kartnema@qti.qualcomm.com>
1 parent a32a730 commit 92ddea6

7 files changed

Lines changed: 93 additions & 32 deletions

File tree

configs/PropertiesConfig.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ PropertyConfigs:
4646

4747
- Name: urm.extensions_lib.count
4848
Value: "6"
49+
50+
- Name: urm.classifier.apply_mode
51+
# Possible values: ACCEPT_AND_PERSIST, ACCEPT_AND_REPLACE
52+
Value: "ACCEPT_AND_PERSIST"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
ls,cp,sh,mv,rm,id,mkdir,touch,find,irqbalance,cpuUsage.sh,which,sudo,cpu.sh,ln,uname,gst-plugin-scan,urmCli,UrmComponentTests,UrmIntegrationTests
1+
ls,cp,sh,mv,rm,id,mkdir,dirname,touch,find,irqbalance,cpuUsage.sh,which,sudo,cpu.sh,ln,uname,gst-plugin-scan,urmCli,UrmComponentTests,UrmIntegrationTests
22
grep,sed,awk,cat,tail,head,less,more,sort,uniq,wc,cut,tr,tee
33
ps,top,sleep,journalctl,xargs,logrotate,systemctl

contextual-classifier/ContextualClassifier.cpp

Lines changed: 65 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ static ContextualClassifier *gClassifier = nullptr;
5656
static const int32_t pendingQueueControlSize = 30;
5757

5858
ContextualClassifier::ContextualClassifier() {
59+
this->mClientTracker = 0;
60+
this->mActiveAppThreshold = 1; // single-app mode
61+
62+
// In multi-app mode, at most 3 concurrent apps are supported
63+
if(UrmSettings::metaConfigs.mAcceptMode & ACCEPT_AND_PERSIST) {
64+
this->mActiveAppThreshold = 3;
65+
}
5966
this->mInference = GetInferenceObject();
6067
}
6168

@@ -179,49 +186,45 @@ void ContextualClassifier::ClassifierMain() {
179186
this->mPendingEv.pop();
180187

181188
if(ev.type == CC_APP_OPEN) {
182-
std::string comm;
183-
uint32_t sigId = URM_SIG_APP_OPEN;
184-
uint32_t sigType = DEFAULT_SIGNAL_TYPE;
185-
uint32_t ctxDetails = 0U;
186-
187189
if(ev.pid != -1) {
190+
std::string comm;
191+
uint32_t sigId = URM_SIG_APP_OPEN;
192+
uint32_t sigType = DEFAULT_SIGNAL_TYPE;
193+
uint32_t ctxDetails = 0U;
188194
if(AuxRoutines::fetchComm(ev.pid, comm) != 0) {
189195
continue;
190196
}
191197

192-
// Step 1: Figure out workload type
193-
int32_t contextType =
194-
this->ClassifyProcess(ev.pid, ev.tgid, comm, ctxDetails);
195-
if(contextType == CC_IGNORE) {
196-
// Ignore and wait for next event
197-
continue;
198-
}
199-
200-
// Identify if any signal configuration exists
201-
// Will return the sigID based on the workload
202-
// For example: game, browser, multimedia
203-
sigId = this->GetSignalIDForWorkload(contextType);
204-
205-
// Step 2:
198+
// Step 1:
206199
// Untune any Configurations from the last proc-invocation
207-
for(int64_t handle: this->mCurrRestuneHandles) {
208-
if(handle > 0) {
209-
this->untuneRequestHelper(handle);
200+
uint64_t currActiveCount = 0;
201+
if(!this->mCurrRestuneHandles.empty()) {
202+
currActiveCount =
203+
this->mClientTracker - this->mCurrRestuneHandles.front().first;
204+
}
205+
206+
if(currActiveCount == this->mActiveAppThreshold) {
207+
uint64_t minClientId = this->mCurrRestuneHandles.front().first;
208+
while(!this->mCurrRestuneHandles.empty()) {
209+
if(minClientId == this->mCurrRestuneHandles.front().first) {
210+
this->mCurrRestuneHandles.pop();
211+
} else {
212+
break;
213+
}
210214
}
211215
}
212-
this->mCurrRestuneHandles.clear();
213216

214-
// Step 3:
217+
// Step 2:
215218
// - Move the process to focused-cgroup, Also involves removing the process
216219
// already there from the cgroup.
217220
// - Move the "threads" from per-app config to appropriate cgroups
218221
this->MoveAppThreadsToCGroup(ev.pid, ev.tgid, comm, FOCUSED_CGROUP_IDENTIFIER);
219222

220-
// Step 4:
223+
// Step 3:
221224
// Configure any per-app config specified signals.
222225
this->configureAppSignals(ev.pid, ev.tgid, comm);
223226

224-
// Step 5: If the post processing block exists, call it
227+
// Step 4: If the post processing block exists, call it
225228
// It might provide us a more specific sigID or sigType
226229
PostProcessingCallback postCb =
227230
Extensions::getPostProcessingCallback(comm);
@@ -237,11 +240,43 @@ void ContextualClassifier::ClassifierMain() {
237240
postCb((void*)&postProcessData);
238241

239242
// Record any Configurations made
240-
if(postProcessData.mHandleAcq != - 1) {
241-
this->mCurrRestuneHandles.push_back(postProcessData.mHandleAcq);
243+
if(postProcessData.mHandleAcq != -1) {
244+
this->mCurrRestuneHandles.push(
245+
{this->mClientTracker, postProcessData.mHandleAcq}
246+
);
247+
}
248+
} else {
249+
// Figure out workload type
250+
int32_t contextType =
251+
this->ClassifyProcess(ev.pid, ev.tgid, comm, ctxDetails);
252+
if(contextType == CC_IGNORE) {
253+
// Ignore and wait for next event
254+
continue;
255+
}
256+
257+
// Identify if any signal configuration exists
258+
// Will return the sigID based on the workload
259+
// For example: game, browser, multimedia
260+
sigId = this->GetSignalIDForWorkload(contextType);
261+
262+
int64_t handle = acquireSignal(
263+
sigId,
264+
sigType,
265+
ev.pid,
266+
ev.tgid
267+
);
268+
if(handle != -1) {
269+
this->mCurrRestuneHandles.push(
270+
{this->mClientTracker, handle}
271+
);
242272
}
243273
}
244274
}
275+
276+
// Increment client count, this helps in tracking older Requests,
277+
// which will need to be untuned once the active threshold is hit.
278+
this->mClientTracker++;
279+
245280
} else if(ev.type == CC_APP_CLOSE) {
246281
// No Action Needed, Pulse Monitor to take care of cleanup
247282
ClientGarbageCollector::getInstance()->submitClientForCleanup(ev.pid);
@@ -462,7 +497,7 @@ void ContextualClassifier::MoveAppThreadsToCGroup(pid_t incomingPID,
462497
// Anything to issue
463498
if(request->getResourcesCount() > 0) {
464499
// Record:
465-
this->mCurrRestuneHandles.push_back(request->getHandle());
500+
this->mCurrRestuneHandles.push({this->mClientTracker, request->getHandle()});
466501

467502
// fast path to Request Queue
468503
submitResProvisionRequest(request, true);
@@ -493,7 +528,7 @@ void ContextualClassifier::configureAppSignals(pid_t incomingPID,
493528
);
494529

495530
if(handle != -1) {
496-
this->mCurrRestuneHandles.push_back(handle);
531+
this->mCurrRestuneHandles.push({this->mClientTracker, handle});
497532
}
498533
}
499534
}

contextual-classifier/Include/ContextualClassifier.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ class ContextualClassifier {
4545
int8_t mDebugMode = false;
4646
volatile int8_t mNeedExit = false;
4747

48+
uint64_t mClientTracker;
49+
uint64_t mActiveAppThreshold;
4850
NetLinkComm mNetLinkComm;
4951
Inference* mInference;
50-
std::vector<int64_t> mCurrRestuneHandles;
52+
std::queue<std::pair<uint64_t, int64_t>> mCurrRestuneHandles;
5153

5254
// PID cache to check for duplicates
5355
MinLRUCache mClassifierPidCache;

modula/Common/Include/Utils.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ enum TranslationUnit {
8787
U_GHz = 1000 * 1000 * 1000,
8888
};
8989

90+
/**
91+
* @enum ClassifierOpMode
92+
*/
93+
enum ClassifierOpMode {
94+
ACCEPT_AND_PERSIST = 0x01,
95+
ACCEPT_AND_REPLACE = 0x02,
96+
};
97+
9098
typedef struct {
9199
int8_t mModuleID;
92100
int8_t mRequestType;
@@ -124,6 +132,7 @@ typedef void (*MessageReceivedCallback)(int32_t, MsgForwardInfo*);
124132
#define LOGGER_LOGGING_LEVEL_TYPE "urm.logging.level.exact"
125133
#define LOGGER_LOGGING_OUTPUT_REDIRECT "urm.logging.redirect_to"
126134
#define URM_MAX_PLUGIN_COUNT "urm.extensions_lib.count"
135+
#define CLASSIFIER_APPLY_MODE "urm.classifier.apply_mode"
127136

128137
#define COMM(pid) ("/proc/" + std::to_string(pid) + "/comm")
129138
#define COMM_S(pidstr) ("/proc/" + pidstr + "/comm")

modula/CoreModules/Include/UrmSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ typedef struct {
2626
double mPenaltyFactor;
2727
double mRewardFactor;
2828
uint32_t mPluginCount;
29+
uint32_t mAcceptMode;
2930
} MetaConfigs;
3031

3132
typedef struct {

resource-tuner/init/RestuneInit.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ static ErrCode fetchMetaConfigs() {
175175
submitPropGetRequest(URM_MAX_PLUGIN_COUNT, resultBuffer, "3");
176176
UrmSettings::metaConfigs.mPluginCount = (uint32_t)std::stol(resultBuffer);
177177

178+
// Start classifier in multi-app mode by default
179+
UrmSettings::metaConfigs.mAcceptMode = ACCEPT_AND_PERSIST;
180+
submitPropGetRequest(CLASSIFIER_APPLY_MODE, resultBuffer, "ACCEPT_AND_PERSIST");
181+
std::string mode = std::string(resultBuffer);
182+
183+
// Move to single-app mode if so configured
184+
if(mode == "ACCEPT_AND_REPLACE") {
185+
UrmSettings::metaConfigs.mAcceptMode = ACCEPT_AND_REPLACE;
186+
}
187+
178188
if(UrmSettings::metaConfigs.mDesiredThreadCount < 1) {
179189
UrmSettings::metaConfigs.mDesiredThreadCount = 5; // Reset to default
180190
}

0 commit comments

Comments
 (0)