mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-27 19:35:32 +00:00
vc: utils: Rename CalculateMilliCPUs() to CalculateCPUsF()
With the change done in the last commit, instead of calculating milli cpus, we're actually converting the CPUs to a fraction number, a float. Let's update the function name (and associated vars) to represent that change. Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
parent
e477ed0e86
commit
5e9cf75937
@ -1272,7 +1272,7 @@ func CalculateContainerSizing(spec *specs.Spec) (numCPU float32, memSizeMB uint3
|
||||
}
|
||||
|
||||
func calculateVMResources(period uint64, quota int64, memory int64) (numCPU float32, memSizeMB uint32) {
|
||||
numCPU = vcutils.CalculateMilliCPUs(quota, period)
|
||||
numCPU = vcutils.CalculateCPUsF(quota, period)
|
||||
|
||||
if memory < 0 {
|
||||
// While spec allows for a negative value to indicate unconstrained, we don't
|
||||
|
@ -2394,7 +2394,7 @@ func (s *Sandbox) calculateSandboxMemory() (uint64, bool, int64) {
|
||||
}
|
||||
|
||||
func (s *Sandbox) calculateSandboxCPUs() (float32, error) {
|
||||
mCPU := float32(0)
|
||||
floatCPU := float32(0)
|
||||
cpusetCount := int(0)
|
||||
|
||||
for _, c := range s.config.Containers {
|
||||
@ -2406,7 +2406,7 @@ func (s *Sandbox) calculateSandboxCPUs() (float32, error) {
|
||||
|
||||
if cpu := c.Resources.CPU; cpu != nil {
|
||||
if cpu.Period != nil && cpu.Quota != nil {
|
||||
mCPU += utils.CalculateMilliCPUs(*cpu.Quota, *cpu.Period)
|
||||
floatCPU += utils.CalculateCPUsF(*cpu.Quota, *cpu.Period)
|
||||
}
|
||||
|
||||
set, err := cpuset.Parse(cpu.Cpus)
|
||||
@ -2420,11 +2420,11 @@ func (s *Sandbox) calculateSandboxCPUs() (float32, error) {
|
||||
// If we aren't being constrained, then we could have two scenarios:
|
||||
// 1. BestEffort QoS: no proper support today in Kata.
|
||||
// 2. We could be constrained only by CPUSets. Check for this:
|
||||
if mCPU == 0 && cpusetCount > 0 {
|
||||
if floatCPU == 0 && cpusetCount > 0 {
|
||||
return float32(cpusetCount), nil
|
||||
}
|
||||
|
||||
return mCPU, nil
|
||||
return floatCPU, nil
|
||||
}
|
||||
|
||||
// GetHypervisorType is used for getting Hypervisor name currently used.
|
||||
|
@ -121,8 +121,8 @@ func WriteToFile(path string, data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CalculateMilliCPUs converts CPU quota and period to milli-CPUs
|
||||
func CalculateMilliCPUs(quota int64, period uint64) float32 {
|
||||
// CalculateCPUsF converts CPU quota and period to a fraction number
|
||||
func CalculateCPUsF(quota int64, period uint64) float32 {
|
||||
// If quota is -1, it means the CPU resource request is
|
||||
// unconstrained. In that case, we don't currently assign
|
||||
// additional CPUs.
|
||||
|
@ -147,22 +147,22 @@ func TestWriteToFile(t *testing.T) {
|
||||
assert.True(reflect.DeepEqual(testData, data))
|
||||
}
|
||||
|
||||
func TestCalculateMilliCPUs(t *testing.T) {
|
||||
func TestCalculateCPUsF(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
n := CalculateMilliCPUs(1, 1)
|
||||
n := CalculateCPUsF(1, 1)
|
||||
expected := float32(1)
|
||||
assert.Equal(n, expected)
|
||||
|
||||
n = CalculateMilliCPUs(1, 0)
|
||||
n = CalculateCPUsF(1, 0)
|
||||
expected = float32(0)
|
||||
assert.Equal(n, expected)
|
||||
|
||||
n = CalculateMilliCPUs(-1, 1)
|
||||
n = CalculateCPUsF(-1, 1)
|
||||
expected = float32(0)
|
||||
assert.Equal(n, expected)
|
||||
|
||||
n = CalculateMilliCPUs(500, 1000)
|
||||
n = CalculateCPUsF(500, 1000)
|
||||
expected = float32(0.5)
|
||||
assert.Equal(n, expected)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user