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

Severin Gehwolf sgehwolf at openjdk.java.net
Wed Mar 30 10:16:38 UTC 2022


On Wed, 30 Mar 2022 09:49:47 GMT, xpbob <duke at openjdk.java.net> wrote:

>> 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 = (long) (hostTicks * (1.0 * containerCPUs / totalCPUs));
>> 
>> The intent is to ensure floating point arithmetic on the second expression, right? A clearer way to express this may be the following. This avoids the `1.0` constant:
>> 
>> 
>> hostTicks = (long) (hostTicks * ((double) containerCPUs)/ totalCPUs)
>
>> The intent is to ensure floating point arithmetic on the second expression, right? A clearer way to express this may be the following. This avoids the `1.0` constant:
>> 
>> ```
>> hostTicks = (long) (hostTicks * ((double) containerCPUs)/ totalCPUs)
>> ```
> 
> 1.0 used to convert the data type to floating point and compute the division first

Right. It seems a strange way to achieve this. Maybe consider this instead?

double scaleFactor = ((double)containerCPUs)/totalCPUs;
hostTicks = (long)(hostTicks * scaleFactor);

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

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


More information about the serviceability-dev mailing list