geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
SysfsDriver.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 SYSFSDRIVER_HPP_INCLUDE
7 #define SYSFSDRIVER_HPP_INCLUDE
8 
9 #include <functional>
10 #include <map>
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 namespace geopm
16 {
23  {
24  public:
30  static constexpr size_t M_IO_BUFFER_SIZE = 128;
32  struct properties_s {
33  std::string name; // The full low level PlatformIO name
34  bool is_writable; // True if this is a control property
35  std::string attribute; // sysfs attribute name
36  std::string description; // Long description for documentation
37  double scaling_factor; // SI unit conversion factor
38  int units; // IOGroup::m_units_e
39  std::function<double(const std::vector<double> &)> aggregation_function;
40  int behavior; // IOGroup::m_signal_behavior_e
41  std::function<std::string(double)> format_function;
42  std::string alias; // Either empty string or name of high level alias
43  };
44  SysfsDriver() = default;
45  virtual ~SysfsDriver() = default;
51  virtual int domain_type(const std::string &name) const = 0;
61  virtual std::string attribute_path(const std::string &name,
62  int domain_idx) = 0;
74  virtual std::function<double(const std::string&)> signal_parse(const std::string &signal_name) const = 0;
83  virtual std::function<std::string(double)> control_gen(const std::string &control_name) const = 0;
87  virtual std::string driver(void) const = 0;
89  virtual std::map<std::string, SysfsDriver::properties_s> properties(void) const = 0;
90  static std::map<std::string, SysfsDriver::properties_s> parse_properties_json(const std::string &iogroup_name, const std::string &properties_json);
91  };
92 }
93 
94 #endif
Class used to implement the SysfsIOGroup base class.
Definition: SysfsDriver.hpp:23
virtual std::function< double(const std::string &)> signal_parse(const std::string &signal_name) const =0
Get function to convert contents of sysfs file into signal.
virtual int domain_type(const std::string &name) const =0
Get the PlatformTopo domain type for an named attribute.
static std::map< std::string, SysfsDriver::properties_s > parse_properties_json(const std::string &iogroup_name, const std::string &properties_json)
Definition: SysfsDriver.cpp:63
virtual ~SysfsDriver()=default
virtual std::map< std::string, SysfsDriver::properties_s > properties(void) const =0
Query the meta data about a signal or control.
virtual std::string driver(void) const =0
static constexpr size_t M_IO_BUFFER_SIZE
Arbitrary buffer size.
Definition: SysfsDriver.hpp:30
SysfsDriver()=default
virtual std::function< std::string(double)> control_gen(const std::string &control_name) const =0
Get a function to convert a control into a sysfs string.
virtual std::string attribute_path(const std::string &name, int domain_idx)=0
Get the path to the sysfs entry for signal.
Definition: Agg.cpp:20
The properties about a signal or control.
Definition: SysfsDriver.hpp:32
std::string name
Definition: SysfsDriver.hpp:33
std::string alias
Definition: SysfsDriver.hpp:42
double scaling_factor
Definition: SysfsDriver.hpp:37
std::function< std::string(double)> format_function
Definition: SysfsDriver.hpp:41
std::string description
Definition: SysfsDriver.hpp:36
bool is_writable
Definition: SysfsDriver.hpp:34
std::string attribute
Definition: SysfsDriver.hpp:35
std::function< double(const std::vector< double > &)> aggregation_function
Definition: SysfsDriver.hpp:39
int behavior
Definition: SysfsDriver.hpp:40
int units
Definition: SysfsDriver.hpp:38