From a311b79bb7779e5d5d4034f852ab0bd57c4f287d Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 17 Mar 2021 10:10:09 -0300 Subject: [PATCH 1/4] [arch] fix -> not skipping dependency checking when the user opts to proceed with a transaction that would break other packages --- CHANGELOG.md | 6 ++++++ bauh/__init__.py | 2 +- bauh/gems/arch/pacman.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bf6553d..a7933200 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [0.9.16] +### Fixes +- Arch + - not skipping dependency checking when the user opts to proceed with a transaction that would break other packages + + ## [0.9.15] 2021-03-03 ### Improvements - UI diff --git a/bauh/__init__.py b/bauh/__init__.py index 7f151822..21db5942 100644 --- a/bauh/__init__.py +++ b/bauh/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.9.15' +__version__ = '0.9.16' __app_name__ = 'bauh' import os diff --git a/bauh/gems/arch/pacman.py b/bauh/gems/arch/pacman.py index 2aeef6b0..e998e3b4 100644 --- a/bauh/gems/arch/pacman.py +++ b/bauh/gems/arch/pacman.py @@ -723,7 +723,7 @@ def upgrade_several(pkgnames: Iterable[str], root_password: str, overwrite_confl cmd.append('--overwrite=*') if skip_dependency_checks: - cmd.append('-d') + cmd.append('-dd') return SimpleProcess(cmd=cmd, root_password=root_password, From e67e5bc0a96d030387597d05213880f66b268b52 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Sun, 4 Apr 2021 10:27:35 -0300 Subject: [PATCH 2/4] [arch] fix -> not restoring the CPUs to previous scaling governors after the package is built when optimizations are on --- CHANGELOG.md | 2 +- README.md | 2 +- bauh/gems/arch/controller.py | 15 ++++--- bauh/gems/arch/cpu_manager.py | 73 +++++++++++++++++++++++++++-------- 4 files changed, 65 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7933200..5d8c3656 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixes - Arch - not skipping dependency checking when the user opts to proceed with a transaction that would break other packages - + - AUR: not restoring the CPUs to previous scaling governors after the package is built when optimizations are on ## [0.9.15] 2021-03-03 ### Improvements diff --git a/README.md b/README.md index de7ab7c8..70da59d7 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ suggestions: c) `ccache` will be added to `BUILDENV` if it is installed on the system and already not defined - d) set the device processors to performance mode + d) set the device CPUs to performance scaling governor Obs: For more information about them, have a look at [Makepkg](https://wiki.archlinux.org/index.php/Makepkg) diff --git a/bauh/gems/arch/controller.py b/bauh/gems/arch/controller.py index fa1c48db..9340d72d 100644 --- a/bauh/gems/arch/controller.py +++ b/bauh/gems/arch/controller.py @@ -1944,13 +1944,12 @@ class ArchManager(SoftwareManager): # building main package context.watcher.change_substatus(self.i18n['arch.building.package'].format(bold(context.name))) - optimize = bool(context.config['optimize']) and cpu_manager.supports_performance_mode() and not cpu_manager.all_in_performance() + optimize = bool(context.config['optimize']) and cpu_manager.supports_performance_mode() + + cpus_changed, cpu_prev_governors = False, None - cpu_optimized = False if optimize: - self.logger.info("Setting cpus to performance mode") - cpu_manager.set_mode('performance', context.root_password) - cpu_optimized = True + cpus_changed, cpu_prev_governors = cpu_manager.set_all_cpus_to('performance', context.root_password, self.logger) try: pkgbuilt, output = makepkg.make(pkgdir=context.project_dir, @@ -1958,9 +1957,9 @@ class ArchManager(SoftwareManager): handler=context.handler, custom_pkgbuild=context.custom_pkgbuild_path) finally: - if cpu_optimized: - self.logger.info("Setting cpus to powersave mode") - cpu_manager.set_mode('powersave', context.root_password) + if cpus_changed and cpu_prev_governors: + self.logger.info("Restoring CPU governors") + cpu_manager.set_cpus(cpu_prev_governors, context.root_password, {'performance'}, self.logger) self._update_progress(context, 65) diff --git a/bauh/gems/arch/cpu_manager.py b/bauh/gems/arch/cpu_manager.py index 421e1526..47731176 100644 --- a/bauh/gems/arch/cpu_manager.py +++ b/bauh/gems/arch/cpu_manager.py @@ -1,6 +1,8 @@ import multiprocessing import os import traceback +from logging import Logger +from typing import Optional, Set, Tuple, Dict from bauh.commons.system import new_root_subprocess @@ -9,30 +11,67 @@ def supports_performance_mode(): return os.path.exists('/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor') -def all_in_performance() -> bool: - for i in range(multiprocessing.cpu_count()): - with open('/sys/devices/system/cpu/cpu{}/cpufreq/scaling_governor'.format(i)) as f: - if f.read().strip() != 'performance': - return False +def current_governors() -> Dict[str, Set[int]]: + governors = {} + for cpu in range(multiprocessing.cpu_count()): + with open('/sys/devices/system/cpu/cpu{}/cpufreq/scaling_governor'.format(cpu)) as f: + gov = f.read().strip() + cpus = governors.get(gov, set()) + cpus.add(cpu) + governors[gov] = cpus - return False + return governors -def set_mode(mode: str, root_password: str): +def set_governor(governor: str, root_password: str, cpu_idxs: Optional[Set[int]] = None): new_gov_file = '/tmp/bauh_scaling_governor' with open(new_gov_file, 'w+') as f: - f.write(mode) + f.write(governor) - for i in range(multiprocessing.cpu_count()): + for idx in (cpu_idxs if cpu_idxs else range(multiprocessing.cpu_count())): + _change_governor(idx, new_gov_file, root_password) + + if os.path.exists(new_gov_file): try: - gov_file = '/sys/devices/system/cpu/cpu{}/cpufreq/scaling_governor'.format(i) - replace = new_root_subprocess(['cp', new_gov_file, gov_file], root_password=root_password) - replace.wait() + os.remove(new_gov_file) except: traceback.print_exc() - if os.path.exists(new_gov_file): - try: - os.remove(new_gov_file) - except: - traceback.print_exc() + +def _change_governor(cpu_idx: int, new_gov_file_path: str, root_password: str): + try: + gov_file = '/sys/devices/system/cpu/cpu{}/cpufreq/scaling_governor'.format(cpu_idx) + replace = new_root_subprocess(['cp', new_gov_file_path, gov_file], root_password=root_password) + replace.wait() + except: + traceback.print_exc() + + +def set_all_cpus_to(governor: str, root_password: str, logger: Optional[Logger] = None) -> Tuple[bool, Optional[Dict[str, Set[int]]]]: + """ + """ + cpus_changed, cpu_governors = False, current_governors() + + if cpu_governors: + not_in_performance = set() + for gov, cpus in cpu_governors.items(): + if gov != governor: + not_in_performance.update(cpus) + + if not_in_performance: + if logger: + logger.info("Changing CPUs {} governors to '{}'".format(not_in_performance, governor)) + + set_governor(governor, root_password, not_in_performance) + cpus_changed = True + + return cpus_changed, cpu_governors + + +def set_cpus(governors: Dict[str, Set[int]], root_password: str, ignore_governors: Optional[Set[str]] = None, logger: Optional[Logger] = None): + for gov, cpus in governors.items(): + if not ignore_governors or gov not in ignore_governors: + if logger: + logger.info("Changing CPUs {} governors to '{}'".format(cpus, gov)) + + set_governor(gov, root_password, cpus) From dfe765450b3bab43d61ea27bcfacbcc2fa7f537f Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Tue, 6 Apr 2021 09:20:25 -0300 Subject: [PATCH 3/4] [arch] fix -> randomly crashing when solving repository packages dependencies --- CHANGELOG.md | 3 ++- bauh/gems/arch/dependencies.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d8c3656..e6d3e1bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixes - Arch - not skipping dependency checking when the user opts to proceed with a transaction that would break other packages - - AUR: not restoring the CPUs to previous scaling governors after the package is built when optimizations are on + - AUR: not restoring the CPUs to previous scaling governors after the package is built when optimizations are on + - randomly crashing when solving repository packages dependencies (RuntimeError: dictionary changed size during iteration) ## [0.9.15] 2021-03-03 ### Improvements diff --git a/bauh/gems/arch/dependencies.py b/bauh/gems/arch/dependencies.py index 1e8180c0..66ebe8ad 100644 --- a/bauh/gems/arch/dependencies.py +++ b/bauh/gems/arch/dependencies.py @@ -393,7 +393,7 @@ class DependenciesAnalyser: for t in aur_threads: t.join() - missing_subdeps = self.map_missing_deps(pkgs_data=deps_data, provided_map=provided_map, aur_index=aur_index, + missing_subdeps = self.map_missing_deps(pkgs_data={**deps_data}, provided_map=provided_map, aur_index=aur_index, deps_checked=deps_checked, sort=False, deps_data=deps_data, watcher=watcher, remote_provided_map=remote_provided_map, From 6feedf45034e28865d7b6521593412d9eefc4440 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Tue, 6 Apr 2021 10:08:07 -0300 Subject: [PATCH 4/4] Updating CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6d3e1bb..41f9fc18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -## [0.9.16] +## [0.9.16] 2021-04-06 ### Fixes - Arch - not skipping dependency checking when the user opts to proceed with a transaction that would break other packages - AUR: not restoring the CPUs to previous scaling governors after the package is built when optimizations are on - randomly crashing when solving repository packages dependencies (RuntimeError: dictionary changed size during iteration) + ## [0.9.15] 2021-03-03 ### Improvements - UI