geopm 3.1.1.dev410+g40bf96ed
GEOPM - Global Extensible Open Power Manager
Loading...
Searching...
No Matches
FrequencyMapAgent.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 FREQUENCYMAPAGENT_HPP_INCLUDE
7#define FREQUENCYMAPAGENT_HPP_INCLUDE
8
9#include <vector>
10#include <map>
11#include <string>
12#include <memory>
13#include <functional>
14#include <set>
15
16#include "geopm/Agent.hpp"
17
18namespace geopm
19{
20 class PlatformIO;
21 class PlatformTopo;
22 class Waiter;
23
24 class FrequencyMapAgent : public Agent
25 {
26 public:
28 FrequencyMapAgent(PlatformIO &plat_io, const PlatformTopo &topo,
29 std::shared_ptr<Waiter> waiter);
30 FrequencyMapAgent(PlatformIO &plat_io, const PlatformTopo &topo,
31 std::shared_ptr<Waiter> waiter,
32 const std::map<uint64_t, double>& hash_freq_map,
33 const std::set<uint64_t>& default_freq_hash);
34 virtual ~FrequencyMapAgent() = default;
35 void init(int level, const std::vector<int> &fan_in, bool is_level_root) override;
36 void validate_policy(std::vector<double> &policy) const override;
37 void split_policy(const std::vector<double> &in_policy,
38 std::vector<std::vector<double> > &out_policy) override;
39 bool do_send_policy(void) const override;
40 void aggregate_sample(const std::vector<std::vector<double> > &in_sample,
41 std::vector<double> &out_sample) override;
42 bool do_send_sample(void) const override;
43 void adjust_platform(const std::vector<double> &in_policy) override;
44 bool do_write_batch(void) const override;
45 void sample_platform(std::vector<double> &out_sample) override;
46 void wait(void) override;
47 std::vector<std::pair<std::string, std::string> > report_header(void) const override;
48 std::vector<std::pair<std::string, std::string> > report_host(void) const override;
49 std::map<uint64_t, std::vector<std::pair<std::string, std::string> > > report_region(void) const override;
50 std::vector<std::string> trace_names(void) const override;
51 std::vector<std::function<std::string(double)> > trace_formats(void) const override;
52 void trace_values(std::vector<double> &values) override;
53 void enforce_policy(const std::vector<double> &policy) const override;
54
55 static std::string plugin_name(void);
56 static std::unique_ptr<Agent> make_plugin(void);
57 static std::vector<std::string> policy_names(void);
58 static std::vector<std::string> sample_names(void);
59
60 private:
61 void update_policy(const std::vector<double> &policy);
62 void init_platform_io(void);
63 static bool is_all_nan(const std::vector<double> &vec);
64
65 enum m_policy_e {
66 M_POLICY_FREQ_CPU_DEFAULT,
67 M_POLICY_FREQ_CPU_UNCORE,
68 M_POLICY_FREQ_GPU_DEFAULT,
69 M_POLICY_FIRST_HASH,
70 M_POLICY_FIRST_FREQUENCY,
71 // The remainder of policy values can be additional pairs of
72 // (hash, frequency)
73 M_NUM_POLICY = 65,
74 };
75
76 static constexpr double M_WAIT_SEC = 0.002;
77 PlatformIO &m_platform_io;
78 const PlatformTopo &m_platform_topo;
79 std::vector<int> m_hash_signal_idx;
80 std::vector<int> m_freq_control_idx;
81 int m_gpu_min_control_idx;
82 int m_gpu_max_control_idx;
83 int m_uncore_min_ctl_idx;
84 int m_uncore_max_ctl_idx;
85 std::vector<uint64_t> m_last_hash;
86 std::vector<double> m_last_freq;
87 double m_last_uncore_freq;
88 double m_last_gpu_freq;
89 int m_num_children;
90 bool m_is_policy_updated;
91 bool m_do_write_batch;
92 bool m_is_adjust_initialized;
93 bool m_is_real_policy;
94 int m_freq_ctl_domain_type;
95 int m_num_freq_ctl_domain;
96 bool m_do_gpu_ctl;
97 double m_core_freq_min;
98 double m_core_freq_max;
99 double m_uncore_init_min;
100 double m_uncore_init_max;
101 double m_gpu_init_freq_min;
102 double m_gpu_init_freq_max;
103 double m_default_freq;
104 double m_uncore_freq;
105 double m_default_gpu_freq;
106 std::map<uint64_t, double> m_hash_freq_map;
107 std::set<uint64_t> m_default_freq_hash;
108 std::shared_ptr<Waiter> m_waiter;
109 };
110}
111
112#endif
Definition Agent.hpp:20
Definition FrequencyMapAgent.hpp:25
void trace_values(std::vector< double > &values) override
Called by Controller to get latest values to be added to the trace.
Definition FrequencyMapAgent.cpp:436
void wait(void) override
Called by Controller to wait for sample period to elapse. This controls the cadence of the Controller...
Definition FrequencyMapAgent.cpp:358
virtual ~FrequencyMapAgent()=default
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 FrequencyMapAgent.cpp:263
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 FrequencyMapAgent.cpp:382
bool do_write_batch(void) const override
Called by the Controller to decide whether to call write_batch() to update platform controls.
Definition FrequencyMapAgent.cpp:346
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 FrequencyMapAgent.cpp:351
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 FrequencyMapAgent.cpp:414
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 FrequencyMapAgent.cpp:258
void validate_policy(std::vector< double > &policy) const override
Called by Controller to validate incoming policy values and configure defaults requested in incoming ...
Definition FrequencyMapAgent.cpp:102
void adjust_platform(const std::vector< double > &in_policy) override
Adjust the platform settings based the policy from above.
Definition FrequencyMapAgent.cpp:274
static std::unique_ptr< Agent > make_plugin(void)
Definition FrequencyMapAgent.cpp:86
static std::vector< std::string > policy_names(void)
Definition FrequencyMapAgent.cpp:363
bool do_send_sample(void) const override
Definition FrequencyMapAgent.cpp:269
std::vector< std::pair< std::string, std::string > > report_host(void) const override
Custom fields for the host section of the report.
Definition FrequencyMapAgent.cpp:387
std::vector< std::string > trace_names(void) const override
Column headers to be added to the trace.
Definition FrequencyMapAgent.cpp:426
static std::vector< std::string > sample_names(void)
Definition FrequencyMapAgent.cpp:377
FrequencyMapAgent()
Definition FrequencyMapAgent.cpp:31
std::vector< std::function< std::string(double)> > trace_formats(void) const override
Returns format string for each column added to the trace.
Definition FrequencyMapAgent.cpp:431
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 FrequencyMapAgent.cpp:441
static std::string plugin_name(void)
Definition FrequencyMapAgent.cpp:81
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 FrequencyMapAgent.cpp:91
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 FrequencyMapAgent.cpp:236
Definition Accumulator.cpp:12