Skip to content

Commit 9395ba2

Browse files
authored
Add helper for fetching target-info (#190)
--- Signed-off-by: Kartik Nema <kartnema@qti.qualcomm.com>
1 parent 9d9b688 commit 9395ba2

4 files changed

Lines changed: 78 additions & 3 deletions

File tree

contextual-classifier/NetLinkComm.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ int32_t NetLinkComm::setListen(int8_t enable) {
107107

108108
nlcn_msg.cn_mcast = enable ? PROC_CN_MCAST_LISTEN : PROC_CN_MCAST_IGNORE;
109109

110-
if(send(mNlSock, &nlcn_msg, sizeof(nlcn_msg), 0) == -1) {
110+
if(send(this->mNlSock, &nlcn_msg, sizeof(nlcn_msg), 0) == -1) {
111111
TYPELOGV(ERRNO_LOG, "netlink send", strerror(errno));
112112
return -1;
113113
}
@@ -125,11 +125,12 @@ int32_t NetLinkComm::recvEvent(ProcEvent &ev) {
125125
};
126126
} nlcn_msg;
127127

128-
rc = recv(mNlSock, &nlcn_msg, sizeof(nlcn_msg), 0);
128+
rc = recv(this->mNlSock, &nlcn_msg, sizeof(nlcn_msg), 0);
129129
if(rc == 0) {
130130
// Socket shutdown or no more data.
131131
return 0;
132132
}
133+
133134
if(rc == -1) {
134135
if(errno == EINTR) {
135136
// Caller (ContextualClassifier::HandleProcEv) will handle EINTR.

resource-tuner/core/Include/RestuneInternal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ void submitResProvisionRequest(Request* request, int8_t isVerified);
4343

4444
size_t submitPropGetRequest(void* request, std::string& result);
4545

46-
size_t submitPropGetRequest(const std::string& propName, std::string& result, const std::string& defVal);
46+
size_t submitPropGetRequest(const std::string& propName,
47+
std::string& result,
48+
const std::string& defVal);
4749

4850
ErrCode translateToPhysicalIDs(Resource* resource);
4951

resource-tuner/core/Include/TargetRegistry.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
#define ONLINE_CPU_FILE_PATH "/sys/devices/system/cpu/online"
3232
#define CPU_CAPACITY_FILE_PATH "/sys/devices/system/cpu/cpu%d/cpu_capacity"
3333

34+
enum TargetQueries {
35+
GET_MASK,
36+
GET_CLUSTER_COUNT,
37+
GET_CORE_COUNT,
38+
GET_PHYSICAL_CLUSTER_ID,
39+
GET_PHYSICAL_CORE_ID,
40+
};
41+
3442
/**
3543
* @struct CGroupConfigInfo
3644
* @brief Representation of a single CGroup Configuration Info
@@ -220,4 +228,9 @@ class CacheInfoBuilder {
220228
CacheInfo* build();
221229
};
222230

231+
// Utility to fetch target-specific information
232+
uint64_t getTargetInfo(int32_t option,
233+
int32_t numArgs,
234+
int32_t* args);
235+
223236
#endif

resource-tuner/core/TargetRegistry.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,3 +815,62 @@ ErrCode CacheInfoBuilder::setPriorityAware(const std::string& isPriorityAwareStr
815815
CacheInfo* CacheInfoBuilder::build() {
816816
return this->mCacheInfo;
817817
}
818+
819+
uint64_t getTargetInfo(int32_t option,
820+
int32_t numArgs,
821+
int32_t* args) {
822+
std::shared_ptr<TargetRegistry> targetRegistry = TargetRegistry::getInstance();
823+
824+
switch(option) {
825+
case GET_MASK: {
826+
if(numArgs < 2) {
827+
return 0;
828+
}
829+
830+
uint64_t mask = 0;
831+
832+
int32_t cluster = args[0];
833+
int32_t coreCount = args[1];
834+
int32_t physicalClusterId = targetRegistry->getPhysicalClusterId(cluster);
835+
836+
ClusterInfo* clusInfo = targetRegistry->getClusterInfo(physicalClusterId);
837+
if(clusInfo == nullptr) {
838+
return 0;
839+
}
840+
841+
if(coreCount == 0) {
842+
// Iterate over all the cores in the cluster
843+
coreCount = clusInfo->mNumCpus;
844+
} else {
845+
// Bound the count to the number of cores in the cluster
846+
coreCount = std::min(coreCount, clusInfo->mNumCpus);
847+
}
848+
849+
for(int32_t i = clusInfo->mStartCpu; i < (clusInfo->mStartCpu + coreCount); i++) {
850+
mask |= (1UL << i);
851+
}
852+
853+
return mask;
854+
}
855+
856+
case GET_CLUSTER_COUNT:
857+
return UrmSettings::targetConfigs.mTotalClusterCount;
858+
859+
case GET_CORE_COUNT:
860+
return UrmSettings::targetConfigs.mTotalCoreCount;
861+
862+
case GET_PHYSICAL_CLUSTER_ID:
863+
if(numArgs < 1) {
864+
return 0;
865+
}
866+
return targetRegistry->getPhysicalClusterId(args[0]);
867+
868+
case GET_PHYSICAL_CORE_ID:
869+
if(numArgs < 2) {
870+
return 0;
871+
}
872+
return targetRegistry->getPhysicalCoreId(args[0], args[1]);
873+
}
874+
875+
return 0;
876+
}

0 commit comments

Comments
 (0)