Exemple #1
0
    def _allocate_task(self, allocations: TaskAllocations,
                       balance_task: TaskId, balance_task_node: NumaNodeId,
                       tasks_data: TasksData, platform: Platform):
        log.debug("Task %r: assiging to node %s." %
                  (balance_task, balance_task_node))
        allocations[balance_task] = {
            AllocationType.CPUSET_CPUS:
            encode_listformat(platform.node_cpus[balance_task_node]),
        }
        if self.cgroups_memory_binding:
            allocations[balance_task][
                AllocationType.CPUSET_MEMS] = encode_listformat(
                    {balance_task_node})

            if self.cgroups_memory_migrate:
                log.debug("Assign task %s to node %s with memory migrate" %
                          (balance_task, balance_task_node))
                allocations[balance_task][
                    AllocationType.CPUSET_MEM_MIGRATE] = 1

        if self.migrate_pages:
            self._pages_to_move[balance_task] += _get_pages_to_move(
                balance_task, tasks_data, balance_task_node,
                'initial assignment')
            allocations.setdefault(balance_task, {})
            allocations[balance_task][
                AllocationType.MIGRATE_PAGES] = balance_task_node
Exemple #2
0
def _discover_pmu_uncore_config(events, dir_prefix):
    """Detect available uncore PMUS and their types and CPUS, that events should be assigned to.
    Can raise PMUNotAvailable exception if the is not cpusmask set for this PMU.
    Returns configuration that can be used to program perf_event subsystem to collect given
    events.
    """
    base_path = '/sys/devices'
    pmus = [d for d in os.listdir(base_path) if d.startswith(dir_prefix)]
    pmu_types = [
        int(open(os.path.join(base_path, imc, 'type')).read().rstrip())
        for imc in pmus
    ]
    pmu_cpus_set = set([
        open(os.path.join(base_path, imc, 'cpumask')).read().rstrip()
        for imc in pmus
    ])
    if len(pmu_cpus_set) == 0:
        raise PMUNotAvailable(
            'there is no PMU types available for "%s" device (in /sys/devices)'
            % dir_prefix[:-1])
    assert len(pmu_cpus_set) == 1
    pmu_cpus_csv = list(pmu_cpus_set)[0]
    cpus = list(decode_listformat(pmu_cpus_csv))
    pmu_events = {pmu: events for pmu in pmu_types}
    log.debug('discovered uncore pmus types for "%s": %r with cpus=%r',
              dir_prefix[:-1], pmu_types, encode_listformat(cpus))
    return cpus, pmu_events
Exemple #3
0
 def _write_listformat(self, intset: Set[int], resource: CgroupResource,
                       cgroup_type: CgroupType):
     encoded_value = encode_listformat(intset)
     try:
         self._write(resource, encoded_value, cgroup_type)
     except PermissionError:
         log.warning(
             'Cannot write {}: "{}" to "{}"! Permission denied.'.format(
                 CgroupResource.CPUSET_CPUS, encoded_value, self.cgroup_cpuset_fullpath))
Exemple #4
0
def test_encode_listformat(intset, expected_encoded):
    got_encoded = encode_listformat(intset)
    assert got_encoded == expected_encoded
Exemple #5
0
 def _read_listformat(self, resource: CgroupResource,
                      cgroup_type: CgroupType):
     listformat = decode_listformat(
         self._read_raw(resource, cgroup_type).strip())
     return encode_listformat(listformat)