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
26 package jdk.internal.platform.cgroupv1;
27
28 import java.io.IOException;
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31 import java.util.stream.Stream;
32
33 import jdk.internal.platform.CgroupSubsystem;
34 import jdk.internal.platform.CgroupSubsystemController;
35 import jdk.internal.platform.CgroupUtil;
36 import jdk.internal.platform.Metrics;
37
38 public class CgroupV1Subsystem implements CgroupSubsystem {
39 private CgroupV1MemorySubSystemController memory;
40 private CgroupV1SubsystemController cpu;
41 private CgroupV1SubsystemController cpuacct;
42 private CgroupV1SubsystemController cpuset;
43 private CgroupV1SubsystemController blkio;
44 private boolean activeSubSystems;
45
46 private static final CgroupV1Subsystem INSTANCE = initSubSystem();
47
48 private static final String PROVIDER_NAME = "cgroupv1";
49
50 private CgroupV1Subsystem() {
51 activeSubSystems = false;
52 }
53
54 public static CgroupV1Subsystem getInstance() {
55 return INSTANCE;
56 }
57
58 private static CgroupV1Subsystem initSubSystem() {
303 return CgroupSubsystemController.getLongEntry(cpuacct, "cpuacct.stat", "system");
304 }
305
306
307 /*****************************************************************
308 * CPU Subsystem
309 ****************************************************************/
310
311
312 public long getCpuPeriod() {
313 return getLongValue(cpu, "cpu.cfs_period_us");
314 }
315
316 public long getCpuQuota() {
317 return getLongValue(cpu, "cpu.cfs_quota_us");
318 }
319
320 public long getCpuShares() {
321 long retval = getLongValue(cpu, "cpu.shares");
322 if (retval == 0 || retval == 1024)
323 return Metrics.LONG_RETVAL_UNLIMITED;
324 else
325 return retval;
326 }
327
328 public long getCpuNumPeriods() {
329 return CgroupSubsystemController.getLongEntry(cpu, "cpu.stat", "nr_periods");
330 }
331
332 public long getCpuNumThrottled() {
333 return CgroupSubsystemController.getLongEntry(cpu, "cpu.stat", "nr_throttled");
334 }
335
336 public long getCpuThrottledTime() {
337 return CgroupSubsystemController.getLongEntry(cpu, "cpu.stat", "throttled_time");
338 }
339
340 public long getEffectiveCpuCount() {
341 return Runtime.getRuntime().availableProcessors();
342 }
343
|
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
26 package jdk.internal.platform.cgroupv1;
27
28 import java.io.IOException;
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31 import java.util.stream.Stream;
32
33 import jdk.internal.platform.CgroupSubsystem;
34 import jdk.internal.platform.CgroupSubsystemController;
35 import jdk.internal.platform.CgroupUtil;
36 import jdk.internal.platform.MetricsCgroupV1;
37
38 public class CgroupV1Subsystem implements CgroupSubsystem, MetricsCgroupV1 {
39 private CgroupV1MemorySubSystemController memory;
40 private CgroupV1SubsystemController cpu;
41 private CgroupV1SubsystemController cpuacct;
42 private CgroupV1SubsystemController cpuset;
43 private CgroupV1SubsystemController blkio;
44 private boolean activeSubSystems;
45
46 private static final CgroupV1Subsystem INSTANCE = initSubSystem();
47
48 private static final String PROVIDER_NAME = "cgroupv1";
49
50 private CgroupV1Subsystem() {
51 activeSubSystems = false;
52 }
53
54 public static CgroupV1Subsystem getInstance() {
55 return INSTANCE;
56 }
57
58 private static CgroupV1Subsystem initSubSystem() {
303 return CgroupSubsystemController.getLongEntry(cpuacct, "cpuacct.stat", "system");
304 }
305
306
307 /*****************************************************************
308 * CPU Subsystem
309 ****************************************************************/
310
311
312 public long getCpuPeriod() {
313 return getLongValue(cpu, "cpu.cfs_period_us");
314 }
315
316 public long getCpuQuota() {
317 return getLongValue(cpu, "cpu.cfs_quota_us");
318 }
319
320 public long getCpuShares() {
321 long retval = getLongValue(cpu, "cpu.shares");
322 if (retval == 0 || retval == 1024)
323 return CgroupSubsystem.LONG_RETVAL_UNLIMITED;
324 else
325 return retval;
326 }
327
328 public long getCpuNumPeriods() {
329 return CgroupSubsystemController.getLongEntry(cpu, "cpu.stat", "nr_periods");
330 }
331
332 public long getCpuNumThrottled() {
333 return CgroupSubsystemController.getLongEntry(cpu, "cpu.stat", "nr_throttled");
334 }
335
336 public long getCpuThrottledTime() {
337 return CgroupSubsystemController.getLongEntry(cpu, "cpu.stat", "throttled_time");
338 }
339
340 public long getEffectiveCpuCount() {
341 return Runtime.getRuntime().availableProcessors();
342 }
343
|