diff --git a/modula/CoreModules/AuxRoutines.cpp b/modula/CoreModules/AuxRoutines.cpp index a30970300..c1a633446 100644 --- a/modula/CoreModules/AuxRoutines.cpp +++ b/modula/CoreModules/AuxRoutines.cpp @@ -89,6 +89,10 @@ int8_t AuxRoutines::fileExists(const std::string& filePath) { return access(filePath.c_str(), F_OK) == 0; } +int8_t AuxRoutines::fileWritable(const std::string& filePath) { + return access(filePath.c_str(), W_OK) == 0; +} + std::string AuxRoutines::getMachineName() { return AuxRoutines::readFromFile(UrmSettings::mDeviceNamePath); } diff --git a/modula/CoreModules/Include/AuxRoutines.h b/modula/CoreModules/Include/AuxRoutines.h index 14dd646e9..066b489d0 100644 --- a/modula/CoreModules/Include/AuxRoutines.h +++ b/modula/CoreModules/Include/AuxRoutines.h @@ -32,6 +32,7 @@ class AuxRoutines { static void deleteFile(const std::string& fileName); static void writeSysFsDefaults(); static int8_t fileExists(const std::string& filePath); + static int8_t fileWritable(const std::string& filePath); static std::string getMachineName(); static int8_t isNumericString(const std::string& str); diff --git a/resource-tuner/core/TargetRegistry.cpp b/resource-tuner/core/TargetRegistry.cpp index 49d2fb3cb..2f2149866 100644 --- a/resource-tuner/core/TargetRegistry.cpp +++ b/resource-tuner/core/TargetRegistry.cpp @@ -824,37 +824,68 @@ uint64_t GET_TARGET_INFO(int32_t option, std::shared_ptr targetRegistry = TargetRegistry::getInstance(); switch(option) { + // Returns a 64-bit mask, encodes cpu ids in the range [0, 63] + // By default mask creation begins at the lowest core within the cluster + // and goes up one at a time to core: (start + min(numCpus, coreCount)). + // Where numCpus is the total count of cpus in the specified cluster. + + // Reverse selection is also possible, if a negative coreCount is provided + // Whereby the highest abs(coreCount) cpu ids within the cluster are considered + // for mask generation. case GET_MASK: { if(numArgs < 2) { return 0; } uint64_t mask = 0; - int32_t cluster = args[0]; int32_t coreCount = args[1]; if(cluster == GET_MAX_CLUSTER) { - int32_t clusterCount = UrmSettings::targetConfigs.mTotalClusterCount; - cluster = clusterCount - 1; + cluster = UrmSettings::targetConfigs.mTotalClusterCount - 1; } int32_t physicalClusterId = targetRegistry->getPhysicalClusterId(cluster); ClusterInfo* clusInfo = targetRegistry->getClusterInfo(physicalClusterId); - if(clusInfo == nullptr) { + if(clusInfo == nullptr || clusInfo->mNumCpus <= 0) { return 0; } + int8_t generateReverseMask = false; if(coreCount == 0) { // Iterate over all the cores in the cluster coreCount = clusInfo->mNumCpus; } else { + if(coreCount < 0) { + // Sanity Check + if(coreCount == std::numeric_limits::min()) { + return 0; + } + + coreCount *= -1; + generateReverseMask = true; + } + // Bound the count to the number of cores in the cluster coreCount = std::min(coreCount, clusInfo->mNumCpus); } - for(int32_t i = clusInfo->mStartCpu; i < (clusInfo->mStartCpu + coreCount); i++) { - mask |= (1UL << i); + int32_t curCpu = clusInfo->mStartCpu; + if(generateReverseMask) { + curCpu = clusInfo->mStartCpu + clusInfo->mNumCpus - 1; + while(coreCount--) { + if(curCpu >= 0 && curCpu < 64) { + mask |= (1ULL << curCpu); + } + curCpu--; + } + } else { + while(coreCount--) { + if(curCpu >= 0 && curCpu < 64) { + mask |= (1ULL << curCpu); + } + curCpu++; + } } return mask; diff --git a/tests/Component/ExtensionIntfTests.cpp b/tests/Component/ExtensionIntfTests.cpp index a9125ba1e..b9617c2db 100644 --- a/tests/Component/ExtensionIntfTests.cpp +++ b/tests/Component/ExtensionIntfTests.cpp @@ -1,10 +1,10 @@ // Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. // SPDX-License-Identifier: BSD-3-Clause-Clear +#include "URMTests.h" #include "TestUtils.h" -#include "ResourceRegistry.h" #include "RestuneParser.h" -#include "URMTests.h" +#include "ResourceRegistry.h" #define TEST_CLASS "COMPONENT" #define TEST_SUBCAT "1_URM_EXTN_INTF"