def __build_topology(all_cores): if all_cores is None: all_cores = (1 << len(core_id_to_package_id)) - 1 if type(all_cores) is list: if len(all_cores) > 0 and type(all_cores[0]) is Core: all_cores = [c.id for c in all_cores] if not all_cores: raise NoCores cores_mask = mask.to_int(all_cores) if not cores_mask: raise NoCores cores_list = mask.to_int_list(cores_mask) top = Topology() top.cores_mask = cores_mask top.id2core = {} top.id2package = {} for core_id in cores_list: try: pkg_i = core_id_to_package_id[core_id] except: raise BadCoreId(core_id) if pkg_i not in top.id2package: top.id2package[pkg_i] = Package(pkg_i) pkg = top.id2package[pkg_i] pkg.add_core(core_id) ts = core_id_to_thread_siblings[core_id] & cores_mask cs = core_id_to_core_siblings[core_id] & cores_mask top.id2core[core_id] = Core(top, core_id, pkg, ts, cs) top.core_ids = list(top.id2core.keys()) top.core_ids.sort() top.cores_mask = mask.to_int(top.core_ids) top.package_ids = list(top.id2package.keys()) top.package_ids.sort() top.real_cores = dict([(c.id, c) for c in top.id2core.values() if c.id == c.real_core]) top.real_core_ids = list(top.real_cores.keys()) top.real_core_ids.sort() top.real_cores_mask = mask.to_int(top.real_core_ids) caches = [ Cache(c[0], c[1] & cores_mask) for c in shared_caches if len(mask.to_int_list(c[1] & cores_mask)) > 1 ] top.shared_caches = {} for cache in caches: if cache.level not in top.shared_caches: top.shared_caches[cache.level] = [] top.shared_caches[cache.level].append(cache) for core_id in cache.core_ids: core = top.id2core[core_id] core.shared_caches[cache.level] = cache return top
def __build_topology(all_cores): if all_cores is None: all_cores = (1 << len(core_id_to_package_id)) - 1 if type(all_cores) is list: if len(all_cores) > 0 and type(all_cores[0]) is Core: all_cores = [c.id for c in all_cores] if not all_cores: raise NoCores cores_mask = mask.to_int(all_cores) if not cores_mask: raise NoCores cores_list = mask.to_int_list(cores_mask) top = Topology() top.cores_mask = cores_mask top.id2core = {} top.id2package = {} for core_id in cores_list: try: pkg_i = core_id_to_package_id[core_id] except: raise BadCoreId(core_id) if pkg_i not in top.id2package: top.id2package[pkg_i] = Package(pkg_i) pkg = top.id2package[pkg_i] pkg.add_core(core_id) ts = core_id_to_thread_siblings[core_id] & cores_mask cs = core_id_to_core_siblings[core_id] & cores_mask top.id2core[core_id] = Core(top, core_id, pkg, ts, cs) top.core_ids = list(top.id2core.keys()) top.core_ids.sort() top.cores_mask = mask.to_int(top.core_ids) top.package_ids = list(top.id2package.keys()) top.package_ids.sort() top.real_cores = dict([(c.id, c) for c in top.id2core.values() if c.id == c.real_core]) top.real_core_ids = list(top.real_cores.keys()) top.real_core_ids.sort() top.real_cores_mask = mask.to_int(top.real_core_ids) caches = [Cache(c[0], c[1] & cores_mask) for c in shared_caches if len(mask.to_int_list(c[1] & cores_mask)) > 1] top.shared_caches = {} for cache in caches: if cache.level not in top.shared_caches: top.shared_caches[cache.level] = [] top.shared_caches[cache.level].append(cache) for core_id in cache.core_ids: core = top.id2core[core_id] core.shared_caches[cache.level] = cache return top
def __init__(self, topology, id, pkg, thread_sibs, core_sibs): # thread_sibs and core_sibs include this core assert (thread_sibs & (1 << id)) != 0 assert (core_sibs & (1 << id)) != 0 self.topology = topology self.id = id self.pkg = pkg self.thread_siblings_mask = mask.to_int(thread_sibs) self.thread_siblings_list = mask.to_int_list(thread_sibs) thread_sibs &= ~(1 << id) self.thread_siblings_ex_mask = mask.to_int(thread_sibs) self.thread_siblings_ex_list = mask.to_int_list(thread_sibs) self.core_siblings_mask = mask.to_int(core_sibs) self.core_siblings_list = mask.to_int_list(core_sibs) core_sibs &= ~(1 << id) self.core_siblings_ex_mask = mask.to_int(core_sibs) self.core_siblings_ex_list = mask.to_int_list(core_sibs) self.real_core = self.thread_siblings_list[0] self.shared_caches = {}
def __get_cache_info(): global shared_caches, core_id_to_package_id if shared_caches: return if not core_id_to_package_id: __get_core_info() shared_caches = set() for core_id in core_id_to_package_id.keys(): for index in range(0, 100): try: cpumask = file_get_strip(sys_cache_cpu_map_f % (core_id,index)) except: break cpumask = mask.comma_sep_hex_to_int(cpumask) cpulist = mask.to_int_list(cpumask) if len(cpulist) > 1: level = file_get_int(sys_cache_level_f % (core_id, index)) cpumask = mask.to_int(cpumask) c = (level, cpumask) shared_caches.add(c)
def __get_cache_info(): global shared_caches, core_id_to_package_id if shared_caches: return if not core_id_to_package_id: __get_core_info() shared_caches = set() for core_id in core_id_to_package_id.keys(): for index in range(0, 100): try: cpumask = file_get_strip(sys_cache_cpu_map_f % (core_id, index)) except: break cpumask = mask.comma_sep_hex_to_int(cpumask) cpulist = mask.to_int_list(cpumask) if len(cpulist) > 1: level = file_get_int(sys_cache_level_f % (core_id, index)) cpumask = mask.to_int(cpumask) c = (level, cpumask) shared_caches.add(c)
def __init__(self, level, cpumask): self.level = level self.core_ids = mask.to_int_list(cpumask) self.cores_mask = mask.to_int(cpumask)