Commit graph

353 commits

Author SHA1 Message Date
Francesco Palmarini
9813d814ae
Merge pull request #390 from ooonea/contrib/improvements
Multiple fixes and code cleanup
2026-04-20 21:49:42 +02:00
ooonea
4bf1faa900
mmio: document read64/write64 helpers
Short one-line docstrings mirroring the style of the existing
read32/write32 methods.

Signed-off-by: ooonea <35407790+ooonea@users.noreply.github.com>
2026-04-19 22:12:08 +02:00
ooonea
b9a0d8634d
throttled: use mmio.write64/read64 for MCHBAR PKG_POWER_LIMIT
Replaces the open-coded write32(0, low) + write32(4, high) pair
(and the matching read32 merge in the debug path) with a single
64-bit access. Besides being less code, this also closes a small
window between the two 32-bit writes in which the register briefly
held (new_low, old_high).

Signed-off-by: ooonea <35407790+ooonea@users.noreply.github.com>
2026-04-19 22:11:53 +02:00
ooonea
2b8f94b23e
mmio: add read64/write64 helpers
Mirror the existing read32/write32 pattern for 64-bit accesses. The
MCHBAR PKG_POWER_LIMIT register is naturally a single 64-bit field,
and having a symmetric helper avoids the open-coded split into two
32-bit writes at the call site.

Signed-off-by: ooonea <35407790+ooonea@users.noreply.github.com>
2026-04-19 22:11:20 +02:00
ooonea
8432e1dcdc
Efficiency: drop the duplicate is_on_battery call in power_thread
In polling mode, power['source'] is already set from is_on_battery
at the top of each iteration, so the HWP check was calling
is_on_battery a second time for the same value. Replace the whole
dbus-vs-polling branch with `power['source'] == 'AC'`, which is
correct for both methods and avoids the extra glob/file read (and a
fallback DBus round-trip).

Signed-off-by: ooonea <35407790+ooonea@users.noreply.github.com>
2026-04-19 21:58:10 +02:00
ooonea
1b815ea3fe
Style: convert to f-strings, add type hints to mmio, run Black
- Replace remaining .format() calls with f-strings (ruff UP032 plus
  manual cleanups for the formats ruff couldn't rewrite); replace
  the lone %-format in mmio.MMIO.__str__ as well.
- Hoist `UNDERVOLT.<source>` and `ICCMAX.<source>` section names to
  local variables in undervolt() / set_icc_max() so the f-string
  appears once.
- Add type hints to the public mmio.MMIO methods (the only real
  module boundary in the project).
- Run Black with the existing pyproject.toml config (line-length 120,
  skip-string-normalization). No semantic changes.

Signed-off-by: ooonea <35407790+ooonea@users.noreply.github.com>
2026-04-19 21:58:09 +02:00
ooonea
2fd89b747b
Clarity: drop dead code, add docstrings, prune dev-commentary
- Remove `from __future__ import print_function` (Python 3 only).
- mmio.py: drop the Python 2 `long = int` shim and `(int, long)`
  isinstance checks; make __enter__ return self so `with MMIO(...)`
  works as expected.
- Drop the redundant `value = config.set(...)` assignment in
  load_config (config.set returns None).
- Replace the personal "for my CPU" comments and the
  "ugly code, just testing..." comment with brief docstrings that
  describe what each helper computes.
- Add concise one-line docstrings to the public-ish functions
  (readmsr/writemsr, get_value_for_bits, is_on_battery, the various
  MSR getters/setters, load_config, calc_reg_values, power_thread,
  monitor, main, etc.) so a reader can navigate without reading the
  body.

Signed-off-by: ooonea <35407790+ooonea@users.noreply.github.com>
2026-04-19 21:58:09 +02:00
ooonea
a6a95bdc1c
Improve robustness: tighten exception handling and skip missing MSRs
- Replace bare `except:` clauses in set_msr_allow_writes, check_cpu,
  and the --log file open with specific exception types so we no
  longer swallow KeyboardInterrupt/SystemExit and we surface the
  actual error in the log.
- check_cpu now re-raises SystemExit instead of calling sys.exit
  again, and includes the underlying error in the fatal message.
- power_thread skips the PKG_POWER_LIMIT (and matching MCHBAR) write
  if no package power limit was computed, instead of KeyError'ing
  when all PL1/PL2 entries are commented out in the config.
- Strip ANSI color escapes when writing to the --log file. The
  OK/ERR/LIM constants embed ANSI codes intended for terminals and
  were leaking into log files.

Signed-off-by: ooonea <35407790+ooonea@users.noreply.github.com>
2026-04-19 21:58:08 +02:00
ooonea
dd60a9843f
Fix correctness bugs in throttled.py and mmio.py
- get_msr_list(): sort numerically and skip non-digit entries (like
  /dev/cpu/microcode). os.listdir() ordering is arbitrary, so the
  previous code returned readmsr() results indexed by enumeration
  order rather than CPU number, breaking the cpu= and flatten=True
  paths on systems where listdir didn't happen to return CPUs in
  order; it would also crash with ValueError when /dev/cpu contained
  any non-CPU entry.
- readmsr/writemsr: close MSR file descriptors via try/finally so a
  failed read/write doesn't leak the fd.
- is_on_battery(): replace bare `raise` (no active exception) and
  catch-all `except:` with specific exceptions; restore the intended
  fall-through to the upower fallback.
- test_msr_rw_capabilities(): declare TESTMSR global. The previous
  `TESTMSR = True` only created a local, so the in-flight detection
  could not actually catch MSR errors and would call fatal() instead.
- power_thread(): always sleep at end of loop. Previously the
  exit_event.wait was only reached in the else-branch of the HWP
  check, so when HWP fired the thread spun without sleeping.
- set_disable_bdprochot(): use `read_value == 0` for the debug
  match check; `~read_value` was always truthy.
- main(): initialize cpuid = None so --force does not raise
  UnboundLocalError when starting the power thread.
- mmio.py: map /dev/mem with PROT_READ | PROT_WRITE so read32 is
  defined and portable; close fd if mmap.mmap raises; fix __str__
  which referenced nonexistent self.base/self.size; drop dead
  self._fd assignment.

Signed-off-by: ooonea <35407790+ooonea@users.noreply.github.com>
2026-04-19 21:58:07 +02:00
Francesco Palmarini
26021c8cd3
Merge pull request #372 from sandy-8925/disabled_cpu_fix
Only attempt changing currently enabled CPUs
2026-01-19 21:54:03 +01:00
Francesco Palmarini
290a3ec0b9
Merge pull request #380 from CasperGamingOne/patch-1
Update tested hardware list in README
2026-01-19 21:52:52 +01:00
CasperGaming
d95106718e
Update tested hardware list in README
Added Precision 7720 to tested hardware list, it works for me best with thermald --adaptive; also setted both HWP to enabled and cTDP to be down and while with thermald it still reached 99 C and more :((; both combined and the rest are amazing, even having my cpu when idle down to 40 C which i barely managed to do.
2026-01-12 20:37:31 +02:00
Sandeep Raghuraman
76905a79e4 Only attempt changing currently enabled CPUs 2025-02-04 00:25:55 +05:30
Francesco Palmarini
a7bf1b3ccf
Merge pull request #371 from spinogrizz/master
Added LunarLake definition
2025-01-22 22:17:47 +01:00
Denis Gryzlov
773962fcc2 added lunar lake definition 2025-01-18 01:02:33 +03:00
Francesco Palmarini
daec74bb53
Merge pull request #369 from deepcube/emg-readme-thermald
Note thermald may be required on some platforms
2024-12-24 09:31:45 +01:00
Evan Gates
af3ff45b00 Note thermald may be required on some platforms 2024-12-23 09:51:28 -07:00
Francesco Palmarini
ba64023235
Merge pull request #364 from amolinae06/alpn-pkg
add alpine linux package to README
2024-11-06 17:48:43 +01:00
Francesco Palmarini
94cec8be19
Merge pull request #357 from voidanix/py313
Bump dependencies
2024-11-06 17:48:02 +01:00
amolinae
15ecc4e914 add alpine linux package to README 2024-10-24 08:33:13 -06:00
Francesco Palmarini
696da9f650
Merge pull request #363 from jcarrano/upower-batt-detection
Query UPower's OnBattery property directly.
2024-10-23 07:01:13 +02:00
Juan I Carrano
aca334a88b Query UPower's OnBattery property directly.
On some systems, the name of the battery or the adapter may be different. The code assumes
the adapter is called "line_power_AC" and the battery "BAT0" but in my system both are different.

UPower has the OnBattery property which we can query and this is more robust. Additionally, we
can do it directly throuth the dbus API without invoking a sub-process.
2024-10-17 23:20:30 +02:00
Francesco Palmarini
174d6f8cdc
Add more supported architectures 2024-09-08 16:28:24 +02:00
voidanix
e7e069e31e
Bump dependencies
Fixes building with Python 3.13 distros
2024-07-26 12:45:53 +02:00
Francesco Palmarini
06a1db99ae
Add RaptorLake U SKU 2024-07-24 08:11:53 +02:00
Francesco Palmarini
596ad496e8
Merge pull request #342 from yuri1969/gentoo-fix
Improve Gentoo systemd README description
2023-12-19 14:35:16 +01:00
yuri1969
5362a45477
Improve Gentoo systemd description 2023-12-14 23:42:16 +01:00
Francesco Palmarini
0b85b38bb4
Update README.md 2023-10-18 08:19:47 +02:00
Francesco Palmarini
e3d5ffd24c
Update README.md 2023-10-18 08:18:22 +02:00
Francesco Palmarini
98c10d5bb5
Merge pull request #321 from ckcr4lyf/patch/x390
Document support for X390
2023-10-18 08:12:37 +02:00
Francesco Palmarini
c7c35885fe
Merge pull request #336 from gdesmott/silverblue
README: document how to install on Fedora Silverblue
2023-10-18 08:12:17 +02:00
Guillaume Desmottes
b448e4bc25 README: document how to install on Fedora Silverblue 2023-07-14 21:59:00 +02:00
Raghu Saxena
94d58e36a5 Document support for X390 2022-12-01 16:45:19 +08:00
Francesco Palmarini
1dd726672f
Update README.md 2022-08-08 08:46:43 +02:00
Francesco Palmarini
77eb1ac080
Merge pull request #310 from lakotamm/patch-2
Adding Alder Lake -U -S and Tiger Lake as supported
2022-08-06 16:45:20 +02:00
lakotamm
4cbf36b2c1
Renamed Tiger Lake-H 2022-08-06 13:16:14 +02:00
lakotamm
cf765c5c99
Added support for i7-1195G7 2022-08-06 13:05:37 +02:00
lakotamm
ccc25f0371
Set default MCHBAR for more CPU families
Added MCHBAR_BASE 0xFEDC0001 as default for Alder Lake -HX, S and Tiger Lake
2022-08-06 12:01:02 +02:00
lakotamm
19a1d1ca41
Added Inspiron 16 Plus 7620 as tested hardware 2022-08-06 11:55:35 +02:00
lakotamm
b14295910b
Adding Alder Lake -U + 6 core -S as supported
As specified in the Intel 12th gen spec sheet, page 7:
https://cdrdv2.intel.com/v1/dl/getContent/682436
2022-08-06 11:34:52 +02:00
erpalma
cc5948b6f4 add support for Alder Lake + dyanamic MCHBAR base address 2022-08-05 17:01:09 +02:00
erpalma
aac6bb016c bump requirement versions 2022-08-05 17:00:37 +02:00
Francesco Palmarini
ab9641a93a
Merge pull request #304 from DL4AX/patch-1
Update README.md
2022-06-30 22:32:39 +02:00
Alexander Heinke
5820c587fb
Update README.md
Add ZBook Firefly 15 G7 as tested hardware
2022-06-08 13:40:08 +02:00
erpalma
fb788f9005 Upower now also reports "pending-charge", fixes #303 2022-06-03 08:16:53 +02:00
Francesco Palmarini
970001ec38
Merge pull request #298 from Troyhy/update-readme-for-ubuntu-install
Add python3-cairo-dev as requirement for ubuntu (21.10)
2022-03-13 15:39:06 +01:00
Toni Röyhy
038b8171e7
Add python3-cairo-dev as requirement for ubuntu (21.10)
Adds missing requirement to  run `sudo ./throttled/install.sh successfully.`
2022-03-11 17:08:36 +02:00
Francesco Palmarini
4b076e1496
Merge pull request #292 from tejaskale/master
Print total power in monitor mode.
2022-02-08 19:39:57 +01:00
Francesco Palmarini
581038c452
Merge pull request #294 from Connor-Frank/patch-1
compatability with non-bash /bin/sh symlinks
2022-02-03 15:15:14 +01:00
Connor Frank
ed5bf8cd90
compatability with non-bash /bin/sh symlinks
This fixes a problem with my recent commit. I used `[ "$INIT" == "systemd" ]` (and similar), which works in bash, but not in `/usr/bin/sh`. I changed it to `[ "$INIT" = "systemd" ]` (and similar) to correct this issue.
2022-01-31 13:39:33 +00:00