Skip to content

Avoid lspci in favor of sysfs - #11259

Open
neheb wants to merge 1 commit into
omacom:quattrofrom
neheb:lspci
Open

neheb wants to merge 1 commit into
omacom:quattrofrom
neheb:lspci

Conversation

@neheb

@neheb neheb commented Sep 11, 2026 •

Copy link
Copy Markdown

Summary

Replace every lspci call with reads from /sys/bus/pci/devices via a small shared helper (install/helpers/pci-sysfs.sh). lspci reads PCI config space, which forces the kernel to runtime-suspend a device that has entered D3cold — on hybrid laptops this means a bare lspci can take over a second waking the discrete GPU. The cached sysfs fields (vendor, device, class, and the driver symlink) never touch config space, so nothing wakes.

Motivation

On hybrid laptops the discrete GPU idles in D3cold, and reading PCI config space forces a resume. This pays the wake penalty during config soaks and per-user setup, at the worst time in the boot/install flow. The vendor, device, class, and bound-driver information is already available from sysfs files the kernel caches — nothing there touches the device.

What changed

New shared helper — install/helpers/pci-sysfs.sh:

  • omarchy-pci-id <vendor> [device ...] — match by vendor + device ID
  • omarchy-pci-class-vendor <class> <vendor> — match by class prefix + vendor
  • omarchy-pci-class-count <class> — count devices with a given class prefix
  • omarchy-pci-driver <driver> — match by bound driver symlink

All matchers walk OMARCHY_PCI_DEVICES_PATH (defaulting to /sys/bus/pci/devices); tests point it at a fixture tree.

Hardware detectors migrated (14 files):

  • bin/omarchy-hw-hybrid-gpu — GPU count via omarchy-pci-class-count 0x03; also adds a timeout guard around supergfxctl so a wedged daemon no longer blocks the menu
  • bin/omarchy-hw-nvidia (new) — NVIDIA GPU detection via omarchy-pci-class-vendor 0x03 0x10de
  • bin/omarchy-hw-intel-sof (new) — Intel SOF audio DSP detection via omarchy-pci-class-vendor 0x04 0x8086
  • install/hardware/vulkan.sh, install/hardware/pacman.sh, install/hardware/apple/fix-t2.sh, install/hardware/apple/fix-brcmfmac-supplicant.sh, install/hardware/fix-bcm43xx.sh, install/hardware/fix-yt6801-ethernet-adapter.sh, install/hardware/intel/fix-wifi7-eht.sh, bin/omarchy-install-gaming-gpu-lib32 — all migrated to sysfs matchers

Nouveau cursor fix — install/user/hardware/fix-nouveau-cursor.sh now uses omarchy-pci-driver nouveau instead of lspci output, and no longer needs a guard that checked whether lspci was available (sysfs is always there).

Migrations — migrations/1784401744.sh, migrations/1785944594.sh, migrations/1786391100.sh updated to use the sysfs helpers.

Why lspci hurts on hybrid laptops

The kernel exposes PCI config space through /sys/bus/pci/devices/<slot>/config, and reading that file triggers a runtime resume if the device is suspended in D3cold. lspci reads config space for every PCI device it enumerates. On a hybrid laptop the discrete GPU typically sits in D3cold while the integrated GPU drives the display, so a single lspci call can force a >1 second wake — paid at the worst time: during config soaks and per-user setup. The vendor, device, class, and driver symlink in sysfs are cached by the kernel and served without waking the device.

Files changed

Area Files Net
New sysfs helper install/helpers/pci-sysfs.sh +69
Hardware detectors bin/omarchy-hw-hybrid-gpu, bin/omarchy-hw-nvidia (new), bin/omarchy-hw-intel-sof (new), bin/omarchy-install-gaming-gpu-lib32 +14 / -15
Install scripts install/hardware/vulkan.sh, install/hardware/pacman.sh, install/hardware/apple/fix-t2.sh, install/hardware/apple/fix-brcmfmac-supplicant.sh, install/hardware/fix-bcm43xx.sh, install/hardware/fix-yt6801-ethernet-adapter.sh, install/hardware/intel/fix-wifi7-eht.sh +81 / -23
Nouveau fix install/user/hardware/fix-nouveau-cursor.sh +6 / -6
Migrations migrations/1784401744.sh, migrations/1785944594.sh, migrations/1786391100.sh +16 / -8
Tests test/shell.d/pci-sysfs-test.sh (new), test/shell.d/base-test.sh, test/shell.d/hw-hybrid-gpu-test.sh, test/shell.d/hw-nvidia-test.sh, test/shell.d/brcmfmac-supplicant-test.sh, test/shell.d/nouveau-cursor-test.sh, test/shell.d/t2-hardware-test.sh +137 / -46

Total: 24 files, +319 / -97

Testing

  • ./test/shell passes
  • pci-sysfs-test.sh exercises all four matchers against fixture trees
  • Existing hardware-detection tests (hw-hybrid-gpu-test, hw-nvidia-test, t2-hardware-test, brcmfmac-supplicant-test, nouveau-cursor-test) updated to use the new write_pci_devices / bind_pci_driver test helpers from base-test.sh

andyholst added a commit to andyholst/omarchy that referenced this pull request Sep 12, 2026
- Add test/shell.d/hw-msi-test.sh with 11 detection tests
- Replace lspci with sysfs reads for RTL8125B detection (aligns with PR omacom#11259)
andyholst added a commit to andyholst/omarchy that referenced this pull request Sep 12, 2026
- Add test/shell.d/hw-msi-test.sh with 11 detection tests
- Replace lspci with sysfs reads for RTL8125B detection (aligns with PR omacom#11259)
@neheb
neheb force-pushed the lspci branch 2 times, most recently from 8c89a5f to f29ffad Compare September 28, 2026 19:54
@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Replaces hardware detection tool with sysfs-based helpers.

The PR appears safe to merge based on the changes since the previous review and the state of the previous threads.

Summary

The PR replaces PCI enumeration through lspci with shared sysfs matchers across hardware detection, installation, and migrations. Since the previous review, three standalone commands gained an installed-path fallback for loading the helper.

Reviews (4) · Last reviewed commit: "avoid lspci in favor of sysfs"

Comment thread bin/omarchy-hw-nvidia
Comment thread bin/omarchy-hw-intel-sof Outdated
Comment thread bin/omarchy-hw-intel-sof Outdated
@jandrusk

Copy link
Copy Markdown

The sysfs helpers look like the right direction (and avoid the lspci D3cold wake). Two consolidate notes:

  1. Detect BCM43xx, T2, Vulkan, and NVIDIA via sysfs helpers #12076 is another open PR doing BCM43xx/T2/Vulkan/NVIDIA via sysfs — please align so we don't land two parallel helpers.
  2. This also rewrites already-shipped migrations (1784401744, 1785944594, 1786391100). Those won't re-run for people who already migrated; if a backfill is needed, a new migration is safer. Rebase also needed (conflicts with quattro).

lspci reads PCI config space, and the kernel resumes a runtime-suspended
device to serve that read. On a hybrid laptop the discrete GPU idles in
D3cold, so a bare lspci can take over a second waking it — a cost paid at
the worst time: during config soaks and per-user setup.

Read the vendor, device, and class IDs from cached sysfs fields instead,
which never touch config space, via a small shared helper
(install/helpers/pci-sysfs.sh). T2 and Broadcom parts match by
vendor/device ID; Intel/AMD/Apple Intel-video packages by class prefix plus
vendor; the nouveau cursor fix by the bound driver symlink (dropping its
lspci-presence guard since sysfs is always there).
@omarchybot

Copy link
Copy Markdown
Collaborator

This pull request was classified at head 6e300ce, and the classification is unsettled, so it carries no class label yet. Opus 5.5 (Claude Code) read it as an enhancement: lspci works on these machines today and this changes how detection is done on purpose, to avoid waking a runtime-suspended discrete GPU. Codex Medium, asked separately from the pull request alone, read it as compatibility: a hardware-specific defect, the dGPU resume on hybrid laptops. Nothing was run on a worker, because verification waits on settling what this is.

Two things for whoever picks it up, checked against the diff: #12076 converts the same BCM43xx, T2, Vulkan and NVIDIA detection to sysfs with its own helpers, so the two overlap and only one approach should land; and the description still lists migrations and tests (migrations/1784401744.sh, test/shell.d/pci-sysfs-test.sh and others) that are not in the current diff of 12 files, and bin/omarchy-hw-hybrid-gpu and bin/omarchy-hw-nvidia already read sysfs on quattro.

This now waits on the maintainer to decide what it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants