def _algorithm(self, total_proc, proc_nr): proc_nr = int(proc_nr) total_proc = int(total_proc) self.get_affinity() allowed_cpus = self.cpusett.get_cpus_idx() # takes into account cgroups/cpusets total_cpus = len(allowed_cpus) alg = BasicCore() alg.create(total_cpus, total_proc) rel_cpus = alg.get_cpus(proc_nr) # rel_cpus is a list relative to the usable cpus of cpusett.cpus for rel_idx, abs_idx in enumerate(allowed_cpus): self.cpusett.cpus[abs_idx] = int(rel_idx in rel_cpus)
def test_basiccore(self): bc = BasicCore() # 4 total cpus, 4 processes to place bc.create(4, 4) self.assertEqual(bc.proc_placement, [[0], [1], [2], [3]]) # 8 total cpus, 4 processes to place bc.create(8, 4) self.assertEqual(bc.proc_placement, [[0], [0], [1], [1], [2], [2], [3], [3]]) # 4 total cpus, 8 processes to place bc.create(4, 8) self.assertEqual(bc.proc_placement, [[0, 1], [2, 3], [4, 5], [6, 7]]) # 6 total cpus, 4 processes to place bc.create(6, 4) self.assertEqual(bc.proc_placement, [[0], [0], [1], [2], [2], [3]]) # 6 total cpus, 8 processes to place bc.create(6, 8) self.assertEqual(bc.proc_placement, [[0], [1], [2, 3], [4], [5], [6, 7]])
def suite(): """ returns all the testcases in this module """ return TestLoader().loadTestsFromTestCase(ProcesscontrolTest) if __name__ == '__main__': """Use this __main__ block to help write and test unittests just uncomment the parts you need """ # cs = TestCpuSetT() # cs.convert_hr_bits('2,5-8,10,11-11') # print cs.nbitmask # print cs.cpusetsize # print cs.cpus[:cs.DEFAULT_CPUSETSIZE] # print cs.bits bc = BasicCore() # 4 total cpus, 4 processes to place bc.create(4, 4) print bc.proc_placement # 8 total cpus, 4 processes to place bc.create(8, 4) print bc.proc_placement # 4 total cpus, 8 processes to place bc.create(4, 8) print bc.proc_placement # 6 total cpus, 4 processes to place bc.create(6, 4)
""" returns all the testcases in this module """ return TestLoader().loadTestsFromTestCase(ProcesscontrolTest) if __name__ == '__main__': """Use this __main__ block to help write and test unittests just uncomment the parts you need """ # cs = TestCpuSetT() # cs.convert_hr_bits('2,5-8,10,11-11') # print cs.nbitmask # print cs.cpusetsize # print cs.cpus[:cs.DEFAULT_CPUSETSIZE] # print cs.bits bc = BasicCore() # 4 total cpus, 4 processes to place bc.create(4, 4) print bc.proc_placement # 8 total cpus, 4 processes to place bc.create(8, 4) print bc.proc_placement # 4 total cpus, 8 processes to place bc.create(4, 8) print bc.proc_placement # 6 total cpus, 4 processes to place bc.create(6, 4)