@@ -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;
0 commit comments