|
powerd++
0.4.4
|
Implements a library intended to be injected into a clock frequency deamon via LD_PRELOAD. More...
#include "utility.hpp"#include "constants.hpp"#include "version.hpp"#include "sys/env.hpp"#include "sys/io.hpp"#include <unordered_map>#include <map>#include <string>#include <regex>#include <memory>#include <thread>#include <exception>#include <mutex>#include <chrono>#include <vector>#include <algorithm>#include <cstring>#include <cassert>#include <csignal>#include <sys/types.h>#include <sys/sysctl.h>#include <sys/resource.h>#include <libutil.h>#include <dlfcn.h>#include <unistd.h>Classes | |
| struct | anonymous_namespace{libloadplay.cpp}::mib_t |
| Represents MIB, but wraps it to provide the necessary operators to use it as an std::map key. More... | |
| class | anonymous_namespace{libloadplay.cpp}::Callback< FunctionArgs > |
| Implements a recursion safe std::function wrapper. More... | |
| class | anonymous_namespace{libloadplay.cpp}::SysctlValue |
| Instances of this class represents a specific sysctl value. More... | |
| class | anonymous_namespace{libloadplay.cpp}::Sysctls |
| Singleton class representing the sysctl table for this library. More... | |
| struct | anonymous_namespace{libloadplay.cpp}::CoreReport |
| The reported state of a single CPU pipeline. More... | |
| struct | anonymous_namespace{libloadplay.cpp}::CoreFrameReport |
| The report frame information for a single CPU pipeline. More... | |
| class | anonymous_namespace{libloadplay.cpp}::Report |
| Provides a mechanism to provide frame wise per core load information. More... | |
| class | anonymous_namespace{libloadplay.cpp}::Report::Frame |
| Represents a frame of the report. More... | |
| class | anonymous_namespace{libloadplay.cpp}::Emulator |
| Instances of this class represent an emulator session. More... | |
| struct | anonymous_namespace{libloadplay.cpp}::Emulator::Core |
| Per core information. More... | |
| class | anonymous_namespace{libloadplay.cpp}::Main |
| Singleton class representing the main execution environment. More... | |
| class | anonymous_namespace{libloadplay.cpp}::Hold< T > |
| Sets a referenced variable to a given value and restores it when going out of context. More... | |
Namespaces | |
| anonymous_namespace{libloadplay.cpp} | |
| File local scope. | |
Typedefs | |
| using | anonymous_namespace{libloadplay.cpp}::cycles_t = uint64_t |
| Clock cycle counting type. | |
| template<auto Ownership> | |
| using | anonymous_namespace{libloadplay.cpp}::ofile = io::file< Ownership, io::write > |
| Output file type alias. More... | |
| template<auto Ownership> | |
| using | anonymous_namespace{libloadplay.cpp}::ifile = io::file< Ownership, io::read > |
| Input file type alias. More... | |
Functions | |
| template<size_t Size> | |
| int | anonymous_namespace{libloadplay.cpp}::strcmp (char const *const s1, char const (&s2)[Size]) |
| Safe wrapper around strncmp, which automatically determines the buffer size of s2. More... | |
| std::regex | anonymous_namespace{libloadplay.cpp}::operator""_r (char const *const str, size_t const len) |
| User defined literal for regular expressions. More... | |
| template<typename ... ArgTs> | |
| constexpr void | anonymous_namespace{libloadplay.cpp}::dprintf (ArgTs &&... args) |
| Calls io::ferr.printf(...) if built with -DEBUG. More... | |
| template<> | |
| std::string | anonymous_namespace{libloadplay.cpp}::SysctlValue::get< std::string > () const |
| Returns a copy of the value string. More... | |
| template<typename... MsgTs> | |
| ofile< io::link > | anonymous_namespace{libloadplay.cpp}::debug (MsgTs &&... msg) |
| Print a debugging message if built with -DEBUG. More... | |
| template<typename... MsgTs> | |
| ofile< io::link > | anonymous_namespace{libloadplay.cpp}::warn (MsgTs &&... msg) |
| Print a warning. More... | |
| int | anonymous_namespace{libloadplay.cpp}::sys_result (int const result) |
| Combine sys_results with a computed result. More... | |
| template<typename... MsgTs> | |
| ofile< io::link > | anonymous_namespace{libloadplay.cpp}::fail (MsgTs &&... msg) |
| This prints an error message and sets sys_results to make the hijacked process fail. More... | |
| ofile< io::link > | anonymous_namespace{libloadplay.cpp}::operator<< (ofile< io::link > fout, CoreFrameReport const &frame) |
| Print recorded and running clock frequency and load for a frame. More... | |
| int | sysctl (const int *name, u_int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen) |
| Functions to intercept. More... | |
| int | sysctlnametomib (const char *name, int *mibp, size_t *sizep) |
| Intercept calls to sysctlnametomib(). More... | |
| int | daemon (int, int) |
| Intercept calls to daemon(). More... | |
| uid_t | geteuid (void) |
| Intercept calls to geteuid(). More... | |
| pidfh * | pidfile_open (const char *, mode_t, pid_t *) |
| Intercept calls to pidfile_open(). More... | |
| int | pidfile_write (pidfh *) |
| Intercept calls to pidfile_write(). More... | |
| int | pidfile_close (pidfh *) |
| Intercept calls to pidfile_close(). More... | |
| int | pidfile_remove (pidfh *) |
| Intercept calls to pidfile_remove(). More... | |
| int | pidfile_fileno (pidfh const *) |
| Intercept calls to pidfile_fileno(). More... | |
Variables | |
| constexpr const flag_t | anonymous_namespace{libloadplay.cpp}::FEATURES |
| The set of supported features. More... | |
| int | anonymous_namespace{libloadplay.cpp}::sys_results = 0 |
| The success return value of intercepted functions. | |
| class anonymous_namespace{libloadplay.cpp}::Sysctls | anonymous_namespace{libloadplay.cpp}::sysctls |
| Sole instance of Sysctls. | |
| bool | anonymous_namespace{libloadplay.cpp}::sysctl_startup = true |
| Set to activate fallback to the original sysctl functions. More... | |
| class anonymous_namespace{libloadplay.cpp}::Main | anonymous_namespace{libloadplay.cpp}::main |
| Sole instance of Main. | |
Implements a library intended to be injected into a clock frequency deamon via LD_PRELOAD.
This library reads instructions from io::fin (stdin) and outputs statistics about the hijacked process on io::fout (stdout).
The following environment variables affect the operation of loadplay:
| Variable | Description |
|---|---|
| LOADPLAY_IN | Alternative input file |
| LOADPLAY_OUT | Alternative output file |
| struct anonymous_namespace{libloadplay.cpp}::CoreReport |
The reported state of a single CPU pipeline.
| Class Members | ||
|---|---|---|
| mhz_t | freq | The core clock frequency in [MHz]. |
| double | load | The core load as a fraction. |
| struct anonymous_namespace{libloadplay.cpp}::CoreFrameReport |
The report frame information for a single CPU pipeline.
| Class Members | ||
|---|---|---|
| CoreReport | rec | The recorded core state. |
| CoreReport | run | The running core state. |
| struct anonymous_namespace{libloadplay.cpp}::Emulator::Core |
Per core information.
| Class Members | ||
|---|---|---|
| cycles_t | carryCycles[CPUSTATES] |
The cycles carried over to the next frame in [cycles]. This is determined at the beginning of frame and used to calculated the simulation load at the beginning of the next frame. |
| SysctlValue * | freqCtl |
The sysctl handler. The constructor ensures this points to a valid handler. |
| mhz_t | recFreq |
The recorded clock frequency. If FREQ_TRACKING is enabled this is updated at during the preliminary stage and used at the beginning of frame stage. |
| mhz_t | runFreq |
The clock frequency the simulation is running at. Updated at the end of frame and used in the next frame. |
| cycles_t | runLoadCycles |
The load cycles simulated for this frame in [cycles]. This is determined at the beginning of frame and used to calculate the reported load at the end of frame. |
| int daemon | ( | int | , |
| int | |||
| ) |
Intercept calls to daemon().
Prevents process from separating from the controlling terminal.
| uid_t geteuid | ( | void | ) |
Intercept calls to geteuid().
Tells the asking process that it is running as root.
| int pidfile_close | ( | pidfh * | ) |
Intercept calls to pidfile_close().
| int pidfile_fileno | ( | pidfh const * | ) |
Intercept calls to pidfile_fileno().
| pidfh* pidfile_open | ( | const char * | , |
| mode_t | , | ||
| pid_t * | |||
| ) |
Intercept calls to pidfile_open().
Prevents pidfile locking and creation by the hijacked process.
| int pidfile_remove | ( | pidfh * | ) |
Intercept calls to pidfile_remove().
| int pidfile_write | ( | pidfh * | ) |
Intercept calls to pidfile_write().
| int sysctl | ( | const int * | name, |
| u_int | namelen, | ||
| void * | oldp, | ||
| size_t * | oldlenp, | ||
| const void * | newp, | ||
| size_t | newlen | ||
| ) |
Functions to intercept.
Intercept calls to sysctl().
Uses the local anonymous_namespace{libloadplay::cpp}::sysctls store.
Falls back to the original under the following conditions:
The call may fail for 3 reasons:
| name,namelen,oldp,oldlenp,newp,newlen | Please refer to sysctl(3) |
| 0 | The call succeeded |
| -1 | The call failed |
| int sysctlnametomib | ( | const char * | name, |
| int * | mibp, | ||
| size_t * | sizep | ||
| ) |
Intercept calls to sysctlnametomib().
| name,mibp,sizep | Please refer to sysctl(3) |
| 0 | The call succeeded |
| -1 | The call failed |
1.8.17