geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
PlatformIOImp.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 PLATFORMIOIMP_HPP_INCLUDE
7 #define PLATFORMIOIMP_HPP_INCLUDE
8 
9 #include <list>
10 #include <map>
11 #include <set>
12 
13 #include "geopm/PlatformIO.hpp"
14 #include "geopm_pio.h"
15 
16 namespace geopm
17 {
18  class IOGroup;
19  class CombinedSignal;
20  class CombinedControl;
21  class PlatformTopo;
22  class BatchServer;
23 
24  class PlatformIOImp : public PlatformIO
25  {
26  public:
27  PlatformIOImp();
28  PlatformIOImp(std::list<std::shared_ptr<IOGroup> > iogroup_list,
29  const PlatformTopo &topo);
30  PlatformIOImp(const PlatformIOImp &other) = delete;
31  PlatformIOImp &operator=(const PlatformIOImp &other) = delete;
32  virtual ~PlatformIOImp() = default;
33  void register_iogroup(std::shared_ptr<IOGroup> iogroup) override;
34  std::set<std::string> signal_names(void) const override;
35  std::set<std::string> control_names(void) const override;
36  int signal_domain_type(const std::string &signal_name) const override;
37  int control_domain_type(const std::string &control_name) const override;
38  int push_signal(const std::string &signal_name,
39  int domain_type,
40  int domain_idx) override;
41  int push_control(const std::string &control_name,
42  int domain_type,
43  int domain_idx) override;
44  double sample(int signal_idx) override;
45  void adjust(int control_idx, double setting) override;
46  void read_batch(void) override;
47  void write_batch(void) override;
48  double read_signal(const std::string &signal_name,
49  int domain_type,
50  int domain_idx) override;
51  void write_control(const std::string &control_name,
52  int domain_type,
53  int domain_idx,
54  double setting) override;
55  void save_control(void) override;
56  void restore_control(void) override;
57  std::function<double(const std::vector<double> &)> agg_function(const std::string &signal_name) const override;
58  std::function<std::string(double)> format_function(const std::string &signal_name) const override;
59  std::string signal_description(const std::string &signal_name) const override;
60  std::string control_description(const std::string &control_name) const override;
61  int signal_behavior(const std::string &signal_name) const override;
62  void save_control(const std::string &save_dir) override;
63  void restore_control(const std::string &save_dir) override;
64  void start_batch_server(int client_pid,
65  const std::vector<geopm_request_s> &signal_config,
66  const std::vector<geopm_request_s> &control_config,
67  int &server_pid,
68  std::string &server_key) override;
69  void stop_batch_server(int server_pid) override;
70 
71  int num_signal_pushed(void) const; // Used for testing only
72  int num_control_pushed(void) const; // Used for testing only
73  private:
90  int push_combined_signal(const std::string &signal_name,
91  int domain_type,
92  int domain_idx,
93  const std::vector<int> &sub_signal_idx);
94  int push_combined_control(const std::string &control_name,
95  int domain_type,
96  int domain_idx,
97  const std::vector<int> &sub_control_idx);
104  void register_combined_signal(int signal_idx,
105  std::vector<int> operands,
106  std::unique_ptr<CombinedSignal> signal);
107  void register_combined_control(int control_idx,
108  std::vector<int> operands,
109  std::unique_ptr<CombinedControl> control);
110  int push_signal_convert_domain(const std::string &signal_name,
111  int domain_type,
112  int domain_idx);
113  int push_control_convert_domain(const std::string &control_name,
114  int domain_type,
115  int domain_idx);
116  double read_signal_convert_domain(const std::string &signal_name,
117  int domain_type,
118  int domain_idx);
119  void write_control_convert_domain(const std::string &control_name,
120  int domain_type,
121  int domain_idx,
122  double setting);
124  double sample_combined(int signal_idx);
125  void adjust_combined(int control_idx, double setting);
127  std::vector<std::shared_ptr<IOGroup> > find_signal_iogroup(const std::string &signal_name) const;
129  std::vector<std::shared_ptr<IOGroup> > find_control_iogroup(const std::string &control_name) const;
134  bool is_control_adjust_same(const std::string &control_name) const;
135  bool m_is_signal_active;
136  bool m_is_control_active;
137  const PlatformTopo &m_platform_topo;
138  std::list<std::shared_ptr<IOGroup> > m_iogroup_list;
139  std::vector<std::pair<std::shared_ptr<IOGroup>, int> > m_active_signal;
140  std::vector<std::pair<std::shared_ptr<IOGroup>, int> > m_active_control;
141  std::map<std::tuple<std::string, int, int>, int> m_existing_signal;
142  std::map<std::tuple<std::string, int, int>, int> m_existing_control;
143  std::map<int, std::pair<std::vector<int>,
144  std::unique_ptr<CombinedSignal> > > m_combined_signal;
145  std::map<int, std::pair<std::vector<int>,
146  std::unique_ptr<CombinedControl> > > m_combined_control;
147  bool m_do_restore;
148  std::map<int, std::shared_ptr<BatchServer> > m_batch_server;
149  std::set<std::string> m_pushed_signal_names;
150  static const std::map<const std::string, const std::string> m_signal_descriptions;
151  static const std::map<const std::string, const std::string> m_control_descriptions;
152  };
153 }
154 
155 #endif
Class which is a collection of all valid control and signal objects for a platform.
Definition: PlatformIO.hpp:26
Definition: PlatformIOImp.hpp:25
std::set< std::string > signal_names(void) const override
Returns the names of all available signals. This includes all signals and aliases provided by IOGroup...
Definition: PlatformIO.cpp:334
int push_control(const std::string &control_name, int domain_type, int domain_idx) override
Push a control onto the end of the vector that can be adjusted.
Definition: PlatformIO.cpp:541
void write_batch(void) override
Write all of the pushed controls so that values previously given to adjust() are written to the platf...
Definition: PlatformIO.cpp:728
int push_signal(const std::string &signal_name, int domain_type, int domain_idx) override
Push a signal onto the end of the vector that can be sampled.
Definition: PlatformIO.cpp:392
int num_control_pushed(void) const
Definition: PlatformIO.cpp:648
int control_domain_type(const std::string &control_name) const override
Query the domain for a named control.
Definition: PlatformIO.cpp:365
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: PlatformIO.cpp:735
std::string control_description(const std::string &control_name) const override
Returns a description of the control. This string can be used by tools to generate help text for user...
Definition: PlatformIO.cpp:965
std::set< std::string > control_names(void) const override
Returns the names of all available controls. This includes all controls and aliases provided by IOGro...
Definition: PlatformIO.cpp:344
void restore_control(void) override
Restore all controls to values recorded in previous call to the save_control() method.
Definition: PlatformIO.cpp:894
PlatformIOImp & operator=(const PlatformIOImp &other)=delete
void stop_batch_server(int server_pid) override
Definition: PlatformIO.cpp:1014
void save_control(void) override
Save the state of all controls so that any subsequent changes made through PlatformIO can be undone w...
Definition: PlatformIO.cpp:886
PlatformIOImp(const PlatformIOImp &other)=delete
virtual ~PlatformIOImp()=default
int signal_domain_type(const std::string &signal_name) const override
Query the domain for a named signal.
Definition: PlatformIO.cpp:354
void write_control(const std::string &control_name, int domain_type, int domain_idx, double setting) override
Interpret the setting and write setting to the platform. Does not modify the values stored by calling...
Definition: PlatformIO.cpp:811
void read_batch(void) override
Read all pushed signals so that the next call to sample() will reflect the updated data.
Definition: PlatformIO.cpp:720
double sample(int signal_idx) override
Sample a single signal that has been pushed on to the signal stack. Must be called after a call to re...
Definition: PlatformIO.cpp:653
int num_signal_pushed(void) const
Definition: PlatformIO.cpp:643
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: PlatformIO.cpp:935
void start_batch_server(int client_pid, const std::vector< geopm_request_s > &signal_config, const std::vector< geopm_request_s > &control_config, int &server_pid, std::string &server_key) override
Definition: PlatformIO.cpp:993
void register_iogroup(std::shared_ptr< IOGroup > iogroup) override
Registers an IOGroup with the PlatformIO so that its signals and controls are available through the P...
Definition: PlatformIO.cpp:258
std::function< double(const std::vector< double > &)> agg_function(const std::string &signal_name) const override
Returns a function appropriate for aggregating multiple values of the given signal into a single valu...
Definition: PlatformIO.cpp:923
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: PlatformIO.cpp:947
int signal_behavior(const std::string &signal_name) const override
Returns a hint about how a signal will change as a function of time.
Definition: PlatformIO.cpp:983
PlatformIOImp()
Definition: PlatformIO.cpp:51
void adjust(int control_idx, double setting) override
Adjust a single control that has been pushed on to the control stack. This control will not take effe...
Definition: PlatformIO.cpp:688
Definition: PlatformTopo.hpp:28
Definition: Agg.cpp:20