def _from_target(cls, target: Target, *, res_dir: ArtifactPath, cpu, freq, switch_governor=True) -> 'UserspaceSanityItem': """ Create a :class:`UserspaceSanityItem` from a live :class:`lisa.target.Target`. :param cpu: CPU to run on. :type cpu: int :param freq: Frequency to run at. :type freq: int :param switch_governor: Switch the governor to userspace, and undo it at the end. If that has been done in advance, not doing it for every item saves substantial time. :type switch_governor: bool """ sysbench = Sysbench(target, res_dir=res_dir) cm = target.cpufreq.use_governor( 'userspace') if switch_governor else nullcontext() with cm: target.cpufreq.set_frequency(cpu, freq) sysbench.run(cpus=[cpu], max_duration_s=1) work = sysbench.output.nr_events return cls(res_dir, target.plat_info, cpu, freq, work)
def _from_target(cls, target: Target, *, res_dir: ArtifactPath = None) -> 'CapacitySanity': """ Factory method to create a bundle using a live target """ with target.cpufreq.use_governor("performance"): sysbench = Sysbench(target, "sysbench", res_dir) cpu_capacities = target.sched.get_capacities() capa_work = { capa: sys.maxsize for capa in list(cpu_capacities.values()) } for cpu in list(cpu_capacities.keys()): sysbench.run(cpus=[cpu], max_duration_s=1) # We could save the work done on each CPU, but we can make # things simpler and just store the smallest amount of work done # per capacity value. capa = cpu_capacities[cpu] capa_work[capa] = min(capa_work[capa], sysbench.output.nr_events) return cls(res_dir, target.plat_info, capa_work)
def _from_target(cls, target, res_dir, freq_count_limit): cpu_work = {} sysbench = Sysbench(target, "sysbench", res_dir) with target.cpufreq.use_governor("userspace"): for domain in target.cpufreq.iter_domains(): cpu = domain[0] cpu_work[cpu] = {} freqs = target.cpufreq.list_frequencies(cpu) if len(freqs) > freq_count_limit: freqs = freqs[::len(freqs) // freq_count_limit + (1 if len(freqs) % 2 else 0)] for freq in freqs: target.cpufreq.set_frequency(cpu, freq) sysbench.run(cpus=[cpu], max_duration_s=1) cpu_work[cpu][freq] = sysbench.output.nr_events return cls(res_dir, target.plat_info, cpu_work)