geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
IOGroup.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef IOGROUP_HPP_INCLUDE
7 #define IOGROUP_HPP_INCLUDE
8 
9 #include <functional>
10 #include <set>
11 #include <string>
12 #include <vector>
13 
14 #include "geopm_public.h"
15 
16 #include "PluginFactory.hpp"
17 
18 namespace geopm
19 {
21  {
22  public:
23  enum m_units_e {
32  M_NUM_UNITS
33  };
34 
45  M_NUM_SIGNAL_BEHAVIOR
46  };
47 
48  IOGroup() = default;
49  virtual ~IOGroup() = default;
50  static std::vector<std::string> iogroup_names(void);
51  static std::unique_ptr<IOGroup> make_unique(const std::string &iogroup_name);
54  virtual std::set<std::string> signal_names(void) const = 0;
57  virtual std::set<std::string> control_names(void) const = 0;
62  virtual bool is_valid_signal(const std::string &signal_name) const = 0;
67  virtual bool is_valid_control(const std::string &control_name) const = 0;
71  virtual int signal_domain_type(const std::string &signal_name) const = 0;
75  virtual int control_domain_type(const std::string &control_name) const = 0;
86  virtual int push_signal(const std::string &signal_name,
87  int domain_type,
88  int domain_idx) = 0;
100  virtual int push_control(const std::string &control_name,
101  int domain_type,
102  int domain_idx) = 0;
106  virtual void read_batch(void) = 0;
110  virtual void write_batch(void) = 0;
117  virtual double sample(int sample_idx) = 0;
125  virtual void adjust(int control_idx,
126  double setting) = 0;
139  virtual double read_signal(const std::string &signal_name,
140  int domain_type,
141  int domain_idx) = 0;
154  virtual void write_control(const std::string &control_name,
155  int domain_type,
156  int domain_idx,
157  double setting) = 0;
162  virtual void save_control(void) = 0;
165  virtual void restore_control(void) = 0;
169  virtual std::function<double(const std::vector<double> &)> agg_function(const std::string &signal_name) const = 0;
174  virtual std::function<std::string(double)> format_function(const std::string &signal_name) const;
178  virtual std::string signal_description(const std::string &signal_name) const = 0;
182  virtual std::string control_description(const std::string &control_name) const = 0;
191  virtual int signal_behavior(const std::string &signal_name) const = 0;
192  virtual void save_control(const std::string &save_path) = 0;
193  virtual void restore_control(const std::string &save_path) = 0;
212  virtual std::string name(void) const = 0;
213 
215  static m_units_e string_to_units(const std::string &str);
217  static std::string units_to_string(int);
219  static m_signal_behavior_e string_to_behavior(const std::string &str);
220 
221  static const std::string M_PLUGIN_PREFIX;
222 
223  private:
224  static const std::string M_UNITS[];
225  static const std::string M_BEHAVIORS[];
226  static const std::map<std::string, m_units_e> M_UNITS_STRING;
227  static const std::map<std::string, m_signal_behavior_e> M_BEHAVIOR_STRING;
228  };
229 
230  class GEOPM_PUBLIC IOGroupFactory : public PluginFactory<IOGroup>
231  {
232  public:
233  IOGroupFactory();
234  virtual ~IOGroupFactory() = default;
235  };
236 
238  iogroup_factory(void);
239 }
240 
241 #endif
Definition: IOGroup.hpp:231
virtual ~IOGroupFactory()=default
Definition: IOGroup.hpp:21
m_signal_behavior_e
Description of the runtime behavior of a signal.
Definition: IOGroup.hpp:36
@ M_SIGNAL_BEHAVIOR_VARIABLE
signals that vary up and down over time
Definition: IOGroup.hpp:42
@ M_SIGNAL_BEHAVIOR_CONSTANT
signals that have a constant value
Definition: IOGroup.hpp:38
@ M_SIGNAL_BEHAVIOR_MONOTONE
signals that increase monotonically
Definition: IOGroup.hpp:40
@ M_SIGNAL_BEHAVIOR_LABEL
signals that should not be summarized over time
Definition: IOGroup.hpp:44
virtual bool is_valid_signal(const std::string &signal_name) const =0
Test if signal_name refers to a signal supported by the group.
virtual void save_control(const std::string &save_path)=0
virtual void save_control(void)=0
Save the state of all controls so that any subsequent changes made through the IOGroup can be undone ...
virtual int signal_behavior(const std::string &signal_name) const =0
Returns a hint about how a signal will change as a function of time.
virtual std::set< std::string > control_names(void) const =0
Returns the names of all controls provided by the IOGroup.
IOGroup()=default
virtual void restore_control(void)=0
Restore all controls to values recorded in previous call to the save() method.
virtual std::string name(void) const =0
Get the IOGroup name.
virtual int control_domain_type(const std::string &control_name) const =0
Query the domain for a named control.
virtual void restore_control(const std::string &save_path)=0
virtual std::string control_description(const std::string &control_name) const =0
Returns a description of the control. This string can be used by tools to generate help text for user...
virtual bool is_valid_control(const std::string &control_name) const =0
Test if control_name refers to a control supported by the group.
virtual double sample(int sample_idx)=0
Retrieve signal value from data read by last call to read_batch() for a particular signal previously ...
virtual void read_batch(void)=0
Read all pushed signals from the platform so that the next call to sample() will reflect the updated ...
virtual double read_signal(const std::string &signal_name, int domain_type, int domain_idx)=0
Read from platform and interpret into SI units a signal given its name and domain....
virtual void write_batch(void)=0
Write all of the pushed controls so that values previously given to adjust() are written to the platf...
virtual void adjust(int control_idx, double setting)=0
Adjust a setting for a particular control that was previously pushed with push_control()....
virtual int push_signal(const std::string &signal_name, int domain_type, int domain_idx)=0
Add a signal to the list of signals that is read by read_batch() and sampled by sample().
virtual std::set< std::string > signal_names(void) const =0
Returns the names of all signals provided by the IOGroup.
virtual std::function< double(const std::vector< double > &)> agg_function(const std::string &signal_name) const =0
Return a function that should be used when aggregating the given signal.
virtual void write_control(const std::string &control_name, int domain_type, int domain_idx, double setting)=0
Interpret the setting and write setting to the platform. Does not modify the values stored by calling...
virtual int push_control(const std::string &control_name, int domain_type, int domain_idx)=0
Add a control to the list of controls that is written by write_batch() and configured with adjust().
virtual ~IOGroup()=default
virtual std::string signal_description(const std::string &signal_name) const =0
Returns a description of the signal. This string can be used by tools to generate help text for users...
m_units_e
Definition: IOGroup.hpp:23
@ M_UNITS_HERTZ
Definition: IOGroup.hpp:26
@ M_UNITS_JOULES
Definition: IOGroup.hpp:28
@ M_UNITS_VOLTS
Definition: IOGroup.hpp:31
@ M_UNITS_CELSIUS
Definition: IOGroup.hpp:29
@ M_UNITS_WATTS
Definition: IOGroup.hpp:27
@ M_UNITS_AMPERES
Definition: IOGroup.hpp:30
@ M_UNITS_NONE
Definition: IOGroup.hpp:24
@ M_UNITS_SECONDS
Definition: IOGroup.hpp:25
static const std::string M_PLUGIN_PREFIX
Definition: IOGroup.hpp:221
virtual int signal_domain_type(const std::string &signal_name) const =0
Query the domain for a named signal.
Definition: PluginFactory.hpp:22
#define GEOPM_PUBLIC
Definition: geopm_public.h:10
Definition: Agg.cpp:20
IOGroupFactory & iogroup_factory(void)
Definition: IOGroup.cpp:171
std::unique_ptr< Type > make_unique(Args &&...args)
Implementation of std::make_unique (C++14) for C++11. Note that this version will only work for non-a...
Definition: Helper.hpp:28