Skip to content

Commit 843f641

Browse files
authored
7903510: JMH: Add core performance checking tests
1 parent 8bc325b commit 843f641

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package org.openjdk.jmh.benchmarks;
26+
27+
import org.openjdk.jmh.annotations.*;
28+
import org.openjdk.jmh.infra.Blackhole;
29+
import org.openjdk.jmh.validation.AffinitySupport;
30+
import org.openjdk.jmh.validation.SpinWaitSupport;
31+
32+
import java.util.concurrent.TimeUnit;
33+
34+
@BenchmarkMode(Mode.Throughput)
35+
@OutputTimeUnit(TimeUnit.SECONDS)
36+
@Threads(1)
37+
@State(Scope.Thread)
38+
public class CoreStabilityBench {
39+
40+
@Param("-1")
41+
int p;
42+
43+
@Setup
44+
public void setup() {
45+
if (p == -1) {
46+
throw new IllegalStateException("Should provide a CPU number");
47+
}
48+
AffinitySupport.bind(p);
49+
}
50+
51+
@Benchmark
52+
public void test() {
53+
Blackhole.consumeCPU(1_000_000);
54+
}
55+
}

jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/Main.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ public static void main(String[] args) throws RunnerException, CommandLineOption
179179
case burst_stability:
180180
new BurstStabilityTest().runWith(pw, opts);
181181
break;
182+
case core_stability:
183+
new CoreStabilityTest().runWith(pw, opts);
184+
break;
182185
case compiler_hints:
183186
new CompilerHintsTest().runWith(pw, opts);
184187
break;
@@ -262,6 +265,7 @@ public enum Test {
262265
thermal,
263266
long_stability,
264267
burst_stability,
268+
core_stability,
265269
thread_scale,
266270
helpers,
267271
blackhole_cpu,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package org.openjdk.jmh.validation.tests;
26+
27+
import org.openjdk.jmh.benchmarks.CoreStabilityBench;
28+
import org.openjdk.jmh.results.Result;
29+
import org.openjdk.jmh.results.RunResult;
30+
import org.openjdk.jmh.runner.Runner;
31+
import org.openjdk.jmh.runner.RunnerException;
32+
import org.openjdk.jmh.runner.options.Options;
33+
import org.openjdk.jmh.runner.options.OptionsBuilder;
34+
import org.openjdk.jmh.runner.options.VerboseMode;
35+
import org.openjdk.jmh.util.Utils;
36+
import org.openjdk.jmh.validation.AffinitySupport;
37+
import org.openjdk.jmh.validation.ValidationTest;
38+
39+
import java.io.PrintWriter;
40+
import java.util.concurrent.ThreadLocalRandom;
41+
42+
public class CoreStabilityTest extends ValidationTest {
43+
44+
@Override
45+
public void runWith(PrintWriter pw, Options parent) throws RunnerException {
46+
pw.println("--------- CORE STABILITY TEST");
47+
pw.println();
48+
49+
org.openjdk.jmh.util.Utils.reflow(pw,
50+
"This test verifies the performance for a single test by running it on different CPUs. " +
51+
"For perfectly symmetric machines, the performance should be the same across all CPUs. " +
52+
"If there is a significant difference between the CPUs, this is usually " +
53+
"indicative of asymmetric machine, making the benchmarks that do not explicitly control " +
54+
"affinity less reliable.",
55+
80, 2);
56+
pw.println();
57+
58+
if (!AffinitySupport.isSupported()) {
59+
pw.println(" Affinity control is not available on this machine, skipping the test.");
60+
pw.println();
61+
return;
62+
}
63+
64+
int threads = Utils.figureOutHotCPUs();
65+
66+
for (int p = 0; p < threads; p++) {
67+
pw.printf(" CPU %3d: ", p);
68+
pw.flush();
69+
70+
Options opts = new OptionsBuilder()
71+
.parent(parent)
72+
.include(CoreStabilityBench.class.getCanonicalName())
73+
.param("p", String.valueOf(p))
74+
.verbosity(VerboseMode.SILENT)
75+
.build();
76+
77+
RunResult result = new Runner(opts).runSingle();
78+
Result r = result.getPrimaryResult();
79+
pw.printf(" %16s", String.format("%.2f \u00b1 %.2f %s%n", r.getScore(), r.getScoreError(), r.getScoreUnit()));
80+
pw.flush();
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)