geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
SSTIOGroup.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 SSTIOGROUP_HPP_INCLUDE
7 #define SSTIOGROUP_HPP_INCLUDE
8 
9 #include <set>
10 #include <functional>
11 
12 #include "geopm/IOGroup.hpp"
13 #include "geopm/Agg.hpp"
14 
15 namespace geopm
16 {
17  class PlatformTopo;
18  class SSTIO;
19  class Signal;
20  class Control;
21  class SaveControl;
22 
24  class SSTIOGroup : public IOGroup
25  {
26  public:
27  SSTIOGroup();
28  SSTIOGroup(const PlatformTopo &topo,
29  std::shared_ptr<SSTIO> sstio,
30  std::shared_ptr<SaveControl> save_control);
31  virtual ~SSTIOGroup() = default;
32  std::set<std::string> signal_names(void) const override;
33  std::set<std::string> control_names(void) const override;
34  bool is_valid_signal(const std::string &signal_name) const override;
35  bool is_valid_control(const std::string &control_name) 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, int domain_type, int domain_idx) override;
39  int push_control(const std::string &control_name, int domain_type, int domain_idx) override;
40  void read_batch(void) override;
41  void write_batch(void) override;
42  double sample(int batch_idx) override;
43  void adjust(int batch_idx, double setting) override;
44  double read_signal(const std::string &signal_name, int domain_type, int domain_idx) override;
45  void write_control(const std::string &control_name, int domain_type, int domain_idx, double setting) override;
46  void save_control(void) override;
47  void restore_control(void) override;
48  std::function<double(const std::vector<double> &)> agg_function(const std::string &signal_name) const override;
49  std::function<std::string(double)> format_function(const std::string &signal_name) const override;
50  std::string signal_description(const std::string &signal_name) const override;
51  std::string control_description(const std::string &control_name) const override;
52  int signal_behavior(const std::string &signal_name) const override;
53  void save_control(const std::string &save_path) override;
54  void restore_control(const std::string &save_path) override;
55  std::string name(void) const override;
56  static std::string plugin_name(void);
57  static std::unique_ptr<IOGroup> make_plugin(void);
58 
59  enum class SSTMailboxCommand : uint16_t {
60  M_TURBO_FREQUENCY = 0x7f,
61  M_CORE_PRIORITY = 0xd0,
63  };
64  private:
65  struct sst_signal_mailbox_field_s {
73  sst_signal_mailbox_field_s(uint32_t request_data, uint32_t begin_bit,
74  uint32_t end_bit, double multiplier,
75  int units, const std::string &description,
76  m_signal_behavior_e behavior)
77  : sst_signal_mailbox_field_s(
78  request_data,
79  begin_bit,
80  end_bit,
81  multiplier,
82  units,
83  description,
84  behavior,
85  Agg::expect_same)
86  {
87  }
88 
89  sst_signal_mailbox_field_s(uint32_t request_data, uint32_t begin_bit,
90  uint32_t end_bit, double multiplier,
91  int units, const std::string &description,
92  m_signal_behavior_e behavior,
93  std::function<double(const std::vector<double> &)> agg_function)
94  : request_data(request_data)
95  , begin_bit(begin_bit)
96  , end_bit(end_bit)
97  , multiplier(multiplier)
98  , units(units)
99  , description(description)
100  , behavior(behavior)
101  , agg_function(std::move(agg_function))
102  {
103  }
104  uint32_t request_data;
105  uint32_t begin_bit;
106  uint32_t end_bit;
107  double multiplier;
108  int units;
109  std::string description;
110  m_signal_behavior_e behavior;
111  std::function<double(const std::vector<double> &)> agg_function;
112  };
113  struct sst_signal_mailbox_raw_s {
117  sst_signal_mailbox_raw_s(SSTIOGroup::SSTMailboxCommand command, uint16_t subcommand,
118  const std::map<std::string, sst_signal_mailbox_field_s>& fields)
119  : command(command)
120  , subcommand(subcommand)
121  , fields(fields)
122  {
123  }
124  SSTMailboxCommand command;
125  uint16_t subcommand;
126  std::map<std::string, sst_signal_mailbox_field_s> fields;
127  };
128 
129  struct sst_control_mailbox_field_s {
130  sst_control_mailbox_field_s(uint32_t write_data, uint32_t begin_bit,
131  uint32_t end_bit, int units,
132  const std::string &description)
133  : sst_control_mailbox_field_s(
134  write_data,
135  begin_bit,
136  end_bit,
137  units,
138  description,
139  Agg::expect_same)
140  {
141  }
142 
143  sst_control_mailbox_field_s(uint32_t write_data, uint32_t begin_bit,
144  uint32_t end_bit, int units,
145  const std::string &description,
146  std::function<double(const std::vector<double> &)> agg_function)
147  : write_data(write_data)
148  , begin_bit(begin_bit)
149  , end_bit(end_bit)
150  , units(units)
151  , description(description)
152  , agg_function(std::move(agg_function))
153  {
154  }
155  uint32_t write_data;
156  uint32_t begin_bit;
157  uint32_t end_bit;
158  int units;
159  std::string description;
160  std::function<double(const std::vector<double> &)> agg_function;
161  };
162  struct sst_control_mailbox_raw_s {
166  sst_control_mailbox_raw_s(
167  SSTMailboxCommand command, uint16_t subcommand, uint32_t write_param,
168  const std::map<std::string, sst_control_mailbox_field_s>& fields,
169  uint16_t read_subcommand, uint32_t read_request_data)
170  : command(command)
171  , subcommand(subcommand)
172  , write_param(write_param)
173  , fields(fields)
174  , read_subcommand(read_subcommand)
175  , read_request_data(read_request_data)
176  {
177  }
178  SSTMailboxCommand command;
179  uint16_t subcommand;
180  uint32_t write_param;
181  std::map<std::string, sst_control_mailbox_field_s> fields;
182  uint16_t read_subcommand;
183  uint32_t read_request_data;
184  };
185 
186  struct sst_control_mmio_field_s {
187  sst_control_mmio_field_s(uint32_t begin_bit, uint32_t end_bit,
188  double multiplier, int units,
189  const std::string &description)
190  : sst_control_mmio_field_s(
191  begin_bit,
192  end_bit,
193  multiplier,
194  units,
195  description,
196  Agg::expect_same)
197  {
198  }
199 
200  sst_control_mmio_field_s(uint32_t begin_bit, uint32_t end_bit,
201  double multiplier, int units,
202  const std::string &description,
203  std::function<double(const std::vector<double> &)> agg_function)
204  : begin_bit(begin_bit)
205  , end_bit(end_bit)
206  , multiplier(multiplier)
207  , units(units)
208  , description(description)
209  , agg_function(std::move(agg_function))
210  {
211  }
212  uint32_t begin_bit;
213  uint32_t end_bit;
214  double multiplier;
215  int units;
216  std::string description;
217  std::function<double(const std::vector<double> &)> agg_function;
218  };
219  struct sst_control_mmio_raw_s {
223  sst_control_mmio_raw_s(int domain_type, uint32_t register_offset,
224  const std::map<std::string, sst_control_mmio_field_s>& fields)
225  : domain_type(domain_type)
226  , register_offset(register_offset)
227  , fields(fields)
228  {
229  }
230  int domain_type;
231  uint32_t register_offset;
232  std::map<std::string, sst_control_mmio_field_s> fields;
233  };
234 
235  struct sst_signal_mmio_field_s {
236  sst_signal_mmio_field_s(uint32_t write_value, uint32_t begin_bit,
237  uint32_t end_bit, double multiplier,
238  int units, const std::string &description,
239  m_signal_behavior_e behavior)
240  : sst_signal_mmio_field_s(
241  write_value,
242  begin_bit,
243  end_bit,
244  multiplier,
245  units,
246  description,
247  behavior,
248  Agg::expect_same)
249  {
250  }
251 
252  sst_signal_mmio_field_s(uint32_t write_value, uint32_t begin_bit,
253  uint32_t end_bit, double multiplier,
254  int units, const std::string &description,
255  m_signal_behavior_e behavior,
256  std::function<double(const std::vector<double> &)> agg_function)
257  : write_value(write_value)
258  , begin_bit(begin_bit)
259  , end_bit(end_bit)
260  , multiplier(multiplier)
261  , units(units)
262  , description(description)
263  , behavior(behavior)
264  , agg_function(std::move(agg_function))
265  {
266  }
267  uint32_t write_value;
268  uint32_t begin_bit;
269  uint32_t end_bit;
270  double multiplier;
271  int units;
272  std::string description;
273  m_signal_behavior_e behavior;
274  std::function<double(const std::vector<double> &)> agg_function;
275  };
276 
277  void add_mbox_signals(const std::string &raw_name,
278  SSTMailboxCommand command, uint16_t subcommand,
279  const std::map<std::string, sst_signal_mailbox_field_s> &fields);
280  void add_mbox_controls(
281  const std::string &raw_name, SSTMailboxCommand command,
282  uint16_t subcommand, uint32_t write_param,
283  const std::map<std::string, sst_control_mailbox_field_s> &fields,
284  uint16_t read_subcommand, uint32_t read_request_data,
285  uint32_t read_mask);
286 
287  void add_mmio_signals(const std::string &raw_name, int domain_type,
288  uint32_t register_offset,
289  const std::map<std::string, sst_signal_mmio_field_s> &fields);
290  void add_mmio_controls(const std::string &raw_name, int domain_type,
291  uint32_t register_offset,
292  const std::map<std::string, sst_control_mmio_field_s> &fields,
293  uint32_t read_mask);
294 
295  static const std::map<std::string, sst_signal_mailbox_raw_s> sst_signal_mbox_info;
296  static const std::map<std::string, sst_control_mailbox_raw_s> sst_control_mbox_info;
297  static const std::map<std::string, sst_control_mmio_raw_s> sst_control_mmio_info;
298  const PlatformTopo &m_topo;
299  std::shared_ptr<SSTIO> m_sstio;
300  bool m_is_read;
301 
302  // All available signals: map from name to signal_info.
303  // The signals vector is over the indices for the domain.
304  // The signals pointers should be copied when signal is
305  // pushed and used directly for read_signal.
306  struct signal_info
307  {
308  std::vector<std::shared_ptr<Signal> > signals;
309  int domain;
310  int units;
311  std::function<double(const std::vector<double> &)> agg_function;
312  std::string description;
313  m_signal_behavior_e behavior;
314  };
315  std::map<std::string, signal_info> m_signal_available;
316 
317  struct control_info
318  {
319  std::vector<std::shared_ptr<Control> > controls;
320  int domain;
321  int units;
322  std::function<double(const std::vector<double> &)> agg_function;
323  std::string description;
324  };
325  std::map<std::string, control_info> m_control_available;
326 
327  // Mapping of signal index to pushed signals.
328  std::vector<std::shared_ptr<Signal> > m_signal_pushed;
329 
330  // Mapping of control index to pushed controls
331  std::vector<std::shared_ptr<Control> > m_control_pushed;
332 
333  std::shared_ptr<SaveControl> m_mock_save_ctl;
334  };
335 }
336 
337 #endif
Definition: Agg.hpp:20
Definition: IOGroup.hpp:21
m_signal_behavior_e
Description of the runtime behavior of a signal.
Definition: IOGroup.hpp:36
Definition: PlatformTopo.hpp:28
IOGroup that provides a signal for the time since GEOPM startup.
Definition: SSTIOGroup.hpp:25
void write_batch(void) override
Write all of the pushed controls so that values previously given to adjust() are written to the platf...
Definition: SSTIOGroup.cpp:477
void restore_control(void) override
Restore all controls to values recorded in previous call to the save() method.
Definition: SSTIOGroup.cpp:558
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: SSTIOGroup.cpp:645
static std::string plugin_name(void)
Definition: SSTIOGroup.cpp:572
int signal_domain_type(const std::string &signal_name) const override
Query the domain for a named signal.
Definition: SSTIOGroup.cpp:388
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: SSTIOGroup.cpp:582
void save_control(void) override
Save the state of all controls so that any subsequent changes made through the IOGroup can be undone ...
Definition: SSTIOGroup.cpp:535
std::set< std::string > control_names(void) const override
Returns the names of all controls provided by the IOGroup.
Definition: SSTIOGroup.cpp:369
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: SSTIOGroup.cpp:607
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: SSTIOGroup.cpp:626
void read_batch(void) override
Read all pushed signals from the platform so that the next call to sample() will reflect the updated ...
Definition: SSTIOGroup.cpp:471
SSTIOGroup()
Definition: SSTIOGroup.cpp:236
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: SSTIOGroup.cpp:436
int control_domain_type(const std::string &control_name) const override
Query the domain for a named control.
Definition: SSTIOGroup.cpp:398
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: SSTIOGroup.cpp:518
SSTMailboxCommand
Definition: SSTIOGroup.hpp:59
static std::unique_ptr< IOGroup > make_plugin(void)
Definition: SSTIOGroup.cpp:577
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: SSTIOGroup.cpp:408
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: SSTIOGroup.cpp:593
virtual ~SSTIOGroup()=default
std::string name(void) const override
Get the IOGroup name.
Definition: SSTIOGroup.cpp:567
void adjust(int batch_idx, double setting) override
Adjust a setting for a particular control that was previously pushed with push_control()....
Definition: SSTIOGroup.cpp:496
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: SSTIOGroup.cpp:501
double sample(int batch_idx) override
Retrieve signal value from data read by last call to read_batch() for a particular signal previously ...
Definition: SSTIOGroup.cpp:482
std::set< std::string > signal_names(void) const override
Returns the names of all signals provided by the IOGroup.
Definition: SSTIOGroup.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: SSTIOGroup.cpp:383
bool is_valid_signal(const std::string &signal_name) const override
Test if signal_name refers to a signal supported by the group.
Definition: SSTIOGroup.cpp:378
Definition: Agg.cpp:20