Documentation
¶
Overview ¶
Package powertune lets a person turn on, one by one, the power savings the kernel leaves off, and take them back (CasaOS#221).
These are the settings PowerTOP calls "tunables": a file of sysfs to write. Nothing here runs PowerTOP: the versions the distributions package cannot list a tunable without applying all of them, nor leave a device out. And nothing is turned on by itself: `powertop --auto-tune` suspends every USB device and network card, which loses keystrokes, drops links and disconnects dongles on many machines.
What is offered is a short list of what is safe to try and easy to take back:
- runtime power management (power/control = auto) of a PCI device of a few classes: USB controllers, audio, SMBus, communication and signal processing controllers. Never one that carries a disk or a network interface. A USB controller only sleeps once every device plugged into it does, so a keyboard or a Zigbee dongle left as it is keeps it awake;
- the same for a SATA port nothing is plugged into;
- two settings of the kernel PowerTOP also changes: the NMI watchdog off, and dirty pages written every 15 seconds instead of 5;
- the processor's energy/performance preference, on machines that have one.
A choice is kept in a file and written again at each start, for the same device only (its vendor and device ids are kept with it). Taking a choice back writes what the file held before.
A setting that freezes a machine must not come back at every boot. While settings are being tried (two minutes after one is turned on, or after the start wrote them again) a marker file exists; a start that finds it writes nothing and says so, until the person turns something on again or takes everything back.
Index ¶
Constants ¶
const Trial = 2 * time.Minute
Trial is how long a setting is watched after it is written: a box that stops within it does not get it back by itself.
Variables ¶
var ( // ErrUnknown is an id that names nothing offered on this machine. ErrUnknown = errors.New("no such power setting on this machine") // ErrPreference is a processor preference the machine does not list. ErrPreference = errors.New("this machine does not offer that processor preference") )
Functions ¶
This section is empty.
Types ¶
type CPU ¶
type CPU struct {
Preference string `json:"preference"`
Available []string `json:"available"`
Chosen bool `json:"chosen"`
}
CPU is the processor's energy/performance preference, absent on machines without one.
type Item ¶
type Item struct {
ID string `json:"id"`
// Kind is usb-controller, sata-port, pci or system.
Kind string `json:"kind"`
// Name says what it is, in the kernel's words: a class, an address, vendor:device.
Name string `json:"name"`
// Saving: the device may sleep when idle (power/control is auto).
Saving bool `json:"saving"`
// Chosen: turned on here, and written again at each start.
Chosen bool `json:"chosen"`
// Status is what the kernel says of it now: active, suspended, or nothing when it does not say.
Status string `json:"status,omitempty"`
}
Item is one device whose runtime power management can be turned on.
type Status ¶
type Status struct {
Items []Item `json:"items"`
CPU *CPU `json:"cpu,omitempty"`
// PackageWatts is what the processor package drew over a short moment, when the machine counts it.
PackageWatts *float64 `json:"package_watts,omitempty"`
// Held: the choices were not written again at this start, because the box stopped while they were being tried.
Held bool `json:"held"`
// Conflicts are other tools set up on this box that write the same settings at each start: powertop, tlp, tuned.
Conflicts []string `json:"conflicts,omitempty"`
}
Status is what the dashboard shows.
type Tuner ¶
type Tuner struct {
Sys string
Proc string
Etc string
State string
// Sleep waits between the two readings of the energy counter; After runs f once d has passed. Tests replace both.
Sleep func(time.Duration)
After func(d time.Duration, f func())
// contains filtered or unexported fields
}
Tuner reads and writes the settings under Sys (the root of sysfs) and Proc, and keeps the choices in State. Etc is where the other tools that do the same are looked for.
func (*Tuner) Apply ¶
Apply writes the choices again, at the start of the box: the kernel forgets them at each boot. A choice whose device is no longer the same one (another card at that address) is left alone, and kept in case the device comes back. Nothing is written when the last trial did not end: the box stopped while settings were being tried, and one of them may be why.
func (*Tuner) SetAll ¶
SetAll turns on everything offered that is not on yet: the list is already only what is safe to try.
func (*Tuner) SetPreference ¶
SetPreference sets the processor's preference on every core; an empty one takes it back to what it was.