Repository navigation
Expand file tree
/
Copy pathnextbsd-e17-tickets.html
More file actions
1659 lines (1476 loc) · 130 KB
/
Copy pathnextbsd-e17-tickets.html
File metadata and controls
1659 lines (1476 loc) · 130 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>E17 ticket drafts — power management</title>
<style>
:root {
--bg: #fbfbf8;
--fg: #1a1a1a;
--muted: #555;
--accent: #b03000;
--accent2: #0a4d68;
--ok: #1f7a1f;
--warn: #b06800;
--bad: #b00020;
--code-bg: #f0ece4;
--rule: #d6cfc0;
--card: #fff;
}
html { -webkit-text-size-adjust: 100%; }
body { margin: 0 auto; max-width: 1080px; padding: 2.5rem 1.5rem 6rem;
font: 16px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
color: var(--fg); background: var(--bg); }
h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 .25rem; }
h2 { font-size: 1.4rem; margin: 2.5rem 0 .75rem; padding-bottom: .25rem; border-bottom: 2px solid var(--rule); }
h3 { font-size: 1.15rem; margin: 1.75rem 0 .5rem; color: var(--accent2); }
h4 { margin: 1.25rem 0 .35rem; }
.subtitle { color: var(--muted); font-size: 1.05rem; margin: 0 0 2rem; }
code, pre, kbd { font-family: "SF Mono", Menlo, Consolas, monospace; }
code { background: var(--code-bg); padding: 1px 5px; border-radius: 3px; font-size: .9em; }
pre { background: var(--code-bg); padding: .85rem 1rem; border-radius: 6px;
overflow-x: auto; font-size: .82rem; line-height: 1.45;
border-left: 3px solid var(--accent2); }
pre code { background: none; padding: 0; }
pre.shell { border-left-color: var(--ok); }
pre.c { border-left-color: var(--accent); }
a { color: var(--accent2); }
a:hover { color: var(--accent); }
.tldr { background: var(--card); border: 1px solid var(--rule); border-left: 4px solid var(--accent2);
padding: 1rem 1.25rem; border-radius: 6px; margin-bottom: 2rem; }
.tldr h3 { margin-top: 0; color: var(--accent2); }
.pill { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 999px;
background: #eee; color: #333; margin-left: .35rem; vertical-align: middle;
font-weight: 600; letter-spacing: .02em; }
.pill.ok { background: #d8efd8; color: var(--ok); }
.pill.warn { background: #f6e4cb; color: var(--warn); }
.pill.bad { background: #f5d0d6; color: var(--bad); }
.pill.info { background: #d6e6f3; color: var(--accent2); }
table { border-collapse: collapse; width: 100%; margin: 1rem 0; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .65rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { background: #eee5d6; }
tr:nth-child(even) td { background: #faf6ed; }
table.compact td, table.compact th { padding: .35rem .55rem; font-size: .88rem; }
.nav { position: sticky; top: 0; background: var(--bg); margin: -2.5rem -1.5rem 2rem;
padding: .75rem 1.5rem; border-bottom: 1px solid var(--rule);
font-size: .88rem; z-index: 10; }
.nav a { margin-right: .9rem; text-decoration: none; }
.gap { background: #fff5f5; border-left: 4px solid var(--bad); padding: .8rem 1rem; margin: 1rem 0; border-radius: 0 6px 6px 0; }
.gap strong { color: var(--bad); }
.resolved { background: #ecf7ec; border-left: 4px solid var(--ok); padding: .8rem 1rem; margin: 1rem 0; border-radius: 0 6px 6px 0; }
.resolved strong { color: var(--ok); }
.open-q { background: #fff8d6; border: 1px solid #e5d76b; padding: .8rem 1rem; margin: 1rem 0; border-radius: 6px; font-size: .92rem; }
.open-q strong { color: #7a5e00; }
.risk { background: #fff5f5; border: 1px solid #e7b8bf; border-left: 4px solid var(--bad); padding: .8rem 1rem; margin: 1rem 0; border-radius: 6px; font-size: .93rem; }
.risk strong { color: var(--bad); }
.ascii-diagram { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .82rem; line-height: 1.3; white-space: pre; background: var(--code-bg); padding: 1rem; border-radius: 6px; overflow-x: auto; }
.rec { background: #eef4f8; border: 1px solid #bcd4e2; border-left: 4px solid var(--accent2); padding: 1rem 1.25rem; margin: 1.25rem 0; border-radius: 6px; }
.rec strong { color: var(--accent2); }
.yesno { font-weight: 600; }
.yesno.yes { color: var(--ok); }
.yesno.no { color: var(--bad); }
.yesno.partial { color: var(--warn); }
</style>
<style>
.tk { background: var(--card); border: 1px solid var(--rule); border-left: 4px solid var(--accent2); border-radius: 6px; padding: .9rem 1.1rem .4rem; margin: 1.25rem 0; }
.tk h3 { margin-top: .1rem; }
.tk .meta { font-size: .88rem; margin: .25rem 0 .6rem; border-collapse: collapse; }
.tk .meta td { padding: .15rem .8rem .15rem 0; vertical-align: top; }
.tk .meta td:first-child { color: var(--muted); white-space: nowrap; }
.tk pre { white-space: pre-wrap; word-wrap: break-word; }
.tk-epic { border-left-color: var(--accent); }
</style>
</head><body>
<nav class="nav">
<a href="#tldr">TL;DR</a>
<a href="#before">Before filing</a>
<a href="#label">Label</a>
<a href="#epic">Epic</a>
<a href="#index">Index</a>
<a href="#tickets">Tickets</a>
<a href="#linked">Linked issues</a>
<a href="#recreate">Recreating</a>
</nav>
<h1>E17 ticket drafts — power management <span class="pill ok">Filed 2026-09-21</span></h1>
<p class="subtitle"><strong>Every issue for EPIC E17, written out in full — and now filed.</strong> This page is the companion to <a href="nextbsd-power-management-plan.html">NextBSD power management</a>. It records the epic, the new <code>area:power</code> label and all 28 child tickets: title, target repo, labels, dependencies, and the exact Markdown body for each. The plan's ticket map is generated from the same source as this page. <strong>Filed on 2026-09-21</strong> as epic <a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a> and 28 child issues, attached as GitHub sub-issues and placed on the Roadmap. The bodies below are what was filed; each issue also carries a footer naming its parent and its dependencies by issue number. E16 was already taken by Bluetooth (nextbsd#473), so this is E17.</p>
<section id="tldr" class="tldr">
<h3>TL;DR</h3>
<ul>
<li><strong>28 child tickets</strong> across four repos, plus the epic <a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a> and the <code>area:power</code> label.</li>
<li><strong>Tracks:</strong> K = kernel bridge · L = libIOKit · D = pmconfigd · C = pmset/caffeinate · S = shutdown and scheduling · V = display and idle · M = the MIG decision · T/E/R = CI, packaging, kernel-later spike.</li>
<li><strong>Order:</strong> K1, K2, K3, K5, K6 and D1 start in parallel; M1 is decided early. K4 follows K1/K3/K5/K6, then K7. D2 needs K4 and L1; D3 needs K7; D4 then D5; L2/L3 follow D3/D4, L4 follows D5; C2 as soon as L3 exists, C1 last. S1 is independent; S2 after S1; S3 and R1 are spikes. T1 and E1 track the rest.</li>
<li><strong>Decide M1 early</strong> — several D, L and C tickets wait on it.</li>
<li><strong>Machine-readable:</strong> every field is also embedded as JSON (<code><script id="e17-data"></code>).</li>
</ul>
</section>
<h2 id="before">Done before filing</h2>
<div class="resolved"><strong>1. Label — done.</strong> <code>area:power</code> was created in all four repos below.</div>
<div class="resolved"><strong>2. Roadmap — done.</strong> <code>E17 Power management</code> was added to the Epic dropdown with all 16 existing options passed back by id; a before-and-after snapshot of all 429 board items showed no Epic value changed. The epic was added to the project, its sub-issues followed automatically, and all 29 items carry Epic = E17 and Status = Backlog.</div>
<div class="resolved"><strong>3. Epic number — confirmed.</strong> E1–E16 existed; E17 was free when filed.</div>
<h2 id="label">Label</h2>
<table class="compact">
<tr><td>Name</td><td><code>area:power</code></td></tr>
<tr><td>Description</td><td>Power management: pmconfigd, IOPMLib, power sources, ACPI sleep/wake, cpufreq, reboot/shutdown</td></tr>
<tr><td>Colour</td><td><code>#fbca04</code></td></tr>
<tr><td>Create in</td><td><a href="https://github.com/nextbsd/nextbsd">nextbsd</a>, <a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a>, <a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a>, <a href="https://github.com/nextbsd/nextbsd-freebsd-compat">nextbsd-freebsd-compat</a></td></tr>
</table>
<h2 id="epic">Epic</h2>
<div class="tk tk-epic" id="e17">
<h3>EPIC: E17 Power management — pmconfigd, IOPMLib/IOPowerSources, ACPI sleep/wake, pmset/caffeinate</h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd">nextbsd</a></td></tr>
<tr><td>Labels</td><td><code>epic</code> <code>area:power</code></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Power management the Darwin way. Apple's `pmconfigd` (shipped as `powerd`) runs as a launchd MachService and plays the role xnu's in-kernel `IOPMrootDomain` plays toward applications, over a small **in-kernel ACPI bridge** that publishes an `IOPMrootDomain` node and `IOPMPowerSource` nodes into the existing `/dev/ioregistry`.
**Read first:** https://pkgdemon.github.io/nextbsd-power-management-plan.html
**Ticket drafts (full bodies):** https://pkgdemon.github.io/nextbsd-e17-tickets.html
## Why
- Nothing from Apple's PowerManagement, and none of Apple's reboot/shutdown/halt, is vendored today. FreeBSD's `powerd` ships but **no LaunchDaemon runs it**, so CPU frequency is unmanaged on laptops.
- **Sleep skips userland entirely.** FreeBSD's `acpi_ReqSleepState` enters S3 at once when nothing holds `/dev/devctl` open -- "If devd(8) is not running, immediately enter the sleep state" -- and devd is gone. No process is told before a suspend, and no `Resume` event is ever sent.
- Every prerequisite has landed: the in-kernel IORegistry (K1/K2), kernel-originated Mach notifications, notifyd, ASL, configd, launchd MachServices.
## Direction (agreed)
Hybrid: userspace `pmconfigd` now, with the bridge shaped so an in-kernel root domain can replace it later (spike R1). v1: power sources + `pmset -g`; assertions + `caffeinate`; ACPI S3 sleep/wake with apps notified; reboot/shutdown/halt + `pmset schedule`. amd64 ACPI laptops first.
## Tracks
- **K** -- kernel bridge and FreeBSD patches
- **L** -- libIOKit power APIs
- **D** -- pmconfigd
- **C** -- pmset / caffeinate
- **S** -- reboot/shutdown/halt and scheduling
- **V** -- display sleep and idle time
- **M** -- the MIG out-of-line decision
- **T / E / R** -- CI, packaging, kernel-later spike
## Children
Replace IDs with issue numbers once filed.
- [ ] K1 kernel: acpi_ReqSleepState waits for a registered sleep listener instead of a /dev/devctl reader; ack timeout becomes tunable
- [ ] K2 kernel: fixed-feature power button emits an ACPI Button event, and the wake PWRBTN status is recorded before it is cleared
- [ ] K3 kernel: devctl_notify hook becomes a list, so an in-kernel bridge can consume ACPI events while /dev/devctl stays unopened
- [ ] K4 kernel: iopmroot bridge driver -- IOPMrootDomain0 node and /dev/iopmroot user client for sleep request, acknowledgement and state
- [ ] K5 kernel: IORegistry property-provider hook, so a driver can add keys to its own node
- [ ] K6 kernel: IORegistry interest notifications -- IOREG_EVENT_INTEREST and an 'IOIN' Mach message carrying messageType, messageArgument and serial
- [ ] K7 kernel: IOPMPowerSource nodes for ACPI batteries and AC, with Apple's power-source keys
- [ ] M1 Decide: pmconfigd's out-of-line MIG routines -- fix OOL in mach.ko (nextbsd#66) or route them over XPC
- [ ] D1 pmconfigd: vendor PowerManagement-1846.120.8.0.1 and boot a minimal daemon as the com.apple.powerd MachService
- [ ] D2 pmconfigd: one kernel shim -- root-domain selectors become /dev/iopmroot ioctls, and 'IOIN' interest messages drive the daemon
- [ ] D3 pmconfigd: power sources from IOPMPowerSource nodes -- kIOPS dictionaries, notify state bits, and an AC-only source when there is no battery
- [ ] D4 pmconfigd: assertion engine and idle-sleep policy -- PreventUserIdleSystemSleep/DisplaySleep, PreventSystemSleep, sleep and displaysleep timers
- [ ] D5 pmconfigd: S3 sleep/wake orchestration -- CanSystemSleep, WillSleep, WillNotSleep, WillPowerOn, HasPoweredOn, with a 30 s acknowledgement budget
- [ ] D6 pmconfigd: publish power state for Gershwin in SCDynamicStore -- battery %, AC, lid, sleep pending
- [ ] D7 pmconfigd: CPU power policy -- set Intel HWP EPP by AC/battery profile; replaces FreeBSD powerd, with an interim LaunchDaemon until then
- [ ] L1 libIOKit: IOServiceAddInterestNotification over 'IOIN', and IORegistryEntrySetCFProperty on the root domain
- [ ] L2 libIOKit: IOPowerSources (ps.subproj) -- IOPSCopyPowerSourcesInfo and friends, plus <IOKit/ps/*.h>
- [ ] L3 libIOKit: IOPMAssertion API and the IOPMLib / IOPMLibPrivate headers
- [ ] L4 libIOKit: IORegisterForSystemPower, IOAllowPowerChange, IOCancelPowerChange and IOPMSleepSystem re-aimed at pmconfigd
- [ ] C1 pmset: port pmset.m -- -g, -g batt, -g assertions, -g log, sleepnow, displaysleep/sleep settings, schedule
- [ ] C2 caffeinate: port caffeinate.c
- [ ] S1 reboot/shutdown/halt: vendor Apple's system_cmds versions over the BSD PID-1 signal protocol launchd already honours
- [ ] S2 pmconfigd: pmset schedule sleep/shutdown/restart performed by pmconfigd itself; wake/poweron waits on S3's RTC alarm
- [ ] S3 Spike: an RTC wake alarm for pmset schedule wake -- FreeBSD has no rtcwake
- [ ] V1 Display sleep and HID idle time without IODisplayWrangler -- pmconfigd owns display idle
- [ ] T1 CI: power boot markers -- PM-BOOT-OK, PM-PS-OK, PM-ASSERT-OK, and PM-SLEEP-OK through QEMU S3
- [ ] E1 Packaging: power LaunchDaemons, build blocks, man pages, compat strip entries, and ACPI sysctl defaults
- [ ] R1 Spike: an in-kernel IOPMrootDomain -- move the sleep/wake fan-out, acknowledgements and policy into iopmroot
## Linked, not sub-issues
- nextbsd/nextbsd#225 (E6) -- Retire /dev/devctl for IOKit notifications -- K3 keeps it inert
- nextbsd/nextbsd#66 (E1) -- MIG out-of-line data -- decides M1
- nextbsd/nextbsd#115 (E9) -- system_cmds port -- its IOPMLib-stub item is delivered by S1
- nextbsd/nextbsd#395 (E11) -- Display brightness -- same pref-pane seam as D6 and V1
- nextbsd/nextbsd#179 (E6) -- ko-to-kext -- needed for acpi_video, coretemp, amdtemp
- nextbsd/nextbsd#182 (E6) -- kext_tools / OSKext -- the kextmanager reboot lock S1 must serve or drop
- nextbsd/nextbsd#390 (E5) -- GPU re-init races -- wake from S3 must re-check /dev/dri
- nextbsd/nextbsd#428 (E10) -- Test gates pass at the login prompt -- pairs with T1</code></pre>
</div>
<h2 id="index">Index</h2>
<table class="compact">
<tr><th>ID</th><th>Ticket</th><th>Repo</th><th>Depends on</th><th>Status</th><th>Issue</th></tr>
<tr><td><a href="#k1"><strong>K1</strong></a></td><td>kernel: acpi_ReqSleepState waits for a registered sleep listener instead of a /dev/devctl reader; ack timeout becomes tunable</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td><td>—</td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/238">nextbsd-kernel#238</a></td></tr>
<tr><td><a href="#k2"><strong>K2</strong></a></td><td>kernel: fixed-feature power button emits an ACPI Button event, and the wake PWRBTN status is recorded before it is cleared</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td><td>—</td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/239">nextbsd-kernel#239</a></td></tr>
<tr><td><a href="#k3"><strong>K3</strong></a></td><td>kernel: devctl_notify hook becomes a list, so an in-kernel bridge can consume ACPI events while /dev/devctl stays unopened</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td><td>—</td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/240">nextbsd-kernel#240</a></td></tr>
<tr><td><a href="#k4"><strong>K4</strong></a></td><td>kernel: iopmroot bridge driver -- IOPMrootDomain0 node and /dev/iopmroot user client for sleep request, acknowledgement and state</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td><td><a href="#k1">K1</a>, <a href="#k3">K3</a>, <a href="#k5">K5</a>, <a href="#k6">K6</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/243">nextbsd-kernel#243</a></td></tr>
<tr><td><a href="#k5"><strong>K5</strong></a></td><td>kernel: IORegistry property-provider hook, so a driver can add keys to its own node</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td><td>—</td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/241">nextbsd-kernel#241</a></td></tr>
<tr><td><a href="#k6"><strong>K6</strong></a></td><td>kernel: IORegistry interest notifications -- IOREG_EVENT_INTEREST and an 'IOIN' Mach message carrying messageType, messageArgument and serial</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td><td>—</td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/242">nextbsd-kernel#242</a></td></tr>
<tr><td><a href="#k7"><strong>K7</strong></a></td><td>kernel: IOPMPowerSource nodes for ACPI batteries and AC, with Apple's power-source keys</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td><td><a href="#k4">K4</a>, <a href="#k5">K5</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/244">nextbsd-kernel#244</a></td></tr>
<tr><td><a href="#m1"><strong>M1</strong></a></td><td>Decide: pmconfigd's out-of-line MIG routines -- fix OOL in mach.ko (nextbsd#66) or route them over XPC</td><td><a href="https://github.com/nextbsd/nextbsd">nextbsd</a></td><td>—</td><td><span class="pill warn">needs answer</span></td><td><a href="https://github.com/nextbsd/nextbsd/issues/491">nextbsd#491</a></td></tr>
<tr><td><a href="#d1"><strong>D1</strong></a></td><td>pmconfigd: vendor PowerManagement-1846.120.8.0.1 and boot a minimal daemon as the com.apple.powerd MachService</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td>—</td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/224">nextbsd-userland#224</a></td></tr>
<tr><td><a href="#d2"><strong>D2</strong></a></td><td>pmconfigd: one kernel shim -- root-domain selectors become /dev/iopmroot ioctls, and 'IOIN' interest messages drive the daemon</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d1">D1</a>, <a href="#k4">K4</a>, <a href="#l1">L1</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/226">nextbsd-userland#226</a></td></tr>
<tr><td><a href="#d3"><strong>D3</strong></a></td><td>pmconfigd: power sources from IOPMPowerSource nodes -- kIOPS dictionaries, notify state bits, and an AC-only source when there is no battery</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d1">D1</a>, <a href="#k7">K7</a>, <a href="#m1">M1</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/227">nextbsd-userland#227</a></td></tr>
<tr><td><a href="#d4"><strong>D4</strong></a></td><td>pmconfigd: assertion engine and idle-sleep policy -- PreventUserIdleSystemSleep/DisplaySleep, PreventSystemSleep, sleep and displaysleep timers</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d1">D1</a>, <a href="#d2">D2</a>, <a href="#m1">M1</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/228">nextbsd-userland#228</a></td></tr>
<tr><td><a href="#d5"><strong>D5</strong></a></td><td>pmconfigd: S3 sleep/wake orchestration -- CanSystemSleep, WillSleep, WillNotSleep, WillPowerOn, HasPoweredOn, with a 30 s acknowledgement budget</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d2">D2</a>, <a href="#k1">K1</a>, <a href="#k4">K4</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/229">nextbsd-userland#229</a></td></tr>
<tr><td><a href="#d6"><strong>D6</strong></a></td><td>pmconfigd: publish power state for Gershwin in SCDynamicStore -- battery %, AC, lid, sleep pending</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d3">D3</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/230">nextbsd-userland#230</a></td></tr>
<tr><td><a href="#d7"><strong>D7</strong></a></td><td>pmconfigd: CPU power policy -- set Intel HWP EPP by AC/battery profile; replaces FreeBSD powerd, with an interim LaunchDaemon until then</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d3">D3</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/231">nextbsd-userland#231</a></td></tr>
<tr><td><a href="#l1"><strong>L1</strong></a></td><td>libIOKit: IOServiceAddInterestNotification over 'IOIN', and IORegistryEntrySetCFProperty on the root domain</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#k6">K6</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/225">nextbsd-userland#225</a></td></tr>
<tr><td><a href="#l2"><strong>L2</strong></a></td><td>libIOKit: IOPowerSources (ps.subproj) -- IOPSCopyPowerSourcesInfo and friends, plus <IOKit/ps/*.h></td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d3">D3</a>, <a href="#m1">M1</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/232">nextbsd-userland#232</a></td></tr>
<tr><td><a href="#l3"><strong>L3</strong></a></td><td>libIOKit: IOPMAssertion API and the IOPMLib / IOPMLibPrivate headers</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d4">D4</a>, <a href="#m1">M1</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/233">nextbsd-userland#233</a></td></tr>
<tr><td><a href="#l4"><strong>L4</strong></a></td><td>libIOKit: IORegisterForSystemPower, IOAllowPowerChange, IOCancelPowerChange and IOPMSleepSystem re-aimed at pmconfigd</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d5">D5</a>, <a href="#l1">L1</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/234">nextbsd-userland#234</a></td></tr>
<tr><td><a href="#c1"><strong>C1</strong></a></td><td>pmset: port pmset.m -- -g, -g batt, -g assertions, -g log, sleepnow, displaysleep/sleep settings, schedule</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d1">D1</a>, <a href="#d3">D3</a>, <a href="#l2">L2</a>, <a href="#l3">L3</a>, <a href="#l4">L4</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/235">nextbsd-userland#235</a></td></tr>
<tr><td><a href="#c2"><strong>C2</strong></a></td><td>caffeinate: port caffeinate.c</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#l3">L3</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/236">nextbsd-userland#236</a></td></tr>
<tr><td><a href="#s1"><strong>S1</strong></a></td><td>reboot/shutdown/halt: vendor Apple's system_cmds versions over the BSD PID-1 signal protocol launchd already honours</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td>—</td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/237">nextbsd-userland#237</a></td></tr>
<tr><td><a href="#s2"><strong>S2</strong></a></td><td>pmconfigd: pmset schedule sleep/shutdown/restart performed by pmconfigd itself; wake/poweron waits on S3's RTC alarm</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d1">D1</a>, <a href="#s1">S1</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/238">nextbsd-userland#238</a></td></tr>
<tr><td><a href="#s3"><strong>S3</strong></a></td><td>Spike: an RTC wake alarm for pmset schedule wake -- FreeBSD has no rtcwake</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td><td><a href="#k4">K4</a></td><td><span class="pill info">spike</span></td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/245">nextbsd-kernel#245</a></td></tr>
<tr><td><a href="#v1"><strong>V1</strong></a></td><td>Display sleep and HID idle time without IODisplayWrangler -- pmconfigd owns display idle</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d4">D4</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/239">nextbsd-userland#239</a></td></tr>
<tr><td><a href="#t1"><strong>T1</strong></a></td><td>CI: power boot markers -- PM-BOOT-OK, PM-PS-OK, PM-ASSERT-OK, and PM-SLEEP-OK through QEMU S3</td><td><a href="https://github.com/nextbsd/nextbsd">nextbsd</a></td><td><a href="#d1">D1</a>, <a href="#d5">D5</a>, <a href="#k2">K2</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd/issues/492">nextbsd#492</a></td></tr>
<tr><td><a href="#e1"><strong>E1</strong></a></td><td>Packaging: power LaunchDaemons, build blocks, man pages, compat strip entries, and ACPI sysctl defaults</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td><td><a href="#d1">D1</a>, <a href="#s1">S1</a>, <a href="#d7">D7</a></td><td><span class="pill ok">ready</span></td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/240">nextbsd-userland#240</a></td></tr>
<tr><td><a href="#r1"><strong>R1</strong></a></td><td>Spike: an in-kernel IOPMrootDomain -- move the sleep/wake fan-out, acknowledgements and policy into iopmroot</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td><td><a href="#d5">D5</a></td><td><span class="pill info">spike</span></td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/246">nextbsd-kernel#246</a></td></tr>
</table>
<h2 id="tickets">Tickets</h2>
<div class="tk" id="k1">
<h3>K1 · kernel: acpi_ReqSleepState waits for a registered sleep listener instead of a /dev/devctl reader; ack timeout becomes tunable <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td></tr>
<tr><td>Labels</td><td><code>bug</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td>—</td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/238">nextbsd-kernel#238</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
With devd gone, **every** ACPI sleep request suspends immediately and nobody is told. `acpi_ReqSleepState()` (`sys/dev/acpica/acpi.c`, releng/15.1 ~3176-3248) only opens the userland acknowledgement window when `devctl_process_running()` -- "is `/dev/devctl` open" (`kern_devctl.c:364-366`) -- and otherwise calls `acpi_EnterSleepState()` straight away:
```c
/* If devd(8) is not running, immediately enter the sleep state. */
if (!devctl_process_running()) {
```
It also only emits the `Resume` notification when `/dev/devctl` is open (~3563), so no wake event exists either. Today `acpiconf -s 3`, a sleep button, or a lid close with `hw.acpi.lid_switch_state` set all suspend without warning.
## Design
New patch in `nk/patches/series` (~60 LOC in `acpi.c` and `acpivar.h`):
- an `acpi_register_sleep_listener()` / `acpi_deregister_sleep_listener()` API; the gate becomes `acpi_sleep_listener != NULL || devctl_process_running()`
- the 10 s force callout (`callout_reset(&sc->susp_force_to, 10*hz, ...)`) becomes a tunable `hw.acpi.suspend_ack_timeout`, **default 45 s** -- above Apple's 30 s app acknowledgement budget, so pmconfigd can finish its fan-out
- keep `/dev/acpi` and `acpiconf` behaviour unchanged
The listener is the K4 bridge driver; its fd deregisters on close, so a crashed pmconfigd cannot wedge sleep -- the timeout is the backstop, exactly as it is for a hung devd today.
## Acceptance
- [ ] with a registered listener, `sysctl hw.acpi.sleep_state=S3` waits until acknowledged (or the timeout)
- [ ] with no listener and no `/dev/devctl` reader, behaviour is unchanged
- [ ] `hw.acpi.suspend_ack_timeout` is honoured
- [ ] verified in QEMU q35 (S3 enabled) with `acpiconf -s 3`</code></pre>
</div>
<div class="tk" id="k2">
<h3>K2 · kernel: fixed-feature power button emits an ACPI Button event, and the wake PWRBTN status is recorded before it is cleared <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td></tr>
<tr><td>Labels</td><td><code>bug</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td>—</td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/239">nextbsd-kernel#239</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Control-method buttons (`acpi_button.c`) notify userland; the **fixed-feature** power button does not. `acpi_event_power_button_sleep/wake` (acpi.c ~3914-3947) only fire the `acpi_sleep_event` eventhandler, with no `acpi_UserNotify("Button", ...)`. QEMU's `system_powerdown` and many laptops use the fixed button, so pmconfigd would never learn of a press.
Separately, on resume `acpi_EnterSleepState` clears a latched fixed power-button status (~3466-3480) so the wake is not misread as a poweroff -- which also erases the only evidence that the button caused the wake.
## Design
- add `acpi_UserNotify("Button", ACPI_ROOT_OBJECT, 0)` in the fixed-feature handlers (~6 LOC), matching the control-method path's value convention
- record the PWRBTN status into the softc before clearing it, so the bridge (K4) can report `Wake Reason` "Power Button" (~10 LOC)
## Acceptance
- [ ] QMP `system_powerdown` in QEMU produces a `Button` event visible to the bridge
- [ ] a button-initiated wake is distinguishable from an RTC or lid wake</code></pre>
</div>
<div class="tk" id="k3">
<h3>K3 · kernel: devctl_notify hook becomes a list, so an in-kernel bridge can consume ACPI events while /dev/devctl stays unopened <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td>—</td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/240">nextbsd-kernel#240</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Every ACPI event goes `acpi_UserNotify()` -> `devctl_notify("ACPI", <subsystem>, ...)` (acpi.c ~4307-4324; subsystems `Lid`, `Button`, `ACAD`, `CMBAT`, `Thermal`, `Suspend`, `Resume`). `devctl_notify` feeds `/dev/devctl` and a **single** `devctl_notify_hook` slot (`kern_devctl.c` ~140-141, 601-609).
On NextBSD nothing consumes either: devd was removed, and the multi-reader netlink route (`nlsysevent`) is **module-only** -- `netlink_sysevent.c` is not in `sys/conf/files`, and NextBSD ships no modules.
## Design
- turn the hook into a short list (~30 LOC in `kern_devctl.c`, `sys/bus.h`); the bridge (K4) registers a filter for `system == "ACPI"`
- `/dev/devctl` stays unopened and inert, keeping nextbsd#225's direction intact: IOKit-shaped notifications, not a second event bus
## Acceptance
- [ ] two in-kernel hook consumers both receive the same ACPI event
- [ ] `/dev/devctl` remains closed on a booted system
Links: nextbsd#225 (E6).</code></pre>
</div>
<div class="tk" id="k4">
<h3>K4 · kernel: iopmroot bridge driver -- IOPMrootDomain0 node and /dev/iopmroot user client for sleep request, acknowledgement and state <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#k1">K1</a>, <a href="#k3">K3</a>, <a href="#k5">K5</a>, <a href="#k6">K6</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/243">nextbsd-kernel#243</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
The kernel half of "pmconfigd plays IOPMrootDomain". A new pseudo-driver publishes the node Apple's code looks for, and a character device stands in for `RootDomainUserClient`.
## Design
New `src-overlay/sys/dev/iokit/iokit_pmroot.c` (~800-1000 LOC), `src-overlay/sys/sys/iopmroot.h` (ABI), `src-overlay/conf/files.iopmroot` -- all `standard`, no module.
- **Node:** a newbus pseudo-device `IOPMrootDomain0` (child of `acpi0` on x86, of `nexus0` elsewhere), so `iokit_registry.c` mints it an id with no registry changes and `IOServiceMatching("IOPMrootDomain")` matches by class name
- **`/dev/iopmroot`** (root:operator 0660), one open per pmconfigd; the fd carries the K1 listener registration:
- `IOPMROOT_SLEEP{reason}` -> records reason/PID, calls `acpi_ReqSleepState(sc, suspend_sx)`
- `IOPMROOT_ACK{serial, allow|errno}` -> `acpi_AckSleepState(sc->acpi_clone, ...)`; an error cancels (clears `acpi_next_sstate`)
- `IOPMROOT_GETSTATE` (sleep supported, clamshell, AC, last sleep/wake reason), `IOPMROOT_SETCLAMSHELLSLEEP`, `IOPMROOT_SETPROP` (`System Shutdown` -> `kern.suspend_blocked`; `SleepDisabled`)
- **Subscribes:** the K1 listener (`Suspend`), `power_suspend_early` (stamp sleep time / UUID), `power_resume` (wake), `acpi_acad_event`, `acpi_sleep_event` / `acpi_wakeup_event`, and the K3 hook for `Lid`, `Button`, `CMBAT`, `Thermal`
- **Publishes** on the node (via K5): `Last Sleep Reason`, `Wake Reason`, `Wake Type`, `AppleClamshellState`, `AppleClamshellCausesSleep`, `IOPMSystemSleepType` = 2, `IOSleepSupported` (from `hw.acpi.supported_sleep_state`), `Supported Features`, `SleepWakeUUID`, `System Capabilities`
- **Emits** (via K6): "sleep requested {serial, reason}", "did wake", `kIOPMMessageClamshellStateChange`, `kIOPMMessageSystemPowerEventOccurred` (thermal `0xcc`)
- **Timestamps:** `kern.sleeptime` / `kern.waketime` with xnu semantics, which pmconfigd and `IOPMGetLastWakeTime` read and FreeBSD lacks
The kernel mints the acknowledgement serial even in v1, so it already has its final meaning if R1 moves the fan-out into the kernel.
## Acceptance
- [ ] `ioreg -c IOPMrootDomain` shows the node and its properties
- [ ] a sleep request -> listener message -> `IOPMROOT_ACK` -> S3 -> resume -> "did wake", in QEMU
- [ ] `IOPMROOT_ACK` with an error cancels the sleep</code></pre>
</div>
<div class="tk" id="k5">
<h3>K5 · kernel: IORegistry property-provider hook, so a driver can add keys to its own node <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td>—</td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/241">nextbsd-kernel#241</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Registry property bags are synthesized from fixed newbus fields only -- id, parent, state, name, class, driver, path, PCI ids, description (`iokit_registry.c` `ioreg_build_bag`, ~260-297). There is no per-driver provider, so nothing can publish `AppleClamshellState` or `CurrentCapacity`.
## Design
`ioreg_register_prop_provider(device_t, int (*)(device_t, nvlist_t *))`, consulted by `ioreg_build_bag` (~40 LOC). A provider change emits a property-change interest notification (K6).
## Acceptance
- [ ] a test provider's keys appear in `ioreg -l` and through `IORegistryEntryCreateCFProperty`</code></pre>
</div>
<div class="tk" id="k6">
<h3>K6 · kernel: IORegistry interest notifications -- IOREG_EVENT_INTEREST and an 'IOIN' Mach message carrying messageType, messageArgument and serial <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td>—</td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/242">nextbsd-kernel#242</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
The kernel already sends Mach notifications for device arrival and departure (`src-overlay/sys/compat/mach/iokit_notify.c`, msgid 'IONT'), but not Apple's per-object **interest** messages -- the channel `IORegisterForSystemPower`, battery changes and clamshell changes all ride on.
## Design
- a new watch kind `IOREG_EVENT_INTEREST` in `IOREGIOCWATCH`, pinned to a node id
- a new msgid 'IOIN' with `{header, NDR, id, messageType (uint32), messageArgument (uint64), serial (uint32)}` -- the existing 'IONT' struct is documented as frozen once shipped
- ~100 LOC in `iokit_registry.c`, ~80 in `iokit_notify.c/.h`
**The same 'IOIN' struct is what pmconfigd sends to apps in v1** (L4), so moving the fan-out into the kernel later (R1) changes the sender, not the wire format.
## Acceptance
- [ ] a watcher pinned to a node receives an interest message with the right type, argument and serial</code></pre>
</div>
<div class="tk" id="k7">
<h3>K7 · kernel: IOPMPowerSource nodes for ACPI batteries and AC, with Apple's power-source keys <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#k4">K4</a>, <a href="#k5">K5</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/244">nextbsd-kernel#244</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
pmconfigd finds batteries with `IOServiceMatching("IOPMPowerSource")` and re-reads every property on any general-interest message. It **drops any battery lacking `BatteryInstalled`, `CurrentCapacity` or `MaxCapacity`** (`BatteryTimeRemaining.m` `_batteryChanged`, ~790-870).
## Design
Children of `IOPMrootDomain0`: `IOPMPowerSource0..N`, one per `acpi_cmbat` unit, plus one AC-only source when `acpi_battery_get_units() == 0` (VMs, desktops). Properties read on demand through `acpi_battery_get_battinfo` / `ACPI_BATT_GET_INFO` / `ACPI_BATT_GET_STATUS` and `acpi_acad_get_acline`:
| Apple key | FreeBSD source |
|---|---|
| `ExternalConnected` | `acpi_acad_get_acline` |
| `BatteryInstalled` | not `ACPI_BATT_STAT_NOT_PRESENT` |
| `IsCharging` | `ACPI_BATT_STAT_CHARGING` |
| `CurrentCapacity` / `MaxCapacity` / `DesignCapacity` | `bst.cap` / `bix.lfcap` / `bix.dcap` (convert mAh x voltage when units are mA, as `acpi_battery.c` does) |
| `TimeRemaining` | `battinfo.min` |
| `Amperage` / `Voltage` | `bst.rate` / `bst.volt` |
| `CycleCount` | `bix.cycles` |
| `Manufacturer` / `Model` / `Serial` | `bix.oeminfo` / `model` / `serial` |
| `AtWarnLevel` / `AtCriticalLevel` | `cap <= wcap` / `lcap` |
`acpi_cmbat`'s notify (`0x80` status, `0x81` info) is the push signal; it arrives through the K3 hook and becomes `kIOPMMessageBatteryStatusHasChanged` on the node (K6).
## Acceptance
- [ ] on a laptop, `ioreg -c IOPMPowerSource` shows real capacity and charge state
- [ ] in QEMU, a single AC-only source appears</code></pre>
</div>
<div class="tk" id="m1">
<h3>M1 · Decide: pmconfigd's out-of-line MIG routines -- fix OOL in mach.ko (nextbsd#66) or route them over XPC <span class="pill warn">needs answer</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd">nextbsd</a></td></tr>
<tr><td>Labels</td><td><code>question</code> <code>area:power</code> <code>area:mach</code></td></tr>
<tr><td>Depends on</td><td>—</td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd/issues/491">nextbsd#491</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Apple's `powermanagement.defs` (IOKitUser, subsystem 73000) passes serialized property lists as out-of-line `pointer_t` data -- `io_pm_assertion_create`, `io_pm_assertion_set_properties`, `io_ps_copy_powersources_info` and others. **MIG out-of-line data is broken in this kernel**: `src/WLAN/wlan.defs` says so and uses only fixed-size arguments, and nextbsd#66 ("OOL receive proper VM fix: mmap-based mig_allocate + real base pointers", E1) is open.
## Options
- **Fix #66.** Keeps Apple's MIG interface unchanged, and every other Darwin daemon that uses OOL benefits.
- **Route over XPC.** Apple's client libraries already use XPC (`com.apple.iokit.powerdxpc`) for power sources and assertions in places, so this diverges least from Apple's own code paths -- but it means patching every OOL routine.
## Blocks
The pmconfigd MIG server (D1), IOPowerSources (L2), the assertion API (L3), `pmset -g batt` and `pmset -g assertions` (C1).</code></pre>
</div>
<div class="tk" id="d1">
<h3>D1 · pmconfigd: vendor PowerManagement-1846.120.8.0.1 and boot a minimal daemon as the com.apple.powerd MachService <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td>—</td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/224">nextbsd-userland#224</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Vendor Apple's PowerManagement into `src/PowerManagement/` with a `freebsd-shims/` directory (the Libnotify pattern) and get a minimal `pmconfigd` running.
## Scope
The shipping target is `powerd-binary` (35,713 lines). The **Xcode project is the source of truth -- the drop's `pmconfigd/Makefile` is stale** (it references files that no longer exist). The portable core: `pmconfigd.m`, `PMStore.c`, `PMSettings.m`, `PrivateLib.m` (trimmed), `CommonLib.c`, `SystemLoad.c`, `TTYKeepAwake.c`. Compile out battery health, SmartPowerNap, LowPowerMode, SkyLight display control (`TARGET_CPU_ARM64`), IOReport, MessageTracer/FDR, SMC and nvram. Target "Intel macOS without SMC/ASBM" (`!TARGET_CPU_ARM64`, `!HAVE_SMART_BATTERY`) to select the most portable branches.
## Shims
- `os_log` / `os_signpost` (68 + 39 sites)
- an Objective-C / Foundation subset, or de-ObjC the few hundred lines that need it
- entitlements: `SecTaskCreateWithAuditToken` / `auditTokenHasEntitlement` -> uid-based checks (no Security.framework)
- `libproc` (`proc_pidinfo`, `proc_name`, `proc_pidpath`) -> `kinfo_proc`
- `dispatch_mach_create_f` / `dispatch_mach_mig_demux` (private libdispatch) -> a `DISPATCH_SOURCE_TYPE_MACH_RECV` source and `powermanagement_server()`, if the private API is missing
- `gethostuuid` -> `kern.hostuuid`
- CF-ICU: `strftime`/`strptime` for the timestamp and date-parsing sites
## launchd
`overlay/System/Library/LaunchDaemons/com.apple.powerd.plist`, keeping Apple's label: MachServices **`com.apple.PowerManagement.control`** (MIG) and **`com.apple.iokit.powerdxpc`** (XPC). Copy the check-in shape from `src/WLAN/mach_service.c` and the plist from `org.nextbsd.wland.plist`.
## Acceptance
- [ ] the daemon checks in and `launchctl list` shows `com.apple.powerd`
- [ ] boot marker `PM-BOOT-OK`</code></pre>
</div>
<div class="tk" id="d2">
<h3>D2 · pmconfigd: one kernel shim -- root-domain selectors become /dev/iopmroot ioctls, and 'IOIN' interest messages drive the daemon <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d1">D1</a>, <a href="#k4">K4</a>, <a href="#l1">L1</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/226">nextbsd-userland#226</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
pmconfigd reaches the kernel through `IOServiceOpen` on `IOPower:/IOPowerConnection/IOPMrootDomain` and `IOConnectCallMethod` with 19 selectors (`IOPMLibDefs.h`). In the userspace model most of those are **pmconfigd's own state**; only a few need the kernel.
## Design
Confine all kernel-facing code to **one shim file** (~400 LOC), a selector -> ioctl table over `/dev/iopmroot`:
| Selector | v1 handling |
|---|---|
| `kPMSleepSystem` (2) | enter pmconfigd's own sleep state machine (D5), then `IOPMROOT_SLEEP` |
| `kPMAllowPowerChange` / `kPMCancelPowerChange` (3/4) | pmconfigd's response tracker, then `IOPMROOT_ACK` |
| `kPMSetAggressiveness` (0), `kPMSetUserAssertionLevels` (9), `kPMActivityTickle` (10), `kPMSetClamshellSleepState` (12), `kPMRequestIdleSleepRevert` (17) | internal policy -- idle timer, assertion gating, clamshell |
| `kPMGetSystemSleepType` (11) | return `kIOPMSleepTypeNormalSleep` |
| watchdog, debug trigger, maintenance wake, display power-on | `kIOReturnUnsupported` for v1 |
Kernel events arrive as 'IOIN' interest messages (K6) on the root-domain and power-source nodes. Keeping the kernel boundary in one file is what makes R1's in-kernel swap cheap.
## Acceptance
- [ ] pmconfigd starts, opens `/dev/iopmroot`, and receives a lid or AC event in its log</code></pre>
</div>
<div class="tk" id="d3">
<h3>D3 · pmconfigd: power sources from IOPMPowerSource nodes -- kIOPS dictionaries, notify state bits, and an AC-only source when there is no battery <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d1">D1</a>, <a href="#k7">K7</a>, <a href="#m1">M1</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/227">nextbsd-userland#227</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Port the core of `BatteryTimeRemaining.m`: first-match on `IOPMPowerSource`, general interest per battery, unpack properties, compute time remaining, and publish.
## Design
- publishes the notify state bits on `com.apple.system.powersources.timeremaining` (packed: valid / external / charging / minutes / active source, `IOPowerSourcesPrivate.h`) plus `percent`, `source`, `attach`, `lowbattery`, `criticallevel`
- serves `io_ps_copy_powersources_info` (the blob behind `IOPSCopyPowerSourcesInfo`; OOL -- see M1)
- `State:/IOKit/LowBatteryWarning` in SCDynamicStore
- no ASBM: `IOPSRequestBatteryUpdate` is a no-op, and `startBatteryPoll` must not spin when the ASBM timestamp keys are missing
- **no battery gives an AC-only list, not an error** -- VMs and desktops
- ~60% of the file (health, NVRAM, calibration, authentication) is deferred
## Acceptance
- [ ] `pmset -g batt` on a laptop matches `acpiconf -i 0`
- [ ] in QEMU it reports "AC Power" with no battery</code></pre>
</div>
<div class="tk" id="d4">
<h3>D4 · pmconfigd: assertion engine and idle-sleep policy -- PreventUserIdleSystemSleep/DisplaySleep, PreventSystemSleep, sleep and displaysleep timers <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d1">D1</a>, <a href="#d2">D2</a>, <a href="#m1">M1</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/228">nextbsd-userland#228</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Port `PMAssertions.c` (7,650 lines), `PMAssertionLog.c` and the v1 parts of `PMSettings.m`. When the system is idle and no assertion prevents it, pmconfigd requests sleep (`IOPMROOT_SLEEP` with reason "Idle Sleep").
## Design
- MIG routines `io_pm_assertion_create` / `set_properties` / `retain_release` / `copy_details`, `io_pm_declare_user_active`
- strip IOReport/powerlog logging, the iOS "async offload" assertion path (verify `gAssertionConnection` still sets up on macOS), SMC, and entitlement gating (D1 shims)
- idle time from `TTYKeepAwake` (utmpx + tty atime) and the HID idle source (V1) -- there is no `IOHIDEventSystem`
- settings in CFPreferences `com.apple.PowerManagement` (and the `<host-UUID>` domain), changes signalled on `com.apple.system.powermanagement.prefschange`
- the assertion timeout and category plists from `Resources/` are loaded at start (`initSystemAssertionTimeoutList` / `initAssertionCategories`) -- ship them
## Acceptance
- [ ] `caffeinate -i sleep 60` holds off idle sleep, and `pmset -g assertions` shows it
- [ ] with no assertions, idle sleep fires after the configured timer</code></pre>
</div>
<div class="tk" id="d5">
<h3>D5 · pmconfigd: S3 sleep/wake orchestration -- CanSystemSleep, WillSleep, WillNotSleep, WillPowerOn, HasPoweredOn, with a 30 s acknowledgement budget <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d2">D2</a>, <a href="#k1">K1</a>, <a href="#k4">K4</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/229">nextbsd-userland#229</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
The central deliverable: pmconfigd reproduces the message sequence apps observe from xnu's `IOPMrootDomain`, then lets the kernel sleep.
## Sequence (xnu semantics)
1. a sleep request: software (`IOPMSleepSystem`), idle (D4), lid or power button (policy below), or low battery
2. **`kIOMessageCanSystemSleep` (0x270) for idle sleep only** -- apps may veto; xnu does not send it for demand sleep
3. `kIOMessageSystemWillSleep` (0x280) -- apps must acknowledge; **30 s budget per client** (`kWillSleepMaxTimeReq`), tardy clients are logged and sleep proceeds
4. `IOPMROOT_ACK{serial, 0}` -> S3; a veto sends `IOPMROOT_ACK{serial, EBUSY}`, then `kIOMessageSystemWillNotSleep` (0x290)
5. on wake: `kIOMessageSystemWillPowerOn` (0x320), then `kIOMessageSystemHasPoweredOn` (0x300)
## Design
- port `PMConnection.m`'s connection and acknowledgement state machine (~1,500 of its 4,153 lines); dark wake, sleep services, TCP keep-alive and auto-power-off are deferred
- v1: every wake is a full wake -- report `CPU|Graphics|Audio|Network` and send a single capability `DidChange`, so the state machine is satisfied
- **policy moves into pmconfigd**: set `hw.acpi.lid_switch_state`, `sleep_button_state` and `power_button_state` to `NONE` so the kernel never initiates sleep itself (except its own thermal-critical poweroff), and apply Apple's clamshell rule and the `Sleep On Power Button` setting in pmconfigd
- publish `Last Sleep Reason` strings exactly as Apple does: "Idle Sleep", "Software Sleep", "Clamshell Sleep", "Power Button Sleep", "Low Power Sleep"
## Acceptance
- [ ] a test client registered with `IORegisterForSystemPower` sees WillSleep -> HasPoweredOn across `pmset sleepnow` in QEMU
- [ ] a client vetoing CanSystemSleep blocks idle sleep, and the veto is logged
- [ ] a client that never acknowledges delays sleep by at most 30 s</code></pre>
</div>
<div class="tk" id="d6">
<h3>D6 · pmconfigd: publish power state for Gershwin in SCDynamicStore -- battery %, AC, lid, sleep pending <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d3">D3</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/230">nextbsd-userland#230</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Gershwin cannot speak Mach -- its libdispatch is built with `HAVE_MACH` disabled -- so it cannot use IOPMLib. It consumes power state through SCDynamicStore keys, notify(3) and the `pmset` CLI.
## Design
Publish `State:/IOKit/PowerManagement/CurrentSettings` (Apple's `kIOPMDynamicStoreSettingsKey`), `State:/IOKit/LowBatteryWarning`, and power-source summary keys through `PMStore`. This is the same pref-pane seam as nextbsd#395 / #396 / #397 (E11).
## Acceptance
- [ ] `scutil` shows battery percentage, AC state and lid state, and they update on change</code></pre>
</div>
<div class="tk" id="d7">
<h3>D7 · pmconfigd: CPU power policy -- set Intel HWP EPP by AC/battery profile; replaces FreeBSD powerd, with an interim LaunchDaemon until then <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d3">D3</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/231">nextbsd-userland#231</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
FreeBSD's `powerd` ships but **no LaunchDaemon runs it**, so laptop CPU frequency is unmanaged today. The srclist marks `usr.sbin/powerd` REPLACE by PowerManagement.
## Design
- **Interim, now:** an `org.nextbsd.powerd` LaunchDaemon running base `powerd -a hiadaptive -b adaptive`
- **pmconfigd:** don't port powerd's polling loop. On Intel HWP machines `hwpstate_intel` is info-only and the hardware picks the frequency; the knob is `dev.hwpstate_intel.N.epp` (0 = performance ... 100 = efficiency). Set it by profile -- e.g. low on AC, high on battery, 100 in low-power mode
- **AMD:** `hwpstate_amd` has no EPP/CPPC in 15.1, only discrete `dev.cpu.N.freq` levels -- lift powerd's adaptive loop (~300 LOC) or leave it to the kernel's `power_profile`
- retire the interim daemon, and add `/usr/sbin/powerd` to `nextbsd-freebsd-compat`'s superseded list, once pmconfigd owns this
## Acceptance
- [ ] on a HWP laptop, unplugging AC changes `dev.hwpstate_intel.0.epp`</code></pre>
</div>
<div class="tk" id="l1">
<h3>L1 · libIOKit: IOServiceAddInterestNotification over 'IOIN', and IORegistryEntrySetCFProperty on the root domain <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#k6">K6</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/225">nextbsd-userland#225</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
libIOKit (`src/libIOKit`) has matching notifications but no interest notifications, no `IOServiceOpen`, and no `IOConnectCallMethod`.
## Design
- `IOServiceAddInterestNotification`: register through `IOREGIOCWATCH` with `IOREG_EVENT_INTEREST`, and decode 'IOIN' in the receive path (`IOKitNotify.c` already demuxes by msgid); deliver `(refcon, service, messageType, messageArgument)` through an `IONotificationPortRef` that supports both dispatch queues and run loops (~200 LOC)
- `IORegistryEntrySetCFProperty(ies)` on the root-domain node -> `IOPMROOT_SETPROP` (~60 LOC)
- keep `IOServiceOpen` / `IOConnectCallMethod` out of scope, as the hardware-registry plan decided; L4 re-aims the power calls instead
## Acceptance
- [ ] a test client receives a clamshell interest message from `IOPMrootDomain0`</code></pre>
</div>
<div class="tk" id="l2">
<h3>L2 · libIOKit: IOPowerSources (ps.subproj) -- IOPSCopyPowerSourcesInfo and friends, plus <IOKit/ps/*.h> <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d3">D3</a>, <a href="#m1">M1</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/232">nextbsd-userland#232</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Port `IOKitUser/ps.subproj` (`IOPowerSources.c` 460, `IOPowerSourcesPrivate.c` 531) and install `IOPowerSources.h`, `IOPSKeys.h` and the private headers.
## Design
- `IOPSCopyPowerSourcesInfo` -> MIG `io_ps_copy_powersources_info` (OOL -- M1)
- `IOPSGetTimeRemainingEstimate`, `IOPSGetProvidingPowerSourceType` and `IOPSDrawingUnlimitedPower` decode `notify_get_state` bits and need nothing more
- `IOPSNotificationCreateRunLoopSource` uses `notify_register_mach_port` + `CFMachPort`
- `IOPSRequestBatteryUpdate` is a no-op; `IOPSPowerSourceSupported` reads `IODeviceTree:/product` -- patch it, or publish `builtin-battery`
## Acceptance
- [ ] a small test prints the same power sources as `pmset -g batt`</code></pre>
</div>
<div class="tk" id="l3">
<h3>L3 · libIOKit: IOPMAssertion API and the IOPMLib / IOPMLibPrivate headers <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d4">D4</a>, <a href="#m1">M1</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/233">nextbsd-userland#233</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Port the assertion client side of `IOKitUser/pwr_mgt.subproj` -- `IOPMAssertions.c` (3,816 lines) and `IOPMLibPrivate.c` (2,305) -- and install `IOPMLib.h`, `IOPMLibPrivate.h`, `IOPMKeys.h` and `powermanagement_mig.h` under `<IOKit/pwr_mgt/>`.
## Design
- `IOPMAssertionCreateWithName` / `Description` / `Properties`, `Retain`, `Release`, `SetProperty`, `CopyAssertionsByProcess`, `CopyAssertionsStatus`, `DeclareUserActivity`
- `_pm_connect` uses `bootstrap_look_up2(kIOPMServerBootstrapName, BOOTSTRAP_PRIVILEGED_SERVER)` -- check launchd's support for the privileged flag
- replace the `CFNumberFormatter` site (`IOPMAssertions.c` ~547-560) with `CFStringCreateWithFormat`
- about 1,500 lines of `IOPMAssertions.c` are the iOS async-offload machinery -- compile out where not needed
- `IOPMEnergyPrefs.c` for `IOPMCopyPMPreferences` / `IOPMSetPMPreferences` / `IOPMFeatureIsAvailable`, which `pmset` needs
## Acceptance
- [ ] a C test creates and releases an assertion, and `pmset -g assertions` lists it by PID</code></pre>
</div>
<div class="tk" id="l4">
<h3>L4 · libIOKit: IORegisterForSystemPower, IOAllowPowerChange, IOCancelPowerChange and IOPMSleepSystem re-aimed at pmconfigd <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d5">D5</a>, <a href="#l1">L1</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/234">nextbsd-userland#234</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Apple's `IOPMLib.c` implements these with `IOServiceOpen` on the root domain, `IOConnectCallScalarMethod` (selectors 2 and 3/4), and `IOServiceAddInterestNotification(kIOAppPowerStateInterest)`. In the userspace design pmconfigd is the notifier, so these calls go to it.
## Design
- `IORegisterForSystemPower` returns an opaque client handle in place of an `io_connect_t` (as `io_object_t` already is) and subscribes to pmconfigd; messages arrive using the **same 'IOIN' wire struct** the kernel sends (K6)
- `IOAllowPowerChange` / `IOCancelPowerChange(refcon)` acknowledge to pmconfigd with the kernel-minted serial
- `IOPMSleepSystem` / `IOPMFindPowerManagement` -> pmconfigd's sleep entry point
- because the wire struct and serials are the kernel's, R1 changes only the destination
## Acceptance
- [ ] an unmodified client written against Apple's `IORegisterForSystemPower` example receives sleep and wake notifications</code></pre>
</div>
<div class="tk" id="c1">
<h3>C1 · pmset: port pmset.m -- -g, -g batt, -g assertions, -g log, sleepnow, displaysleep/sleep settings, schedule <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d1">D1</a>, <a href="#d3">D3</a>, <a href="#l2">L2</a>, <a href="#l3">L3</a>, <a href="#l4">L4</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/235">nextbsd-userland#235</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Port `pmset/pmset.m` (8,640 lines, Objective-C). The hardware-registry plan's K3 marker is "`pmset -g` prints sensible output".
## Paths
- `pmset -g` reads SCDynamicStore `State:/IOKit/PowerManagement/CurrentSettings` and root-domain `Supported Features`
- `pmset -g batt` -> `IOPSCopyPowerSourcesInfo`; `pmset -g assertions` -> `IOPMCopyAssertionsStatus` / `ByProcess`
- `pmset sleepnow` -> `IOPMSleepSystem`, returning `kIOReturnNotPrivileged` for non-root
- setting values -> `IOPMSetPMPreferences` + the prefs-change notify
- `pmset -g log` queries ASL (43 sites) against powerd's store
- `pmset schedule` -> `IOPMSchedulePowerEvent` (S2)
## Porting
- `CFDateFormatter` date parsing for `pmset schedule` is the one real ICU dependency -> `strptime`
- compile out IOReport (53 sites) and SkyLight (arm64)
## Acceptance
- [ ] `pmset -g`, `pmset -g batt` and `pmset -g assertions` print sensible output on a laptop and in QEMU
- [ ] `pmset sleepnow` suspends a QEMU guest through D5</code></pre>
</div>
<div class="tk" id="c2">
<h3>C2 · caffeinate: port caffeinate.c <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code> <code>good first issue</code></td></tr>
<tr><td>Depends on</td><td><a href="#l3">L3</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/236">nextbsd-userland#236</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
`caffeinate/caffeinate.c` is 297 lines of plain C using libdispatch and CF, and makes exactly two IOPMLib calls: `IOPMAssertionCreateWithDescription` and `IOPMAssertionSetProperty(kIOPMAssertionOnBehalfOfPID)`. It holds the assertion until its child exits (`DISPATCH_SOURCE_TYPE_PROC`).
Flags map to `PreventUserIdleSystemSleep` (`-i`, default), `PreventUserIdleDisplaySleep` (`-d`), `PreventSystemSleep` (`-s`), `UserIsActive` (`-u`) and `PreventDiskIdle` (`-m`).
It hard-codes `/System/Library/CoreServices/powerd.bundle` as its localization bundle path -- ship that layout or patch the string. **The ideal first end-to-end smoke test.**
## Acceptance
- [ ] `caffeinate -d sleep 30` shows a display-sleep assertion in `pmset -g assertions` for 30 s</code></pre>
</div>
<div class="tk" id="s1">
<h3>S1 · reboot/shutdown/halt: vendor Apple's system_cmds versions over the BSD PID-1 signal protocol launchd already honours <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code> <code>area:base</code></td></tr>
<tr><td>Depends on</td><td>—</td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/237">nextbsd-userland#237</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
None of Apple's reboot, shutdown or halt is vendored -- FreeBSD's ship live. The compat audit's "Apple reboot vendored but deferred on IOPMLib" is stale.
## Design
From `system_cmds-1042.120.1`:
- on `__APPLE__`, `shutdown`/`reboot` call `reboot3(howto)` ("launchd(8) handles reboot"), which lives in macOS libxpc; **NextBSD has no `reboot3`**. The `!__APPLE__` branch sends PID 1 `SIGINT` (reboot), `SIGUSR1` (halt), `SIGUSR2` (poweroff), `SIGWINCH` (power cycle) -- and **launchd already honours exactly that** (`src/launchd/src/core.c` ~4390-4440, nextbsd#398 closed). Use it.
- IOPMLib is only needed for `shutdown -s` (`IOPMFindPowerManagement` + `IOPMSleepSystem`) -- compile `-s` out until L4
- both call `reserve_reboot()` -> `kextmanager_lock_reboot` on `com.apple.KernelExtensionServer`, which kextd does not currently register. Either have kextd serve a trivial lock, or ifdef it out (E6, nextbsd#182)
- `halt` is `reboot` under another name
- add `/sbin/reboot`, `/sbin/halt` and `/sbin/shutdown` to `nextbsd-freebsd-compat`'s superseded list
Remove the "IOPMLib stubs for halt/shutdown/reboot" item from nextbsd#115 (E9); this ticket delivers it.
## Acceptance
- [ ] Apple's `reboot`, `halt` and `shutdown -h/-r now` work on a booted system</code></pre>
</div>
<div class="tk" id="s2">
<h3>S2 · pmconfigd: pmset schedule sleep/shutdown/restart performed by pmconfigd itself; wake/poweron waits on S3's RTC alarm <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d1">D1</a>, <a href="#s1">S1</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/238">nextbsd-userland#238</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Port `AutoWakeScheduler.c` and `RepeatingAutoWake.c` (`io_pm_schedule_power_event`, `_schedule_repeat_event`, `_cancel_repeat_events`), persisting to SCPreferences `com.apple.AutoWake.xml`.
## Design
- On macOS, scheduled sleep, shutdown and restart only post a **distributed CF notification** for loginwindow to act on (`_askNicelyThen*`). NextBSD has no loginwindow doing that, and no `distnoted` -- so pmconfigd performs them itself: sleep through its own state machine (D5), shutdown and restart through the S1 signal path
- replace the `CFCalendar` (Gregorian) sites with plain C time arithmetic
- **wake / poweron** needs an RTC alarm programmed at sleep time -- blocked on S3
## Acceptance
- [ ] `pmset schedule sleep "<in 2 minutes>"` sleeps the machine; `pmset -g sched` lists it</code></pre>
</div>
<div class="tk" id="s3">
<h3>S3 · Spike: an RTC wake alarm for pmset schedule wake -- FreeBSD has no rtcwake <span class="pill info">spike</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td></tr>
<tr><td>Labels</td><td><code>area:power</code> <code>area:research</code></td></tr>
<tr><td>Depends on</td><td><a href="#k4">K4</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/245">nextbsd-kernel#245</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
`pmset schedule wake` reaches the hardware in xnu through root-domain properties (`WakeByCalendarDate`, `wake` seconds), which program an RTC or SMC alarm at sleep. FreeBSD has **no `rtcwake`-style API** to arm an S3 wake alarm.
## Questions
- an `atrtc` alarm ioctl, the ACPI time-and-alarm device (`ACPI000E`, `_TIV` / `_STV`), or something else?
- which laptops expose a usable RTC alarm, and does it wake from S3?
- QEMU: `system_wakeup` over QMP covers CI; is there an emulated RTC-alarm path?
## Deliverable
A design note with a recommendation, then the implementation ticket.</code></pre>
</div>
<div class="tk" id="v1">
<h3>V1 · Display sleep and HID idle time without IODisplayWrangler -- pmconfigd owns display idle <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d4">D4</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/239">nextbsd-userland#239</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
On Intel Macs pmconfigd watches `IODisplayWrangler` for display power and reads HID idle time from `IOHIDSystem` / `IOHIDEventSystemClient` (47 IOHID sites). NextBSD has neither.
## Design
- **Idle time:** evdev -- `/dev/input/event*` timestamps -- or the display server's idle notifier, published as the idle source SystemLoad and TTYKeepAwake consume
- **Display sleep actor:** pmconfigd runs the display idle timer from `displaysleep`, and blanks through DPMS (the X server) or DRM
- `pmset displaysleepnow` sets `IORequestIdle` on the wrangler on macOS -- route it to the same actor
Links: nextbsd#395 (brightness, E11), E5 (display and DRM resume, nextbsd#390).
## Acceptance
- [ ] with no input for the `displaysleep` interval, the display blanks; input wakes it</code></pre>
</div>
<div class="tk" id="t1">
<h3>T1 · CI: power boot markers -- PM-BOOT-OK, PM-PS-OK, PM-ASSERT-OK, and PM-SLEEP-OK through QEMU S3 <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd">nextbsd</a></td></tr>
<tr><td>Labels</td><td><code>area:ci</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d1">D1</a>, <a href="#d5">D5</a>, <a href="#k2">K2</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd/issues/492">nextbsd#492</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
Make the power path testable in the CI VM, which can exercise the whole sleep handshake but not batteries, lid or HWP.
## Stages
- **PM-BOOT-OK** -- pmconfigd checks in
- **PM-PS-OK** -- `pmset -g batt` reports an AC-only source (QEMU has no ACPI battery)
- **PM-ASSERT-OK** -- `caffeinate` plus `pmset -g assertions`
- **PM-SLEEP-OK** -- guest `pmset sleepnow` -> S3 -> QMP `system_wakeup` -> HasPoweredOn seen by a test client; needs QEMU q35 with S3 enabled (`ICH9-LPC.disable_s3=0`)
- **power button** -- QMP `system_powerdown` raises the fixed-feature button (K2)
Pairs with nextbsd#428 (the test gates pass at the login prompt).</code></pre>
</div>
<div class="tk" id="e1">
<h3>E1 · Packaging: power LaunchDaemons, build blocks, man pages, compat strip entries, and ACPI sysctl defaults <span class="pill ok">ready</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-userland">nextbsd-userland</a></td></tr>
<tr><td>Labels</td><td><code>enhancement</code> <code>area:power</code></td></tr>
<tr><td>Depends on</td><td><a href="#d1">D1</a>, <a href="#s1">S1</a>, <a href="#d7">D7</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-userland/issues/240">nextbsd-userland#240</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
- LaunchDaemon plists: `com.apple.powerd` (D1), the interim `org.nextbsd.powerd` (D7)
- `build-userland.sh` blocks for PowerManagement and the libIOKit additions, after notifyd
- man pages: `pmset.1`, `caffeinate.8`, `reboot.8`, `shutdown.8`
- `nextbsd-freebsd-compat` superseded entries for `/sbin/reboot`, `/sbin/halt`, `/sbin/shutdown` and, later, `/usr/sbin/powerd`
- defaults: `hw.acpi.lid_switch_state`, `sleep_button_state` and `power_button_state` = `NONE` once pmconfigd owns the policy (D5), falling back to the kernel's S5 on the power button only when pmconfigd is not running</code></pre>
</div>
<div class="tk" id="r1">
<h3>R1 · Spike: an in-kernel IOPMrootDomain -- move the sleep/wake fan-out, acknowledgements and policy into iopmroot <span class="pill info">spike</span></h3>
<table class="meta">
<tr><td>Repo</td><td><a href="https://github.com/nextbsd/nextbsd-kernel">nextbsd-kernel</a></td></tr>
<tr><td>Labels</td><td><code>area:power</code> <code>area:research</code></td></tr>
<tr><td>Depends on</td><td><a href="#d5">D5</a></td></tr>
<tr><td>Filed as</td><td><a href="https://github.com/nextbsd/nextbsd-kernel/issues/246">nextbsd-kernel#246</a></td></tr>
<tr><td>Parent</td><td><a href="https://github.com/nextbsd/nextbsd/issues/490">nextbsd#490</a></td></tr>
</table>
<pre><code>## Summary
The hybrid's kernel-later path. It is cheaper than first assumed: **the IORegistry is already in the kernel** (hwregd was retired, nextbsd#218), and kernel-originated Mach sends already work (`iokit_notify.c`, `ipc_mqueue_send_always`). The original reason to keep this in userspace -- "no in-kernel IOKit" -- no longer holds.
## Questions
- a per-port client registry in `iokit_pmroot.c` for `kIOAppPowerStateInterest` -- a generalisation of the `apm_clone` voter model -- with a 30 s acknowledgement callout (`kern.pmtimeout`) and CanSystemSleep for idle sleep only
- acknowledgement by ioctl (cheap) or an in-kernel MIG server (faithful; in-kernel MIG servers already exist in `files.compat_mach`)
- which policy moves in -- idle timer, assertion-level gating, clamshell and power-button rules, low-battery and thermal emergency sleep -- and what stays in pmconfigd: assertion aggregation, preferences, power-source republishing, scheduled wake
- estimate: +1,000-1,500 kernel LOC; the userland change is deleting pmconfigd's fan-out and pointing L4 at `/dev/iopmroot`
## Deliverable
A design note with a recommendation, as E14's S1 (nextbsd-kernel#227). Cross-links E12 (nextbsd#445), nextbsd#225, `nextbsd-inkernel-iokit-feasibility.html`.</code></pre>
</div>
<h2 id="linked">Linked issues</h2>
<p>These stay in their current epics; E17 cross-links them.</p>
<table class="compact">
<tr><th>Issue</th><th>Epic</th><th>Why it relates</th></tr>
<tr><td><a href="https://github.com/nextbsd/nextbsd/issues/225">nextbsd#225</a></td><td>E6</td><td>Retire /dev/devctl for IOKit notifications -- K3 keeps it inert</td></tr>
<tr><td><a href="https://github.com/nextbsd/nextbsd/issues/66">nextbsd#66</a></td><td>E1</td><td>MIG out-of-line data -- decides M1</td></tr>
<tr><td><a href="https://github.com/nextbsd/nextbsd/issues/115">nextbsd#115</a></td><td>E9</td><td>system_cmds port -- its IOPMLib-stub item is delivered by S1</td></tr>
<tr><td><a href="https://github.com/nextbsd/nextbsd/issues/395">nextbsd#395</a></td><td>E11</td><td>Display brightness -- same pref-pane seam as D6 and V1</td></tr>
<tr><td><a href="https://github.com/nextbsd/nextbsd/issues/179">nextbsd#179</a></td><td>E6</td><td>ko-to-kext -- needed for acpi_video, coretemp, amdtemp</td></tr>
<tr><td><a href="https://github.com/nextbsd/nextbsd/issues/182">nextbsd#182</a></td><td>E6</td><td>kext_tools / OSKext -- the kextmanager reboot lock S1 must serve or drop</td></tr>
<tr><td><a href="https://github.com/nextbsd/nextbsd/issues/390">nextbsd#390</a></td><td>E5</td><td>GPU re-init races -- wake from S3 must re-check /dev/dri</td></tr>
<tr><td><a href="https://github.com/nextbsd/nextbsd/issues/428">nextbsd#428</a></td><td>E10</td><td>Test gates pass at the login prompt -- pairs with T1</td></tr>
</table>
<h2 id="recreate">Recreating in GitHub</h2>
<p>Everything is filed; these commands are kept in case the issues ever need recreating. File the epic first, so each child can name its parent, then the children in dependency order, attaching each as a sub-issue of the epic.</p>
<pre class="shell"><code># 1. the label, in all four repos
gh label create area:power --color fbca04 \
--description "Power management: pmconfigd, IOPMLib, power sources, ACPI sleep/wake, cpufreq, reboot/shutdown" \
--repo nextbsd/nextbsd-kernel # repeat for each repo
# 2. any single ticket: copy its body from this page into a file
gh issue create --repo nextbsd/nextbsd-kernel \
--title "..." --label bug,area:power --body-file K1.md