aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Yue Gan <yueg@google.com>2016-04-05 09:00:22 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2016-04-05 14:09:07 +0000
commita6ae3e7a43d32c13081886ffa64b5d14157f4910 (patch)
tree0e97efc27924b470f7915acb574c76acdb979bc7 /src
parenteea74e902818b5808834061d61a3183d87346a83 (diff)
Add SMT detection for mac. Fixes #963.
-- Change-Id: Ib83af0d0a04dc6b173bef1df28d17abc7a3c824d Reviewed-on: https://bazel-review.googlesource.com/#/c/3120/ MOS_MIGRATED_REVID=119027507
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/BUILD1
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/LocalHostCapacity.java130
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceFallback.java36
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerDarwin.java60
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerLinux.java132
-rw-r--r--src/main/java/com/google/devtools/build/lib/unix/NativePosixSystem.java43
-rw-r--r--src/main/native/unix_jni.cc21
-rw-r--r--src/main/native/unix_jni.h7
-rw-r--r--src/main/native/unix_jni_darwin.cc6
-rw-r--r--src/main/native/unix_jni_freebsd.cc4
-rw-r--r--src/main/native/unix_jni_linux.cc8
-rw-r--r--src/test/java/com/google/devtools/build/lib/actions/LocalHostCapacityTest.java392
-rw-r--r--src/test/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerLinuxTest.java340
13 files changed, 677 insertions, 503 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/BUILD b/src/main/java/com/google/devtools/build/lib/actions/BUILD
index e51fbea1af..8f717e78da 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/actions/BUILD
@@ -18,6 +18,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib:packages-internal",
"//src/main/java/com/google/devtools/build/lib:shell",
"//src/main/java/com/google/devtools/build/lib:skylarkinterface",
+ "//src/main/java/com/google/devtools/build/lib:unix",
"//src/main/java/com/google/devtools/build/lib:util",
"//src/main/java/com/google/devtools/build/lib:vfs",
"//src/main/java/com/google/devtools/build/skyframe",
diff --git a/src/main/java/com/google/devtools/build/lib/actions/LocalHostCapacity.java b/src/main/java/com/google/devtools/build/lib/actions/LocalHostCapacity.java
index 43509b5cd9..74ef6830c9 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/LocalHostCapacity.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/LocalHostCapacity.java
@@ -14,17 +14,8 @@
package com.google.devtools.build.lib.actions;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Splitter;
-import com.google.common.io.Files;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible;
-import com.google.devtools.build.lib.util.ProcMeminfoParser;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.util.HashSet;
-import java.util.Set;
+import com.google.devtools.build.lib.util.OS;
/**
* This class estimates the local host's resource capacity.
@@ -32,115 +23,34 @@ import java.util.Set;
@ThreadCompatible
public final class LocalHostCapacity {
- /* If /proc/* information is not available, guess based on what the JVM thinks. Anecdotally,
- * the JVM picks 0.22 the total available memory as maxMemory (tested on a standard Mac), so
- * multiply by 3, and divide by 2^20 because we want megabytes.
- */
- private static final ResourceSet DEFAULT_RESOURCES = ResourceSet.create(
- 3.0 * (Runtime.getRuntime().maxMemory() >> 20),
- Runtime.getRuntime().availableProcessors(), 1.0,
- Integer.MAX_VALUE);
+ private static final OS currentOS = OS.getCurrent();
+ private static ResourceSet localHostCapacity;
private LocalHostCapacity() {}
- /**
- * Estimates of the local host's resource capacity,
- * obtained by reading /proc/cpuinfo and /proc/meminfo.
- */
- private static ResourceSet localHostCapacity;
-
- /**
- * Estimates of the local host's resource capacity,
- * obtained by reading /proc/cpuinfo and /proc/meminfo.
- */
public static ResourceSet getLocalHostCapacity() {
if (localHostCapacity == null) {
- localHostCapacity = getLocalHostCapacity("/proc/cpuinfo", "/proc/meminfo");
+ localHostCapacity = getNewLocalHostCapacity();
}
return localHostCapacity;
}
- private static final Splitter NEWLINE_SPLITTER = Splitter.on('\n').omitEmptyStrings();
-
- @VisibleForTesting
- static int getLogicalCpuCount(String cpuinfoContent) {
- Iterable<String> lines = NEWLINE_SPLITTER.split(cpuinfoContent);
- int count = 0;
- for (String line : lines) {
- if(line.startsWith("processor")) {
- count++;
- }
- }
- if (count == 0) {
- throw new IllegalArgumentException("Can't locate processor in the /proc/cpuinfo");
- }
- return count;
- }
-
- @VisibleForTesting
- static int getPhysicalCpuCount(String cpuinfoContent, int logicalCpuCount) {
- Iterable<String> lines = NEWLINE_SPLITTER.split(cpuinfoContent);
- Set<String> uniq = new HashSet<>();
- for (String line : lines) {
- if(line.startsWith("physical id")) {
- uniq.add(line);
- }
- }
- int physicalCpuCount = uniq.size();
- if (physicalCpuCount == 0) {
- physicalCpuCount = logicalCpuCount;
- }
- return physicalCpuCount;
- }
-
- @VisibleForTesting
- static int getCoresPerCpu(String cpuinfoFileContent) {
- Iterable<String> lines = NEWLINE_SPLITTER.split(cpuinfoFileContent);
- Set<String> uniq = new HashSet<>();
- for (String line : lines) {
- if(line.startsWith("core id")) {
- uniq.add(line);
- }
- }
- int coresPerCpu = uniq.size();
- if (coresPerCpu == 0) {
- coresPerCpu = 1;
- }
- return coresPerCpu;
- }
-
- @VisibleForTesting
- static ResourceSet getLocalHostCapacity(String cpuinfoFile, String meminfoFile) {
- try {
- String cpuinfoContent = readContent(cpuinfoFile);
- ProcMeminfoParser memInfo = new ProcMeminfoParser(meminfoFile);
- int logicalCpuCount = getLogicalCpuCount(cpuinfoContent);
- int physicalCpuCount = getPhysicalCpuCount(cpuinfoContent, logicalCpuCount);
- int coresPerCpu = getCoresPerCpu(cpuinfoContent);
- int totalCores = coresPerCpu * physicalCpuCount;
- boolean hyperthreading = (logicalCpuCount != totalCores);
- double ramMb = ProcMeminfoParser.kbToMb(memInfo.getTotalKb());
- final double EFFECTIVE_CPUS_PER_HYPERTHREADED_CPU = 0.6;
- return ResourceSet.create(
- ramMb,
- logicalCpuCount * (hyperthreading ? EFFECTIVE_CPUS_PER_HYPERTHREADED_CPU : 1.0),
- 1.0,
- Integer.MAX_VALUE);
- } catch (IOException | IllegalArgumentException e) {
- return DEFAULT_RESOURCES;
- }
- }
-
- /**
- * For testing purposes only. Do not use it.
- */
- @VisibleForTesting
- static void setLocalHostCapacity(ResourceSet resources) {
- localHostCapacity = resources;
- }
-
- private static String readContent(String filename) throws IOException {
- return Files.toString(new File(filename), Charset.defaultCharset());
+ private static ResourceSet getNewLocalHostCapacity() {
+ ResourceSet localResources = null;
+ switch (currentOS) {
+ case DARWIN:
+ localResources = LocalHostResourceManagerDarwin.getLocalHostResources();
+ break;
+ case LINUX:
+ localResources = LocalHostResourceManagerLinux.getLocalHostResources();
+ break;
+ default:
+ break;
+ }
+ if (localResources == null) {
+ localResources = LocalHostResourceFallback.getLocalHostResources();
+ }
+ return localResources;
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceFallback.java b/src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceFallback.java
new file mode 100644
index 0000000000..2829cb4dd2
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceFallback.java
@@ -0,0 +1,36 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.actions;
+
+/**
+ * This class provide a fallback of the local host's resource capacity.
+ */
+public class LocalHostResourceFallback {
+
+ /* If /proc/* information is not available, guess based on what the JVM thinks. Anecdotally,
+ * the JVM picks 0.22 the total available memory as maxMemory (tested on a standard Mac), so
+ * multiply by 3, and divide by 2^20 because we want megabytes.
+ */
+ private static final ResourceSet DEFAULT_RESOURCES =
+ ResourceSet.create(
+ 3.0 * (Runtime.getRuntime().maxMemory() >> 20),
+ Runtime.getRuntime().availableProcessors(),
+ 1.0,
+ Integer.MAX_VALUE);
+
+ public static ResourceSet getLocalHostResources() {
+ return DEFAULT_RESOURCES;
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerDarwin.java b/src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerDarwin.java
new file mode 100644
index 0000000000..1ada1bfd0c
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerDarwin.java
@@ -0,0 +1,60 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.actions;
+
+import com.google.devtools.build.lib.unix.NativePosixSystem;
+
+import java.io.IOException;
+
+/**
+ * This class estimates the local host's resource capacity for Darwin.
+ */
+public class LocalHostResourceManagerDarwin {
+ private static final Boolean JNI_UNAVAILABLE =
+ "0".equals(System.getProperty("io.bazel.UnixFileSystem"));
+ private static final double EFFECTIVE_CPUS_PER_HYPERTHREADED_CPU = 0.6;
+
+ private static int getLogicalCpuCount() throws IOException {
+ return (int) NativePosixSystem.sysctlbynameGetLong("hw.logicalcpu");
+ }
+
+ private static int getPhysicalCpuCount() throws IOException {
+ return (int) NativePosixSystem.sysctlbynameGetLong("hw.physicalcpu");
+ }
+
+ private static double getMemoryInMb() throws IOException {
+ return NativePosixSystem.sysctlbynameGetLong("hw.memsize") / 1E6;
+ }
+
+ public static ResourceSet getLocalHostResources() {
+ if (JNI_UNAVAILABLE) {
+ return null;
+ }
+ try {
+ int logicalCpuCount = getLogicalCpuCount();
+ int physicalCpuCount = getPhysicalCpuCount();
+ double ramMb = getMemoryInMb();
+ boolean hyperthreading = (logicalCpuCount != physicalCpuCount);
+
+ return ResourceSet.create(
+ ramMb,
+ logicalCpuCount * (hyperthreading ? EFFECTIVE_CPUS_PER_HYPERTHREADED_CPU : 1.0),
+ 1.0,
+ Integer.MAX_VALUE);
+ } catch (IOException e) {
+ return null;
+ }
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerLinux.java b/src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerLinux.java
new file mode 100644
index 0000000000..a9b50f98bb
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerLinux.java
@@ -0,0 +1,132 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.actions;
+
+import com.google.common.base.Splitter;
+import com.google.common.io.Files;
+import com.google.devtools.build.lib.util.ProcMeminfoParser;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * This class estimates the local host's resource capacity for Linux.
+ */
+public class LocalHostResourceManagerLinux {
+ private static String cpuInfoContent = null;
+
+ private static final Splitter NEWLINE_SPLITTER = Splitter.on('\n').omitEmptyStrings();
+ private static final String CPU_INFO_FILE = "/proc/cpuinfo";
+ private static final String MEM_INFO_FILE = "/proc/meminfo";
+
+ private static int getLogicalCpuCount() throws IOException {
+ String content = getCpuInfoContent();
+ return getLogicalCpuCountHelper(content);
+ }
+
+ private static int getPhysicalCpuCount(int logicalCpuCount) throws IOException {
+ String content = getCpuInfoContent();
+ return getPhysicalCpuCountHelper(logicalCpuCount, content);
+ }
+
+ private static double getMemoryInMb() throws IOException {
+ return getMemoryInMbHelper(MEM_INFO_FILE);
+ }
+
+ public static ResourceSet getLocalHostResources() {
+ try {
+ int logicalCpuCount = getLogicalCpuCount();
+ int physicalCpuCount = getPhysicalCpuCount(logicalCpuCount);
+ double ramMb = getMemoryInMb();
+
+ boolean hyperthreading = (logicalCpuCount != physicalCpuCount);
+ final double EFFECTIVE_CPUS_PER_HYPERTHREADED_CPU = 0.6;
+ return ResourceSet.create(
+ ramMb,
+ logicalCpuCount * (hyperthreading ? EFFECTIVE_CPUS_PER_HYPERTHREADED_CPU : 1.0),
+ 1.0,
+ Integer.MAX_VALUE);
+ } catch (IOException | IllegalArgumentException e) {
+ return null;
+ }
+ }
+
+ private static String getCpuInfoContent() throws IOException {
+ if (cpuInfoContent == null) {
+ cpuInfoContent = readContent(CPU_INFO_FILE);
+ }
+ return cpuInfoContent;
+ }
+
+ private static String readContent(String filename) throws IOException {
+ return Files.toString(new File(filename), Charset.defaultCharset());
+ }
+
+ /**
+ * For testing purposes only. Do not use it.
+ */
+ public static int getLogicalCpuCountHelper(String content) throws IOException {
+ int count = 0;
+ Iterable<String> lines = NEWLINE_SPLITTER.split(content);
+ for (String line : lines) {
+ if (line.startsWith("processor")) {
+ count++;
+ }
+ }
+ if (count == 0) {
+ throw new IllegalArgumentException("Can't get logical CPU count");
+ }
+ return count;
+ }
+
+ public static int getPhysicalCpuCountHelper(int logicalCpuCount, String content)
+ throws IOException {
+ // CPU count
+ Iterable<String> lines = NEWLINE_SPLITTER.split(content);
+ Set<String> uniq = new HashSet<>();
+ for (String line : lines) {
+ if (line.startsWith("physical id")) {
+ uniq.add(line);
+ }
+ }
+ int cpuCount = uniq.size();
+ if (cpuCount == 0) {
+ cpuCount = logicalCpuCount;
+ }
+
+ // core per CPU
+ uniq = new HashSet<>();
+ for (String line : lines) {
+ if (line.startsWith("core id")) {
+ uniq.add(line);
+ }
+ }
+ int coresPerCpu = uniq.size();
+ if (coresPerCpu == 0) {
+ coresPerCpu = 1;
+ }
+
+ return cpuCount * coresPerCpu;
+ }
+
+ public static double getMemoryInMbHelper(String memInfoFileName) throws IOException {
+ ProcMeminfoParser memInfo = new ProcMeminfoParser(memInfoFileName);
+ double ramMb = ProcMeminfoParser.kbToMb(memInfo.getTotalKb());
+ return ramMb;
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/unix/NativePosixSystem.java b/src/main/java/com/google/devtools/build/lib/unix/NativePosixSystem.java
new file mode 100644
index 0000000000..9834f24ada
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/unix/NativePosixSystem.java
@@ -0,0 +1,43 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.unix;
+
+import com.google.devtools.build.lib.UnixJniLoader;
+
+import java.io.IOException;
+
+/**
+ * Utility methods for access to UNIX system calls not exposed by the Java
+ * SDK. Exception messages are selected to be consistent with those generated
+ * by the java.io package where appropriate--see package javadoc for details.
+ */
+public class NativePosixSystem {
+
+ private NativePosixSystem() {}
+
+ static {
+ if (!"0".equals(System.getProperty("io.bazel.UnixFileSystem"))) {
+ UnixJniLoader.loadJni();
+ }
+ }
+
+ /**
+ * Native wrapper around POSIX sysctlbyname(3) syscall.
+ *
+ * @param name the name for value to get from sysctl
+ * @throws IOException iff the sysctlbyname() syscall failed.
+ */
+ public static native long sysctlbynameGetLong(String name) throws IOException;
+}
diff --git a/src/main/native/unix_jni.cc b/src/main/native/unix_jni.cc
index fb70370a76..801710f072 100644
--- a/src/main/native/unix_jni.cc
+++ b/src/main/native/unix_jni.cc
@@ -232,6 +232,14 @@ void PostFileException(JNIEnv *env, int error_number, const char *filename) {
+ ")");
}
+// See unix_jni.h.
+void PostSystemException(JNIEnv *env, int error_number, const char *function,
+ const char *name) {
+ ::PostException(env, error_number, std::string(function) + "(" +
+ std::string(name) + ")" + " (" +
+ ErrorMessage(error_number) + ")");
+}
+
// TODO(bazel-team): split out all the FileSystem class's native methods
// into a separate source file, fsutils.cc.
@@ -849,3 +857,16 @@ Java_com_google_devtools_build_lib_unix_NativePosixFiles_md5sumAsBytes(
ReleaseStringLatin1Chars(path_chars);
return result;
}
+
+extern "C" JNIEXPORT jlong JNICALL
+Java_com_google_devtools_build_lib_unix_NativePosixSystem_sysctlbynameGetLong(
+ JNIEnv *env, jclass clazz, jstring name) {
+ const char *name_chars = GetStringLatin1Chars(env, name);
+ jlong r;
+ size_t len = sizeof(r);
+ if (portable_sysctlbyname(name_chars, &r, &len) == -1) {
+ ::PostSystemException(env, errno, "sysctlbyname", name_chars);
+ }
+ ReleaseStringLatin1Chars(name_chars);
+ return r;
+}
diff --git a/src/main/native/unix_jni.h b/src/main/native/unix_jni.h
index 49ec589e5c..f4a1600161 100644
--- a/src/main/native/unix_jni.h
+++ b/src/main/native/unix_jni.h
@@ -59,6 +59,10 @@ extern void PostException(JNIEnv *env, int error_number,
extern void PostFileException(JNIEnv *env, int error_number,
const char *filename);
+// Like PostFileException, but with a different error message.
+extern void PostSystemException(JNIEnv *env, int error_number,
+ const char *name);
+
// Returns the standard error message for a given UNIX error number.
extern std::string ErrorMessage(int error_number);
@@ -87,4 +91,7 @@ ssize_t portable_getxattr(const char *path, const char *name, void *value,
ssize_t portable_lgetxattr(const char *path, const char *name, void *value,
size_t size);
+// Run sysctlbyname(3), only available on darwin
+int portable_sysctlbyname(const char *name_chars, long *mibp, size_t *sizep);
+
#endif // BAZEL_SRC_MAIN_NATIVE_UNIX_JNI_H__
diff --git a/src/main/native/unix_jni_darwin.cc b/src/main/native/unix_jni_darwin.cc
index ae7288c3b8..70852a3a86 100644
--- a/src/main/native/unix_jni_darwin.cc
+++ b/src/main/native/unix_jni_darwin.cc
@@ -20,7 +20,9 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <sys/sysctl.h>
#include <sys/syslimits.h>
+#include <sys/types.h>
#include <string>
@@ -111,3 +113,7 @@ ssize_t portable_lgetxattr(const char *path, const char *name, void *value,
errno = ENOSYS;
return -1;
}
+
+int portable_sysctlbyname(const char *name_chars, long *mibp, size_t *sizep) {
+ return sysctlbyname(name_chars, mibp, sizep, NULL, 0);
+}
diff --git a/src/main/native/unix_jni_freebsd.cc b/src/main/native/unix_jni_freebsd.cc
index 310281c4ce..2ed1b2a130 100644
--- a/src/main/native/unix_jni_freebsd.cc
+++ b/src/main/native/unix_jni_freebsd.cc
@@ -79,3 +79,7 @@ ssize_t portable_lgetxattr(const char *path, const char *name, void *value,
size_t size) {
return extattr_get_link(path, EXTATTR_NAMESPACE_SYSTEM, name, value, size);
}
+
+int portable_sysctlbyname(const char *name_chars, long *mibp, size_t *sizep) {
+ return sysctlbyname(name_chars, mibp, sizep, NULL, 0);
+}
diff --git a/src/main/native/unix_jni_linux.cc b/src/main/native/unix_jni_linux.cc
index 44e23531f1..75d4e5072c 100644
--- a/src/main/native/unix_jni_linux.cc
+++ b/src/main/native/unix_jni_linux.cc
@@ -14,8 +14,9 @@
#include "src/main/native/unix_jni.h"
-#include <string.h>
+#include <errno.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/xattr.h>
@@ -73,3 +74,8 @@ ssize_t portable_lgetxattr(const char *path, const char *name, void *value,
size_t size) {
return ::lgetxattr(path, name, value, size);
}
+
+int portable_sysctlbyname(const char *name_chars, long *mibp, size_t *sizep) {
+ errno = ENOSYS;
+ return -1;
+}
diff --git a/src/test/java/com/google/devtools/build/lib/actions/LocalHostCapacityTest.java b/src/test/java/com/google/devtools/build/lib/actions/LocalHostCapacityTest.java
deleted file mode 100644
index e1f17429f9..0000000000
--- a/src/test/java/com/google/devtools/build/lib/actions/LocalHostCapacityTest.java
+++ /dev/null
@@ -1,392 +0,0 @@
-// Copyright 2015 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.lib.actions;
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-
-import com.google.devtools.build.lib.util.StringUtilities;
-import com.google.devtools.build.lib.vfs.util.FsApparatus;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-@RunWith(JUnit4.class)
-public class LocalHostCapacityTest {
-
- private FsApparatus scratch = FsApparatus.newNative();
-
- @Test
- public void testNonHyperthreadedMachine() throws Exception {
- String cpuinfoContent = StringUtilities.joinLines(
- "processor\t: 0",
- "vendor_id\t: GenuineIntel",
- "cpu family\t: 15",
- "model\t\t: 4",
- "model name\t: Intel(R) Pentium(R) 4 CPU 3.40GHz",
- "stepping\t: 10",
- "cpu MHz\t\t: 3400.000",
- "cache size\t: 2048 KB",
- "fpu\t\t: yes",
- "fpu_exception\t: yes",
- "cpuid level\t: 5",
- "wp\t\t: yes",
- "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca "
- + "cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm "
- + "syscall nx lm constant_tsc up pni monitor ds_cpl est cid cx16 "
- + "xtpr lahf_lm",
- "bogomips\t: 6803.83",
- "clflush size\t: 64",
- "cache_alignment\t: 128",
- "address sizes\t: 36 bits physical, 48 bits virtual",
- "power management:"
- );
- String cpuinfoFile =
- scratch.file("test_cpuinfo_nonht", cpuinfoContent).getPathString();
- String meminfoContent = StringUtilities.joinLines(
- "MemTotal: 3091732 kB",
- "MemFree: 2167344 kB",
- "Buffers: 60644 kB",
- "Cached: 509940 kB",
- "SwapCached: 0 kB",
- "Active: 636892 kB",
- "Inactive: 212760 kB",
- "HighTotal: 0 kB",
- "HighFree: 0 kB",
- "LowTotal: 3091732 kB",
- "LowFree: 2167344 kB",
- "SwapTotal: 9124880 kB",
- "SwapFree: 9124880 kB",
- "Dirty: 0 kB",
- "Writeback: 0 kB",
- "AnonPages: 279028 kB",
- "Mapped: 54404 kB",
- "Slab: 42820 kB",
- "PageTables: 5184 kB",
- "NFS_Unstable: 0 kB",
- "Bounce: 0 kB",
- "CommitLimit: 10670744 kB",
- "Committed_AS: 665840 kB",
- "VmallocTotal: 34359738367 kB",
- "VmallocUsed: 300484 kB",
- "VmallocChunk: 34359437307 kB",
- "HugePages_Total: 0",
- "HugePages_Free: 0",
- "HugePages_Rsvd: 0",
- "Hugepagesize: 2048 kB"
- );
- String stat1Content = StringUtilities.joinLines(
- "cpu 29793342 260290 3479274 636259369 6683218 656426 714057 0",
- "cpu0 29793342 260290 3479274 636259369 6683218 656426 714057 0",
- "intr 2870488853 2486517107 3 0 0 2 0 5 0 0 0 0 0 3 0 74363716 " +
- "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " +
- "0 0 52483586 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 973315 0 0 0 0 0 0 0 46 " +
- "0 0 0 0 0 0 0 98792358 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " +
- "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " +
- "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 114339590 " +
- "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " +
- "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 43019122 0 0 0 0 0",
- "ctxt 15053799843",
- "btime 1199289688",
- "processes 25799993",
- "procs_running 1",
- "procs_blocked 0"
- );
- String stat2Content = StringUtilities.joinLines(
- "cpu 29794509 260290 3479474 636287862 6683283 656450 714087 0 0",
- "cpu0 29794509 260290 3479474 636287862 6683283 656450 714087 0 0",
- "intr 2870488853 2486517107 3 0 0 2 0 5 0 0 0 0 0 3 0 74363716 " +
- "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " +
- "0 0 52483586 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 973315 0 0 0 0 0 0 0 46 " +
- "0 0 0 0 0 0 0 98792358 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " +
- "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " +
- "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 114339590 " +
- "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " +
- "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 43019122 0 0 0 0 0",
- "ctxt 15053799843",
- "btime 1199289688",
- "processes 25799993",
- "procs_running 1",
- "procs_blocked 0"
- );
- String meminfoFile =
- scratch.file("test_meminfo_nonht", meminfoContent).getPathString();
- assertEquals(1, LocalHostCapacity.getLogicalCpuCount(cpuinfoContent));
- assertEquals(1, LocalHostCapacity.getPhysicalCpuCount(cpuinfoContent, 1));
- assertEquals(1, LocalHostCapacity.getCoresPerCpu(cpuinfoContent));
- ResourceSet capacity =
- LocalHostCapacity.getLocalHostCapacity(cpuinfoFile, meminfoFile);
- assertEquals(1.0, capacity.getCpuUsage(), 0.01);
- assertEquals(3091.732, capacity.getMemoryMb(), 0.1); // +/- 0.1MB
- LocalHostCapacity.setLocalHostCapacity(capacity);
- assertSame(capacity, LocalHostCapacity.getLocalHostCapacity());
- }
-
- @Test
- public void testHyperthreadedMachine() throws Exception {
- String cpuinfoContent = StringUtilities.joinLines(
- "processor\t: 0",
- "vendor_id\t: GenuineIntel",
- "cpu family\t: 15",
- "model\t\t: 4",
- "model name\t: Intel(R) Pentium(R) 4 CPU 3.40GHz",
- "stepping\t: 1",
- "cpu MHz\t\t: 3400.245",
- "cache size\t: 1024 KB",
- "physical id\t: 0",
- "siblings\t: 2",
- "core id\t\t: 0",
- "cpu cores\t: 1",
- "fpu\t\t: yes",
- "fpu_exception\t: yes",
- "cpuid level\t: 5",
- "wp\t\t: yes",
- "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge "
- + "mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm "
- + "syscall lm constant_tsc pni monitor ds_cpl cid cx16 xtpr",
- "bogomips\t: 6806.31",
- "clflush size\t: 64",
- "cache_alignment\t: 128",
- "address sizes\t: 36 bits physical, 48 bits virtual",
- "power management:",
- "",
- "processor\t: 1",
- "vendor_id\t: GenuineIntel",
- "cpu family\t: 15",
- "model\t\t: 4",
- "model name\t: Intel(R) Pentium(R) 4 CPU 3.40GHz",
- "stepping\t: 1",
- "cpu MHz\t\t: 3400.245",
- "cache size\t: 1024 KB",
- "physical id\t: 0",
- "siblings\t: 2",
- "core id\t\t: 0",
- "cpu cores\t: 1",
- "fpu\t\t: yes",
- "fpu_exception\t: yes",
- "cpuid level\t: 5",
- "wp\t\t: yes",
- "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge "
- + "mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm "
- + "syscall lm constant_tsc pni monitor ds_cpl cid cx16 xtpr",
- "bogomips\t: 6800.76",
- "clflush size\t: 64",
- "cache_alignment\t: 128",
- "address sizes\t: 36 bits physical, 48 bits virtual",
- "power management:",
- ""
- );
- String cpuinfoFile =
- scratch.file("test_cpuinfo_ht", cpuinfoContent).getPathString();
- String meminfoContent = StringUtilities.joinLines(
- "MemTotal: 3092004 kB",
- "MemFree: 26124 kB",
- "Buffers: 3836 kB",
- "Cached: 52400 kB",
- "SwapCached: 68204 kB",
- "Active: 2281464 kB",
- "Inactive: 260908 kB",
- "HighTotal: 0 kB",
- "HighFree: 0 kB",
- "LowTotal: 3092004 kB",
- "LowFree: 26124 kB",
- "SwapTotal: 9124880 kB",
- "SwapFree: 8264920 kB",
- "Dirty: 616 kB",
- "Writeback: 0 kB",
- "AnonPages: 2466336 kB",
- "Mapped: 37576 kB",
- "Slab: 483004 kB",
- "PageTables: 11912 kB",
- "NFS_Unstable: 0 kB",
- "Bounce: 0 kB",
- "CommitLimit: 10670880 kB",
- "Committed_AS: 3627984 kB",
- "VmallocTotal: 34359738367 kB",
- "VmallocUsed: 300460 kB",
- "VmallocChunk: 34359437307 kB",
- "HugePages_Total: 0",
- "HugePages_Free: 0",
- "HugePages_Rsvd: 0",
- "Hugepagesize: 2048 kB"
- );
- String meminfoFile =
- scratch.file("test_meminfo_ht", meminfoContent).getPathString();
- assertEquals(2, LocalHostCapacity.getLogicalCpuCount(cpuinfoContent));
- assertEquals(1, LocalHostCapacity.getPhysicalCpuCount(cpuinfoContent, 2));
- assertEquals(1, LocalHostCapacity.getCoresPerCpu(cpuinfoContent));
- ResourceSet capacity =
- LocalHostCapacity.getLocalHostCapacity(cpuinfoFile, meminfoFile);
- assertEquals(1.2, capacity.getCpuUsage(), .0001);
- assertEquals(3092.004, capacity.getMemoryMb(), 0.1); // +/- 0.1MB
- }
-
- @Test
- public void testAMDMachine() throws Exception {
- String cpuinfoContent = StringUtilities.joinLines(
- "processor\t: 0",
- "vendor_id\t: AuthenticAMD",
- "cpu family\t: 15",
- "model\t\t: 65",
- "model name\t: Dual-Core AMD Opteron(tm) Processor 8214 HE",
- "stepping\t: 2",
- "cpu MHz\t\t: 2200.000",
- "cache size\t: 1024 KB",
- "physical id\t: 0",
- "siblings\t: 2",
- "core id\t\t: 0",
- "cpu cores\t: 2",
- "fpu\t\t: yes",
- "fpu_exception\t: yes",
- "cpuid level\t: 1",
- "wp\t\t: yes",
- "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr "
- + "pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall "
- + "nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm "
- + "cmp_legacy svm cr8_legacy",
- "bogomips\t: 4425.84",
- "TLB size\t: 1024 4K pages",
- "clflush size\t: 64",
- "cache_alignment\t: 64",
- "address sizes\t: 40 bits physical, 48 bits virtual",
- "power management: ts fid vid ttp tm stc",
- "",
- "processor\t: 1",
- "vendor_id\t: AuthenticAMD",
- "cpu family\t: 15",
- "model\t\t: 65",
- "model name\t: Dual-Core AMD Opteron(tm) Processor 8214 HE",
- "stepping\t: 2",
- "cpu MHz\t\t: 2200.000",
- "cache size\t: 1024 KB",
- "physical id\t: 0",
- "siblings\t: 2",
- "core id\t\t: 1",
- "cpu cores\t: 2",
- "fpu\t\t: yes",
- "fpu_exception\t: yes",
- "cpuid level\t: 1",
- "wp\t\t: yes",
- "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr "
- + "pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall "
- + "nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm "
- + "cmp_legacy svm cr8_legacy",
- "bogomips\t: 4460.61",
- "TLB size\t: 1024 4K pages",
- "clflush size\t: 64",
- "cache_alignment\t: 64",
- "address sizes\t: 40 bits physical, 48 bits virtual",
- "power management: ts fid vid ttp tm stc",
- "",
- "processor\t: 2",
- "vendor_id\t: AuthenticAMD",
- "cpu family\t: 15",
- "model\t\t: 65",
- "model name\t: Dual-Core AMD Opteron(tm) Processor 8214 HE",
- "stepping\t: 2",
- "cpu MHz\t\t: 2200.000",
- "cache size\t: 1024 KB",
- "physical id\t: 1",
- "siblings\t: 2",
- "core id\t\t: 0",
- "cpu cores\t: 2",
- "fpu\t\t: yes",
- "fpu_exception\t: yes",
- "cpuid level\t: 1",
- "wp\t\t: yes",
- "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr "
- + "pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall "
- + "nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm "
- + "cmp_legacy svm cr8_legacy",
- "bogomips\t: 4420.45",
- "TLB size\t: 1024 4K pages",
- "clflush size\t: 64",
- "cache_alignment\t: 64",
- "address sizes\t: 40 bits physical, 48 bits virtual",
- "power management: ts fid vid ttp tm stc",
- "",
- "processor\t: 3",
- "vendor_id\t: AuthenticAMD",
- "cpu family\t: 15",
- "model\t\t: 65",
- "model name\t: Dual-Core AMD Opteron(tm) Processor 8214 HE",
- "stepping\t: 2",
- "cpu MHz\t\t: 2200.000",
- "cache size\t: 1024 KB",
- "physical id\t: 1",
- "siblings\t: 2",
- "core id\t\t: 1",
- "cpu cores\t: 2",
- "fpu\t\t: yes",
- "fpu_exception\t: yes",
- "cpuid level\t: 1",
- "wp\t\t: yes",
- "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr "
- + "pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall "
- + "nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm "
- + "cmp_legacy svm cr8_legacy",
- "bogomips\t: 4460.39",
- "TLB size\t: 1024 4K pages",
- "clflush size\t: 64",
- "cache_alignment\t: 64",
- "address sizes\t: 40 bits physical, 48 bits virtual",
- "power management: ts fid vid ttp tm stc",
- ""
- );
- String cpuinfoFile =
- scratch.file("test_cpuinfo_amd", cpuinfoContent).getPathString();
- String meminfoContent = StringUtilities.joinLines(
- "MemTotal: 8223956 kB",
- "MemFree: 3670396 kB",
- "Buffers: 374068 kB",
- "Cached: 3366980 kB",
- "SwapCached: 0 kB",
- "Active: 3275860 kB",
- "Inactive: 737816 kB",
- "HighTotal: 0 kB",
- "HighFree: 0 kB",
- "LowTotal: 8223956 kB",
- "LowFree: 3670396 kB",
- "SwapTotal: 6024332 kB",
- "SwapFree: 6024332 kB",
- "Dirty: 84 kB",
- "Writeback: 0 kB",
- "AnonPages: 272308 kB",
- "Mapped: 62604 kB",
- "Slab: 506140 kB",
- "PageTables: 4608 kB",
- "NFS_Unstable: 0 kB",
- "Bounce: 0 kB",
- "CommitLimit: 10136308 kB",
- "Committed_AS: 600672 kB",
- "VmallocTotal: 34359738367 kB",
- "VmallocUsed: 299068 kB",
- "VmallocChunk: 34359438843 kB",
- "HugePages_Total: 0",
- "HugePages_Free: 0",
- "HugePages_Rsvd: 0",
- "Hugepagesize: 2048 kB");
- String meminfoFile =
- scratch.file("test_meminfo_amd", meminfoContent).getPathString();
- assertEquals(4, LocalHostCapacity.getLogicalCpuCount(cpuinfoContent));
- assertEquals(2, LocalHostCapacity.getPhysicalCpuCount(cpuinfoContent, 4));
- assertEquals(2, LocalHostCapacity.getCoresPerCpu(cpuinfoContent));
- ResourceSet capacity =
- LocalHostCapacity.getLocalHostCapacity(cpuinfoFile, meminfoFile);
- assertEquals(capacity.getCpuUsage(), 4.0, 0.01);
- assertEquals(8223.956, capacity.getMemoryMb(), 0.1); // +/- 0.1MB
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerLinuxTest.java b/src/test/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerLinuxTest.java
new file mode 100644
index 0000000000..3cd5ded358
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/actions/LocalHostResourceManagerLinuxTest.java
@@ -0,0 +1,340 @@
+// Copyright 2015 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.actions;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.devtools.build.lib.util.StringUtilities;
+import com.google.devtools.build.lib.vfs.util.FsApparatus;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * Test for LocalHostResourceManagerLinux.
+ */
+@RunWith(JUnit4.class)
+public class LocalHostResourceManagerLinuxTest {
+
+ private final FsApparatus scratch = FsApparatus.newNative();
+
+ @Test
+ public void testNonHyperthreadedMachine() throws Exception {
+ String cpuinfoContent =
+ StringUtilities.joinLines(
+ "processor\t: 0",
+ "vendor_id\t: GenuineIntel",
+ "cpu family\t: 15",
+ "model\t\t: 4",
+ "model name\t: Intel(R) Pentium(R) 4 CPU 3.40GHz",
+ "stepping\t: 10",
+ "cpu MHz\t\t: 3400.000",
+ "cache size\t: 2048 KB",
+ "fpu\t\t: yes",
+ "fpu_exception\t: yes",
+ "cpuid level\t: 5",
+ "wp\t\t: yes",
+ "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca "
+ + "cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm "
+ + "syscall nx lm constant_tsc up pni monitor ds_cpl est cid cx16 "
+ + "xtpr lahf_lm",
+ "bogomips\t: 6803.83",
+ "clflush size\t: 64",
+ "cache_alignment\t: 128",
+ "address sizes\t: 36 bits physical, 48 bits virtual",
+ "power management:");
+ String meminfoContent =
+ StringUtilities.joinLines(
+ "MemTotal: 3091732 kB",
+ "MemFree: 2167344 kB",
+ "Buffers: 60644 kB",
+ "Cached: 509940 kB",
+ "SwapCached: 0 kB",
+ "Active: 636892 kB",
+ "Inactive: 212760 kB",
+ "HighTotal: 0 kB",
+ "HighFree: 0 kB",
+ "LowTotal: 3091732 kB",
+ "LowFree: 2167344 kB",
+ "SwapTotal: 9124880 kB",
+ "SwapFree: 9124880 kB",
+ "Dirty: 0 kB",
+ "Writeback: 0 kB",
+ "AnonPages: 279028 kB",
+ "Mapped: 54404 kB",
+ "Slab: 42820 kB",
+ "PageTables: 5184 kB",
+ "NFS_Unstable: 0 kB",
+ "Bounce: 0 kB",
+ "CommitLimit: 10670744 kB",
+ "Committed_AS: 665840 kB",
+ "VmallocTotal: 34359738367 kB",
+ "VmallocUsed: 300484 kB",
+ "VmallocChunk: 34359437307 kB",
+ "HugePages_Total: 0",
+ "HugePages_Free: 0",
+ "HugePages_Rsvd: 0",
+ "Hugepagesize: 2048 kB");
+ String meminfoFile = scratch.file("test_meminfo_nonht", meminfoContent).getPathString();
+ assertEquals(1, LocalHostResourceManagerLinux.getLogicalCpuCountHelper(cpuinfoContent));
+ assertEquals(1, LocalHostResourceManagerLinux.getPhysicalCpuCountHelper(1, cpuinfoContent));
+ // +/- 0.1MB
+ assertEquals(3091.732, LocalHostResourceManagerLinux.getMemoryInMbHelper(meminfoFile), 0.1);
+ }
+
+ @Test
+ public void testHyperthreadedMachine() throws Exception {
+ String cpuinfoContent =
+ StringUtilities.joinLines(
+ "processor\t: 0",
+ "vendor_id\t: GenuineIntel",
+ "cpu family\t: 15",
+ "model\t\t: 4",
+ "model name\t: Intel(R) Pentium(R) 4 CPU 3.40GHz",
+ "stepping\t: 1",
+ "cpu MHz\t\t: 3400.245",
+ "cache size\t: 1024 KB",
+ "physical id\t: 0",
+ "siblings\t: 2",
+ "core id\t\t: 0",
+ "cpu cores\t: 1",
+ "fpu\t\t: yes",
+ "fpu_exception\t: yes",
+ "cpuid level\t: 5",
+ "wp\t\t: yes",
+ "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge "
+ + "mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm "
+ + "syscall lm constant_tsc pni monitor ds_cpl cid cx16 xtpr",
+ "bogomips\t: 6806.31",
+ "clflush size\t: 64",
+ "cache_alignment\t: 128",
+ "address sizes\t: 36 bits physical, 48 bits virtual",
+ "power management:",
+ "",
+ "processor\t: 1",
+ "vendor_id\t: GenuineIntel",
+ "cpu family\t: 15",
+ "model\t\t: 4",
+ "model name\t: Intel(R) Pentium(R) 4 CPU 3.40GHz",
+ "stepping\t: 1",
+ "cpu MHz\t\t: 3400.245",
+ "cache size\t: 1024 KB",
+ "physical id\t: 0",
+ "siblings\t: 2",
+ "core id\t\t: 0",
+ "cpu cores\t: 1",
+ "fpu\t\t: yes",
+ "fpu_exception\t: yes",
+ "cpuid level\t: 5",
+ "wp\t\t: yes",
+ "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge "
+ + "mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm "
+ + "syscall lm constant_tsc pni monitor ds_cpl cid cx16 xtpr",
+ "bogomips\t: 6800.76",
+ "clflush size\t: 64",
+ "cache_alignment\t: 128",
+ "address sizes\t: 36 bits physical, 48 bits virtual",
+ "power management:",
+ "");
+ String meminfoContent =
+ StringUtilities.joinLines(
+ "MemTotal: 3092004 kB",
+ "MemFree: 26124 kB",
+ "Buffers: 3836 kB",
+ "Cached: 52400 kB",
+ "SwapCached: 68204 kB",
+ "Active: 2281464 kB",
+ "Inactive: 260908 kB",
+ "HighTotal: 0 kB",
+ "HighFree: 0 kB",
+ "LowTotal: 3092004 kB",
+ "LowFree: 26124 kB",
+ "SwapTotal: 9124880 kB",
+ "SwapFree: 8264920 kB",
+ "Dirty: 616 kB",
+ "Writeback: 0 kB",
+ "AnonPages: 2466336 kB",
+ "Mapped: 37576 kB",
+ "Slab: 483004 kB",
+ "PageTables: 11912 kB",
+ "NFS_Unstable: 0 kB",
+ "Bounce: 0 kB",
+ "CommitLimit: 10670880 kB",
+ "Committed_AS: 3627984 kB",
+ "VmallocTotal: 34359738367 kB",
+ "VmallocUsed: 300460 kB",
+ "VmallocChunk: 34359437307 kB",
+ "HugePages_Total: 0",
+ "HugePages_Free: 0",
+ "HugePages_Rsvd: 0",
+ "Hugepagesize: 2048 kB");
+ String meminfoFile = scratch.file("test_meminfo_ht", meminfoContent).getPathString();
+ assertEquals(2, LocalHostResourceManagerLinux.getLogicalCpuCountHelper(cpuinfoContent));
+ assertEquals(1, LocalHostResourceManagerLinux.getPhysicalCpuCountHelper(2, cpuinfoContent));
+ // +/- 0.1MB
+ assertEquals(3092.004, LocalHostResourceManagerLinux.getMemoryInMbHelper(meminfoFile), 0.1);
+ }
+
+ @Test
+ public void testAMDMachine() throws Exception {
+ String cpuinfoContent =
+ StringUtilities.joinLines(
+ "processor\t: 0",
+ "vendor_id\t: AuthenticAMD",
+ "cpu family\t: 15",
+ "model\t\t: 65",
+ "model name\t: Dual-Core AMD Opteron(tm) Processor 8214 HE",
+ "stepping\t: 2",
+ "cpu MHz\t\t: 2200.000",
+ "cache size\t: 1024 KB",
+ "physical id\t: 0",
+ "siblings\t: 2",
+ "core id\t\t: 0",
+ "cpu cores\t: 2",
+ "fpu\t\t: yes",
+ "fpu_exception\t: yes",
+ "cpuid level\t: 1",
+ "wp\t\t: yes",
+ "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr "
+ + "pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall "
+ + "nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm "
+ + "cmp_legacy svm cr8_legacy",
+ "bogomips\t: 4425.84",
+ "TLB size\t: 1024 4K pages",
+ "clflush size\t: 64",
+ "cache_alignment\t: 64",
+ "address sizes\t: 40 bits physical, 48 bits virtual",
+ "power management: ts fid vid ttp tm stc",
+ "",
+ "processor\t: 1",
+ "vendor_id\t: AuthenticAMD",
+ "cpu family\t: 15",
+ "model\t\t: 65",
+ "model name\t: Dual-Core AMD Opteron(tm) Processor 8214 HE",
+ "stepping\t: 2",
+ "cpu MHz\t\t: 2200.000",
+ "cache size\t: 1024 KB",
+ "physical id\t: 0",
+ "siblings\t: 2",
+ "core id\t\t: 1",
+ "cpu cores\t: 2",
+ "fpu\t\t: yes",
+ "fpu_exception\t: yes",
+ "cpuid level\t: 1",
+ "wp\t\t: yes",
+ "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr "
+ + "pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall "
+ + "nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm "
+ + "cmp_legacy svm cr8_legacy",
+ "bogomips\t: 4460.61",
+ "TLB size\t: 1024 4K pages",
+ "clflush size\t: 64",
+ "cache_alignment\t: 64",
+ "address sizes\t: 40 bits physical, 48 bits virtual",
+ "power management: ts fid vid ttp tm stc",
+ "",
+ "processor\t: 2",
+ "vendor_id\t: AuthenticAMD",
+ "cpu family\t: 15",
+ "model\t\t: 65",
+ "model name\t: Dual-Core AMD Opteron(tm) Processor 8214 HE",
+ "stepping\t: 2",
+ "cpu MHz\t\t: 2200.000",
+ "cache size\t: 1024 KB",
+ "physical id\t: 1",
+ "siblings\t: 2",
+ "core id\t\t: 0",
+ "cpu cores\t: 2",
+ "fpu\t\t: yes",
+ "fpu_exception\t: yes",
+ "cpuid level\t: 1",
+ "wp\t\t: yes",
+ "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr "
+ + "pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall "
+ + "nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm "
+ + "cmp_legacy svm cr8_legacy",
+ "bogomips\t: 4420.45",
+ "TLB size\t: 1024 4K pages",
+ "clflush size\t: 64",
+ "cache_alignment\t: 64",
+ "address sizes\t: 40 bits physical, 48 bits virtual",
+ "power management: ts fid vid ttp tm stc",
+ "",
+ "processor\t: 3",
+ "vendor_id\t: AuthenticAMD",
+ "cpu family\t: 15",
+ "model\t\t: 65",
+ "model name\t: Dual-Core AMD Opteron(tm) Processor 8214 HE",
+ "stepping\t: 2",
+ "cpu MHz\t\t: 2200.000",
+ "cache size\t: 1024 KB",
+ "physical id\t: 1",
+ "siblings\t: 2",
+ "core id\t\t: 1",
+ "cpu cores\t: 2",
+ "fpu\t\t: yes",
+ "fpu_exception\t: yes",
+ "cpuid level\t: 1",
+ "wp\t\t: yes",
+ "flags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr "
+ + "pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall "
+ + "nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm "
+ + "cmp_legacy svm cr8_legacy",
+ "bogomips\t: 4460.39",
+ "TLB size\t: 1024 4K pages",
+ "clflush size\t: 64",
+ "cache_alignment\t: 64",
+ "address sizes\t: 40 bits physical, 48 bits virtual",
+ "power management: ts fid vid ttp tm stc",
+ "");
+ String meminfoContent =
+ StringUtilities.joinLines(
+ "MemTotal: 8223956 kB",
+ "MemFree: 3670396 kB",
+ "Buffers: 374068 kB",
+ "Cached: 3366980 kB",
+ "SwapCached: 0 kB",
+ "Active: 3275860 kB",
+ "Inactive: 737816 kB",
+ "HighTotal: 0 kB",
+ "HighFree: 0 kB",
+ "LowTotal: 8223956 kB",
+ "LowFree: 3670396 kB",
+ "SwapTotal: 6024332 kB",
+ "SwapFree: 6024332 kB",
+ "Dirty: 84 kB",
+ "Writeback: 0 kB",
+ "AnonPages: 272308 kB",
+ "Mapped: 62604 kB",
+ "Slab: 506140 kB",
+ "PageTables: 4608 kB",
+ "NFS_Unstable: 0 kB",
+ "Bounce: 0 kB",
+ "CommitLimit: 10136308 kB",
+ "Committed_AS: 600672 kB",
+ "VmallocTotal: 34359738367 kB",
+ "VmallocUsed: 299068 kB",
+ "VmallocChunk: 34359438843 kB",
+ "HugePages_Total: 0",
+ "HugePages_Free: 0",
+ "HugePages_Rsvd: 0",
+ "Hugepagesize: 2048 kB");
+ String meminfoFile = scratch.file("test_meminfo_amd", meminfoContent).getPathString();
+ assertEquals(4, LocalHostResourceManagerLinux.getLogicalCpuCountHelper(cpuinfoContent));
+ assertEquals(4, LocalHostResourceManagerLinux.getPhysicalCpuCountHelper(4, cpuinfoContent));
+ // +/- 0.1MB
+ assertEquals(8223.956, LocalHostResourceManagerLinux.getMemoryInMbHelper(meminfoFile), 0.1);
+ }
+}