On Wed, 30 Mar 2022 06:20:19 GMT, xpbob <d...@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:
> 
>   Change the expression

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)

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

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

Reply via email to