geopm  3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
ConstConfigIOGroup.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 CONSTCONFIGIOGROUP_HPP_INCLUDE
7 #define CONSTCONFIGIOGROUP_HPP_INCLUDE
8 
9 #include <map>
10 #include <string>
11 #include <memory>
12 
13 #include "geopm/json11.hpp"
14 
15 #include "geopm/IOGroup.hpp"
16 
17 namespace geopm
18 {
19  class PlatformTopo;
20 
21  class ConstConfigIOGroup : public IOGroup
22  {
23  public:
25  ConstConfigIOGroup(const PlatformTopo& topo,
26  const std::string &user_file_path,
27  const std::string &default_file_path,
28  const std::string &hostname);
29  std::set<std::string> signal_names(void) const override;
31  std::set<std::string> control_names(void) const override;
32  bool is_valid_signal(const std::string &signal_name) const override;
34  bool is_valid_control(const std::string &control_name) const override;
36  int signal_domain_type(const std::string &signal_name) const override;
38  int control_domain_type(const std::string &control_name) const override;
39  int push_signal(const std::string &signal_name, int domain_type, int domain_idx) override;
43  int push_control(const std::string &control_name, int domain_type, int domain_idx) override;
45  void read_batch(void) override;
47  void write_batch(void) override;
48  double sample(int batch_idx) override;
52  void adjust(int batch_idx, double setting) override;
53  double read_signal(const std::string &signal_name, int domain_type, int domain_idx) override;
57  void write_control(const std::string &control_name, int domain_type, int domain_idx, double setting) override;
59  void save_control(void) override;
61  void restore_control(void) override;
62  std::function<double(const std::vector<double> &)> agg_function(const std::string &signal_name) const override;
63  std::function<std::string(double)> format_function(const std::string &signal_name) const override;
64  std::string signal_description(const std::string &signal_name) const override;
66  std::string control_description(const std::string &control_name) const override;
68  int signal_behavior(const std::string &signal_name) const override;
72  void save_control(const std::string &save_path) override;
76  void restore_control(const std::string &save_path) override;
77  std::string name(void) const override;
78  static std::string plugin_name(void);
79  static std::unique_ptr<IOGroup> make_plugin(void);
80 
81  private:
82  struct m_signal_desc_s {
83  json11::Json::Type type;
84  bool required;
85  };
86 
87  struct m_signal_info_s {
88  int units;
89  int domain;
90  std::function<double(const std::vector<double> &)> agg_function;
91  std::string description;
92  bool is_common_value_provided;
93  std::vector<double> values;
94  };
95 
96  struct m_signal_ref_s {
97  std::shared_ptr<m_signal_info_s> signal_info;
98  int domain_idx;
99  };
100 
101  void parse_config_json(const std::string &config);
102  static json11::Json construct_config_json_obj(const std::string &config);
103  static void check_json_signal(const json11::Json::object::value_type &signal);
104 
105  static const std::string M_PLUGIN_NAME;
106  static const std::string M_SIGNAL_PREFIX;
107  static const std::map<std::string, m_signal_desc_s> M_SIGNAL_FIELDS;
108  static const std::string M_CONFIG_PATH_ENV;
109  static const std::string M_DEFAULT_CONFIG_FILE_PATH;
110 
111  const PlatformTopo &m_platform_topo;
112  const std::string M_THIS_HOST;
113  std::map<std::string, std::shared_ptr<m_signal_info_s> > m_signal_available;
114  std::vector<m_signal_ref_s> m_pushed_signals;
115  };
116 }
117 
118 #endif
Definition: ConstConfigIOGroup.hpp:22
void restore_control(void) override
Does nothing; this IOGroup does not provide any controls.
Definition: ConstConfigIOGroup.cpp:244
std::string signal_description(const std::string &signal_name) const override
Returns a description of the signal. This string can be used by tools to generate help text for users...
Definition: ConstConfigIOGroup.cpp:271
static std::unique_ptr< IOGroup > make_plugin(void)
Definition: ConstConfigIOGroup.cpp:319
ConstConfigIOGroup()
Definition: ConstConfigIOGroup.cpp:41
void save_control(void) override
Does nothing; this IOGroup does not provide any controls.
Definition: ConstConfigIOGroup.cpp:240
std::set< std::string > signal_names(void) const override
Returns the names of all signals provided by the IOGroup.
Definition: ConstConfigIOGroup.cpp:79
double sample(int batch_idx) override
Retrieve signal value from data read by last call to read_batch() for a particular signal previously ...
Definition: ConstConfigIOGroup.cpp:175
void write_batch(void) override
Does nothing; this IOGroup does not provide any controls.
Definition: ConstConfigIOGroup.cpp:171
double read_signal(const std::string &signal_name, int domain_type, int domain_idx) override
Read from platform and interpret into SI units a signal given its name and domain....
Definition: ConstConfigIOGroup.cpp:198
std::set< std::string > control_names(void) const override
Definition: ConstConfigIOGroup.cpp:88
bool is_valid_control(const std::string &control_name) const override
Definition: ConstConfigIOGroup.cpp:98
int control_domain_type(const std::string &control_name) const override
Definition: ConstConfigIOGroup.cpp:114
int signal_domain_type(const std::string &signal_name) const override
Definition: ConstConfigIOGroup.cpp:103
static std::string plugin_name(void)
Definition: ConstConfigIOGroup.cpp:314
std::function< double(const std::vector< double > &)> agg_function(const std::string &signal_name) const override
Return a function that should be used when aggregating the given signal.
Definition: ConstConfigIOGroup.cpp:249
bool is_valid_signal(const std::string &signal_name) const override
Test if signal_name refers to a signal supported by the group.
Definition: ConstConfigIOGroup.cpp:93
int signal_behavior(const std::string &signal_name) const override
Definition: ConstConfigIOGroup.cpp:298
int push_control(const std::string &control_name, int domain_type, int domain_idx) override
Should not be called; this IOGroup does not provide any controls.
Definition: ConstConfigIOGroup.cpp:159
void adjust(int batch_idx, double setting) override
Should not be called; this IOGroup does not provide any controls.
Definition: ConstConfigIOGroup.cpp:191
void write_control(const std::string &control_name, int domain_type, int domain_idx, double setting) override
Should not be called; this IOGroup does not provide any controls.
Definition: ConstConfigIOGroup.cpp:231
int push_signal(const std::string &signal_name, int domain_type, int domain_idx) override
Add a signal to the list of signals that is read by read_batch() and sampled by sample().
Definition: ConstConfigIOGroup.cpp:119
std::function< std::string(double)> format_function(const std::string &signal_name) const override
Returns a function that can be used to convert a signal of the given name into a printable string....
Definition: ConstConfigIOGroup.cpp:261
void read_batch(void) override
this is essentially a no-op as this IOGroup's signals are constant.
Definition: ConstConfigIOGroup.cpp:167
std::string name(void) const override
Get the IOGroup name.
Definition: ConstConfigIOGroup.cpp:309
std::string control_description(const std::string &control_name) const override
Definition: ConstConfigIOGroup.cpp:290
Definition: IOGroup.hpp:21
Definition: PlatformTopo.hpp:28
Definition: Agg.cpp:20
std::string hostname(void)
Returns the current hostname as a string.
Definition: Helper.cpp:132