Esempio n. 1
0
def bitmask(value):
    if isinstance(value, basestring):
        value = ranges_to_list(value)
    if isiterable(value):
        value = list_to_mask(value)
    if not isinstance(value, int):
        raise ValueError(value)
    return value
Esempio n. 2
0
def bitmask(value):
    if isinstance(value, basestring):
        value = ranges_to_list(value)
    if isiterable(value):
        value = list_to_mask(value)
    if not isinstance(value, int):
        raise ValueError(value)
    return value
Esempio n. 3
0
    def run(self, cpus=None, cgroup=None, background=False, as_root=False, timeout=None):
        """
        Execute the workload on the configured target.

        :param cpus: CPUs on which to restrict the workload execution (taskset)
        :type cpus: list(int)

        :param cgroup: cgroup in which to run the workload
        :type cgroup: str

        :param background: Whether to run the workload in background or not
        :type background: bool

        :param as_root: Whether to run the workload as root or not
        :type as_root: bool

        :param timeout: Timeout in seconds for the workload execution.
        :type timeout: int

        :raise devlib.exception.TimeoutError: When the specified ``timeout`` is hit.

        The standard output will be saved into a file in ``self.res_dir``
        """
        logger = self.get_logger()
        if not self.command:
            raise RuntimeError("Workload does not specify any command to execute")

        _command = self.command
        target = self.target

        if cpus:
            taskset_bin = target.which('taskset')
            if not taskset_bin:
                raise RuntimeError("Could not find 'taskset' executable on the target")

            cpumask = list_to_mask(cpus)
            taskset_cmd = '{} {}'.format(quote(taskset_bin), quote('0x{:x}'.format(cpumask)))
            _command = '{} {}'.format(taskset_cmd, _command)

        if cgroup:
            _command = target.cgroups.run_into_cmd(cgroup, _command)

        _command = 'cd {} && {}'.format(quote(self.run_dir), _command)

        logger.info("Execution start: {}".format(_command))

        if background:
            target.background(_command, as_root=as_root)
        else:
            self.output = target.execute(_command, as_root=as_root, timeout=timeout)
            logger.info("Execution complete")

            logfile = ArtifactPath.join(self.res_dir, 'output.log')
            logger.debug('Saving stdout to {}...'.format(logfile))

            with open(logfile, 'w') as ofile:
                ofile.write(self.output)
Esempio n. 4
0
    def _basic_run(self, **kwargs):
        """
        Basic run function to be used in subclasses' implementation of
        ``_run()``.

        By default, it will use the settings saved in ``_settings`` attribute
        by :class:`Workload`'s ``__init__``, but they can all be overridden
        manually with keyword arguments if that is really necessary.
        """
        logger = self.get_logger()
        target = self.target

        settings = {
            **self._settings,
            **kwargs
        }
        as_root = settings.get('as_root')
        timeout = settings.get('timeout')
        command = settings.get('command')
        cpus = settings.get('cpus')
        cgroup = settings.get('cgroup')

        if command is None:
            raise ValueError('command must not be None')

        # Log the "clean" unmodified command. If the user wants the details,
        # debug log from devlib will provide it
        logger.info(f"Execution start: {command}")

        if cpus:
            target.install_tools(['taskset'])
            cpumask = list_to_mask(cpus)
            taskset_cmd = f"taskset {quote(f'0x{cpumask:x}')}"
            command = f'{taskset_cmd} {command}'

        if cgroup:
            command = target.cgroups.run_into_cmd(cgroup, command)

        command = f'cd {quote(self.run_dir)} && {command}'

        bg = target.background(command, as_root=as_root, timeout=timeout)
        return bg
Esempio n. 5
0
    def _matching_masks(self, cpus):
        df = self.trace.df_event('thermal_power_cpu_limit')

        global_mask = list_to_mask(cpus)
        cpumasks = df['cpus'].unique().tolist()
        return [m for m in cpumasks if m & global_mask]
Esempio n. 6
0
    def _matchingMasks(self, cpus):
        df = self._dfg_trace_event('thermal_power_cpu_limit')

        global_mask = list_to_mask(cpus)
        cpumasks = df['cpus'].unique().tolist()
        return [m for m in cpumasks if m & global_mask]