Skip to content

Commit a5b8362

Browse files
authored
Improve CPU mask creation utility to consider higher ids first (#210)
--- Signed-off-by: Kartik Nema <kartnema@qti.qualcomm.com>
1 parent 3722df2 commit a5b8362

4 files changed

Lines changed: 44 additions & 8 deletions

File tree

modula/CoreModules/AuxRoutines.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ int8_t AuxRoutines::fileExists(const std::string& filePath) {
8989
return access(filePath.c_str(), F_OK) == 0;
9090
}
9191

92+
int8_t AuxRoutines::fileWritable(const std::string& filePath) {
93+
return access(filePath.c_str(), W_OK) == 0;
94+
}
95+
9296
std::string AuxRoutines::getMachineName() {
9397
return AuxRoutines::readFromFile(UrmSettings::mDeviceNamePath);
9498
}

modula/CoreModules/Include/AuxRoutines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class AuxRoutines {
3232
static void deleteFile(const std::string& fileName);
3333
static void writeSysFsDefaults();
3434
static int8_t fileExists(const std::string& filePath);
35+
static int8_t fileWritable(const std::string& filePath);
3536
static std::string getMachineName();
3637

3738
static int8_t isNumericString(const std::string& str);

resource-tuner/core/TargetRegistry.cpp

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -824,37 +824,68 @@ uint64_t GET_TARGET_INFO(int32_t option,
824824
std::shared_ptr<TargetRegistry> targetRegistry = TargetRegistry::getInstance();
825825

826826
switch(option) {
827+
// Returns a 64-bit mask, encodes cpu ids in the range [0, 63]
828+
// By default mask creation begins at the lowest core within the cluster
829+
// and goes up one at a time to core: (start + min(numCpus, coreCount)).
830+
// Where numCpus is the total count of cpus in the specified cluster.
831+
832+
// Reverse selection is also possible, if a negative coreCount is provided
833+
// Whereby the highest abs(coreCount) cpu ids within the cluster are considered
834+
// for mask generation.
827835
case GET_MASK: {
828836
if(numArgs < 2) {
829837
return 0;
830838
}
831839

832840
uint64_t mask = 0;
833-
834841
int32_t cluster = args[0];
835842
int32_t coreCount = args[1];
836843

837844
if(cluster == GET_MAX_CLUSTER) {
838-
int32_t clusterCount = UrmSettings::targetConfigs.mTotalClusterCount;
839-
cluster = clusterCount - 1;
845+
cluster = UrmSettings::targetConfigs.mTotalClusterCount - 1;
840846
}
841847

842848
int32_t physicalClusterId = targetRegistry->getPhysicalClusterId(cluster);
843849
ClusterInfo* clusInfo = targetRegistry->getClusterInfo(physicalClusterId);
844-
if(clusInfo == nullptr) {
850+
if(clusInfo == nullptr || clusInfo->mNumCpus <= 0) {
845851
return 0;
846852
}
847853

854+
int8_t generateReverseMask = false;
848855
if(coreCount == 0) {
849856
// Iterate over all the cores in the cluster
850857
coreCount = clusInfo->mNumCpus;
851858
} else {
859+
if(coreCount < 0) {
860+
// Sanity Check
861+
if(coreCount == std::numeric_limits<int32_t>::min()) {
862+
return 0;
863+
}
864+
865+
coreCount *= -1;
866+
generateReverseMask = true;
867+
}
868+
852869
// Bound the count to the number of cores in the cluster
853870
coreCount = std::min(coreCount, clusInfo->mNumCpus);
854871
}
855872

856-
for(int32_t i = clusInfo->mStartCpu; i < (clusInfo->mStartCpu + coreCount); i++) {
857-
mask |= (1UL << i);
873+
int32_t curCpu = clusInfo->mStartCpu;
874+
if(generateReverseMask) {
875+
curCpu = clusInfo->mStartCpu + clusInfo->mNumCpus - 1;
876+
while(coreCount--) {
877+
if(curCpu >= 0 && curCpu < 64) {
878+
mask |= (1ULL << curCpu);
879+
}
880+
curCpu--;
881+
}
882+
} else {
883+
while(coreCount--) {
884+
if(curCpu >= 0 && curCpu < 64) {
885+
mask |= (1ULL << curCpu);
886+
}
887+
curCpu++;
888+
}
858889
}
859890

860891
return mask;

tests/Component/ExtensionIntfTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
22
// SPDX-License-Identifier: BSD-3-Clause-Clear
33

4+
#include "URMTests.h"
45
#include "TestUtils.h"
5-
#include "ResourceRegistry.h"
66
#include "RestuneParser.h"
7-
#include "URMTests.h"
7+
#include "ResourceRegistry.h"
88

99
#define TEST_CLASS "COMPONENT"
1010
#define TEST_SUBCAT "1_URM_EXTN_INTF"

0 commit comments

Comments
 (0)