runtime: delete func ConstraintsToVCPUs

ConstraintsToVCPUs is not used any more.

Fixes: #2741

Signed-off-by: bin <bin@hyper.sh>
This commit is contained in:
bin 2021-09-30 14:44:41 +08:00
parent 4f4854308a
commit 762922a521
2 changed files with 2 additions and 34 deletions

View File

@ -112,7 +112,7 @@ func WriteToFile(path string, data []byte) error {
return nil
}
//CalculateMilliCPUs converts CPU quota and period to milli-CPUs
// CalculateMilliCPUs converts CPU quota and period to milli-CPUs
func CalculateMilliCPUs(quota int64, period uint64) uint32 {
// If quota is -1, it means the CPU resource request is
@ -125,27 +125,12 @@ func CalculateMilliCPUs(quota int64, period uint64) uint32 {
return 0
}
//CalculateVCpusFromMilliCpus converts from mCPU to CPU, taking the ceiling
// CalculateVCpusFromMilliCpus converts from mCPU to CPU, taking the ceiling
// value when necessary
func CalculateVCpusFromMilliCpus(mCPU uint32) uint32 {
return (mCPU + 999) / 1000
}
// ConstraintsToVCPUs converts CPU quota and period to vCPUs
func ConstraintsToVCPUs(quota int64, period uint64) uint {
if quota != 0 && period != 0 {
// Use some math magic to round up to the nearest whole vCPU
// (that is, a partial part of a quota request ends up assigning
// a whole vCPU, for instance, a request of 1.5 'cpu quotas'
// will give 2 vCPUs).
// This also has the side effect that we will always allocate
// at least 1 vCPU.
return uint((uint64(quota) + (period - 1)) / period)
}
return 0
}
// GetVirtDriveName returns the disk name format for virtio-blk
// Reference: https://github.com/torvalds/linux/blob/master/drivers/block/virtio_blk.c @c0aa3e0916d7e531e69b02e426f7162dfb1c6c0
func GetVirtDriveName(index int) (string, error) {

View File

@ -170,23 +170,6 @@ func TestCaluclateVCpusFromMilliCpus(t *testing.T) {
assert.Equal(n, expected)
}
func TestConstraintsToVCPUs(t *testing.T) {
assert := assert.New(t)
vcpus := ConstraintsToVCPUs(0, 100)
assert.Zero(vcpus)
vcpus = ConstraintsToVCPUs(100, 0)
assert.Zero(vcpus)
expectedVCPUs := uint(4)
vcpus = ConstraintsToVCPUs(4000, 1000)
assert.Equal(expectedVCPUs, vcpus)
vcpus = ConstraintsToVCPUs(4000, 1200)
assert.Equal(expectedVCPUs, vcpus)
}
func TestGetVirtDriveNameInvalidIndex(t *testing.T) {
assert := assert.New(t)
_, err := GetVirtDriveName(-1)