geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
Classes | Public Member Functions | Static Public Member Functions | List of all members
geopm::SaveControl Class Referenceabstract

Class that enables the save/restore feature for IOGroups. More...

#include <SaveControl.hpp>

Inheritance diagram for geopm::SaveControl:
Inheritance graph
[legend]

Classes

struct  m_setting_s
 Structure that holds the parameters passed to the IOGroup::write_control() method. More...
 

Public Member Functions

 SaveControl ()=default
 
virtual ~SaveControl ()=default
 
virtual std::string json (void) const =0
 Get saved control settings JSON. More...
 
virtual std::vector< m_setting_ssettings (void) const =0
 Get saved control settings structures. More...
 
virtual void write_json (const std::string &save_path) const =0
 Write the JSON formatted settings to a file. More...
 
virtual void restore (IOGroup &io_group) const =0
 Write all of the control settings to the platform. More...
 
virtual std::set< std::string > unsaved_controls (const std::set< std::string > &all_controls) const =0
 

Static Public Member Functions

static std::unique_ptr< SaveControlmake_unique (const std::vector< m_setting_s > &settings)
 Create a unique pointer to SaveControl object from a vector of setting structures. More...
 
static std::unique_ptr< SaveControlmake_unique (const std::string &json_string)
 Create a unique pointer to SaveControl object from a JSON formatted string. More...
 
static std::unique_ptr< SaveControlmake_unique (IOGroup &io_group)
 Create a unique pointer to SaveControl object by querying an IOGroup. More...
 

Detailed Description

Class that enables the save/restore feature for IOGroups.

This is a helper class that can be used by IOGroups to enable control settings to be stored to and loaded from disk in JSON format. Additionally it can write all the settings to facilitate the restore.

The JSON format for the data structure is a list of maps. Each map represents a m_setting_s structure by mapping a string naming the structure field to the value. An example JSON string follows

[{"name": "MSR::PERF_CTL:FREQ",
  "domain_type": 2,
  "domain_idx": 0,
  "setting": 2.4e9},
 {"name": "MSR::PERF_CTL:FREQ",
  "domain_type": 2,
  "domain_idx": 1,
  "setting": 2.4e9}]

Constructor & Destructor Documentation

◆ SaveControl()

geopm::SaveControl::SaveControl ( )
default

◆ ~SaveControl()

virtual geopm::SaveControl::~SaveControl ( )
virtualdefault

Member Function Documentation

◆ json()

virtual std::string geopm::SaveControl::json ( void  ) const
pure virtual

Get saved control settings JSON.

Returns
A JSON representation of a vector of m_setting_s structures

Implemented in geopm::SaveControlImp.

◆ make_unique() [1/3]

std::unique_ptr< SaveControl > geopm::SaveControl::make_unique ( const std::string &  json_string)
static

Create a unique pointer to SaveControl object from a JSON formatted string.

Parameters
json_string[in] A JSON representation of a vector of m_setting_s structures.
Returns
A unique pointer to an object that implements the SaveControl interface.

◆ make_unique() [2/3]

std::unique_ptr< SaveControl > geopm::SaveControl::make_unique ( const std::vector< m_setting_s > &  settings)
static

Create a unique pointer to SaveControl object from a vector of setting structures.

This method enables the construction when the user wants explicit control of the setting parameters.

Parameters
settingsVector of setting structures for all controls to be restored
Returns
A unique pointer to an object that implements the SaveControl interface.

◆ make_unique() [3/3]

std::unique_ptr< SaveControl > geopm::SaveControl::make_unique ( IOGroup io_group)
static

Create a unique pointer to SaveControl object by querying an IOGroup.

A list of all low level control names is determined based on the control_names() return values that are within the IOGroup namespace. The corresponding signal is read for all these low level controls at their native domain. The values that are read are stored in the SaveControl object that is returned.

Parameters
io_group[in] An IOGroup that implements controls
Returns
A unique pointer to an object that implements the SaveControl interface.

◆ restore()

virtual void geopm::SaveControl::restore ( IOGroup io_group) const
pure virtual

Write all of the control settings to the platform.

Make a sequence of calls to io_group.write_control() with the parameters returned by the settings() method.

Parameters
io_group[in] An IOGroup that implements controls

Implemented in geopm::SaveControlImp.

◆ settings()

virtual std::vector<m_setting_s> geopm::SaveControl::settings ( void  ) const
pure virtual

Get saved control settings structures.

Returns
Vector of setting structures that represent the saved control state.

Implemented in geopm::SaveControlImp.

◆ unsaved_controls()

virtual std::set<std::string> geopm::SaveControl::unsaved_controls ( const std::set< std::string > &  all_controls) const
pure virtual

Implemented in geopm::SaveControlImp.

◆ write_json()

virtual void geopm::SaveControl::write_json ( const std::string &  save_path) const
pure virtual

Write the JSON formatted settings to a file.

Writes the string to the specified output file. The file is overwritten if it already exists. An exception is raised if the directory containing the output does not exist, or if the file cannot be created for any other reason.

Parameters
save_path[in] The file path where the JSON string is written.

Implemented in geopm::SaveControlImp.


The documentation for this class was generated from the following files: