test/hotspot/jtreg/runtime/containers/docker/TestCPUAwareness.java
changeset 49058 15765495db12
parent 48176 59ebea050a0d
child 50545 292a4a87c321
equal deleted inserted replaced
49056:91ada5977172 49058:15765495db12
     1 /*
     1 /*
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    92             List<Integer> cpuSet = CPUSetsReader.parseCpuSet(cpuSetStr);
    92             List<Integer> cpuSet = CPUSetsReader.parseCpuSet(cpuSetStr);
    93 
    93 
    94             // Test subset of cpuset with one element
    94             // Test subset of cpuset with one element
    95             if (cpuSet.size() >= 1) {
    95             if (cpuSet.size() >= 1) {
    96                 String testCpuSet = CPUSetsReader.listToString(cpuSet, 1);
    96                 String testCpuSet = CPUSetsReader.listToString(cpuSet, 1);
    97                 testAPCCombo(testCpuSet, 200*1000, 100*1000,   4*1024, 1);
    97                 testAPCCombo(testCpuSet, 200*1000, 100*1000,   4*1024, true, 1);
    98             }
    98             }
    99 
    99 
   100             // Test subset of cpuset with two elements
   100             // Test subset of cpuset with two elements
   101             if (cpuSet.size() >= 2) {
   101             if (cpuSet.size() >= 2) {
   102                 String testCpuSet = CPUSetsReader.listToString(cpuSet, 2);
   102                 String testCpuSet = CPUSetsReader.listToString(cpuSet, 2);
   103                 testAPCCombo(testCpuSet, 200*1000, 100*1000, 4*1024, 2);
   103                 testAPCCombo(testCpuSet, 200*1000, 100*1000, 4*1024, true, 2);
   104                 testAPCCombo(testCpuSet, 200*1000, 100*1000, 1*1024, 2);
   104                 testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023,   true, 2);
       
   105                 testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023,   false,  1);
       
   106             }
       
   107 
       
   108             // Test subset of cpuset with three elements
       
   109             if (cpuSet.size() >= 3) {
       
   110                 String testCpuSet = CPUSetsReader.listToString(cpuSet, 3);
       
   111                 testAPCCombo(testCpuSet, 100*1000, 100*1000, 2*1024, true, 1);
       
   112                 testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023,   true, 2);
       
   113                 testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023,   false,  1);
   105             }
   114             }
   106         }
   115         }
   107     }
   116     }
   108 
   117 
   109 
   118 
   157     }
   166     }
   158 
   167 
   159 
   168 
   160     // Test correctess of automatically selected active processor cound
   169     // Test correctess of automatically selected active processor cound
   161     private static void testAPCCombo(String cpuset, int quota, int period, int shares,
   170     private static void testAPCCombo(String cpuset, int quota, int period, int shares,
   162                                          int expectedAPC) throws Exception {
   171                                      boolean usePreferContainerQuotaForCPUCount,
       
   172                                      int expectedAPC) throws Exception {
   163         Common.logNewTestCase("test APC Combo");
   173         Common.logNewTestCase("test APC Combo");
   164         System.out.println("cpuset = " + cpuset);
   174         System.out.println("cpuset = " + cpuset);
   165         System.out.println("quota = " + quota);
   175         System.out.println("quota = " + quota);
   166         System.out.println("period = " + period);
   176         System.out.println("period = " + period);
   167         System.out.println("shares = " + period);
   177         System.out.println("shares = " + period);
       
   178         System.out.println("usePreferContainerQuotaForCPUCount = " + usePreferContainerQuotaForCPUCount);
   168         System.out.println("expectedAPC = " + expectedAPC);
   179         System.out.println("expectedAPC = " + expectedAPC);
   169 
   180 
   170         expectedAPC = adjustExpectedAPCForAvailableCPUs(expectedAPC);
   181         expectedAPC = adjustExpectedAPCForAvailableCPUs(expectedAPC);
   171 
   182 
   172         DockerRunOptions opts = Common.newOpts(imageName)
   183         DockerRunOptions opts = Common.newOpts(imageName)
   173             .addDockerOpts("--cpuset-cpus", "" + cpuset)
   184             .addDockerOpts("--cpuset-cpus", "" + cpuset)
   174             .addDockerOpts("--cpu-period=" + period)
   185             .addDockerOpts("--cpu-period=" + period)
   175             .addDockerOpts("--cpu-quota=" + quota)
   186             .addDockerOpts("--cpu-quota=" + quota)
   176             .addDockerOpts("--cpu-shares=" + shares);
   187             .addDockerOpts("--cpu-shares=" + shares);
       
   188 
       
   189         if (!usePreferContainerQuotaForCPUCount) opts.addJavaOpts("-XX:-PreferContainerQuotaForCPUCount");
       
   190 
   177         Common.run(opts)
   191         Common.run(opts)
   178             .shouldMatch("active_processor_count.*" + expectedAPC);
   192             .shouldMatch("active_processor_count.*" + expectedAPC);
   179     }
   193     }
   180 
   194 
   181 
   195