Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
OpenBSD’s New Suspend and ResumeFramework
Paul [email protected]
10th European BSD ConferenceOctober 6–9, 2011
Maarssen, The Netherlands
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Outline
1 IntroductionHistoryThe Winds of Change
2 Device Configuration3 Activate Functions
ChangesQuiesce
4 APM and ACPIDesignAPMACPI
5 IssuesOverviewQuirks
6 Conclusions
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
History
Early Days
KISSPower upPower off
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
History
Time Passes...
Power ManagementComputers start consuming less powerThe system gains some power controlAPM enters the sceneMachines can suspend and resume via APM
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
The Winds of Change
ACPI
The Machine Gets To Be In ChargeIn theory:
Knob fiddlingBetter controlMore features
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
The Winds of Change
Implications
Reality CheckExtremely complexSpecifications that nobody respectsEvery vendor has its own quirksThe machine has to do everything
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
The Winds of Change
Results
ACPINew power management approachAffects device drivers as wellHard to get rightFit into the APM logicLots of system changesNew MI suspend/resume framework
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Structure
Kernel Device TrackingTree hierarchyEverything starts at mainbus(4)Device drivers attach to the proper parent device
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Example
Dependency viewA memory stick is attached to the system
sd(4)scsibus(4)umass(4)uhub(4)usb(4)ehci(4)pci(4)mainbus(4)
The stick becomes available to the user as sd0.
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Configuration
Specific functionalityMatch – proper device driver matchingAttach – attach to a proper place in the device treeActivate – activate the deviceDeactivate – turn off the deviceDetach – remove it from the device tree
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Suspend and Resume
Low Power States ImplicationsACPI support required:
New system statesDriver awarenessDevice notification of state changesResult: The need for new activate actions in autoconf(9)
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Changes
New Actions
DVACT_QUIESCE
Prepare to suspend (discussed later on).
DVACT_SUSPEND
Set the device drivers in a suspend state.
DVACT_RESUME
Resume the device drivers back to running state.
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Changes
Expanding autoconf(9)
Code Changesconfig_suspend()
Similar with attach/detach activate/deactivateSignals the drivers
config_activate_children()
Handle the new casesconfig_suspend() the device’s children
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Quiesce
What is Quiesce?
DefinitionThe action of pausing or modifying a given process so that dataconsistency can be achieved.
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Quiesce
Why is it important?
Because...Some devices need pre-suspend notifications to:
Finish-up disk I/ODump audio buffersVT switch out of XWait on other actions to finishDo misc. operations requiring a ’normal’ running state
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Design
Starting Point
APM MachinesAPM userland daemonUserland notifies the kernelKernel APM MD state machinesLots of MD code, specially for devices
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Design
Integrating Other PM Implementations
RulesKeep the same APM mechanism.Mold other implementations into it.Make it opaque to the userland.Let the drivers do the work for them.Implementation specific bits in MDMostly whacky assembly routines
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Design
ACPI Implementation
Reiterating...ACPI will be fit in the same modelCreate a fake apm-like kernel ACPI state-machineKeep the same code-paths all the way downNo difference from a userland perspectiveOnly the kernel can tell APM and ACPI apart
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
APM
Improvements
More MI, Less MDThe BIOS does most of the workRemove MD device related codeLet the device drivers do it in their activate functionsBare MD APM state machine
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
APM
On Suspend
Code Flowwsdisplay_suspend()
bufq_quiesce()
config_suspend(DVACT_QUIESCE)
splhigh()
disableintr()
config_suspend(DVACT_SUSPEND)
sys_platform->suspend()
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
APM
On Resume
Code Flowsys_platform->resume()
config_suspend(DVACT_RESUME)
enableintr()
splx()
bufq_restart()
wsdisplay_resume()
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
ACPI
Implementations
Microsoft WindowsIntel ACPICAOpenBSD
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
ACPI
How It Works
System PerspectiveACPI is a proxy between the BIOS and the OSAccess AML methods according to the ACPI spec.Lots of spec violationsLots of quirks and workaroundsThe drivers have to handle device state
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
ACPI
APM-like
FlowThe userland needs no changeacpiioctl() – notfication ioctlSame commands as APMACPI tasks (e.g. acpi_sleep_task())
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
ACPI
On Suspend
Flowacpi_sleep_task(S3) – checks state changesacpi_sleep_mode(S3) – handles state changesacpi_prepare_sleep_state(S3) – AML nightmareacpi_sleep_machdep(S3) – MD codeacpi_enter_sleep_state(S3) – PM regs fiddling
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
ACPI
Not APM-Like
AML MethodsTTS – transition to state, before device notificationPTS – prepare to sleep, after device notificationSST – system status indicatorGTS – firmware execution before S3PM – power management registersGTE – wake registers
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
ACPI
On Resume
Completely different from APMReal-mode: ACPI trampolineReal-mode: Might reenable videoReal-mode: Enable pagingReal-mode: Restore CPU registersJump to where ACPI code stopped during suspendClear PM registersTransition to S0 (more AML methods)Reset the lampEnable runtime GPEsResume the device drivers
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Overview
Devices
ProblemsThe order in which we suspend/resume themThe device registersThe memory mapsHow much state do we need to keep?
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Overview
ACPI
No Man’s LandThe specifications are just a guide in realityAML is Windows-targetedAML is autogenerated codeMagic methods that poke into CMOS and whatnotThe AML parser is always finding quirks in production code
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Quirks
Video
RepostingCan be done by:
Real-mode BIOS callx86emuThe driver itselfNeed for an PCI ID tablenVidia is not supported at allEven then, some cards don’t work
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Quirks
USB
ProblemsMost machines have no problems (luck?)Some machines get their usb ports reset on resumeSome don’t get them at allKeep usb state vs whack the whole stack
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Quirks
Other
MiscellaneousMount points for usb drives don’t get restoredAudio sometimes gets trashedAucat doesn’t handle suspend/resumeX doesn’t come back on some machinesX gets some image noise, fixed by VT switchingTaking the cpu to 1-cpu is done at the wrong placeSome drivers are not supported yet
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
Don’t Panic
It Works!Most laptops are supportedMost workstations as wellThe sub-system is stableThe design is goodLoongson is the newest userLots of non suspend/resume bugs in drivers got fixed as aresult