geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
PowerGovernorAgent.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 POWERGOVERNORAGENT_HPP_INCLUDE
7 #define POWERGOVERNORAGENT_HPP_INCLUDE
8 
9 #include <vector>
10 #include <functional>
11 #include <memory>
12 
13 #include "geopm/Agent.hpp"
14 #include "geopm/CircularBuffer.hpp"
15 
16 namespace geopm
17 {
18  class PlatformIO;
19  class PlatformTopo;
20  class PowerGovernor;
21  class Waiter;
22 
23  class PowerGovernorAgent : public Agent
24  {
25  public:
26  enum m_policy_e {
29  };
33  };
37  };
38  enum m_sample_e { // Tree samples
43  };
44 
46  PowerGovernorAgent(PlatformIO &platform_io,
47  std::unique_ptr<PowerGovernor> power_gov,
48  std::shared_ptr<Waiter> waiter);
49  virtual ~PowerGovernorAgent() = default;
50  void init(int level, const std::vector<int> &fan_in, bool is_level_root) override;
51  void validate_policy(std::vector<double> &policy) const override;
52  void split_policy(const std::vector<double> &in_policy,
53  std::vector<std::vector<double> > &out_policy) override;
54  bool do_send_policy(void) const override;
55  void aggregate_sample(const std::vector<std::vector<double> > &in_sample,
56  std::vector<double> &out_sample) override;
57  bool do_send_sample(void) const override;
58  void adjust_platform(const std::vector<double> &in_policy) override;
59  bool do_write_batch(void) const override;
60  void sample_platform(std::vector<double> &out_sample) override;
61  void wait(void) override;
62  std::vector<std::pair<std::string, std::string> > report_header(void) const override;
63  std::vector<std::pair<std::string, std::string> > report_host(void) const override;
64  std::map<uint64_t, std::vector<std::pair<std::string, std::string> > > report_region(void) const override;
65  std::vector<std::string> trace_names(void) const override;
66  std::vector<std::function<std::string(double)> > trace_formats(void) const override;
67  void trace_values(std::vector<double> &values) override;
68  void enforce_policy(const std::vector<double> &policy) const override;
69 
70  static std::string plugin_name(void);
71  static std::unique_ptr<Agent> make_plugin(void);
72  static std::vector<std::string> policy_names(void);
73  static std::vector<std::string> sample_names(void);
74  private:
75  void init_platform_io(void);
76  PlatformIO &m_platform_io;
77  int m_level;
78  bool m_is_sample_stable;
79  bool m_do_send_sample;
80  double m_min_power_setting;
81  double m_max_power_setting;
82  double m_tdp_power_setting;
83  std::unique_ptr<PowerGovernor> m_power_gov;
84  std::vector<int> m_pio_idx;
85  std::vector<std::function<double(const std::vector<double>&)> > m_agg_func;
86  int m_num_children;
87  double m_last_power_budget;
88  bool m_power_budget_changed;
89  std::unique_ptr<CircularBuffer<double> > m_epoch_power_buf;
90  std::vector<double> m_sample;
91  int m_ascend_count;
92  const int m_ascend_period;
93  const int m_min_num_converged;
94  double m_adjusted_power;
95  static constexpr double M_WAIT_SEC = 0.005;
96  std::shared_ptr<Waiter> m_waiter;
97  };
98 }
99 
100 #endif
Definition: Agent.hpp:20
Definition: PowerGovernorAgent.hpp:24
void split_policy(const std::vector< double > &in_policy, std::vector< std::vector< double > > &out_policy) override
Called by Controller to split policy for children at next level down the tree.
Definition: PowerGovernorAgent.cpp:114
void init(int level, const std::vector< int > &fan_in, bool is_level_root) override
Set the level where this Agent is active and push signals/controls for that level.
Definition: PowerGovernorAgent.cpp:58
bool do_send_sample(void) const override
Definition: PowerGovernorAgent.cpp:206
std::vector< std::pair< std::string, std::string > > report_host(void) const override
Custom fields for the host section of the report.
Definition: PowerGovernorAgent.cpp:271
std::vector< std::function< std::string(double)> > trace_formats(void) const override
Returns format string for each column added to the trace.
Definition: PowerGovernorAgent.cpp:286
void aggregate_sample(const std::vector< std::vector< double > > &in_sample, std::vector< double > &out_sample) override
Aggregate samples from children for the next level up the tree.
Definition: PowerGovernorAgent.cpp:162
std::vector< std::pair< std::string, std::string > > report_header(void) const override
Custom fields that will be added to the report header when this agent is used.
Definition: PowerGovernorAgent.cpp:266
void wait(void) override
Called by Controller to wait for sample period to elapse. This controls the cadence of the Controller...
Definition: PowerGovernorAgent.cpp:261
bool do_send_policy(void) const override
Called by Controller to determine if new policy values should be sent down the tree to the Agent's ch...
Definition: PowerGovernorAgent.cpp:157
m_sample_e
Definition: PowerGovernorAgent.hpp:38
@ M_SAMPLE_POWER
Definition: PowerGovernorAgent.hpp:39
@ M_NUM_SAMPLE
Definition: PowerGovernorAgent.hpp:42
@ M_SAMPLE_POWER_ENFORCED
Definition: PowerGovernorAgent.hpp:41
@ M_SAMPLE_IS_CONVERGED
Definition: PowerGovernorAgent.hpp:40
std::vector< std::string > trace_names(void) const override
Column headers to be added to the trace.
Definition: PowerGovernorAgent.cpp:281
m_policy_e
Definition: PowerGovernorAgent.hpp:26
@ M_NUM_POLICY
Definition: PowerGovernorAgent.hpp:28
@ M_POLICY_POWER
Definition: PowerGovernorAgent.hpp:27
m_plat_signal_e
Definition: PowerGovernorAgent.hpp:30
@ M_PLAT_SIGNAL_PKG_POWER
Definition: PowerGovernorAgent.hpp:31
@ M_PLAT_NUM_SIGNAL
Definition: PowerGovernorAgent.hpp:32
virtual ~PowerGovernorAgent()=default
static std::vector< std::string > policy_names(void)
Definition: PowerGovernorAgent.cpp:321
void adjust_platform(const std::vector< double > &in_policy) override
Adjust the platform settings based the policy from above.
Definition: PowerGovernorAgent.cpp:211
void trace_values(std::vector< double > &values) override
Called by Controller to get latest values to be added to the trace.
Definition: PowerGovernorAgent.cpp:291
void enforce_policy(const std::vector< double > &policy) const override
Enforce the policy one time with PlatformIO::write_control(). Called to enforce static policies in th...
Definition: PowerGovernorAgent.cpp:302
static std::unique_ptr< Agent > make_plugin(void)
Definition: PowerGovernorAgent.cpp:316
static std::vector< std::string > sample_names(void)
Definition: PowerGovernorAgent.cpp:326
void validate_policy(std::vector< double > &policy) const override
Called by Controller to validate incoming policy values and configure defaults requested in incoming ...
Definition: PowerGovernorAgent.cpp:99
static std::string plugin_name(void)
Definition: PowerGovernorAgent.cpp:311
bool do_write_batch(void) const override
Called by the Controller to decide whether to call write_batch() to update platform controls.
Definition: PowerGovernorAgent.cpp:224
m_trace_sample_e
Definition: PowerGovernorAgent.hpp:34
@ M_TRACE_NUM_SAMPLE
Definition: PowerGovernorAgent.hpp:36
@ M_TRACE_SAMPLE_PWR_BUDGET
Definition: PowerGovernorAgent.hpp:35
PowerGovernorAgent()
Definition: PowerGovernorAgent.cpp:24
std::map< uint64_t, std::vector< std::pair< std::string, std::string > > > report_region(void) const override
Custom fields for each region in the report.
Definition: PowerGovernorAgent.cpp:276
void sample_platform(std::vector< double > &out_sample) override
Read signals from the platform and interpret/aggregate these signals to create a sample which can be ...
Definition: PowerGovernorAgent.cpp:229
Definition: Accumulator.cpp:12