Skip to content

Commit dde7e47

Browse files
committed
Extra Attrs
1 parent 2e3f738 commit dde7e47

14 files changed

Lines changed: 653 additions & 217 deletions

File tree

contextual-classifier/ContextualClassifier.cpp

Lines changed: 22 additions & 136 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-
uint32_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, args);
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) {
@@ -294,17 +234,15 @@ void ContextualClassifier::ClassifierMain() {
294234
.mSigType = sigType,
295235
.mNumArgs = numArgs,
296236
.mArgs = args,
237+
.mHandleAcq = -1,
297238
};
298239
postCb((void*)&postProcessData);
299240

300-
sigId = postProcessData.mSigId;
301-
sigType = postProcessData.mSigType;
302-
numArgs = postProcessData.mNumArgs;
303-
args = postProcessData.mArgs;
241+
// Record any Configurations made
242+
if(postProcessData.mHandleAcq != - 1) {
243+
this->mCurrRestuneHandles.push_back(postProcessData.mHandleAcq);
244+
}
304245
}
305-
306-
// Apply actions, call tuneSignal
307-
this->ApplyActions(sigId, sigType, ev.pid, ev.tgid, numArgs, args);
308246
}
309247
} else if(ev.type == CC_APP_CLOSE) {
310248
// No Action Needed, Pulse Monitor to take care of cleanup
@@ -405,46 +343,6 @@ int32_t ContextualClassifier::ClassifyProcess(pid_t processPid,
405343
return context;
406344
}
407345

408-
void ContextualClassifier::ApplyActions(uint32_t sigId,
409-
uint32_t sigType,
410-
pid_t incomingPID,
411-
pid_t incomingTID,
412-
int32_t numArgs,
413-
uint32_t* args) {
414-
LOGI(CLASSIFIER_TAG, "LogBook: sigId=" + std::to_string(sigId));
415-
LOGI(CLASSIFIER_TAG, "LogBook: sigType=" + std::to_string(sigType));
416-
LOGI(CLASSIFIER_TAG, "LogBook: numArgs=" + std::to_string(numArgs));
417-
418-
if(numArgs > 0) {
419-
LOGI(CLASSIFIER_TAG, "front: Printing Stats");
420-
LOGI(CLASSIFIER_TAG, "front: fps=" + std::to_string(args[SIGNAL_EXTRA_ATTR_FPS]));
421-
LOGI(CLASSIFIER_TAG, "front: height=" + std::to_string(args[SIGNAL_EXTRA_ATTR_HEIGHT]));
422-
LOGI(CLASSIFIER_TAG, "front: width=" + std::to_string(args[SIGNAL_EXTRA_ATTR_WIDTH]));
423-
}
424-
425-
Request* request =
426-
createTuneRequestFromSignal(sigId, sigType, incomingPID, incomingTID, numArgs, args);
427-
if(request != nullptr) {
428-
if(request->getResourcesCount() > 0) {
429-
// Record:
430-
this->mCurrRestuneHandles.push_back(request->getHandle());
431-
432-
// fast path to Request Queue
433-
submitResProvisionRequest(request, false);
434-
435-
} else {
436-
Request::cleanUpRequest(request);
437-
}
438-
}
439-
}
440-
441-
void ContextualClassifier::RemoveActions(pid_t processPid, pid_t processTgid) {
442-
(void)processPid;
443-
(void)processTgid;
444-
445-
return;
446-
}
447-
448346
uint32_t ContextualClassifier::GetSignalIDForWorkload(int32_t contextType) {
449347
switch(contextType) {
450348
case CC_MULTIMEDIA:
@@ -584,36 +482,24 @@ void ContextualClassifier::MoveAppThreadsToCGroup(pid_t incomingPID,
584482
void ContextualClassifier::configureAppSignals(pid_t incomingPID,
585483
pid_t incomingTID,
586484
const std::string& comm) {
587-
try {
588-
// Configure any associated signal
589-
AppConfig* appConfig = AppConfigs::getInstance()->getAppConfig(comm);
590-
if(appConfig != nullptr && appConfig->mSignalCodes != nullptr) {
591-
int32_t numSignals = appConfig->mNumSignals;
592-
// Go over the list of proc names (comm) and get their pids
593-
for(int32_t i = 0; i < numSignals; i++) {
594-
Request* request = createTuneRequestFromSignal(
595-
appConfig->mSignalCodes[i],
596-
0,
597-
incomingPID,
598-
incomingTID,
599-
0,
600-
nullptr);
601-
602-
if(request != nullptr) {
603-
if(request->getResourcesCount() > 0) {
604-
// fast path to Request Queue
605-
this->mCurrRestuneHandles.push_back(request->getHandle());
606-
submitResProvisionRequest(request, false);
607-
608-
} else {
609-
Request::cleanUpRequest(request);
610-
}
611-
}
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+
0,
496+
nullptr
497+
);
498+
499+
if(handle != -1) {
500+
this->mCurrRestuneHandles.push_back(handle);
612501
}
613502
}
614-
} catch(const std::exception& e) {
615-
LOGE(CLASSIFIER_TAG,
616-
"Failed to acquire per-app config signal, Error: " + std::string(e.what()));
617503
}
618504
}
619505

extensions/Include/Extensions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ typedef struct {
2525
uint32_t mSigType;
2626
int32_t mNumArgs;
2727
uint32_t* mArgs;
28+
int64_t mHandleAcq;
2829
} PostProcessCBData;
2930

3031
/**

resource-tuner/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +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/SignalRegistry.h
67+
${CMAKE_CURRENT_SOURCE_DIR}/signals/Include/SignalInternal.h
6868
${CMAKE_CURRENT_SOURCE_DIR}/core/Include/TargetRegistry.h
6969
)
7070

resource-tuner/init/RestuneInit.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ static void preAllocateMemory() {
9696
MakeAlloc<std::unordered_set<int64_t>> (maxBlockCount);
9797
MakeAlloc<MsgForwardInfo> (maxBlockCount);
9898
MakeAlloc<ResIterable> (maxBlockCount);
99-
MakeAlloc<SigIterable> (maxBlockCount);
10099
MakeAlloc<char[REQ_BUFFER_SIZE]> (maxBlockCount);
101100
MakeAlloc<Signal> (concurrentRequestsUB);
102101
MakeAlloc<std::vector<Resource*>> (concurrentRequestsUB * resourcesPerRequestUB);

resource-tuner/init/RestuneParser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,9 @@ ErrCode RestuneParser::parseSignalConfigYamlNode(const std::string& filePath) {
826826
ADD_TO_SIGNAL_BUILDER(SIGNAL_CONFIGS_ELEM_TIMEOUT, setTimeout);
827827
ADD_TO_SIGNAL_BUILDER(SIGNAL_CONFIGS_ELEM_ENABLE, setIsEnabled);
828828
ADD_TO_SIGNAL_BUILDER(SIGNAL_CONFIGS_ELEM_FPS, setFps);
829-
ADD_TO_SIGNAL_BUILDER(SIGNAL_CONFIGS_ELEM_HEIGHT, setHeight);
829+
ADD_TO_SIGNAL_BUILDER(SIGNAL_CONFIGS_ELEM_HEIGHT,setHeight);
830830
ADD_TO_SIGNAL_BUILDER(SIGNAL_CONFIGS_ELEM_WIDTH, setWidth);
831831

832-
833832
ADD_RES_TO_SIGNAL_BUILDER(SIGNAL_CONFIGS_ELEM_RESOURCE_CODE, setResCode);
834833
ADD_RES_TO_SIGNAL_BUILDER(SIGNAL_CONFIGS_ELEM_RESOURCE_RESINFO, setResInfo);
835834

resource-tuner/signals/Include/SignalInternal.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@
99
#define SIGNAL_INTERNAL_H
1010

1111
#include "ErrCodes.h"
12-
#include "Signal.h"
13-
#include "ExtFeaturesRegistry.h"
14-
#include "ClientDataManager.h"
15-
#include "RateLimiter.h"
16-
#include "ResourceRegistry.h"
17-
#include "RestuneInternal.h"
1812

1913
/**
2014
* @brief Internal API for submitting Signal Requests for Processing
21-
* @details Resource Tuner Modules can directly use this API to submit Requests rather than
15+
* @details URM Modules and Extensions can directly use this API to submit Requests rather than
2216
* using the Client Interface.
2317
*/
2418
ErrCode submitSignalRequest(void* clientReq);
2519

20+
/**
21+
* @brief Internal API for Acquiring a Signal
22+
* @details URM Modules and Extensions can directly use this API to submit Requests rather than
23+
* using the Client Interface.
24+
*/
25+
int64_t acquireSignal(uint32_t sigId,
26+
uint32_t sigType,
27+
pid_t incomingPID,
28+
pid_t incomingTID,
29+
int32_t numArgs,
30+
uint32_t* args);
2631
#endif

resource-tuner/signals/Include/SignalRegistry.h

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include "Utils.h"
1313
#include "Logger.h"
1414
#include "Resource.h"
15-
#include "DLManager.h"
16-
#include "MemoryPool.h"
1715
#include "UrmSettings.h"
1816
#include "UrmPlatformAL.h"
1917

@@ -24,7 +22,7 @@ enum SignalExtraAttrIndex {
2422
SIGNAL_EXTRA_ATTR_FPS = 0, //!< Frames per second
2523
SIGNAL_EXTRA_ATTR_HEIGHT = 1, //!< Frame height in pixels
2624
SIGNAL_EXTRA_ATTR_WIDTH = 2, //!< Frame width in pixels
27-
SIGNAL_EXTRA_ATTRS_COUNT = 3 //!< Total number of extra attributes (must remain last)
25+
SIGNAL_EXTRA_ATTRS_COUNT = 3 //!< Total number of extra attributes
2826
};
2927

3028
/**
@@ -33,7 +31,7 @@ enum SignalExtraAttrIndex {
3331
* @details This information is read from the Config files.\n
3432
* Note this (SignalInfo) struct is separate from the Signal struct.
3533
*/
36-
typedef struct {
34+
typedef struct _signalInfo {
3735
/**
3836
* @brief Category of the Signal
3937
*/
@@ -70,17 +68,11 @@ typedef struct {
7068
/**
7169
* @brief Array of optional extra attributes associated with the Signal.
7270
* Each index corresponds to a named attribute (see SIGNAL_EXTRA_ATTR_* constants).
73-
* A value of 0 at any index indicates that attribute is not set.
74-
* Index layout:
75-
* [SIGNAL_EXTRA_ATTR_FPS] = frames per second
76-
* [SIGNAL_EXTRA_ATTR_HEIGHT] = frame height in pixels
77-
* [SIGNAL_EXTRA_ATTR_WIDTH] = frame width in pixels
7871
*/
7972
uint32_t mExtraAttrs[SIGNAL_EXTRA_ATTRS_COUNT];
8073

8174
/**
82-
* @brief Indicates whether any ExtraAttrs were present in the Signal config.
83-
* Set to true if an ExtraAttrs block was parsed; false otherwise.
75+
* @brief Indicates whether any ExtraAttrs are present
8476
*/
8577
int8_t mHasExtraAttrs;
8678

@@ -89,8 +81,16 @@ typedef struct {
8981
* Values to be configured for the Resources.
9082
*/
9183
std::vector<Resource*>* mSignalResources;
84+
85+
_signalInfo* next;
9286
} SignalInfo;
9387

88+
struct SignalConf {
89+
SignalInfo* mSignalInfo;
90+
SignalInfo* mFeatureSignals;
91+
SignalConf() : mSignalInfo(nullptr), mFeatureSignals(nullptr) {}
92+
};
93+
9494
/**
9595
* @brief SignalRegistry
9696
* @details Stores information Relating to all the Signals available for Tuning.
@@ -101,11 +101,17 @@ class SignalRegistry {
101101
static std::shared_ptr<SignalRegistry> signalRegistryInstance;
102102

103103
int32_t mTotalSignals;
104-
std::unordered_map<uint64_t, std::vector<SignalInfo*>> mSignalsConfigs;
104+
std::unordered_map<uint64_t, SignalConf> mSignalsConfigs;
105105

106106
SignalRegistry();
107107

108-
SignalInfo* findBestExtraAttrsMatch(std::vector<SignalInfo*>& dlm, const uint32_t* extraAttrs) const;
108+
SignalInfo* findBestExtraAttrsMatch(SignalInfo* featureSignalHead,
109+
int32_t numArgs,
110+
const uint32_t* extraAttrs);
111+
int8_t isDuplicateConfig(SignalInfo* src, SignalInfo* dest);
112+
void addToFeaturedSigList(SignalInfo** mFeatureSignals,
113+
SignalInfo* newSignal,
114+
int8_t& isOverriden);
109115

110116
public:
111117
~SignalRegistry();
@@ -129,7 +135,9 @@ class SignalRegistry {
129135
* A non-null pointer selects the extra-attrs storage path.
130136
* @return SignalInfo* or nullptr if not found.
131137
*/
132-
SignalInfo* getSignalConfigById(uint64_t sigID, const uint32_t* extraAttrs = nullptr);
138+
SignalInfo* getSignalConfigById(uint64_t sigID,
139+
int32_t numArgs = 0,
140+
const uint32_t* extraAttrs = nullptr);
133141

134142
/**
135143
* @brief Get the SignalInfo object corresponding to the given Signal ID and type.
@@ -141,7 +149,10 @@ class SignalRegistry {
141149
* A non-null pointer selects the extra-attrs storage path.
142150
* @return SignalInfo* or nullptr if not found.
143151
*/
144-
SignalInfo* getSignalConfigById(uint32_t sigCode, uint32_t sigType, const uint32_t* extraAttrs = nullptr);
152+
SignalInfo* getSignalConfigByIdAndType(uint32_t sigCode,
153+
uint32_t sigType,
154+
int32_t numArgs = 0,
155+
const uint32_t* extraAttrs = nullptr);
145156

146157
int32_t getSignalsConfigCount();
147158

@@ -151,7 +162,8 @@ class SignalRegistry {
151162
signalRegistryInstance = std::shared_ptr<SignalRegistry>(new SignalRegistry());
152163
} catch(const std::bad_alloc& e) {
153164
LOGE("RESTUNE_SIGNAL_REGISTRY",
154-
"Failed to allocate memory for SignalRegistry instance: " + std::string(e.what()));
165+
"Failed to allocate memory for SignalRegistry: "
166+
+ std::string(e.what()));
155167
return nullptr;
156168
}
157169
}
@@ -203,6 +215,4 @@ class ResourceBuilder {
203215
Resource* build();
204216
};
205217

206-
typedef Iterable<SignalInfo*> SigIterable;
207-
208218
#endif

0 commit comments

Comments
 (0)