8283903: GetContainerCpuLoad does not return the correct result in share mode

Reviewed-by: jiefu, sgehwolf, kevinw, dholmes
This commit is contained in:
bobpengxie 2022-03-30 17:06:38 +00:00 committed by Kevin Walls
parent 97c7298a39
commit a625bfdba4

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -93,7 +93,8 @@ class OperatingSystemImpl extends BaseOperatingSystemImpl
int totalCPUs = getHostOnlineCpuCount0();
int containerCPUs = getAvailableProcessors();
// scale the total host load to the actual container cpus
hostTicks = hostTicks * containerCPUs / totalCPUs;
double scaleFactor = ((double) containerCPUs) / totalCPUs;
hostTicks = (long) (hostTicks * scaleFactor);
return getUsageDividesTotal(cpuUsageSupplier().getAsLong(), hostTicks);
} else {
// If CPU quotas and shares are not active then find the average load for