2727#define CLASSIFIER_TAG " CONTEXTUAL_CLASSIFIER"
2828#define CLASSIFIER_CONFIGS_DIR " /etc/urm/classifier/"
2929
30- #define CURR_RESTUNE_CGRP_HNDL 0
31- #define CURR_RESTUNE_SIG_HNDL 1
32-
33- static const std::string FT_MODEL_PATH =
34- CLASSIFIER_CONFIGS_DIR " fasttext_model_supervised.bin" ;
35- static const std::string IGNORE_PROC_PATH =
30+ const std::string FT_MODEL_PATH =
31+ CLASSIFIER_CONFIGS_DIR " floret_model_supervised.bin" ;
32+ const std::string IGNORE_PROC_PATH =
3633 CLASSIFIER_CONFIGS_DIR " classifier-blocklist.txt" ;
3734static const std::string IGNORE_TOKENS_PATH =
3835 CLASSIFIER_CONFIGS_DIR " ignore-tokens.txt" ;
3936static const std::string ALLOW_LIST_PATH =
4037 CLASSIFIER_CONFIGS_DIR " allow-list.txt" ;
4138
42- #ifdef USE_FASTTEXT
39+ #ifdef USE_FLORET
4340#include " MLInference.h"
4441#include " FeatureExtractor.h"
4542#include " FeaturePruner.h"
@@ -60,17 +57,15 @@ static ContextualClassifier *gClassifier = nullptr;
6057static const int32_t pendingQueueControlSize = 30 ;
6158
6259ContextualClassifier::ContextualClassifier () {
63- this ->mRestuneHandles [CURR_RESTUNE_CGRP_HNDL ].mCurHandle = -1 ;
64- this ->mRestuneHandles [CURR_RESTUNE_SIG_HNDL ].mCurHandle = -1 ;
6560 mInference = GetInferenceObject ();
6661}
6762
68- void ContextualClassifier::untuneRequestHelper (int32_t index ) {
63+ void ContextualClassifier::untuneRequestHelper (int64_t handle ) {
6964 try {
7065 Request* untuneRequest = MPLACED (Request);
7166
7267 untuneRequest->setRequestType (REQ_RESOURCE_UNTUNING );
73- untuneRequest->setHandle (this -> mRestuneHandles [index]. mCurHandle );
68+ untuneRequest->setHandle (handle );
7469 untuneRequest->setDuration (-1 );
7570 // Passing priority as HIGH_TRANSFER_PRIORITY (= -1)
7671 // - Ensures untune requests are processed before even SERVER_HIGH priority tune requests
@@ -79,8 +74,8 @@ void ContextualClassifier::untuneRequestHelper(int32_t index) {
7974 // not free up the underlying Request object, allowing for reuse.
8075 // Priority Level: -2 is used to force server termination and cleanup so should not be used otherwise.
8176 untuneRequest->setPriority (SYSTEM_HIGH );
82- untuneRequest->setClientPID (this -> mRestuneHandles [index]. mCurReqPid );
83- untuneRequest->setClientTID (this -> mRestuneHandles [index]. mCurReqTid );
77+ untuneRequest->setClientPID (0 );
78+ untuneRequest->setClientTID (0 );
8479
8580 // fast path to Request Queue
8681 // Mark verification status as true. Request still goes through RequestManager though.
@@ -257,6 +252,15 @@ void ContextualClassifier::ClassifierMain() {
257252 // For example: game, browser, multimedia
258253 sigId = this ->GetSignalIDForWorkload (contextType);
259254
255+ // Step 2:
256+ // Untune any Configurations from the last proc-invocation
257+ for (int64_t handle: this ->mCurrRestuneHandles ) {
258+ if (handle > 0 ) {
259+ untuneRequestHelper (handle);
260+ }
261+ }
262+ this ->mCurrRestuneHandles .clear ();
263+
260264 // Step 2:
261265 // - Move the process to focused-cgroup, Also involves removing the process
262266 // already there from the cgroup.
@@ -379,26 +383,17 @@ void ContextualClassifier::ApplyActions(uint32_t sigId,
379383 uint32_t sigType,
380384 pid_t incomingPID,
381385 pid_t incomingTID) {
382-
383- if (this ->mRestuneHandles [CURR_RESTUNE_SIG_HNDL ].mCurHandle != -1 ) {
384- untuneRequestHelper (CURR_RESTUNE_SIG_HNDL );
385- mRestuneHandles [CURR_RESTUNE_SIG_HNDL ].mCurHandle = -1 ;
386- }
387-
388386 Request* request = createTuneRequestFromSignal (sigId, sigType, incomingPID, incomingTID);
389387 if (request != nullptr ) {
390388 if (request->getResourcesCount () > 0 ) {
391389 // Record:
392- this ->mRestuneHandles [CURR_RESTUNE_SIG_HNDL ].mCurHandle = request->getHandle ();
393- this ->mRestuneHandles [CURR_RESTUNE_SIG_HNDL ].mCurReqPid = incomingPID;
394- this ->mRestuneHandles [CURR_RESTUNE_SIG_HNDL ].mCurReqTid = incomingTID;
390+ this ->mCurrRestuneHandles .push_back (request->getHandle ());
395391
396392 // fast path to Request Queue
397393 submitResProvisionRequest (request, true );
398394
399395 } else {
400396 Request::cleanUpRequest (request);
401- this ->mRestuneHandles [CURR_RESTUNE_SIG_HNDL ].mCurHandle = -1 ;
402397 }
403398 }
404399}
@@ -496,12 +491,6 @@ void ContextualClassifier::MoveAppThreadsToCGroup(pid_t incomingPID,
496491 const std::string& comm,
497492 int32_t cgroupIdentifier) {
498493 try {
499- // Check for any outstanding request, if found untune it.
500- if (this ->mRestuneHandles [CURR_RESTUNE_CGRP_HNDL ].mCurHandle != -1 ) {
501- untuneRequestHelper (CURR_RESTUNE_CGRP_HNDL );
502- mRestuneHandles [CURR_RESTUNE_CGRP_HNDL ].mCurHandle = -1 ;
503- }
504-
505494 int64_t handleGenerated = -1 ;
506495 // Issue a tune request for the new pid (and any associated app-config pids)
507496 Request* request = MPLACED (Request);
@@ -537,22 +526,42 @@ void ContextualClassifier::MoveAppThreadsToCGroup(pid_t incomingPID,
537526 // Anything to issue
538527 if (request->getResourcesCount () > 0 ) {
539528 // Record:
540- this ->mRestuneHandles [CURR_RESTUNE_CGRP_HNDL ].mCurHandle = handleGenerated;
541- this ->mRestuneHandles [CURR_RESTUNE_CGRP_HNDL ].mCurReqPid = incomingPID;
542- this ->mRestuneHandles [CURR_RESTUNE_CGRP_HNDL ].mCurReqTid = incomingTID;
529+ this ->mCurrRestuneHandles .push_back (request->getHandle ());
543530
544531 // fast path to Request Queue
545532 submitResProvisionRequest (request, true );
546533
547534 } else {
548535 Request::cleanUpRequest (request);
549- this ->mRestuneHandles [CURR_RESTUNE_CGRP_HNDL ].mCurHandle = -1 ;
536+ }
537+
538+ // Configure any associated signal
539+ if (appConfig != nullptr && appConfig->mSignalCodes != nullptr ) {
540+ int32_t numSignals = appConfig->mNumSignals ;
541+ // Go over the list of proc names (comm) and get their pids
542+ for (int32_t i = 0 ; i < numSignals; i++) {
543+ Request* request = createTuneRequestFromSignal (
544+ appConfig->mSignalCodes [i],
545+ 0 ,
546+ incomingPID,
547+ incomingTID);
548+
549+ if (request != nullptr ) {
550+ if (request->getResourcesCount () > 0 ) {
551+ // fast path to Request Queue
552+ this ->mCurrRestuneHandles .push_back (request->getHandle ());
553+ submitResProvisionRequest (request, true );
554+
555+ } else {
556+ Request::cleanUpRequest (request);
557+ }
558+ }
559+ }
550560 }
551561
552562 } catch (const std::exception& e) {
553563 LOGE (CLASSIFIER_TAG ,
554564 " Failed to move per-app threads to cgroup, Error: " + std::string (e.what ()));
555- this ->mRestuneHandles [CURR_RESTUNE_CGRP_HNDL ].mCurHandle = -1 ;
556565 }
557566}
558567
0 commit comments