geopm  3.1.1.dev214+gba4f9f6d
GEOPM - Global Extensible Open Power Manager
CPUActivityAgent.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 CPUACTIVITYAGENT_HPP_INCLUDE
7 #define CPUACTIVITYAGENT_HPP_INCLUDE
8 
9 #include <vector>
10 
11 #include "geopm/Agent.hpp"
12 
13 namespace geopm
14 {
15  class PlatformTopo;
16  class PlatformIO;
17  class FrequencyGovernor;
18  class Waiter;
19 
21  class CPUActivityAgent : public Agent
22  {
23  public:
25  CPUActivityAgent(PlatformIO &plat_io,
26  const PlatformTopo &topo,
27  std::shared_ptr<FrequencyGovernor> gov,
28  std::shared_ptr<Waiter> waiter);
29  virtual ~CPUActivityAgent() = default;
30  void init(int level, const std::vector<int> &fan_in, bool is_level_root) override;
31  void validate_policy(std::vector<double> &in_policy) const override;
32  void split_policy(const std::vector<double> &in_policy,
33  std::vector<std::vector<double> > &out_policy) override;
34  bool do_send_policy(void) const override;
35  void aggregate_sample(const std::vector<std::vector<double> > &in_sample,
36  std::vector<double> &out_sample) override;
37  bool do_send_sample(void) const override;
38  void adjust_platform(const std::vector<double> &in_policy) override;
39  bool do_write_batch(void) const override;
40  void sample_platform(std::vector<double> &out_sample) override;
41  void wait(void) override;
42  std::vector<std::pair<std::string, std::string> > report_header(void) const override;
43  std::vector<std::pair<std::string, std::string> > report_host(void) const override;
44  std::map<uint64_t, std::vector<std::pair<std::string, std::string> > > report_region(void) const override;
45  std::vector<std::string> trace_names(void) const override;
46  void trace_values(std::vector<double> &values) override;
47  void enforce_policy(const std::vector<double> &policy) const override;
48  std::vector<std::function<std::string(double)> > trace_formats(void) const override;
49 
50  static std::string plugin_name(void);
51  static std::unique_ptr<Agent> make_plugin(void);
52  static std::vector<std::string> policy_names(void);
53  static std::vector<std::string> sample_names(void);
54  private:
55  PlatformIO &m_platform_io;
56  const PlatformTopo &m_platform_topo;
57  static constexpr double M_WAIT_SEC = 0.010; // 10ms wait default;
58  const double M_POLICY_PHI_DEFAULT;
59  const int M_NUM_PACKAGE;
60  bool m_do_write_batch;
61  bool m_do_send_policy;
62  std::shared_ptr<FrequencyGovernor> m_freq_governor;
63  int m_freq_ctl_domain_type;
64  int m_num_freq_ctl_domain;
65  double m_core_batch_writes;
66  double m_uncore_frequency_requests;
67  double m_uncore_frequency_clamped;
68  double m_resolved_f_uncore_efficient;
69  double m_resolved_f_uncore_max;
70  double m_resolved_f_core_efficient;
71  double m_resolved_f_core_max;
72  double m_freq_uncore_min;
73  double m_freq_uncore_max;
74  double m_freq_uncore_efficient;
75  double m_freq_core_min;
76  double m_freq_core_max;
77  double m_freq_core_efficient;
78 
79  struct signal
80  {
81  int batch_idx;
82  double value;
83  };
84 
85  struct control
86  {
87  int batch_idx;
88  double last_setting;
89  };
90 
91  // Policy indices; must match policy_names()
92  enum m_policy_e {
93  M_POLICY_CPU_PHI,
94  M_NUM_POLICY,
95  };
96 
97  // Sample indices; must match sample_names()
98  enum m_sample_e {
99  M_NUM_SAMPLE
100  };
101 
102  std::map<std::string, double> m_policy_available;
103  // Maps uncore frequency -> maximum memory bandwidth achieved by
104  // that frequency (determined by system characterization)
105  std::map<double, double> m_qm_max_rate;
106 
107  std::vector<signal> m_core_scal;
108  std::vector<control> m_core_freq_control;
109 
110  std::vector<signal> m_qm_rate;
111  std::vector<signal> m_uncore_freq_status;
112  std::vector<control> m_uncore_freq_min_control;
113  std::vector<control> m_uncore_freq_max_control;
114  std::shared_ptr<Waiter> m_waiter;
115 
116  void init_platform_io(void);
117  void init_constconfig_io(void);
118  };
119 }
120 #endif
Definition: Agent.hpp:20
Agent.
Definition: CPUActivityAgent.hpp:22
bool do_write_batch(void) const override
Called by the Controller to decide whether to call write_batch() to update platform controls.
Definition: CPUActivityAgent.cpp:411
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: CPUActivityAgent.cpp:246
std::vector< std::pair< std::string, std::string > > report_host(void) const override
Custom fields for the host section of the report.
Definition: CPUActivityAgent.cpp:453
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: CPUActivityAgent.cpp:447
std::vector< std::string > trace_names(void) const override
Column headers to be added to the trace.
Definition: CPUActivityAgent.cpp:487
void wait(void) override
Called by Controller to wait for sample period to elapse. This controls the cadence of the Controller...
Definition: CPUActivityAgent.cpp:441
static std::vector< std::string > policy_names(void)
Definition: CPUActivityAgent.cpp:520
void validate_policy(std::vector< double > &in_policy) const override
Called by Controller to validate incoming policy values and configure defaults requested in incoming ...
Definition: CPUActivityAgent.cpp:213
bool do_send_sample(void) const override
Definition: CPUActivityAgent.cpp:258
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: CPUActivityAgent.cpp:69
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: CPUActivityAgent.cpp:481
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: CPUActivityAgent.cpp:497
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: CPUActivityAgent.cpp:417
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: CPUActivityAgent.cpp:251
static std::vector< std::string > sample_names(void)
Definition: CPUActivityAgent.cpp:527
static std::string plugin_name(void)
Definition: CPUActivityAgent.cpp:508
CPUActivityAgent()
Definition: CPUActivityAgent.cpp:30
static std::unique_ptr< Agent > make_plugin(void)
Definition: CPUActivityAgent.cpp:514
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: CPUActivityAgent.cpp:237
std::vector< std::function< std::string(double)> > trace_formats(void) const override
Returns format string for each column added to the trace.
Definition: CPUActivityAgent.cpp:502
void trace_values(std::vector< double > &values) override
Called by Controller to get latest values to be added to the trace.
Definition: CPUActivityAgent.cpp:493
virtual ~CPUActivityAgent()=default
void adjust_platform(const std::vector< double > &in_policy) override
Adjust the platform settings based the policy from above.
Definition: CPUActivityAgent.cpp:263
Definition: Accumulator.cpp:12