RFR: 8283903: GetContainerCpuLoad does not return the correct result in share mode [v2]

David Holmes dholmes at openjdk.java.net
Wed Mar 30 04:58:36 UTC 2022


On Wed, 30 Mar 2022 02:08:16 GMT, xpbob <duke at openjdk.java.net> wrote:

>> ```        
>>                long hostTicks = getHostTotalCpuTicks0();
>>                 int totalCPUs = getHostOnlineCpuCount0();
>>                 int containerCPUs = getAvailableProcessors();
>>                 // scale the total host load to the actual container cpus
>>                 hostTicks = hostTicks * containerCPUs / totalCPUs;
>> 
>> hostTicks=175476155560000000
>> totalCPUs=96
>> containerCPUs=90
>> 
>> Calculate the overflow
>
> xpbob has updated the pull request incrementally with one additional commit since the last revision:
> 
>   update copyright year

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

> 94:                 int containerCPUs = getAvailableProcessors();
> 95:                 // scale the total host load to the actual container cpus
> 96:                 hostTicks = hostTicks / totalCPUs * containerCPUs;

It might be better to convert to a floating-point calculation before converting back to a whole number:

`hostTicks = (long) (hostTicks * (1.0 * containerCPUs / totalCPUs));`

-------------

PR: https://git.openjdk.java.net/jdk/pull/8028


More information about the serviceability-dev mailing list