geopm  3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
SysfsIOGroup.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 SYSFSIOGROUP_HPP_INCLUDE
7 #define SYSFSIOGROUP_HPP_INCLUDE
8 
9 #include <functional>
10 
11 #include "geopm/IOGroup.hpp"
12 #include "geopm/PlatformTopo.hpp"
13 
14 #include "SysfsDriver.hpp"
15 #include "UniqueFd.hpp"
16 
17 namespace geopm
18 {
19 
20  class SaveControl;
21  class IOUring;
22 
23  class SysfsIOGroup : public IOGroup
24  {
25  public:
26  SysfsIOGroup() = delete;
27  SysfsIOGroup(std::shared_ptr<SysfsDriver> driver);
28  SysfsIOGroup(std::shared_ptr<SysfsDriver> driver,
29  const PlatformTopo &topo,
30  std::shared_ptr<SaveControl> control_saver,
31  std::shared_ptr<IOUring> batch_reader,
32  std::shared_ptr<IOUring> batch_writer);
33  virtual ~SysfsIOGroup();
34  std::set<std::string> signal_names(void) const override;
35  std::set<std::string> control_names(void) const override;
36  bool is_valid_signal(const std::string &signal_name) const override;
37  bool is_valid_signal_domain(const std::string &signal_name, int domain_idx) const;
38  bool is_valid_control(const std::string &control_name) const override;
39  bool is_valid_control_domain(const std::string &control_name, int domain_idx) const;
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, int domain_type, int domain_idx) override;
43  int push_control(const std::string &control_name, int domain_type, int domain_idx) override;
44  void read_batch(void) override;
45  void write_batch(void) override;
46  double sample(int batch_idx) override;
47  void adjust(int batch_idx, double setting) override;
48  double read_signal(const std::string &signal_name, int domain_type, int domain_idx) override;
49  void write_control(const std::string &control_name, int domain_type, int domain_idx, double setting) override;
50  void save_control(void) override;
51  void save_control(const std::string &save_path) override;
52  void restore_control(void) override;
53  void restore_control(const std::string &save_path) override;
54  std::function<double(const std::vector<double> &)> agg_function(const std::string &signal_name) const override;
55  std::function<std::string(double)> format_function(const std::string &signal_name) const override;
56  std::string signal_description(const std::string &signal_name) const override;
57  std::string control_description(const std::string &control_name) const override;
58  int signal_behavior(const std::string &signal_name) const override;
59  std::string name(void) const override;
60  private:
61  std::string canonical_name(const std::string &name) const;
62  std::string check_request(const std::string &method_name,
63  const std::string &signal_name,
64  const std::string &control_name,
65  int domain_type,
66  int domain_idx) const;
67  std::shared_ptr<SysfsDriver> m_driver;
68  const geopm::PlatformTopo &m_platform_topo;
70  bool m_do_batch_read;
71  bool m_do_batch_write;
73  bool m_is_batch_read;
74  bool m_is_batch_write;
75  std::vector<double> m_control_value;
76  const std::map<std::string, SysfsDriver::properties_s> m_properties;
77  std::map<std::string, std::reference_wrapper<const SysfsDriver::properties_s> > m_signals;
78  std::map<std::string, std::reference_wrapper<const SysfsDriver::properties_s> > m_controls;
79 
80  // Information about a single pushed signal or control
81  struct m_pushed_info_s {
82  UniqueFd fd;
83  std::string name;
84  int domain_type;
85  int domain_idx;
86  double value;
87  bool do_write;
88  std::shared_ptr<int> last_io_return;
89  std::array<char, SysfsDriver::M_IO_BUFFER_SIZE> buf;
90  std::function<double(const std::string&)> parse;
91  std::function<std::string(double)> gen;
92  };
93 
94  // Pushed signals
95  std::vector<m_pushed_info_s> m_pushed_info_signal;
96  std::vector<m_pushed_info_s> m_pushed_info_control;
97  std::shared_ptr<SaveControl> m_control_saver;
98  std::shared_ptr<IOUring> m_batch_reader;
99  std::shared_ptr<IOUring> m_batch_writer;
100  std::set<std::string> m_unsaved_controls;
101  };
102 
103 }
104 
105 #endif
Definition: IOGroup.hpp:21
Definition: PlatformTopo.hpp:28
Definition: SysfsIOGroup.hpp:24
double sample(int batch_idx) override
Retrieve signal value from data read by last call to read_batch() for a particular signal previously ...
Definition: SysfsIOGroup.cpp:394
void write_batch(void) override
Write all of the pushed controls so that values previously given to adjust() are written to the platf...
Definition: SysfsIOGroup.cpp:360
bool is_valid_control(const std::string &control_name) const override
Test if control_name refers to a control supported by the group.
Definition: SysfsIOGroup.cpp:200
void adjust(int batch_idx, double setting) override
Adjust a setting for a particular control that was previously pushed with push_control()....
Definition: SysfsIOGroup.cpp:408
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: SysfsIOGroup.cpp:288
bool is_valid_signal_domain(const std::string &signal_name, int domain_idx) const
Definition: SysfsIOGroup.cpp:184
void restore_control(void) override
Restore all controls to values recorded in previous call to the save() method.
Definition: SysfsIOGroup.cpp:458
std::set< std::string > signal_names(void) const override
Returns the names of all signals provided by the IOGroup.
Definition: SysfsIOGroup.cpp:142
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: SysfsIOGroup.cpp:489
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: SysfsIOGroup.cpp:477
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: SysfsIOGroup.cpp:520
int control_domain_type(const std::string &control_name) const override
Query the domain for a named control.
Definition: SysfsIOGroup.cpp:233
void read_batch(void) override
Read all pushed signals from the platform so that the next call to sample() will reflect the updated ...
Definition: SysfsIOGroup.cpp:331
bool is_valid_control_domain(const std::string &control_name, int domain_idx) const
Definition: SysfsIOGroup.cpp:205
std::string name(void) const override
Get the IOGroup name.
Definition: SysfsIOGroup.cpp:541
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: SysfsIOGroup.cpp:244
bool is_valid_signal(const std::string &signal_name) const override
Test if signal_name refers to a signal supported by the group.
Definition: SysfsIOGroup.cpp:179
void save_control(void) override
Save the state of all controls so that any subsequent changes made through the IOGroup can be undone ...
Definition: SysfsIOGroup.cpp:437
int signal_domain_type(const std::string &signal_name) const override
Query the domain for a named signal.
Definition: SysfsIOGroup.cpp:222
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: SysfsIOGroup.cpp:530
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: SysfsIOGroup.cpp:421
virtual ~SysfsIOGroup()
Definition: SysfsIOGroup.cpp:137
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: SysfsIOGroup.cpp:501
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: SysfsIOGroup.cpp:430
std::set< std::string > control_names(void) const override
Returns the names of all controls provided by the IOGroup.
Definition: SysfsIOGroup.cpp:161
A wrapper to close a file descriptor when the descriptor goes out of scope.
Definition: UniqueFd.hpp:13
Definition: Agg.cpp:20