powerd++  0.4.4
Classes | Enumerations | Functions | Variables
anonymous_namespace{powerd++.cpp} Namespace Reference

File local scope. More...

Classes

struct  Core
 Contains the management information for a single CPU core. More...
 
struct  CoreGroup
 Contains the management information for a group of cores with a common clock frequency. More...
 
class  FreqGuard
 A core frequency guard. More...
 
struct  Global
 A collection of all the gloabl, mutable states. More...
 

Enumerations

enum  AcLineState : unsigned int { AcLineState::BATTERY, AcLineState::ONLINE, AcLineState::UNKNOWN, AcLineState::LENGTH }
 The available AC line states. More...
 
enum  OE {
  OE::USAGE, OE::MODE_AC, OE::MODE_BATT, OE::FREQ_MIN,
  OE::FREQ_MAX, OE::FREQ_MIN_AC, OE::FREQ_MAX_AC, OE::FREQ_MIN_BATT,
  OE::FREQ_MAX_BATT, OE::FREQ_RANGE, OE::FREQ_RANGE_AC, OE::FREQ_RANGE_BATT,
  OE::HITEMP_RANGE, OE::MODE_UNKNOWN, OE::TEMP_CTL, OE::IVAL_POLL,
  OE::FILE_PID, OE::FLAG_VERBOSE, OE::FLAG_FOREGROUND, OE::FLAG_NICE,
  OE::CNT_SAMPLES, OE::IGNORE, OE::OPT_UNKNOWN, OE::OPT_NOOPT,
  OE::OPT_DASH, OE::OPT_LDASH, OE::OPT_DONE
}
 An enum for command line parsing. More...
 

Functions

template<typename... MsgTs>
void verbose (MsgTs &&... msg)
 Outputs the given printf style message on stderr if g.verbose is set. More...
 
void sysctl_fail (sys::sc_error< sys::ctl::error > const err)
 Treat sysctl errors. More...
 
void init ()
 Perform initial tasks. More...
 
template<bool Load = 1, bool Temperature = 0>
void update_loads ()
 Updates the cp_times ring buffer and computes the load average for each core. More...
 
template<>
void update_loads< 0, 0 > ()
 Do nada if neither load nor temperature are to be updated.
 
template<bool Foreground, bool Temperature, bool Fixed>
void update_freq (Global::ACSet const &acstate)
 Update the CPU clocks depending on the AC line state and targets. More...
 
void update_freq ()
 Dispatch update_freq<>().
 
void init_loads ()
 Fill the loads buffers with n samples. More...
 
void set_mode (AcLineState const line, char const *const str)
 Sets a load target or fixed frequency for the given AC line state. More...
 
void read_args (int const argc, char const *const argv[])
 Parse command line arguments. More...
 
void show_settings ()
 Prints the configuration on stderr in verbose mode.
 
void signal_recv (int signal)
 Sets g.signal, terminating the main loop. More...
 
void run_daemon ()
 Daemonise and run the main loop.
 

Variables

struct anonymous_namespace{powerd++.cpp}::Global g
 The gobal state.
 
const char *const USAGE = "[-hvfN] [-abn mode] [-mM freq] [-FAB freq:freq] [-H temp:temp] [-t sysctl] [-p ival] [-s cnt] [-P file]"
 The short usage string.
 
const Parameter< OEPARAMETERS []
 Definitions of command line parameters. More...
 

Detailed Description

File local scope.


Class Documentation

◆ anonymous_namespace{powerd++.cpp}::Core

struct anonymous_namespace{powerd++.cpp}::Core

Contains the management information for a single CPU core.

Collaboration diagram for anonymous_namespace{powerd++.cpp}::Core:
[legend]
Class Members
cptime_t all Count of all ticks.
const cptime_t * cp_time A pointer to the kern.cp_times section for this core.
CoreGroup * group The core that controls the frequency for this core.
cptime_t idle The idle ticks count.
SysctlSync< decikelvin_t > temp The dev.cpu.

d.temperature sysctl, if present.

◆ anonymous_namespace{powerd++.cpp}::CoreGroup

struct anonymous_namespace{powerd++.cpp}::CoreGroup

Contains the management information for a group of cores with a common clock frequency.

Collaboration diagram for anonymous_namespace{powerd++.cpp}::CoreGroup:
[legend]
Class Members
coreid_t corei The number of the core owning dev.cpu.

d.freq.

SysctlSync< mhz_t > freq The sysctl dev.cpu.

d.freq.

Max< mhz_t > load The maximum load reported by all cores in the group.

This is updated by update_loads().

unique_ptr< mhz_t[]> loads A ring buffer of maximum load samples for this core group.

Each maximum load sample is weighted with the core frequency at which it was taken.

This is updated by update_loads().

mhz_t loadsum The maximum load sum of all controlled cores.

This is updated by update_loads().

Min< mhz_t > max The maximum group clock rate.

The least of all core maxima in the group.

Max< mhz_t > min The minimum group clock rate.

The greatest of all core minima in the group.

mhz_t sample_freq The dev.cpu.

d.freq value for the current load sample.

This is updated by update_loads().

Max< decikelvin_t > temp The maximum temperature measurement taken in the group.
Min< decikelvin_t > temp_crit Critical core temperature in dK.
Min< decikelvin_t > temp_high High core temperature in dK.

Enumeration Type Documentation

◆ AcLineState

enum anonymous_namespace{powerd++.cpp}::AcLineState : unsigned int
strong

The available AC line states.

Enumerator
BATTERY 

Battery is power source.

ONLINE 

External power source.

UNKNOWN 

Unknown power source.

LENGTH 

Enum length.

◆ OE

enum anonymous_namespace{powerd++.cpp}::OE
strong

An enum for command line parsing.

Enumerator
USAGE 

Print help.

MODE_AC 

Set AC power mode.

MODE_BATT 

Set battery power mode.

FREQ_MIN 

Set minimum clock frequency.

FREQ_MAX 

Set maximum clock frequency.

FREQ_MIN_AC 

Set minimum clock frequency on AC power.

FREQ_MAX_AC 

Set maximum clock frequency on AC power.

FREQ_MIN_BATT 

Set minimum clock frequency on battery power.

FREQ_MAX_BATT 

Set maximum clock frequency on battery power.

FREQ_RANGE 

Set clock frequency range.

FREQ_RANGE_AC 

Set clock frequency range on AC power.

FREQ_RANGE_BATT 

Set clock frequency range on battery power.

HITEMP_RANGE 

Set a high temperature range.

MODE_UNKNOWN 

Set unknown power source mode.

TEMP_CTL 

Override temperature sysctl.

IVAL_POLL 

Set polling interval.

FILE_PID 

Set pidfile.

FLAG_VERBOSE 

Activate verbose output on stderr.

FLAG_FOREGROUND 

Stay in foreground, log events to stdout.

FLAG_NICE 

Treat nice time as idle.

CNT_SAMPLES 

Set number of load samples.

IGNORE 

Legacy settings.

OPT_UNKNOWN 

Obligatory.

OPT_NOOPT 

Obligatory.

OPT_DASH 

Obligatory.

OPT_LDASH 

Obligatory.

OPT_DONE 

Obligatory.

Function Documentation

◆ init()

void anonymous_namespace{powerd++.cpp}::init ( )

Perform initial tasks.

  • Get number of CPU cores/threads
  • Determine the clock controlling core for each core
  • Set the MIBs of hw.acpi.acline and kern.cp_times

◆ init_loads()

void anonymous_namespace{powerd++.cpp}::init_loads ( )

Fill the loads buffers with n samples.

The samples are filled with the target load, this creates a bias to stay at the initial frequency until sufficient real measurements come in to flush these initial samples out.

◆ read_args()

void anonymous_namespace{powerd++.cpp}::read_args ( int const  argc,
char const *const  argv[] 
)

Parse command line arguments.

Parameters
argc,argvThe command line arguments

◆ set_mode()

void anonymous_namespace{powerd++.cpp}::set_mode ( AcLineState const  line,
char const *const  str 
)

Sets a load target or fixed frequency for the given AC line state.

The string must be in the following format:

mode_predefined = "minimum" | "min" | "maximum" | "max" |
                  "adaptive" | "adp" | "hiadptive" | "hadp";
mode =            mode_predefined | load | freq;

Scalar values are treated as loads.

The predefined values have the following meaning:

Symbol Meaning
minimum The minimum clock rate (default 0 MHz)
min
maximum The maximum clock rate (default 1000000 MHz)
max
adaptive A target load of 50%
adp
hiadptive A target load of 37.5%
hadp
Parameters
lineThe power line state to set the mode for
strA mode string

◆ signal_recv()

void anonymous_namespace{powerd++.cpp}::signal_recv ( int  signal)

Sets g.signal, terminating the main loop.

Parameters
signalThe signal number received

◆ sysctl_fail()

void anonymous_namespace{powerd++.cpp}::sysctl_fail ( sys::sc_error< sys::ctl::error > const  err)
inline

Treat sysctl errors.

Fails appropriately for the given error.

Parameters
errThe errno value after calling sysctl

◆ update_freq()

template<bool Foreground, bool Temperature, bool Fixed>
void anonymous_namespace{powerd++.cpp}::update_freq ( Global::ACSet const &  acstate)

Update the CPU clocks depending on the AC line state and targets.

Template Parameters
ForegroundSet for foreground operation (reporting on std::cout)
TemperatureSet for temperature based throttling
FixedSet for fixed frequency mode
Parameters
acstateThe set of acline dependent variables

◆ update_loads()

template<bool Load = 1, bool Temperature = 0>
void anonymous_namespace{powerd++.cpp}::update_loads ( )

Updates the cp_times ring buffer and computes the load average for each core.

Template Parameters
LoadDetermines whether CoreGroup::loadsum is updated
TemperatureDetermines whether CoreGroup::temp is updated

◆ verbose()

template<typename... MsgTs>
void anonymous_namespace{powerd++.cpp}::verbose ( MsgTs &&...  msg)
inline

Outputs the given printf style message on stderr if g.verbose is set.

Template Parameters
MsgTsThe message argument types
Parameters
msgThe message to output

Variable Documentation

◆ PARAMETERS

const Parameter<OE> anonymous_namespace{powerd++.cpp}::PARAMETERS[]
Initial value:
{
{OE::USAGE, 'h', "help", "", "Show usage and exit"},
{OE::FLAG_VERBOSE, 'v', "verbose", "", "Be verbose"},
{OE::FLAG_FOREGROUND, 'f', "foreground", "", "Stay in foreground"},
{OE::FLAG_NICE, 'N', "idle-nice", "", "Treat nice time as idle"},
{OE::MODE_AC, 'a', "ac", "mode", "Mode while on AC power"},
{OE::MODE_BATT, 'b', "batt", "mode", "Mode while on battery power"},
{OE::MODE_UNKNOWN, 'n', "unknown", "mode", "Mode while power source is unknown"},
{OE::FREQ_MIN, 'm', "min", "freq", "Minimum CPU frequency"},
{OE::FREQ_MAX, 'M', "max", "freq", "Maximum CPU frequency"},
{OE::FREQ_MIN_AC, 0 , "min-ac", "freq", "Minimum CPU frequency on AC power"},
{OE::FREQ_MAX_AC, 0 , "max-ac", "freq", "Maximum CPU frequency on AC power"},
{OE::FREQ_MIN_BATT, 0 , "min-batt", "freq", "Minimum CPU frequency on battery power"},
{OE::FREQ_MAX_BATT, 0 , "max-batt", "freq", "Maximum CPU frequency on battery power"},
{OE::FREQ_RANGE, 'F', "freq-range", "freq:freq", "CPU frequency range (min:max)"},
{OE::FREQ_RANGE_AC, 'A', "freq-range-ac", "freq:freq", "CPU frequency range on AC power"},
{OE::FREQ_RANGE_BATT, 'B', "freq-range-batt", "freq:freq", "CPU frequency range on battery power"},
{OE::HITEMP_RANGE, 'H', "hitemp-range", "temp:temp", "High temperature range (high:critical)"},
{OE::TEMP_CTL, 't', "temperature", "sysctl", "Override temperature source sysctl"},
{OE::IVAL_POLL, 'p', "poll", "ival", "The polling interval"},
{OE::CNT_SAMPLES, 's', "samples", "cnt", "The number of samples to use"},
{OE::FILE_PID, 'P', "pid", "file", "Alternative PID file"},
{OE::IGNORE, 'i', "", "load", "Ignored"},
{OE::IGNORE, 'r', "", "load", "Ignored"}
}

Definitions of command line parameters.

anonymous_namespace{powerd++.cpp}::USAGE
const char *const USAGE
The short usage string.
Definition: powerd++.cpp:991