示例#1
0
    def _get_assign_threads(cpu: Cpu, thread_count: int) -> List[Thread]:
        empty_threads = cpu.get_empty_threads()

        if len(empty_threads) >= thread_count:
            random.shuffle(empty_threads)
            return empty_threads[:thread_count]

        # If there aren't enough empty threads, fill the gap with random claimed threads
        claimed_threads = cpu.get_claimed_threads()
        random.shuffle(claimed_threads)
        claimed_threads = claimed_threads[:thread_count - len(empty_threads)]

        return empty_threads + claimed_threads
示例#2
0
    def get_free_threads(
            self,
            cpu: Cpu,
            workload_map:
            Dict[str, Workload],
            cpu_usage: Dict[str, float] = None) -> List[Thread]:

        if cpu_usage is None:
            log.error("CPU usage is required, defaulting to EMPTY threads being free.")
            return cpu.get_empty_threads()

        free_threads = []
        for c in get_free_cores(self.__threshold, cpu, workload_map, cpu_usage):
            free_threads += c.get_threads()

        return free_threads