From 888a89efd3b639ce0ff48c35233ba95fed79bfc3 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 14 Apr 2021 22:20:57 +0200 Subject: simulator: Introduce SimProcessingUnit This change introduces the SimProcessingUnit which represents a simulated processing unit which the user can control during the workload execution. --- .../org/opendc/simulator/compute/SimMachineTest.kt | 20 +++++++++++++ .../compute/cpufreq/DemandScalingGovernorTest.kt | 2 +- .../compute/cpufreq/PStateScalingDriverTest.kt | 34 ++++++++++------------ 3 files changed, 36 insertions(+), 20 deletions(-) (limited to 'simulator/opendc-simulator/opendc-simulator-compute/src/test') diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt index d947b9cb..d88dec52 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt @@ -71,6 +71,26 @@ class SimMachineTest { } } + @Test + fun testDualSocketMachine() = runBlockingTest { + val clock = DelayControllerClockAdapter(this) + val cpuNode = machineModel.cpus[0].node + val machineModel = SimMachineModel( + cpus = List(cpuNode.coreCount * 2) { ProcessingUnit(cpuNode, it % 2, 1000.0) }, + memory = List(4) { MemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) } + ) + val machine = SimBareMetalMachine(coroutineContext, clock, machineModel, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0))) + + try { + machine.run(SimFlopsWorkload(2_000, utilization = 1.0)) + + // Two sockets with two cores execute 2000 MFlOps per second (500 ms) + assertEquals(500, currentTime) + } finally { + machine.close() + } + } + @Test fun testUsage() = runBlockingTest { val clock = DelayControllerClockAdapter(this) diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernorTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernorTest.kt index c02b6285..c482d348 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernorTest.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernorTest.kt @@ -35,7 +35,7 @@ internal class DemandScalingGovernorTest { fun testSetDemandLimit() { val ctx = mockk(relaxUnitFun = true) - every { ctx.resource.speed } returns 2100.0 + every { ctx.cpu.speed } returns 2100.0 val logic = DemandScalingGovernor().createLogic(ctx) diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriverTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriverTest.kt index c6f233a6..bbea3ee2 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriverTest.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriverTest.kt @@ -27,10 +27,9 @@ import io.mockk.mockk import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.opendc.simulator.compute.SimBareMetalMachine -import org.opendc.simulator.compute.model.ProcessingUnit +import org.opendc.simulator.compute.SimProcessingUnit import org.opendc.simulator.compute.power.ConstantPowerModel import org.opendc.simulator.compute.power.LinearPowerModel -import org.opendc.simulator.resources.SimResourceSource /** * Test suite for [PStateScalingDriver]. @@ -55,11 +54,10 @@ internal class PStateScalingDriverTest { @Test fun testPowerWithSingleGovernor() { val machine = mockk() - val cpu = mockk() - val resource = mockk() + val cpu = mockk() - every { cpu.frequency } returns 4100.0 - every { resource.speed } returns 1200.0 + every { cpu.model.frequency } returns 4100.0 + every { cpu.speed } returns 1200.0 val driver = PStateScalingDriver( sortedMapOf( @@ -71,7 +69,7 @@ internal class PStateScalingDriverTest { val logic = driver.createLogic(machine) - val scalingContext = logic.createContext(cpu, resource) + val scalingContext = logic.createContext(cpu) scalingContext.setTarget(3200.0) assertEquals(300.0, logic.computePower()) @@ -80,11 +78,10 @@ internal class PStateScalingDriverTest { @Test fun testPowerWithMultipleGovernors() { val machine = mockk() - val cpu = mockk() - val resource = mockk() + val cpu = mockk() - every { cpu.frequency } returns 4100.0 - every { resource.speed } returns 1200.0 + every { cpu.model.frequency } returns 4100.0 + every { cpu.speed } returns 1200.0 val driver = PStateScalingDriver( sortedMapOf( @@ -96,10 +93,10 @@ internal class PStateScalingDriverTest { val logic = driver.createLogic(machine) - val scalingContextA = logic.createContext(cpu, resource) + val scalingContextA = logic.createContext(cpu) scalingContextA.setTarget(1000.0) - val scalingContextB = logic.createContext(cpu, resource) + val scalingContextB = logic.createContext(cpu) scalingContextB.setTarget(3400.0) assertEquals(350.0, logic.computePower()) @@ -108,10 +105,9 @@ internal class PStateScalingDriverTest { @Test fun testPowerBasedOnUtilization() { val machine = mockk() - val cpu = mockk() - val resource = mockk() + val cpu = mockk() - every { cpu.frequency } returns 4200.0 + every { cpu.model.frequency } returns 4200.0 val driver = PStateScalingDriver( sortedMapOf( @@ -123,13 +119,13 @@ internal class PStateScalingDriverTest { val logic = driver.createLogic(machine) - val scalingContext = logic.createContext(cpu, resource) + val scalingContext = logic.createContext(cpu) - every { resource.speed } returns 1400.0 + every { cpu.speed } returns 1400.0 scalingContext.setTarget(1400.0) assertEquals(150.0, logic.computePower()) - every { resource.speed } returns 1400.0 + every { cpu.speed } returns 1400.0 scalingContext.setTarget(4000.0) assertEquals(235.0, logic.computePower()) } -- cgit v1.2.3