def test_assign_two_workloads_empty_cpu_ip(self): """ Workload 0: 2 threads --> (p:0 c:0 t:0) (p:0 c:1 t:0) Workload 1: 1 thread --> (p:1 c:0 t:0) """ cpu = get_cpu() allocator = IntegerProgramCpuAllocator(cpu) w0 = Workload(uuid.uuid4(), 2, STATIC) w1 = Workload(uuid.uuid4(), 1, STATIC) allocator.assign_threads(w0) allocator.assign_threads(w1) self.assertEqual(3, len(cpu.get_claimed_threads())) packages = cpu.get_packages() # WORKLOAD 0 core00 = packages[0].get_cores()[0] core01 = packages[0].get_cores()[1] thread0 = core00.get_threads()[0] self.assertEqual(0, thread0.get_id()) self.assertTrue(thread0.is_claimed()) thread1 = core01.get_threads()[0] self.assertEqual(1, thread1.get_id()) self.assertTrue(thread1.is_claimed()) # WORKLOAD 1 core00 = packages[1].get_cores()[0] thread4 = core00.get_threads()[0] self.assertEqual(4, thread4.get_id()) self.assertTrue(thread4.is_claimed())
def test_shared_core_violation(self): allocator = IntegerProgramCpuAllocator() # Claim all thread but one cpu = get_cpu() w = get_test_workload(uuid.uuid4(), len(cpu.get_threads()) - 1, STATIC) workloads = {w.get_id(): w} request = AllocateThreadsRequest(cpu, w.get_id(), workloads, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.assign_threads(request).get_cpu() log.info("{}".format(cpu)) violations = get_shared_core_violations(cpu) log.info("shared core violations: {}".format(violations)) self.assertEqual(0, len(violations)) # Assign another workload which will force core sharing w = get_test_workload(uuid.uuid4(), 1, STATIC) workloads[w.get_id()] = w request = AllocateThreadsRequest(cpu, w.get_id(), workloads, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.assign_threads(request).get_cpu() log.info("{}".format(cpu)) violations = get_shared_core_violations(cpu) log.info("shared core violations: {}".format(violations)) self.assertEqual(1, len(violations))
def test_one_cross_package_violation(self): cpu = get_cpu() allocator = IntegerProgramCpuAllocator(cpu) w = Workload(uuid.uuid4(), 9, STATIC) allocator.assign_threads(w) violations = get_cross_package_violations(cpu) self.assertEqual(1, len(violations))
def test_cache_ip(self): """ [add a=2, add b=2, remove b=2, add c=2, remove a=2, add d=2] should lead to the following cache entries: (state=[], req=[2]) (state=[2], req=[2,2]) (state=[2,2], req=[2,0]) [cache hit] [cache hit] (state=[2,2], req=[2,2]) but different layout """ cpu = get_cpu() allocator = IntegerProgramCpuAllocator() workloads = {} workload = get_test_workload("a", 2, STATIC) workloads[workload.get_id()] = workload request = AllocateThreadsRequest(cpu, workload.get_id(), workloads, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.assign_threads(request).get_cpu() self.assertEqual(1, len(allocator._IntegerProgramCpuAllocator__cache)) workload = get_test_workload("b", 2, STATIC) workloads[workload.get_id()] = workload request = AllocateThreadsRequest(cpu, workload.get_id(), workloads, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.assign_threads(request).get_cpu() self.assertEqual(2, len(allocator._IntegerProgramCpuAllocator__cache)) request = AllocateThreadsRequest(cpu, "b", workloads, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.free_threads(request).get_cpu() self.assertEqual(3, len(allocator._IntegerProgramCpuAllocator__cache)) workloads.pop("b") workload = get_test_workload("c", 2, STATIC) workloads[workload.get_id()] = workload request = AllocateThreadsRequest(cpu, workload.get_id(), workloads, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.assign_threads(request).get_cpu() self.assertEqual(3, len(allocator._IntegerProgramCpuAllocator__cache)) request = AllocateThreadsRequest(cpu, "a", workloads, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.free_threads(request).get_cpu() self.assertEqual(4, len(allocator._IntegerProgramCpuAllocator__cache)) workloads.pop("a") workload = get_test_workload("d", 2, STATIC) workloads[workload.get_id()] = workload request = AllocateThreadsRequest(cpu, workload.get_id(), workloads, {}, DEFAULT_TEST_REQUEST_METADATA) allocator.assign_threads(request).get_cpu() self.assertEqual(5, len(allocator._IntegerProgramCpuAllocator__cache))
def test_cache_ip(self): """ [add a=2, add b=2, remove b=2, add c=2, remove a=2, add d=2] should lead to the following cache entries: (state=[], req=[2]) (state=[2], req=[2,2]) (state=[2,2], req=[2,0]) [cache hit] [cache hit] (state=[2,2], req=[2,2]) but different layout """ cpu = get_cpu() allocator = IntegerProgramCpuAllocator(cpu) allocator.assign_threads(Workload("a", 2, STATIC)) self.assertEqual(1, len(allocator._IntegerProgramCpuAllocator__cache)) allocator.assign_threads(Workload("b", 2, STATIC)) self.assertEqual(2, len(allocator._IntegerProgramCpuAllocator__cache)) allocator.free_threads("b") self.assertEqual(3, len(allocator._IntegerProgramCpuAllocator__cache)) allocator.assign_threads(Workload("c", 2, STATIC)) self.assertEqual(3, len(allocator._IntegerProgramCpuAllocator__cache)) allocator.free_threads("a") self.assertEqual(4, len(allocator._IntegerProgramCpuAllocator__cache)) allocator.assign_threads(Workload("d", 2, STATIC)) self.assertEqual(5, len(allocator._IntegerProgramCpuAllocator__cache))
def test_filling_holes_ip(self): """ Initialize with fragmented placement, then fill the instance. Result should be less fragmented, with the first workload completely filling a socket. | a | | a | | | | a | | a | | ------------- | | | a | | a | | a | | a | | """ cpu = get_cpu() allocator = IntegerProgramCpuAllocator(cpu) # Initialize fragmented workload wa = Workload(uuid.uuid4(), 8, STATIC) p0 = cpu.get_packages()[0] p0.get_cores()[0].get_threads()[0].claim(wa.get_id()) p0.get_cores()[1].get_threads()[1].claim(wa.get_id()) p0.get_cores()[2].get_threads()[0].claim(wa.get_id()) p0.get_cores()[3].get_threads()[1].claim(wa.get_id()) p1 = cpu.get_packages()[1] p1.get_cores()[0].get_threads()[1].claim(wa.get_id()) p1.get_cores()[1].get_threads()[0].claim(wa.get_id()) p1.get_cores()[2].get_threads()[1].claim(wa.get_id()) p1.get_cores()[3].get_threads()[0].claim(wa.get_id()) self.assertEqual(8, len(cpu.get_empty_threads())) # Fill the rest of the CPU w0 = Workload(uuid.uuid4(), 2, STATIC) w1 = Workload(uuid.uuid4(), 3, STATIC) w2 = Workload(uuid.uuid4(), 1, STATIC) w3 = Workload(uuid.uuid4(), 2, STATIC) workloads = [wa, w0, w1, w2, w3] for w in workloads: allocator.assign_threads(w) self.assertEqual(0, len(cpu.get_empty_threads())) # first workload should be filling completely a socket to avoid cross-socket job layout for package in cpu.get_packages(): if package.get_cores()[0].get_threads()[0].get_workload_id() != wa.get_id(): continue ids = [t.get_workload_id() for core in package.get_cores() for t in core.get_threads()] self.assertListEqual(ids, [wa.get_id()] * 8)
def test_one_cross_package_violation(self): cpu = get_cpu() allocator = IntegerProgramCpuAllocator() w = get_test_workload(uuid.uuid4(), 9, STATIC) request = get_no_usage_threads_request(cpu, [w]) cpu = allocator.assign_threads(request).get_cpu() violations = get_cross_package_violations(cpu) self.assertEqual(1, len(violations))
def test_one_cross_package_violation(self): cpu = get_cpu() allocator = IntegerProgramCpuAllocator() w = get_test_workload(uuid.uuid4(), 9, STATIC) request = AllocateThreadsRequest(cpu, w.get_id(), {w.get_id(): w}, {}, DEFAULT_TEST_REQUEST_METADATA) cpu = allocator.assign_threads(request).get_cpu() violations = get_cross_package_violations(cpu) self.assertEqual(1, len(violations))
def test_assign_two_threads_empty_cpu_ip(self): """ Workload 0: 2 threads --> (p:0 c:0 t:0) (p:0 c:1 t:0) """ cpu = get_cpu() allocator = IntegerProgramCpuAllocator(cpu) w = Workload(uuid.uuid4(), 2, STATIC) allocator.assign_threads(w) self.assertEqual(2, len(cpu.get_claimed_threads())) # Expected core and threads core00 = cpu.get_packages()[0].get_cores()[0] core01 = cpu.get_packages()[0].get_cores()[1] thread0 = core00.get_threads()[0] self.assertEqual(0, thread0.get_id()) self.assertTrue(thread0.is_claimed()) thread1 = core01.get_threads()[0] self.assertEqual(1, thread1.get_id()) self.assertTrue(thread1.is_claimed())
def test_shared_core_violation(self): allocator = IntegerProgramCpuAllocator() # Claim all thread but one cpu = get_cpu() w_0 = get_test_workload(uuid.uuid4(), len(cpu.get_threads()) - 1, STATIC) request = get_no_usage_threads_request(cpu, [w_0]) cpu = allocator.assign_threads(request).get_cpu() log.info("{}".format(cpu)) violations = get_shared_core_violations(cpu) log.info("shared core violations: {}".format(violations)) self.assertEqual(0, len(violations)) # Assign another workload which will force core sharing w_1 = get_test_workload(uuid.uuid4(), 1, STATIC) request = get_no_usage_threads_request(cpu, [w_0, w_1]) cpu = allocator.assign_threads(request).get_cpu() log.info("{}".format(cpu)) violations = get_shared_core_violations(cpu) log.info("shared core violations: {}".format(violations)) self.assertEqual(1, len(violations))
def test_assign_ten_threads_empty_cpu_ip(self): """ Workload 0: 10 threads --> (p:0 c:[0-7] t:[0-9]) | 1 | 1 | 1 | 1 | | 1 | 1 | | | | ------------- | | 1 | 1 | 1 | 1 | | | | | | """ cpu = get_cpu() allocator = IntegerProgramCpuAllocator(cpu) w = Workload(uuid.uuid4(), 10, STATIC) allocator.assign_threads(w) self.assertEqual(10, len(cpu.get_claimed_threads())) expected_thread_ids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 12] thread_ids = [thread.get_id() for thread in cpu.get_claimed_threads()] thread_ids.sort() self.assertEqual(expected_thread_ids, thread_ids)
def test_shared_core_violation(self): cpu = get_cpu() violations = get_shared_core_violations(cpu) log.info("shared core violations: {}".format(violations)) self.assertEqual(0, len(violations)) # Claim 1 thread on every core dummy_workload_id = uuid.uuid4() for p in cpu.get_packages(): for c in p.get_cores(): c.get_threads()[0].claim(dummy_workload_id) violations = get_shared_core_violations(cpu) log.info("shared core violations: {}".format(violations)) self.assertEqual(0, len(violations)) # Assign another workload which will force core sharing allocator = IntegerProgramCpuAllocator(cpu) w = Workload(uuid.uuid4(), 2, STATIC) allocator.assign_threads(w) violations = get_shared_core_violations(cpu) log.info("shared core violations: {}".format(violations)) self.assertEqual(2, len(violations))
def test_cache_ip(self): """ [add a=2, add b=2, remove b=2, add c=2, remove a=2, add d=2] should lead to the following cache entries: (state=[], req=[2]) (state=[2], req=[2,2]) (state=[2,2], req=[2,0]) [cache hit] [cache hit] (state=[2,2], req=[2,2]) but different layout """ cpu = get_cpu() allocator = IntegerProgramCpuAllocator() w_a = get_test_workload("a", 2, STATIC) w_b = get_test_workload("b", 2, STATIC) w_c = get_test_workload("c", 2, STATIC) w_d = get_test_workload("d", 2, STATIC) workloads = [w_a] request = get_no_usage_threads_request(cpu, workloads) cpu = allocator.assign_threads(request).get_cpu() self.assertEqual(1, len(allocator._IntegerProgramCpuAllocator__cache)) workloads = [w_a, w_b] request = get_no_usage_threads_request(cpu, workloads) allocator.assign_threads(request).get_cpu() self.assertEqual(2, len(allocator._IntegerProgramCpuAllocator__cache)) cpu = allocator.free_threads(request).get_cpu() self.assertEqual(3, len(allocator._IntegerProgramCpuAllocator__cache)) workloads = [w_a, w_c] request = get_no_usage_threads_request(cpu, workloads) cpu = allocator.assign_threads(request).get_cpu() self.assertEqual(3, len(allocator._IntegerProgramCpuAllocator__cache)) workloads = [w_c, w_a] request = get_no_usage_threads_request(cpu, workloads) cpu = allocator.free_threads(request).get_cpu() self.assertEqual(4, len(allocator._IntegerProgramCpuAllocator__cache)) workloads = [w_c, w_d] request = get_no_usage_threads_request(cpu, workloads) allocator.assign_threads(request).get_cpu() self.assertEqual(5, len(allocator._IntegerProgramCpuAllocator__cache))