powerd++  0.4.4
Classes | Namespaces | Enumerations | Functions | Variables
powerd++.cpp File Reference

Implements powerd++ a drop in replacement for FreeBSD's powerd. More...

#include "Options.hpp"
#include "Cycle.hpp"
#include "types.hpp"
#include "constants.hpp"
#include "errors.hpp"
#include "clas.hpp"
#include "utility.hpp"
#include "sys/sysctl.hpp"
#include "sys/pidfile.hpp"
#include "sys/signal.hpp"
#include "sys/io.hpp"
#include <locale>
#include <memory>
#include <algorithm>
#include <limits>
#include <cstdlib>
#include <cstdint>
#include <sys/resource.h>
Include dependency graph for powerd++.cpp:

Classes

struct  anonymous_namespace{powerd++.cpp}::CoreGroup
 Contains the management information for a group of cores with a common clock frequency. More...
 
struct  anonymous_namespace{powerd++.cpp}::Core
 Contains the management information for a single CPU core. More...
 
struct  anonymous_namespace{powerd++.cpp}::Global
 A collection of all the gloabl, mutable states. More...
 
struct  anonymous_namespace{powerd++.cpp}::Global::ACSet
 Per AC line state settings. More...
 
class  anonymous_namespace{powerd++.cpp}::FreqGuard
 A core frequency guard. More...
 

Namespaces

 anonymous_namespace{powerd++.cpp}
 File local scope.
 

Enumerations

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

Functions

template<typename... MsgTs>
void anonymous_namespace{powerd++.cpp}::verbose (MsgTs &&... msg)
 Outputs the given printf style message on stderr if g.verbose is set. More...
 
void anonymous_namespace{powerd++.cpp}::sysctl_fail (sys::sc_error< sys::ctl::error > const err)
 Treat sysctl errors. More...
 
void anonymous_namespace{powerd++.cpp}::init ()
 Perform initial tasks. More...
 
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. More...
 
template<>
void anonymous_namespace{powerd++.cpp}::update_loads< 0, 0 > ()
 Do nada if neither load nor temperature are to be updated.
 
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. More...
 
void anonymous_namespace{powerd++.cpp}::update_freq ()
 Dispatch update_freq<>().
 
void anonymous_namespace{powerd++.cpp}::init_loads ()
 Fill the loads buffers with n samples. More...
 
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. More...
 
void anonymous_namespace{powerd++.cpp}::read_args (int const argc, char const *const argv[])
 Parse command line arguments. More...
 
void anonymous_namespace{powerd++.cpp}::show_settings ()
 Prints the configuration on stderr in verbose mode.
 
void anonymous_namespace{powerd++.cpp}::signal_recv (int signal)
 Sets g.signal, terminating the main loop. More...
 
void anonymous_namespace{powerd++.cpp}::run_daemon ()
 Daemonise and run the main loop.
 
int main (int argc, char *argv[])
 Main routine, setup and execute daemon, print errors. More...
 

Variables

struct anonymous_namespace{powerd++.cpp}::Global anonymous_namespace{powerd++.cpp}::g
 The gobal state.
 
const char *const anonymous_namespace{powerd++.cpp}::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< OE > anonymous_namespace{powerd++.cpp}::PARAMETERS []
 Definitions of command line parameters. More...
 

Detailed Description

Implements powerd++ a drop in replacement for FreeBSD's powerd.


Class Documentation

◆ 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.

◆ 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}::Global::ACSet

struct anonymous_namespace{powerd++.cpp}::Global::ACSet

Per AC line state settings.

Collaboration diagram for anonymous_namespace{powerd++.cpp}::Global::ACSet:
[legend]
Class Members
mhz_t freq_max Highest frequency to set in MHz.
mhz_t freq_min Lowest frequency to set in MHz.
const char *const name The string representation of this state.
mhz_t target_freq Fixed clock frequencies to use if the target load is set to 0.
cptime_t target_load Target load times [0, 1024].

The value 0 indicates the corresponding fixed frequency setting from target_freqs should be used.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main routine, setup and execute daemon, print errors.

Parameters
argc,argvThe command line arguments
Returns
An exit code
See also
Exit