Skip to content

Commit 76c7a7e

Browse files
bobpengxieDamonFool
authored andcommitted
8283903: GetContainerCpuLoad does not return the correct result in share mode
Backport-of: a625bfdba45d49bc717bcc9be4112db93b50f50a
1 parent 6e457ab commit 76c7a7e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/jdk.management/unix/classes/com/sun/management/internal/OperatingSystemImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -93,7 +93,8 @@ public double getContainerCpuLoad() {
9393
int totalCPUs = getHostOnlineCpuCount0();
9494
int containerCPUs = getAvailableProcessors();
9595
// scale the total host load to the actual container cpus
96-
hostTicks = hostTicks * containerCPUs / totalCPUs;
96+
double scaleFactor = ((double) containerCPUs) / totalCPUs;
97+
hostTicks = (long) (hostTicks * scaleFactor);
9798
return getUsageDividesTotal(cpuUsageSupplier().getAsLong(), hostTicks);
9899
} else {
99100
// If CPU quotas and shares are not active then find the average load for

0 commit comments

Comments
 (0)