On Wed, 30 Mar 2022 09:49:47 GMT, xpbob <d...@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

Reply via email to