Page MenuHomeFreeBSD

zzz: Rewrite to use new power device
ClosedPublic

Authored by obiwac on Sun, May 10, 8:54 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, May 27, 2:17 AM
Unknown Object (File)
Tue, May 26, 12:22 PM
Unknown Object (File)
Tue, May 26, 9:40 AM
Unknown Object (File)
Tue, May 26, 1:29 AM
Unknown Object (File)
Mon, May 25, 9:43 PM
Unknown Object (File)
Mon, May 25, 4:54 PM
Unknown Object (File)
Mon, May 25, 9:59 AM
Unknown Object (File)
Sun, May 24, 10:46 PM
Subscribers

Details

Summary

Previous script called acpiconf(8) (or apm(8) if ACPI wasn't supported,
although this was anyway redundant because APMIO just uses ACPI now).

Since a new generic power management interface was introduced, this isn't
sufficient, as this would only work for ACPI systems and for ACPI S3 suspend
(so no way to select suspend-to-idle). Rewrite in C to take advantage of the
new power interface.

We may want to add a switch to manually override the kern.power.suspend sysctl,
which is otherwise what the power device uses to decide which suspend type to
switch to (suspend-to-idle or firmware suspend), but this will require us to
amend the power interface.

Sponsored by: The FreeBSD Foundation

Test Plan

Still need to test this on an ACPI machine. Expected behaviour on machines which support S3: just suspend to S3 when running zzz.

If someone with a machine that supports ACPI S3 could test this works that'd be great :)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 72964
Build 69847: arc lint + arc unit

Event Timeline

also, TODO, update manpage

usr.sbin/zzz/Makefile
3

probably don't want this to be in the acpi package! but I don't know what the most appropriate thing here is.

usr.sbin/zzz/zzz.c
40–42

I don't know if it's worth adding fallback support to APCIIO or APMIO?

This revision is now accepted and ready to land.Mon, May 11, 9:37 PM

I think my laptop works with ACPI S3; I will try this out!

usr.sbin/zzz/zzz.c
21

I learned about this new style(9) convention recently:

Global pathnames are defined in <paths.h>.  Pathnames local to the
program go in "pathnames.h" in the local directory.

#include <paths.h>

Even for such a small utility, it seems to apply here. See e.g. usr.sbin/pciconf/pathnames.h.

42–43

I believe this is equivalent.

56

I tried it out. The machine didn't suspend, instead it just froze :/

I haven't looked at the pathways for this new power device yet, but I will try to familiarize myself with it. That's all I can report today.

usr.sbin/zzz/Makefile
3

Right now it defaults to -utilities. I suggest keeping it there if there is no an actual dependency on ACPI but just the power interface.

usr.sbin/zzz/zzz.c
37

This is necessary here, as argv contains the name of the utility. I forget if getopt() adjusts for this.

obiwac marked 5 inline comments as done.

respond to mhorne@'s suggestions

This revision now requires review to proceed.Wed, May 20, 10:22 PM

I tried it out. The machine didn't suspend, instead it just froze :/

I haven't looked at the pathways for this new power device yet, but I will try to familiarize myself with it. That's all I can report today.

aie, can you confirm this works with acpiconf -s 3? Is this what you were using previously? Also, could you show me your kern.power sysctl tree?

thanks for trying this out and reviewing!

I tried it out. The machine didn't suspend, instead it just froze :/

I haven't looked at the pathways for this new power device yet, but I will try to familiarize myself with it. That's all I can report today.

aie, can you confirm this works with acpiconf -s 3? Is this what you were using previously? Also, could you show me your kern.power sysctl tree?

thanks for trying this out and reviewing!

I tried a few more tests today. It seems that the new zzz hangs when I have a graphical desktop loaded (sddm/kde), but it succeeds in suspend/resume when I tried with just the vt(4) console.

Strangely, acpiconf -s 3 succeeds in both cases. I believe this is what I was using before, based on the previous implementation of zzz.

Here is some of the relevant sysctl info:

hw.acpi.handle_reboot: 1
hw.acpi.disable_on_reboot: 0
hw.acpi.verbose: 0
hw.acpi.s4bios_supported: 0
hw.acpi.s4bios: 0
hw.acpi.sleep_delay: 1
hw.acpi.standby_state: NONE
hw.acpi.suspend_state: S3
hw.acpi.lid_switch_state: NONE
hw.acpi.sleep_button_state: fw_suspen
hw.acpi.power_button_state: poweroff
hw.acpi.supported_sleep_state: S3 S4 S5
kern.power.hibernate: fw_hibern
kern.power.suspend: fw_suspen
kern.power.standby: NONE
kern.power.supported_stype: awake fw_suspend suspend_to_idle fw_hibernate poweroff

One thing: I think you need to bump the length of the input character arrays in these sysctls, to accommodate for the new name lengths.

include/paths.h
56 ↗(On Diff #178292)

It should go here, alphabetically.

obiwac added inline comments.
include/paths.h
56 ↗(On Diff #178292)

yup i had called it just _PATH_POWER initially and forgot to move. thanks for catching that

obiwac marked an inline comment as done.

fix path ordering

Strangely, acpiconf -s 3 succeeds in both cases. I believe this is what I was using before, based on the previous implementation of zzz.

I will look into this more tomorrow but maybe the power code is opting to do suspend-to-idle on your machine rather than FW suspend. that may explain why you're hanging

One thing: I think you need to bump the length of the input character arrays in these sysctls, to accommodate for the new name lengths.

Indeed, will commit a fix tomorrow :)

@mhorne just committed f814650aaf788323b3d485d96996fce6cd7b2d7f, does it work with that? I'm surprised it was hanging considering if the suspend stype is unknown it should just not do anything. If it's still hanging I'll send you a patch to try out to exit out of acpi_EnterSleepState() early and see what's going on there.

This change looks OK per se, but before committing we have to confirm that we can get the same behavior as before. The divergence in behavior with acpiconf -s 3 should be fixed by D57239. Could you give it a try?

usr.sbin/zzz/zzz.c
35–37

Nitpick, but nothing a priori prevents someone from launching this executable with an empty argv[], and although unlikely that shouldn't be a problem.

This revision is now accepted and ready to land.Mon, May 25, 4:22 PM

LGTM. Indeed, D57239 was the key difference.

An update to the manual page would also be welcome, as its content is now essentially stale (except on the essential point that zzz serves to suspend :-)).

usr.sbin/zzz/zzz.c
43–48

I'm not sure this comment is really useful here. Perhaps put it in the commit message instead?

obiwac marked 2 inline comments as done.

respond to olce@'s comments

This revision now requires review to proceed.Tue, May 26, 4:35 PM

Good to go (with one more small nit, the ordering of headers, to fix).

usr.sbin/zzz/zzz.c
10–21

Kernel headers should be first.

This revision is now accepted and ready to land.Tue, May 26, 7:30 PM
This revision was automatically updated to reflect the committed changes.