geopm 3.1.1.dev491+g91408294
GEOPM - Global Extensible Open Power Manager
Loading...
Searching...
No Matches
FrequencyBalancerAgent.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 - 2025, Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef FREQUENCYBALANCERAGENT_HPP_INCLUDE
7#define FREQUENCYBALANCERAGENT_HPP_INCLUDE
8
9#include <functional>
10#include <map>
11#include <memory>
12#include <string>
13#include <vector>
14
15#include "geopm/Agent.hpp"
16#include "geopm/CircularBuffer.hpp"
17#include "geopm_time.h"
18
21
22#include <unordered_map>
23
24namespace geopm
25{
26 class PlatformIO;
27 class PlatformTopo;
28 class PowerGovernor;
29 class FrequencyGovernor;
30 class SSTClosGovernor;
31 class Waiter;
32
34 {
35 public:
37 FrequencyBalancerAgent(PlatformIO &plat_io,
38 const PlatformTopo &topo,
39 std::shared_ptr<Waiter> waiter,
40 std::shared_ptr<PowerGovernor> power_gov,
41 std::shared_ptr<FrequencyGovernor> frequency_gov,
42 std::shared_ptr<SSTClosGovernor> sst_gov,
43 std::vector<std::shared_ptr<FrequencyTimeBalancer> > package_balancers,
44 std::shared_ptr<FrequencyLimitDetector> frequency_limit_detector);
45 virtual ~FrequencyBalancerAgent() = default;
46 void init(int level, const std::vector<int> &fan_in,
47 bool is_level_root) override;
48 void validate_policy(std::vector<double> &policy) const override;
49 void split_policy(const std::vector<double> &in_policy,
50 std::vector<std::vector<double> > &out_policy) override;
51 bool do_send_policy(void) const override;
52 void aggregate_sample(const std::vector<std::vector<double> > &in_sample,
53 std::vector<double> &out_sample) override;
54 bool do_send_sample(void) const override;
55 void adjust_platform(const std::vector<double> &in_policy) override;
56 bool do_write_batch(void) const override;
57 void sample_platform(std::vector<double> &out_sample) override;
58 void wait(void) override;
59 std::vector<std::pair<std::string, std::string> > report_header(void) const override;
60 std::vector<std::pair<std::string, std::string> > report_host(void) const override;
61 std::map<uint64_t, std::vector<std::pair<std::string, std::string> > >
62 report_region(void) const override;
63 std::vector<std::string> trace_names(void) const override;
64 std::vector<std::function<std::string(double)> > trace_formats(void) const override;
65 void trace_values(std::vector<double> &values) override;
66 void enforce_policy(const std::vector<double> &policy) const override;
67
68 static std::string plugin_name(void);
69 static std::unique_ptr<Agent> make_plugin(void);
70 static std::vector<std::string> policy_names(void);
71 static std::vector<std::string> sample_names(void);
72
73 private:
74 void update_policy(const std::vector<double> &policy);
75 void init_platform_io(void);
76
77 // Initialize policy-dependent members of this agent
78 void initialize_policies(const std::vector<double> &in_policy);
79
80 enum m_policy_e {
81 M_POLICY_POWER_PACKAGE_LIMIT_TOTAL,
82 M_POLICY_USE_FREQUENCY_LIMITS,
83 M_POLICY_USE_SST_TF,
84 M_NUM_POLICY,
85 };
86
87 static constexpr double M_WAIT_SEC = 0.005;
88 PlatformIO &m_platform_io;
89 const PlatformTopo &m_platform_topo;
90 std::shared_ptr<Waiter> m_waiter;
91 geopm_time_s m_update_time;
92 int m_epoch_signal_idx;
93 std::vector<int> m_acnt_signal_idx;
94 std::vector<int> m_mcnt_signal_idx;
95 std::vector<int> m_hash_signal_idx;
96 std::vector<int> m_hint_signal_idx;
97 std::vector<int> m_time_hint_network_idx;
98 std::vector<double> m_last_ctl_frequency;
99 std::vector<double> m_last_ctl_clos;
100 std::vector<double> m_last_epoch_acnt;
101 std::vector<double> m_last_epoch_mcnt;
102 std::vector<double> m_last_sample_acnt;
103 std::vector<double> m_last_sample_mcnt;
104 std::vector<double> m_last_hash;
105 std::vector<std::vector<double> > m_last_epoch_frequency;
106 std::vector<double> m_current_epoch_max_frequency;
107 std::vector<double> m_last_epoch_max_frequency;
108 std::vector<std::vector<double> > m_last_epoch_network_time;
109 std::vector<std::vector<double> > m_last_epoch_non_network_time_diff;
110 std::unordered_map<double, double> m_region_max_observed_frequency;
111 double m_last_epoch_time;
112 double m_last_epoch_count;
113 int m_num_children;
114 bool m_is_policy_updated;
115 bool m_do_write_batch;
116 bool m_is_adjust_initialized;
117 bool m_is_real_policy;
118 int m_package_count;
119 int m_core_count;
120 std::vector<std::vector<size_t> > m_package_core_indices;
121 double m_policy_power_package_limit_total;
122 bool m_policy_use_frequency_limits;
123 bool m_use_sst_tf;
124 double m_min_power_setting;
125 double m_max_power_setting;
126 double m_tdp_power_setting;
127 double m_frequency_min;
128 double m_frequency_sticker;
129 double m_frequency_max;
130 double m_frequency_step;
131 std::shared_ptr<PowerGovernor> m_power_gov;
132 std::shared_ptr<FrequencyGovernor> m_freq_governor;
133 std::shared_ptr<SSTClosGovernor> m_sst_clos_governor;
134 int m_frequency_ctl_domain_type;
135 int m_frequency_control_domain_count;
136 std::vector<long long> m_network_hint_sample_length;
137 std::vector<long long> m_non_network_hint_sample_length;
138 std::vector<size_t> m_last_hp_count;
139 bool m_handle_new_epoch;
140 int m_epoch_wait_count;
141 /* One balancer per package */
142 std::vector<std::shared_ptr<FrequencyTimeBalancer> > m_package_balancers;
143 std::shared_ptr<FrequencyLimitDetector> m_frequency_limit_detector;
144 };
145}
146
147#endif
Definition Agent.hpp:21
Definition FrequencyBalancerAgent.hpp:34
virtual ~FrequencyBalancerAgent()=default
std::vector< std::pair< std::string, std::string > > report_host(void) const override
Custom fields for the host section of the report.
Definition FrequencyBalancerAgent.cpp:537
static std::vector< std::string > policy_names(void)
Definition FrequencyBalancerAgent.cpp:516
void adjust_platform(const std::vector< double > &in_policy) override
Adjust the platform settings based the policy from above.
Definition FrequencyBalancerAgent.cpp:283
void wait(void) override
Called by Controller to wait for sample period to elapse. This controls the cadence of the Controller...
Definition FrequencyBalancerAgent.cpp:511
void trace_values(std::vector< double > &values) override
Called by Controller to get latest values to be added to the trace.
Definition FrequencyBalancerAgent.cpp:577
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 FrequencyBalancerAgent.cpp:245
bool do_write_batch(void) const override
Called by the Controller to decide whether to call write_batch() to update platform controls.
Definition FrequencyBalancerAgent.cpp:410
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 FrequencyBalancerAgent.cpp:419
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 FrequencyBalancerAgent.cpp:216
static std::unique_ptr< Agent > make_plugin(void)
Definition FrequencyBalancerAgent.cpp:155
static std::vector< std::string > sample_names(void)
Definition FrequencyBalancerAgent.cpp:522
bool do_send_sample(void) const override
Definition FrequencyBalancerAgent.cpp:252
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 FrequencyBalancerAgent.cpp:528
std::vector< std::string > trace_names(void) const override
Column headers to be added to the trace.
Definition FrequencyBalancerAgent.cpp:548
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 FrequencyBalancerAgent.cpp:543
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 FrequencyBalancerAgent.cpp:240
FrequencyBalancerAgent()
Definition FrequencyBalancerAgent.cpp:56
static std::string plugin_name(void)
Definition FrequencyBalancerAgent.cpp:150
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 FrequencyBalancerAgent.cpp:160
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 FrequencyBalancerAgent.cpp:595
std::vector< std::function< std::string(double)> > trace_formats(void) const override
Returns format string for each column added to the trace.
Definition FrequencyBalancerAgent.cpp:563
void validate_policy(std::vector< double > &policy) const override
Called by Controller to validate incoming policy values and configure defaults requested in incoming ...
Definition FrequencyBalancerAgent.cpp:175
Definition Accumulator.cpp:12