diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-05-20 02:25:39 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-05-20 02:25:39 +0200 |
| commit | b7201f7d2184be7a7a843878f0292cbcaa733d73 (patch) | |
| tree | 744e1621dba54aeca284f01403668b0881943552 | |
| parent | cbf8c3d0463c7ace0c659235fcc4234c6c71a2c0 (diff) | |
perf: Cache slice values in vCPU
| -rw-r--r-- | opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt index 6e335797..9ac76864 100644 --- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt +++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/virt/driver/SimpleVirtDriver.kt @@ -411,6 +411,7 @@ class SimpleVirtDriver( if (queue.hasNext()) { activeSlice = queue.next() + vcpus.forEach { it.refresh() } } } @@ -420,6 +421,7 @@ class SimpleVirtDriver( fun cancel() { queue = emptyList<ServerContext.Slice>().iterator() activeSlice = null + vcpus.forEach { it.refresh() } } /** @@ -436,6 +438,10 @@ class SimpleVirtDriver( val slice = if (needsMerge) merge(activeSlice, candidateSlice) else candidateSlice this.activeSlice = slice + + // Update the vCPU cache + vcpus.forEach { it.refresh() } + false } else { this.activeSlice = null @@ -460,8 +466,7 @@ class SimpleVirtDriver( /** * The current limit on the vCPU. */ - val limit: Double - get() = vm.activeSlice?.limit?.takeIf { id < it.size }?.get(id) ?: 0.0 + var limit: Double = 0.0 /** * The limit allocated by the hypervisor. @@ -471,21 +476,29 @@ class SimpleVirtDriver( /** * The current burst running on the vCPU. */ - var burst: Long - get() = vm.activeSlice?.burst?.takeIf { id < it.size }?.get(id) ?: 0 - set(value) { - vm.activeSlice?.burst?.takeIf { id < it.size }?.set(id, value) - } + var burst: Long = 0L /** * Consume the specified burst on this vCPU. */ fun consume(burst: Long): Boolean { this.burst = max(0, this.burst - burst) + + // Flush the result to the slice if it exists + vm.activeSlice?.burst?.takeIf { id < it.size }?.set(id, this.burst) + return allocatedLimit > 0.0 && this.burst == 0L } /** + * Refresh the information of this vCPU based on the current slice. + */ + fun refresh() { + limit = vm.activeSlice?.limit?.takeIf { id < it.size }?.get(id) ?: 0.0 + burst = vm.activeSlice?.burst?.takeIf { id < it.size }?.get(id) ?: 0 + } + + /** * Compare to another vCPU based on the current load of the vCPU. */ override fun compareTo(other: VCpu): Int { |
