示例#1
0
def _get_current_node(allocations: Optional[TaskAllocations],
                      platform: Platform) -> NumaNodeId:
    cpus_assigned = decode_listformat(allocations[AllocationType.CPUSET_CPUS])
    for node, cpus in platform.node_cpus.items():
        if cpus == cpus_assigned:
            return node
    return -1
示例#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
示例#3
0
    def perform_allocations(self):
        mems = decode_listformat(self.value)

        if len(self.subcgroups) > 0:
            for subcgroup in self.subcgroups:
                subcgroup.set_cpuset_mems(mems)
        else:
            self.cgroup.set_cpuset_mems(mems)
示例#4
0
 def generate_metrics(self) -> List[Metric]:
     mems = decode_listformat(self.value)
     metrics = [Metric(
         name='allocation_cpuset_mems_number_of_mems',
         value=len(mems),
         type=MetricType.GAUGE,
         labels=dict(allocation_type=AllocationType.CPUSET_MEMS)
     )]
     self.labels_updater.update_labels(metrics)
     return metrics
示例#5
0
 def validate(self):
     try:
         value = decode_listformat(self.value)
     except ValueError as e:
         raise InvalidAllocations('cannot decode list format %r: %s' % (self.value, e)) from e
     as_sorted_list = list(sorted(value))
     assert self.max_value is not None, 'should be initialized by subclass'
     if len(self.value) > 0:
         if as_sorted_list[0] < self.min_value or as_sorted_list[-1] > self.max_value:
             raise InvalidAllocations(
                 '{} not in range <{};{}>'.format(self.value, self.min_value,
                                                  self.max_value))
     else:
         log.debug('found cpuset/memset set to empty string!')
示例#6
0
 def __eq__(self, other) -> bool:
     """Compare listformat based value to another value by taking value into consideration."""
     assert isinstance(other, self.__class__)
     return decode_listformat(self.value) == decode_listformat(other.value)
示例#7
0
def test_decode_listform(raw_cpulist, expected_cpus):
    got_cpus = decode_listformat(raw_cpulist)
    assert got_cpus == expected_cpus
示例#8
0
 def _read_listformat(self, resource: CgroupResource,
                      cgroup_type: CgroupType):
     listformat = decode_listformat(
         self._read_raw(resource, cgroup_type).strip())
     return encode_listformat(listformat)