geopm 3.1.1.dev491+g91408294
GEOPM - Global Extensible Open Power Manager
Loading...
Searching...
No Matches
Agent.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 AGENT_HPP_INCLUDE
7#define AGENT_HPP_INCLUDE
8
9#include <functional>
10#include <map>
11#include <string>
12#include <vector>
13#include <cstdint>
14
15#include "geopm/PluginFactory.hpp"
16#include "geopm_public.h"
17
18namespace geopm
19{
20 class GEOPM_PUBLIC Agent
21 {
22 public:
23 Agent() = default;
24 virtual ~Agent() = default;
25 static std::vector<std::string> agent_names(void);
26 static std::unique_ptr<Agent> make_unique(const std::string &agent_name);
38 virtual void init(int level, const std::vector<int> &fan_in, bool is_level_root) = 0;
49 virtual void validate_policy(std::vector<double> &policy) const = 0;
55 virtual void split_policy(const std::vector<double> &in_policy,
56 std::vector<std::vector<double> > &out_policy) = 0;
60 virtual bool do_send_policy(void) const = 0;
67 virtual void aggregate_sample(const std::vector<std::vector<double> > &in_sample,
68 std::vector<double> &out_sample) = 0;
70 virtual bool do_send_sample(void) const = 0;
75 virtual void adjust_platform(const std::vector<double> &in_policy) = 0;
79 virtual bool do_write_batch(void) const = 0;
85 virtual void sample_platform(std::vector<double> &out_sample) = 0;
89 virtual void wait(void) = 0;
92 virtual std::vector<std::pair<std::string, std::string> > report_header(void) const = 0;
94 virtual std::vector<std::pair<std::string, std::string> > report_host(void) const = 0;
96 virtual std::map<uint64_t, std::vector<std::pair<std::string, std::string> > > report_region(void) const = 0;
98 virtual std::vector<std::string> trace_names(void) const = 0;
100 virtual std::vector<std::function<std::string(double)> > trace_formats(void) const;
103 virtual void trace_values(std::vector<double> &values) = 0;
107 virtual void enforce_policy(const std::vector<double> &policy) const = 0;
115 static int num_policy(const std::map<std::string, std::string> &dictionary);
120 static int num_policy(const std::string &agent_name);
128 static int num_sample(const std::map<std::string, std::string> &dictionary);
133 static int num_sample(const std::string &agent_name);
141 static std::vector<std::string> policy_names(const std::map<std::string, std::string> &dictionary);
146 static std::vector<std::string> policy_names(const std::string &agent_name);
154 static std::vector<std::string> sample_names(const std::map<std::string, std::string> &dictionary);
159 static std::vector<std::string> sample_names(const std::string &agent_name);
166 static std::map<std::string, std::string> make_dictionary(const std::vector<std::string> &policy_names,
167 const std::vector<std::string> &sample_names);
180 static void aggregate_sample(const std::vector<std::vector<double> > &in_sample,
181 const std::vector<std::function<double(const std::vector<double>&)> > &agg_func,
182 std::vector<double> &out_sample);
183 static const std::string M_PLUGIN_PREFIX;
184 private:
185 static const std::string m_num_sample_string;
186 static const std::string m_num_policy_string;
187 static const std::string m_sample_prefix;
188 static const std::string m_policy_prefix;
189 };
190
191 class GEOPM_PUBLIC AgentFactory : public PluginFactory<Agent>
192 {
193 public:
194 AgentFactory();
195 virtual ~AgentFactory() = default;
196 };
197
198 AgentFactory GEOPM_PUBLIC &
199 agent_factory(void);
200}
201
202#endif
Definition Agent.hpp:192
virtual ~AgentFactory()=default
Definition Agent.hpp:21
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 std::vector< std::pair< std::string, std::string > > report_host(void) const =0
Custom fields for the host section of the report.
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.
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.
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 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:183
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 trace_values(std::vector< double > &values)=0
Called by Controller to get latest values to be added to the trace.
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 std::vector< std::string > trace_names(void) const =0
Column headers to be added to the trace.
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:81