geopm  3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
Agent.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 AGENT_HPP_INCLUDE
7 #define AGENT_HPP_INCLUDE
8 
9 #include <functional>
10 #include <map>
11 #include <string>
12 #include <vector>
13 
14 #include "geopm/PluginFactory.hpp"
15 #include "geopm_public.h"
16 
17 namespace geopm
18 {
19  class GEOPM_PUBLIC Agent
20  {
21  public:
22  Agent() = default;
23  virtual ~Agent() = default;
24  static std::vector<std::string> agent_names(void);
25  static std::unique_ptr<Agent> make_unique(const std::string &agent_name);
37  virtual void init(int level, const std::vector<int> &fan_in, bool is_level_root) = 0;
48  virtual void validate_policy(std::vector<double> &policy) const = 0;
54  virtual void split_policy(const std::vector<double> &in_policy,
55  std::vector<std::vector<double> > &out_policy) = 0;
59  virtual bool do_send_policy(void) const = 0;
66  virtual void aggregate_sample(const std::vector<std::vector<double> > &in_sample,
67  std::vector<double> &out_sample) = 0;
69  virtual bool do_send_sample(void) const = 0;
74  virtual void adjust_platform(const std::vector<double> &in_policy) = 0;
78  virtual bool do_write_batch(void) const = 0;
84  virtual void sample_platform(std::vector<double> &out_sample) = 0;
88  virtual void wait(void) = 0;
91  virtual std::vector<std::pair<std::string, std::string> > report_header(void) const = 0;
93  virtual std::vector<std::pair<std::string, std::string> > report_host(void) const = 0;
95  virtual std::map<uint64_t, std::vector<std::pair<std::string, std::string> > > report_region(void) const = 0;
97  virtual std::vector<std::string> trace_names(void) const = 0;
99  virtual std::vector<std::function<std::string(double)> > trace_formats(void) const;
102  virtual void trace_values(std::vector<double> &values) = 0;
106  virtual void enforce_policy(const std::vector<double> &policy) const = 0;
114  static int num_policy(const std::map<std::string, std::string> &dictionary);
119  static int num_policy(const std::string &agent_name);
127  static int num_sample(const std::map<std::string, std::string> &dictionary);
132  static int num_sample(const std::string &agent_name);
140  static std::vector<std::string> policy_names(const std::map<std::string, std::string> &dictionary);
145  static std::vector<std::string> policy_names(const std::string &agent_name);
153  static std::vector<std::string> sample_names(const std::map<std::string, std::string> &dictionary);
158  static std::vector<std::string> sample_names(const std::string &agent_name);
165  static std::map<std::string, std::string> make_dictionary(const std::vector<std::string> &policy_names,
166  const std::vector<std::string> &sample_names);
179  static void aggregate_sample(const std::vector<std::vector<double> > &in_sample,
180  const std::vector<std::function<double(const std::vector<double>&)> > &agg_func,
181  std::vector<double> &out_sample);
182  static const std::string M_PLUGIN_PREFIX;
183  private:
184  static const std::string m_num_sample_string;
185  static const std::string m_num_policy_string;
186  static const std::string m_sample_prefix;
187  static const std::string m_policy_prefix;
188  };
189 
190  class GEOPM_PUBLIC AgentFactory : public PluginFactory<Agent>
191  {
192  public:
193  AgentFactory();
194  virtual ~AgentFactory() = default;
195  };
196 
197  AgentFactory GEOPM_PUBLIC &
198  agent_factory(void);
199 }
200 
201 #endif
Definition: Agent.hpp:191
virtual ~AgentFactory()=default
Definition: Agent.hpp:20
virtual bool do_send_sample(void) const =0
virtual void wait(void)=0
Called by Controller to wait for sample period to elapse. This controls the cadence of the Controller...
virtual void sample_platform(std::vector< double > &out_sample)=0
Read signals from the platform and interpret/aggregate these signals to create a sample which can be ...
virtual void init(int level, const std::vector< int > &fan_in, bool is_level_root)=0
Set the level where this Agent is active and push signals/controls for that level.
virtual void split_policy(const std::vector< double > &in_policy, std::vector< std::vector< double > > &out_policy)=0
Called by Controller to split policy for children at next level down the tree.
virtual void aggregate_sample(const std::vector< std::vector< double > > &in_sample, std::vector< double > &out_sample)=0
Aggregate samples from children for the next level up the tree.
virtual void adjust_platform(const std::vector< double > &in_policy)=0
Adjust the platform settings based the policy from above.
Agent()=default
virtual void validate_policy(std::vector< double > &policy) const =0
Called by Controller to validate incoming policy values and configure defaults requested in incoming ...
virtual std::map< uint64_t, std::vector< std::pair< std::string, std::string > > > report_region(void) const =0
Custom fields for each region in the report.
virtual std::vector< std::string > trace_names(void) const =0
Column headers to be added to the trace.
virtual std::vector< std::pair< std::string, std::string > > report_host(void) const =0
Custom fields for the host section of the report.
virtual bool do_send_policy(void) const =0
Called by Controller to determine if new policy values should be sent down the tree to the Agent's ch...
static const std::string M_PLUGIN_PREFIX
Definition: Agent.hpp:182
virtual void trace_values(std::vector< double > &values)=0
Called by Controller to get latest values to be added to the trace.
virtual std::vector< std::pair< std::string, std::string > > report_header(void) const =0
Custom fields that will be added to the report header when this agent is used.
virtual void enforce_policy(const std::vector< double > &policy) const =0
Enforce the policy one time with PlatformIO::write_control(). Called to enforce static policies in th...
virtual ~Agent()=default
virtual bool do_write_batch(void) const =0
Called by the Controller to decide whether to call write_batch() to update platform controls.
Definition: Accumulator.cpp:12
AgentFactory & agent_factory(void)
Definition: Agent.cpp:76