geopm  3.1.0
GEOPM - Global Extensible Open Power Manager
All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Pages
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 {
30  M_NUM_UNITS
31  };
32 
43  M_NUM_SIGNAL_BEHAVIOR
44  };
45 
46  IOGroup() = default;
47  virtual ~IOGroup() = default;
48  static std::vector<std::string> iogroup_names(void);
49  static std::unique_ptr<IOGroup> make_unique(const std::string &iogroup_name);
52  virtual std::set<std::string> signal_names(void) const = 0;
55  virtual std::set<std::string> control_names(void) const = 0;
60  virtual bool is_valid_signal(const std::string &signal_name) const = 0;
65  virtual bool is_valid_control(const std::string &control_name) const = 0;
69  virtual int signal_domain_type(const std::string &signal_name) const = 0;
73  virtual int control_domain_type(const std::string &control_name) const = 0;
84  virtual int push_signal(const std::string &signal_name,
85  int domain_type,
86  int domain_idx) = 0;
98  virtual int push_control(const std::string &control_name,
99  int domain_type,
100  int domain_idx) = 0;
104  virtual void read_batch(void) = 0;
108  virtual void write_batch(void) = 0;
115  virtual double sample(int sample_idx) = 0;
123  virtual void adjust(int control_idx,
124  double setting) = 0;
137  virtual double read_signal(const std::string &signal_name,
138  int domain_type,
139  int domain_idx) = 0;
152  virtual void write_control(const std::string &control_name,
153  int domain_type,
154  int domain_idx,
155  double setting) = 0;
160  virtual void save_control(void) = 0;
163  virtual void restore_control(void) = 0;
167  virtual std::function<double(const std::vector<double> &)> agg_function(const std::string &signal_name) const = 0;
172  virtual std::function<std::string(double)> format_function(const std::string &signal_name) const;
176  virtual std::string signal_description(const std::string &signal_name) const = 0;
180  virtual std::string control_description(const std::string &control_name) const = 0;
189  virtual int signal_behavior(const std::string &signal_name) const = 0;
190  virtual void save_control(const std::string &save_path) = 0;
191  virtual void restore_control(const std::string &save_path) = 0;
210  virtual std::string name(void) const = 0;
211 
213  static m_units_e string_to_units(const std::string &str);
215  static std::string units_to_string(int);
217  static m_signal_behavior_e string_to_behavior(const std::string &str);
218 
219  static const std::string M_PLUGIN_PREFIX;
220 
221  private:
222  static const std::string M_UNITS[];
223  static const std::string M_BEHAVIORS[];
224  static const std::map<std::string, m_units_e> M_UNITS_STRING;
225  static const std::map<std::string, m_signal_behavior_e> M_BEHAVIOR_STRING;
226  };
227 
228  class GEOPM_PUBLIC IOGroupFactory : public PluginFactory<IOGroup>
229  {
230  public:
231  IOGroupFactory();
232  virtual ~IOGroupFactory() = default;
233  };
234 
236  iogroup_factory(void);
237 }
238 
239 #endif
Definition: IOGroup.hpp:229
virtual ~IOGroupFactory()=default
Definition: IOGroup.hpp:21
m_signal_behavior_e
Description of the runtime behavior of a signal.
Definition: IOGroup.hpp:34
@ M_SIGNAL_BEHAVIOR_VARIABLE
signals that vary up and down over time
Definition: IOGroup.hpp:40
@ M_SIGNAL_BEHAVIOR_CONSTANT
signals that have a constant value
Definition: IOGroup.hpp:36
@ M_SIGNAL_BEHAVIOR_MONOTONE
signals that increase monotonically
Definition: IOGroup.hpp:38
@ M_SIGNAL_BEHAVIOR_LABEL
signals that should not be summarized over time
Definition: IOGroup.hpp:42
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_CELSIUS
Definition: IOGroup.hpp:29
@ M_UNITS_WATTS
Definition: IOGroup.hpp:27
@ M_UNITS_NONE
Definition: IOGroup.hpp:24
@ M_UNITS_SECONDS
Definition: IOGroup.hpp:25
static const std::string M_PLUGIN_PREFIX
Definition: IOGroup.hpp:219
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:165
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:27