Skip to content

Commit

Permalink
Logical cores iteration (#1362)
Browse files Browse the repository at this point in the history
* This fails on core 63, which is a long with a 1 followed by 63 zeroes. This works out to Long.MIN_VALUE which is not > 0.

* CHANGELOG.md

* bugfix for cores with too high numbers
  • Loading branch information
Jimmy-653 committed Oct 15, 2020
1 parent f131fa1 commit 4b4c269
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
5.3.1 (in progress)
================
* Your contribution here
* [#1362](https://github.com/oshi/oshi/pull/1362): 63.rd core is wrongly calculated due to too high numbers - [@J-Jimmy](https://github.com/J-Jimmy).

5.3.0 (2020-10-11)
================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static List<LogicalProcessor> getLogicalProcessorInformationEx() {
int lowBit = Long.numberOfTrailingZeros(mask);
int hiBit = 63 - Long.numberOfLeadingZeros(mask);
for (int lp = lowBit; lp <= hiBit; lp++) {
if ((mask & (1L << lp)) > 0) {
if ((mask & (1L << lp)) != 0) {
LogicalProcessor logProc = new LogicalProcessor(lp, getMatchingCore(cores, group, lp),
getMatchingPackage(packages, group, lp), getMatchingNumaNode(numaNodes, group, lp), group);
logProcs.add(logProc);
Expand All @@ -112,7 +112,7 @@ public static List<LogicalProcessor> getLogicalProcessorInformationEx() {
private static int getMatchingPackage(List<GROUP_AFFINITY[]> packages, int g, int lp) {
for (int i = 0; i < packages.size(); i++) {
for (int j = 0; j < packages.get(i).length; j++) {
if ((packages.get(i)[j].mask.longValue() & (1L << lp)) > 0 && packages.get(i)[j].group == g) {
if ((packages.get(i)[j].mask.longValue() & (1L << lp)) != 0 && packages.get(i)[j].group == g) {
return i;
}
}
Expand All @@ -122,7 +122,7 @@ private static int getMatchingPackage(List<GROUP_AFFINITY[]> packages, int g, in

private static int getMatchingNumaNode(List<NUMA_NODE_RELATIONSHIP> numaNodes, int g, int lp) {
for (int j = 0; j < numaNodes.size(); j++) {
if ((numaNodes.get(j).groupMask.mask.longValue() & (1L << lp)) > 0
if ((numaNodes.get(j).groupMask.mask.longValue() & (1L << lp)) != 0
&& numaNodes.get(j).groupMask.group == g) {
return numaNodes.get(j).nodeNumber;
}
Expand All @@ -132,7 +132,7 @@ private static int getMatchingNumaNode(List<NUMA_NODE_RELATIONSHIP> numaNodes, i

private static int getMatchingCore(List<GROUP_AFFINITY> cores, int g, int lp) {
for (int j = 0; j < cores.size(); j++) {
if ((cores.get(j).mask.longValue() & (1L << lp)) > 0 && cores.get(j).group == g) {
if ((cores.get(j).mask.longValue() & (1L << lp)) != 0 && cores.get(j).group == g) {
return j;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private static List<LogicalProcessor> matchBitmasks(long group1, List<Long> grou

private static int getMatchingBitmask(List<Long> bitmasks, int lp) {
for (int j = 0; j < bitmasks.size(); j++) {
if ((bitmasks.get(j).longValue() & (1L << lp)) > 0) {
if ((bitmasks.get(j).longValue() & (1L << lp)) != 0) {
return j;
}
}
Expand Down

0 comments on commit 4b4c269

Please sign in to comment.