geopm  3.1.1.dev214+gba4f9f6d
GEOPM - Global Extensible Open Power Manager
ServiceIOGroup.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 SERVICEIOGROUP_HPP_INCLUDE
7 #define SERVICEIOGROUP_HPP_INCLUDE
8 
9 #include <map>
10 
11 #include "geopm/IOGroup.hpp"
12 
13 struct geopm_request_s;
14 
15 namespace geopm
16 {
17  class PlatformTopo;
18  class ServiceProxy;
19  class BatchClient;
20  struct signal_info_s;
21  struct control_info_s;
22 
26  class ServiceIOGroup : public IOGroup
27  {
28  public:
31  std::shared_ptr<ServiceProxy> service_proxy,
32  std::shared_ptr<BatchClient> batch_client_mock);
33  ServiceIOGroup(const ServiceIOGroup &other) = delete;
34  ServiceIOGroup &operator=(const ServiceIOGroup &other) = delete;
35  virtual ~ServiceIOGroup();
36  std::set<std::string> signal_names(void) const override;
37  std::set<std::string> control_names(void) const override;
38  bool is_valid_signal(const std::string &signal_name) const override;
39  bool is_valid_control(const std::string &control_name) const override;
40  int signal_domain_type(const std::string &signal_name) const override;
41  int control_domain_type(const std::string &control_name) const override;
42  int push_signal(const std::string &signal_name,
43  int domain_type,
44  int domain_idx) override;
45  int push_control(const std::string &control_name,
46  int domain_type,
47  int domain_idx) override;
48  void read_batch(void) override;
49  void write_batch(void) override;
50  double sample(int sample_idx) override;
51  void adjust(int control_idx,
52  double setting) override;
53  double read_signal(const std::string &signal_name,
54  int domain_type,
55  int domain_idx) override;
56  void write_control(const std::string &control_name,
57  int domain_type,
58  int domain_idx,
59  double setting) override;
60  // NOTE: This IOGroup will not directly implement a
61  // save/restore since it is a proxy. Creating this
62  // IOGroup will start a session with the service,
63  // and save and restore will be managed by the
64  // geopmd service for every session that is opened.
65  void save_control(void) override;
66  void restore_control(void) override;
67  std::function<double(const std::vector<double> &)> agg_function(const std::string &signal_name) const override;
68  std::function<std::string(double)> format_function(const std::string &signal_name) const override;
69  std::string signal_description(const std::string &signal_name) const override;
70  std::string control_description(const std::string &control_name) const override;
71  int signal_behavior(const std::string &signal_name) const override;
72  void save_control(const std::string &save_path) override;
73  void restore_control(const std::string &save_path) override;
74  std::string name(void) const override;
75  static std::string plugin_name(void);
76  static std::unique_ptr<IOGroup> make_plugin(void);
77  private:
78  void init_batch_server(void);
79  static const std::string M_PLUGIN_NAME;
80  static std::map<std::string, signal_info_s> service_signal_info(std::shared_ptr<ServiceProxy> service_proxy);
81  static std::map<std::string, control_info_s> service_control_info(std::shared_ptr<ServiceProxy> service_proxy);
82  static std::string strip_plugin_name(const std::string &name);
83  const PlatformTopo &m_platform_topo;
84  std::shared_ptr<ServiceProxy> m_service_proxy;
85  std::map<std::string, signal_info_s> m_signal_info;
86  std::map<std::string, control_info_s> m_control_info;
87  std::vector<geopm_request_s> m_signal_requests;
88  std::vector<geopm_request_s> m_control_requests;
89  std::shared_ptr<BatchClient> m_batch_client;
90  std::vector<double> m_batch_samples;
91  std::vector<double> m_batch_settings;
92  int m_session_pid;
93  bool m_is_batch_active;
94  };
95 }
96 
97 #endif
Definition: IOGroup.hpp:21
Definition: PlatformTopo.hpp:28
IOGroup that uses DBus interface to access geopmd provided signals and controls. This IOGroup is not ...
Definition: ServiceIOGroup.hpp:27
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: ServiceIOGroup.cpp:274
void write_batch(void) override
Write all of the pushed controls so that values previously given to adjust() are written to the platf...
Definition: ServiceIOGroup.cpp:213
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: ServiceIOGroup.cpp:318
bool is_valid_signal(const std::string &signal_name) const override
Test if signal_name refers to a signal supported by the group.
Definition: ServiceIOGroup.cpp:112
void adjust(int control_idx, double setting) override
Adjust a setting for a particular control that was previously pushed with push_control()....
Definition: ServiceIOGroup.cpp:238
virtual ~ServiceIOGroup()
Definition: ServiceIOGroup.cpp:49
std::set< std::string > control_names(void) const override
Returns the names of all controls provided by the IOGroup.
Definition: ServiceIOGroup.cpp:103
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: ServiceIOGroup.cpp:253
void read_batch(void) override
Read all pushed signals from the platform so that the next call to sample() will reflect the updated ...
Definition: ServiceIOGroup.cpp:204
void restore_control(void) override
Restore all controls to values recorded in previous call to the save() method.
Definition: ServiceIOGroup.cpp:302
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: ServiceIOGroup.cpp:142
bool is_valid_control(const std::string &control_name) const override
Test if control_name refers to a control supported by the group.
Definition: ServiceIOGroup.cpp:117
ServiceIOGroup()
Definition: ServiceIOGroup.cpp:26
int signal_domain_type(const std::string &signal_name) const override
Query the domain for a named signal.
Definition: ServiceIOGroup.cpp:122
ServiceIOGroup(const ServiceIOGroup &other)=delete
int push_control(const std::string &control_name, int domain_type, int domain_idx) override
Add a control to the list of controls that is written by write_batch() and configured with adjust().
Definition: ServiceIOGroup.cpp:173
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: ServiceIOGroup.cpp:351
int control_domain_type(const std::string &control_name) const override
Query the domain for a named control.
Definition: ServiceIOGroup.cpp:132
static std::string plugin_name(void)
Definition: ServiceIOGroup.cpp:411
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: ServiceIOGroup.cpp:307
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: ServiceIOGroup.cpp:340
std::string name(void) const override
Get the IOGroup name.
Definition: ServiceIOGroup.cpp:406
void save_control(void) override
Save the state of all controls so that any subsequent changes made through the IOGroup can be undone ...
Definition: ServiceIOGroup.cpp:296
std::set< std::string > signal_names(void) const override
Returns the names of all signals provided by the IOGroup.
Definition: ServiceIOGroup.cpp:94
static std::unique_ptr< IOGroup > make_plugin(void)
Definition: ServiceIOGroup.cpp:416
double sample(int sample_idx) override
Retrieve signal value from data read by last call to read_batch() for a particular signal previously ...
Definition: ServiceIOGroup.cpp:221
ServiceIOGroup & operator=(const ServiceIOGroup &other)=delete
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: ServiceIOGroup.cpp:329
Definition: Agg.cpp:20
const PlatformTopo & platform_topo(void)
Definition: PlatformTopo.cpp:81
Definition: PlatformIO.hpp:19