openbsd's new suspend and resume frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017....
TRANSCRIPT
![Page 1: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/1.jpg)
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
![Page 2: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/2.jpg)
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
![Page 3: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/3.jpg)
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
History
Early Days
KISSPower upPower off
![Page 4: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/4.jpg)
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
![Page 5: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/5.jpg)
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
![Page 6: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/6.jpg)
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
![Page 7: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/7.jpg)
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
![Page 8: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/8.jpg)
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
![Page 9: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/9.jpg)
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.
![Page 10: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/10.jpg)
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
![Page 11: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/11.jpg)
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)
![Page 12: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/12.jpg)
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.
![Page 13: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/13.jpg)
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
![Page 14: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/14.jpg)
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.
![Page 15: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/15.jpg)
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
![Page 16: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/16.jpg)
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
![Page 17: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/17.jpg)
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
![Page 18: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/18.jpg)
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
![Page 19: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/19.jpg)
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
![Page 20: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/20.jpg)
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()
![Page 21: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/21.jpg)
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()
![Page 22: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/22.jpg)
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
ACPI
Implementations
Microsoft WindowsIntel ACPICAOpenBSD
![Page 23: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/23.jpg)
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
![Page 24: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/24.jpg)
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())
![Page 25: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/25.jpg)
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
![Page 26: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/26.jpg)
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
![Page 27: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/27.jpg)
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
![Page 28: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/28.jpg)
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?
![Page 29: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/29.jpg)
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
![Page 30: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/30.jpg)
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
![Page 31: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/31.jpg)
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
![Page 32: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/32.jpg)
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
![Page 33: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/33.jpg)
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
![Page 34: OpenBSD's New Suspend and Resume Frameworkftp.openbsd.org/papers/zzz-presentation.pdf · 2017. 4. 2. · Introduction Device Configuration Activate Functions APM and ACPI IssuesConclusions](https://reader033.vdocuments.mx/reader033/viewer/2022051907/5ffaa6fa5c52092d7a62b228/html5/thumbnails/34.jpg)
Introduction Device Configuration Activate Functions APM and ACPI Issues Conclusions
So Long, and Thanks for All the Fish
Questions?