Commit Graph

13 Commits

Author SHA1 Message Date
kellito 8157eda85f v5.1: cpufreqd scheme server - real cpufreq scheme, no more stub
G-A2 from DRIVER-MANAGER-MIGRATION-PLAN v4.8: thermald was
silently failing to switch governors because cpufreqd provided
no 'cpufreq' scheme. thermald writes /scheme/cpufreq/governor
(thermald/src/main.rs:38, :348-358); cpufreqd only wrote
/scheme/cpufreq/state via fs::write - the path was a stub.

Fix: cpufreqd now registers the 'cpufreq' scheme at startup via
redox-scheme::scheme::register_sync_scheme, exposing a real
Linux-compatible interface.

Path surface (read-write where noted):
- /scheme/cpufreq/governor                      (rw - global default)
- /scheme/cpufreq/cpu<N>/scaling_governor       (rw - per-CPU override)
- /scheme/cpufreq/cpu<N>/scaling_cur_freq       (ro)
- /scheme/cpufreq/cpu<N>/scaling_min_freq       (ro)
- /scheme/cpufreq/cpu<N>/scaling_max_freq       (ro)
- /scheme/cpufreq/cpu<N>/cpuinfo_min_freq       (ro)
- /scheme/cpufreq/cpu<N>/cpuinfo_max_freq       (ro)
- /scheme/cpufreq/cpu<N>/scaling_available_governors (ro)
- /scheme/cpufreq/cpu<N>/cpuinfo_cur_freq       (ro - alias)
- /scheme/cpufreq/control/governor              (rw - alias, thermald fallback)
- /scheme/cpufreq/state                        (ro - existing key=value)

Implementation:
- scheme.rs (NEW, 639 lines): SchemeSync impl, path parsing,
  per-CPU vs global governor resolution, atomic-rename
  persistence of last governor.
- main.rs: governor -> Arc<Mutex<Governor>>, cpus ->
  Arc<Mutex<Vec<CpuInfo>>>, spawn scheme server, removed the
  fs::write('/scheme/cpufreq/state') stub line, added
  Governor::as_str()/from_name(), 4 pre-existing clippy
  collapsible_if warnings fixed.
- Cargo.toml: added redox-scheme, libredox, syscall (redox_syscall)
  path deps with [patch.crates-io] per local AGENTS.md rules.

Lock ordering documented inline: governor -> overrides -> cpus.
Main loop snapshots governor+overrides before locking cpus so
the scheme server can never deadlock against it.

Linux-compat extras added (real functionality, not stubs):
scaling_available_governors (root + per-CPU), cpuinfo_cur_freq
alias, control/governor alias, getdents on all directories.

Per-CPU override behavior matches Linux: writing global governor
clears all per-CPU overrides; writing cpu<N>/scaling_governor
sets a per-CPU override. Main loop honors overrides via
effective_governor() each tick.

state format: now emits lowercase governor names (governor=ondemand)
instead of the old {:?} (governor=Ondemand). This matches
redbear-power's lowercase expectations.

Tests: 21 new (governor name parsing case-insensitive + rejection
of invalid, Arc<Mutex> round-trip, global-write-clears-overrides,
path parsing for cpu0/scaling_governor/governor/control/governor,
unknown-CPU/leaf rejection, per-CPU override fallback, frequency
helpers, state format backward compat, integration test). All pass.

Compile: cargo check --target x86_64-unknown-redox - zero new
warnings (only pre-existing libredox FFI warnings).

Constraints per local/AGENTS.md:
- No new branches (work on 0.3.1)
- No new Cat-2 dependencies (redox-scheme is already a path-dep)
- No stubs, no todo!/unimplemented!
- Cat 1 in-house recipe - source IS the durable location

Closes v5.1 of the v5.x work program. Closes G-A2 from v4.8.
2026-07-26 00:22:32 +09:00
vasilito 67db66681a comprehensive cleanup: remove dead code in cpufreqd, iommu, numad
Three Red Bear-original daemons had dead code that the compiler
flagged. Removed it; the fix is purely deletional — no functionality
changed.

cpufreqd (local/recipes/system/cpufreqd/source/src/main.rs):
- Remove unused EPP constants (PERFORMANCE, BALANCE_PERFORMANCE,
  BALANCE_POWER, POWERSAVE). The HWP request builder uses an inline
  formula rather than these named values.
- Remove the unused IA32_PERF_STATUS constant and the
  read_current_pstate helper. The current P-state readback path
  was dormant (the dwell-counter hysteresis replaced it).
- Remove the unused 'unsafe' block from the cpuid_hypervisor_bit
  call. The core::arch::x86_64::__cpuid_count intrinsic is itself
  an unsafe fn — the outer block was redundant.
- Remove unused PState.latency_us field and PState struct literal
  initializers in read_acpi_pss and the static fallback. The field
  was never read.
- Remove unused CpuInfo.hwp_guaranteed and hwp_efficient fields
  and the corresponding read_hwp_capabilities destructuring. The
  fields were never read after the initial extraction.

iommu (local/recipes/system/iommu/source/src/interrupt.rs):
- Add #[allow(dead_code)] to InterruptRemapTable.buffer. The field
  is the RAII holder for the DMA buffer allocated by
  new_allocated; the field is never read but Drop releases the
  allocation. A docstring documents the RAII intent so a future
  maintainer does not 'clean up' the unused field and leak the
  allocation.

numad (local/recipes/system/numad/source/src/main.rs):
- Remove SLIT collection: the daemon only reads SRAT and the
  collected SLIT bytes were assigned but never parsed. Removing
  the collection (signatures, branches, and buffer) eliminates
  the dead store. The SLIT_SIGNATURE constant goes with it.
- Remove unused MAX_NUMA_NODES constant.
- Remove unused SratMemory struct (SRAT Memory Affinity entry
  layout). The daemon only handles SratProcessorApic today.
- Remove dead w[4].parse() call in read_acpi_pss. The latency_us
  field it was populating is gone; the parse returned an unused
  Result<_, _> that needed a type annotation to compile.

Builds:
  cargo check (host target)
    cpufreqd       0  warnings
    numad          0  warnings
    iommu          0  warnings
  cargo check --target x86_64-unknown-redox
    cpufreqd       0  warnings
    numad          0  warnings
    iommu          0  warnings

Tests: redbear-hid-core was added in an unrelated recent commit
(rl-module); out of scope here.
2026-07-25 15:06:02 +09:00
vasilito 4ded365124 cpufreqd: only log transitions that actually happened; skip dwell on read-only
In read-only mode (detected VM/QEMU/KVM) apply_pstate is a no-op
so c.current_idx never advances. The previous log line was
emitted whenever the *requested* target (n) differed from
current_idx, regardless of whether the write actually fired —
on QEMU that produced thousands of P0->P1 lines per boot even
though no transition ever took place.

Gate the info!() on whether current_idx actually changed. Also
skip the dwell accumulation entirely on read-only hosts: writes
cannot take effect, so the hysteresis counter is meaningless.
The governor still tracks the target so the load value
reflects real demand, but no work fires per poll.

Closes Phase H of the LG Gram 16 (2025) S/P-state work.
2026-07-01 00:03:32 +03:00
vasilito 68b1f74dbf cpufreqd: correct VM detection paths (Redox DMI + CPUID hypervisor bit)
The earlier commit (6d1b11726) read /sys/class/dmi/id/sys_vendor
and /sys/class/dmi/id/product_name. Those are the Linux paths.
Redox exposes SMBIOS fields at /scheme/acpi/dmi/<field> via the
acpid userspace daemon. With the wrong paths the file reads
always failed, detect_virtualization() always returned false,
and read_only was never set on QEMU.

Now we read /scheme/acpi/dmi/sys_vendor and product_name (the
Redox-correct paths), and as a fallback when SMBIOS is absent
or uninformative we check the CPUID hypervisor-present bit
(leaf 1 ECX bit 31) via inline assembly. The CPUID pattern
mirrors local/recipes/system/redbear-power/source/src/cpuid.rs:168
which already uses this bit for the same purpose.

When either signal indicates virtualization, every CpuInfo is
constructed with read_only = true and apply_pstate() short-
circuits at the top. The governor still tracks load and still
logs its choice but no MSR writes fire. On bare metal the
existing path is preserved exactly.

The companion kernel fix in local/sources/kernel (commit
c2312627 on master) corrects a path-strip bug in the sys
scheme dispatcher that was preventing every MSR open from
succeeding with ENOENT. With both fixes together, cpufreqd
on QEMU enters read-only mode and the Ondemand governor stops
the P0->P1->P0 oscillation.
2026-06-30 23:58:33 +03:00
vasilito 6d1b117264 cpufreqd: detect virtualized host, skip MSR writes on QEMU/VM
QEMU's PIIX4 emulation does not model IA32_PERF_STATUS, so the
dwell counter cannot confirm a state transition actually took
effect and the governor oscillates P0<->P1 on idle. On a real
hypervisor (QEMU/KVM, VMware, VirtualBox, Hyper-V, Xen) the MSR
writes are also typically no-ops on the underlying emulation.

detect_virtualization() reads /sys/class/dmi/id/sys_vendor and
product_name. If the system vendor contains 'qemu', 'kvm',
'vmware', 'virtualbox', 'hyper-v', or 'xen', CpuInfo is
constructed with read_only=true and apply_pstate() short-
circuits at the top: the load value is still tracked and the
governor still logs its choice, but no MSR writes fire. On
real hardware (LG Gram 2025, etc.) the existing behavior is
preserved exactly.

The redundant DWELL_CYCLES constant is removed (DWELL_POLLS
already serves that role).

Phase H of CONSOLE-TO-KDE-DESKTOP-PLAN.md.
2026-06-30 22:26:06 +03:00
vasilito 5780fbc1ce cpufreqd: auto-detect virtualization for MSR read-only mode 2026-06-30 22:23:00 +03:00
vasilito 3e57b52a2d cpufreqd: add MSR readback and hysteresis to prevent P-state thrashing 2026-06-30 22:20:04 +03:00
Red Bear OS d24d0e2174 cpufreqd: add HWP (Hardware P-states / Intel Speed Shift) detection
Phase G.2 of the ACPI/Arrow Lake port. The LG Gram 2025 (Core Ultra 7
255H, Arrow Lake-H) uses Intel HWP for P-state control — legacy
IA32_PERF_CTL writes are silently ignored when HWP is active.

The previous cpufreqd always wrote IA32_PERF_CTL (MSR 0x199), which
on Arrow Lake-H had zero effect. We now:

1. Detect HWP at startup by reading IA32_PM_ENABLE (MSR 0x770) bit 0
2. If HWP is active:
   a. Read IA32_HWP_CAPABILITIES (MSR 0x771) for the
      min/max/guaranteed/efficient performance range
   b. Translate the governor's P-state index into the HWP
      "Desired Performance" field + EPP hint
   c. Write IA32_HWP_REQUEST (MSR 0x774) instead of IA32_PERF_CTL
3. If HWP is not active, fall back to the legacy IA32_PERF_CTL path
   (preserves backward compatibility for older CPUs)

The kernel's new /scheme/sys/msr/ scheme (Phase G.1) provides the
in-memory storage backing the MSR reads/writes. On the real LG Gram
2025 hardware, the kernel's MSR scheme will be wired to the actual
hardware MSRs (Phase G+ work); the cpufreqd interface is unchanged.

HWP layout (Intel SDM Vol 3B §14.4.4):
  [7:0]    Minimum Performance
  [15:8]   Maximum Performance
  [23:16] Desired Performance
  [31:24] Energy-Performance Preference (EPP)
  [42:32] Activity Window (0 = auto)
  [42]    Package Control

EPP follows the same index as desired perf: 0 = performance,
255 = power-save. We map the linear P-state index to both the
"Desired Performance" and EPP so the H/W sees a single hint that
the OS wants both the performance and energy level it implies.

Includes:
- PstateMode enum (LegacyPerfCtl | Hwp) for compile-time dispatch
- detect_pstate_mode() reads MSR 0x770
- read_hwp_capabilities() reads MSR 0x771, returns (min, max,
  guaranteed, efficient) bytes
- hwp_request_for() maps P-state index to IA32_HWP_REQUEST u64
- apply_pstate() dispatches to the right MSR based on ci.mode
- The /scheme/cpufreq/state output now tags each CPU with [HWP] or
  [legacy] for observability

Hardware test plan: on the LG Gram 2025, "performance" governor
should pin IA32_HWP_REQUEST.Desired = hwp_max with EPP=0; "powersave"
should pin it to hwp_min with EPP=255; "ondemand" should ramp
between. Reading IA32_PERF_STATUS (MSR 0x198) via /scheme/sys/msr
should reflect the new operating point within ~1ms.
2026-06-30 12:53:57 +03:00
vasilito 909cce0f5d cpufreqd, redbear-power: read CPU count from /scheme/sys/cpu
On Redox the kernel's sys:cpu scheme is a single file (kernel/src/scheme/
sys/cpu.rs) whose contents start with 'CPUs: N\n', not a per-CPU directory.
The kernel does not create /dev/cpu/ at all, so the prior read_dir-based
enumeration always fell through to the single-CPU fallback on Redox —
hiding the fact that the kernel had successfully brought up the APs and
reporting only CPU 0 to the governor / power TUI.

Read /scheme/sys/cpu and parse the 'CPUs:' line first; fall back to
/dev/cpu/ for Linux hosts.
2026-06-28 16:26:30 +03:00
vasilito 04b7641e85 config: add x11proto dependency for libxau and SDDM
- Add x11proto to redbear-full.toml package list
- libxau recipe updated with x11proto dependency and custom build script
- Fixes libxau build failure: 'Package xproto was not found'
2026-06-20 14:57:46 +03:00
vasilito b723b276f5 fix: cpufreqd MSR spam, udev-shim PCI spam, scheme throttle, keymaps dir
- cpufreqd: suppress MSR errors after 1 failure (was 10)
- udev-shim: demote PCI scan failures from WARN to DEBUG
- accessibility/ime/keymapd: throttle EBADF loop with 100ms sleep
- config: create /etc/keymaps directory for keymapd
2026-05-04 14:28:19 +01:00
vasilito 48ec92b486 fix: udev-shim panic, sessiond duplicate, scheme Bad-fd handling
- udev-shim: replace .expect() with graceful errors (no more panic on Broken pipe)
- P4-initfs: remove duplicate sessiond (conflicted with config)
- accessibility/ime/keymapd: break instead of exit(1) on EBADF
- P6 driver patches rebased
- Docs: archive old reports, add implementation master plan
2026-05-04 14:04:03 +01:00
vasilito a140014226 feat: recipe durability guard — prevents build system from deleting local recipes
Add guard-recipes.sh with four modes:
- --verify: check all local/recipes have correct symlinks into recipes/
- --fix: repair broken symlinks (run before builds)
- --save-all: snapshot all recipe.toml into local/recipes/
- --restore: recreate all symlinks from local/recipes/ (run after sync-upstream)

Wired into apply-patches.sh (post-patch) and sync-upstream.sh (post-sync).
This prevents the build system from deleting recipe files during
cargo cook, make distclean, or upstream source refresh.
2026-04-30 18:47:03 +01:00