Exemplo n.º 1
0
    def add_target_src(self,
                       target,
                       rta_calib_res_dir,
                       src='target',
                       **kwargs):
        info = {
            'nrg-model': self._nrg_model_from_target(target),
            'kernel': {
                'version': target.kernel_version,
                'config': target.config.typed_config,
            },
            'abi': target.abi,
            'os': target.os,
            'rtapp': {
                # Since it is expensive to compute, use an on-demand DeferredValue
                'calib':
                DeferredValue(RTA.get_cpu_calibrations, target,
                              rta_calib_res_dir)
            },
            'cpus-count': target.number_of_cpus
        }

        if hasattr(target, 'cpufreq'):
            info['freq-domains'] = list(target.cpufreq.iter_domains())
            info['freqs'] = {
                cpu: target.cpufreq.list_frequencies(cpu)
                for cpu in range(target.number_of_cpus)
            }

        if hasattr(target, 'sched'):
            info['cpu-capacities'] = target.sched.get_capacities(default=1024)

        return self.add_src(src, info, filter_none=True, **kwargs)
Exemplo n.º 2
0
    def test_derived_with_deferred_base(self):
        conf = copy.deepcopy(self.conf)
        conf.add_src(
            'mysrc', {
                'foo': DeferredValue(lambda: 1),
                'bar': [1, 2],
                'sublevel': {
                    'subkey': 42
                }
            })
        # Check that the value we get is transitively a DeferredValue
        val = conf.get_key('derived', eval_deferred=False)
        assert isinstance(val, DeferredValue)

        # Regular access will evaluate all the bases
        assert conf['derived'] == 46
Exemplo n.º 3
0
 def evaluate(existing_info, key, val):
     if isinstance(val, Mapping):
         return dfs(existing_info[key], val)
     else:
         if only_missing and key in existing_info:
             return None
         else:
             renamed_val = rename_f(val, key)
             if val is None or isinstance(val, DeferredValue):
                 return renamed_val
             elif deferred:
                 return DeferredValue(renamed_val)
             else:
                 try:
                     return val()
                 except Exception as e:
                     logger.error('Cannot retrieve value of key {}: {}'.format(key, e))
                     return DeferredExcep(excep=e)
Exemplo n.º 4
0
    def add_target_src(self,
                       target,
                       rta_calib_res_dir,
                       src='target',
                       only_missing=True,
                       **kwargs):
        """
        Add source from a live :class:`lisa.target.Target`.

        :param target: Target to inspect.
        :type target: lisa.target.Target

        :param rta_calib_res_dir: Result directory for rt-app calibrations.
        :type rta_calib_res_dir: str

        :param src: Named of the added source.
        :type src: str

        :param only_missing: If ``True``, only add values for the keys that are
            not already provided by another source. This allows speeding up the
            connection to target, at the expense of not being able to spot
            inconsistencies between user-provided values and autodetected values.
        :type only_missing: bool

        :Variable keyword arguments: Forwarded to
            :class:`lisa.conf.MultiSrcConf.add_src`.
        """
        info = {
            'nrg-model': lambda: self._nrg_model_from_target(target),
            'kernel': {
                'version': lambda: target.kernel_version,
                'config': lambda: target.config.typed_config,
            },
            'abi': lambda: target.abi,
            'os': lambda: target.os,
            'rtapp': {
                # Since it is expensive to compute, use an on-demand DeferredValue
                'calib':
                lambda: DeferredValue(RTA.get_cpu_calibrations, target,
                                      rta_calib_res_dir)
            },
            'cpus-count': lambda: target.number_of_cpus,
            'numa-nodes-count': lambda: target.number_of_nodes
        }

        def get_freq_domains():
            if target.is_module_available('cpufreq'):
                return list(target.cpufreq.iter_domains())
            else:
                return None

        info['freq-domains'] = get_freq_domains

        def get_freqs():
            if target.is_module_available('cpufreq'):
                freqs = {
                    cpu: target.cpufreq.list_frequencies(cpu)
                    for cpu in range(target.number_of_cpus)
                }
                # Only add the frequency info if there is any, otherwise don't
                # mislead the client code with empty frequency list
                if all(freqs.values()):
                    return freqs
                else:
                    return None
            else:
                return None

        info['freqs'] = get_freqs

        @memoized
        def get_orig_capacities():
            if target.is_module_available('sched'):
                return target.sched.get_capacities(default=1024)
            else:
                return None

        def get_writeable_capacities():
            orig_capacities = get_orig_capacities()

            if orig_capacities is None:
                return None
            else:
                cpu = 0
                path = '/sys/devices/system/cpu/cpu{}/cpu_capacity'.format(cpu)
                capa = orig_capacities[cpu]
                test_capa = capa - 1 if capa > 1 else capa + 1

                try:
                    target.write_value(path, test_capa, verify=True)
                except TargetStableError:
                    writeable = False
                else:
                    writeable = True
                finally:
                    with contextlib.suppress(TargetStableError):
                        target.write_value(path, capa)

                return writeable

        info['cpu-capacities'] = {
            'writeable': get_writeable_capacities,
            'orig': get_orig_capacities,
        }

        info['kernel']['symbols-address'] = lambda: DeferredValue(
            self._read_kallsyms, target)

        def dfs(existing_info, new_info):
            def evaluate(existing_info, key, val):
                if isinstance(val, Mapping):
                    return dfs(existing_info[key], val)
                else:
                    if only_missing and key in existing_info:
                        return None
                    else:
                        return val()

            return {
                key: evaluate(existing_info, key, val)
                for key, val in new_info.items()
            }

        info = dfs(self, info)

        return self.add_src(src, info, filter_none=True, **kwargs)