geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
EndpointImp.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 ENDPOINTIMP_HPP_INCLUDE
7 #define ENDPOINTIMP_HPP_INCLUDE
8 
9 #include <pthread.h>
10 
11 #include "geopm_endpoint.h"
12 #include "geopm_time.h"
13 #include "geopm/Endpoint.hpp"
14 
15 namespace geopm
16 {
18  geopm_time_s timestamp; // 16 bytes
19  size_t count; // 8 bytes
20  double values; // 8 bytes
21  };
22 
24  geopm_time_s timestamp; // 16 bytes
25  char agent[GEOPM_ENDPOINT_AGENT_NAME_MAX]; // 256 bytes
26  char profile_name[GEOPM_ENDPOINT_PROFILE_NAME_MAX]; // 256 bytes
27  char hostlist_path[GEOPM_ENDPOINT_HOSTLIST_PATH_MAX]; // 512 bytes
28  size_t count; // 8 bytes
29  double values; // 8 bytes
30  };
31 
34  geopm_time_s timestamp;
36  size_t count;
38  double values[(4096 - offsetof(struct geopm_endpoint_policy_shmem_header, values)) / sizeof(double)];
39  };
40 
43  geopm_time_s timestamp;
45  char agent[GEOPM_ENDPOINT_AGENT_NAME_MAX];
48  char profile_name[GEOPM_ENDPOINT_PROFILE_NAME_MAX];
51  char hostlist_path[GEOPM_ENDPOINT_HOSTLIST_PATH_MAX];
53  size_t count;
55  double values[(4096 - offsetof(struct geopm_endpoint_sample_shmem_header, values)) / sizeof(double)];
56  };
57 
58  static_assert(sizeof(struct geopm_endpoint_policy_shmem_s) == 4096, "Alignment issue with geopm_endpoint_policy_shmem_s.");
59  static_assert(sizeof(struct geopm_endpoint_sample_shmem_s) == 4096, "Alignment issue with geopm_endpoint_sample_shmem_s.");
60 
61  class SharedMemory;
62 
63  class EndpointImp : public Endpoint
64  {
65  public:
66  EndpointImp() = delete;
67  EndpointImp(const EndpointImp &other) = delete;
68  EndpointImp &operator=(const EndpointImp &other) = delete;
69 
70  EndpointImp(const std::string &data_path);
71  EndpointImp(const std::string &data_path,
72  std::shared_ptr<SharedMemory> policy_shmem,
73  std::shared_ptr<SharedMemory> sample_shmem,
74  size_t num_policy,
75  size_t num_sample);
76  virtual ~EndpointImp();
77 
78  void open(void) override;
79  void close(void) override;
80  void write_policy(const std::vector<double> &policy) override;
81  double read_sample(std::vector<double> &sample) override;
82  std::string get_agent(void) override;
83  void wait_for_agent_attach(double timeout) override;
84  void wait_for_agent_detach(double timeout) override;
85  void stop_wait_loop(void) override;
86  void reset_wait_loop(void) override;
87  std::string get_profile_name(void) override;
88  std::set<std::string> get_hostnames(void) override;
89  static std::string shm_policy_postfix(void);
90  static std::string shm_sample_postfix(void);
91  private:
92  std::string m_path;
93  std::shared_ptr<SharedMemory> m_policy_shmem;
94  std::shared_ptr<SharedMemory> m_sample_shmem;
95  size_t m_num_policy;
96  size_t m_num_sample;
97  bool m_is_open;
98  volatile bool m_continue_loop;
99  };
100 }
101 
102 #endif
Definition: Endpoint.hpp:20
Definition: EndpointImp.hpp:64
void write_policy(const std::vector< double > &policy) override
Write a set of policy values for the Agent.
Definition: Endpoint.cpp:103
void reset_wait_loop(void) override
Re-enables wait loops occurring after this call.
Definition: Endpoint.cpp:199
virtual ~EndpointImp()
Definition: Endpoint.cpp:65
std::string get_agent(void) override
Returns the Agent name, or empty string if no Agent is attached.
Definition: Endpoint.cpp:143
std::string get_profile_name(void) override
Returns the profile name associated with the attached application, or empty if no controller is attac...
Definition: Endpoint.cpp:204
EndpointImp & operator=(const EndpointImp &other)=delete
void close(void) override
Unlink the shared memory regions belonging to the Endpoint.
Definition: Endpoint.cpp:90
EndpointImp(const EndpointImp &other)=delete
void stop_wait_loop(void) override
Cancels any current wait loops in this Endpoint.
Definition: Endpoint.cpp:194
static std::string shm_sample_postfix(void)
Definition: Endpoint.cpp:38
void wait_for_agent_detach(double timeout) override
Blocks as long as the same agent is still attached to the endpoint, a timeout is reached,...
Definition: Endpoint.cpp:178
double read_sample(std::vector< double > &sample) override
Read a set of samples from the Agent.
Definition: Endpoint.cpp:120
void wait_for_agent_attach(double timeout) override
Blocks until an agent attaches to the endpoint, a timeout is reached, or the operation is canceled wi...
Definition: Endpoint.cpp:162
static std::string shm_policy_postfix(void)
Definition: Endpoint.cpp:33
std::set< std::string > get_hostnames(void) override
Returns the list of hostnames used by the attached application, or empty if no controller is attached...
Definition: Endpoint.cpp:219
void open(void) override
Create the shared memory regions belonging to the Endpoint.
Definition: Endpoint.cpp:70
Definition: Accumulator.cpp:12
Definition: EndpointImp.hpp:17
size_t count
Definition: EndpointImp.hpp:19
geopm_time_s timestamp
Definition: EndpointImp.hpp:18
double values
Definition: EndpointImp.hpp:20
Definition: EndpointImp.hpp:32
double values[(4096 - offsetof(struct geopm_endpoint_policy_shmem_header, values))/sizeof(double)]
Holds resource manager data.
Definition: EndpointImp.hpp:38
geopm_time_s timestamp
Time that the memory was last updated.
Definition: EndpointImp.hpp:34
size_t count
Specifies the size of the following array.
Definition: EndpointImp.hpp:36
Definition: EndpointImp.hpp:23
double values
Definition: EndpointImp.hpp:29
geopm_time_s timestamp
Definition: EndpointImp.hpp:24
char hostlist_path[GEOPM_ENDPOINT_HOSTLIST_PATH_MAX]
Definition: EndpointImp.hpp:27
char profile_name[GEOPM_ENDPOINT_PROFILE_NAME_MAX]
Definition: EndpointImp.hpp:26
char agent[GEOPM_ENDPOINT_AGENT_NAME_MAX]
Definition: EndpointImp.hpp:25
size_t count
Definition: EndpointImp.hpp:28
Definition: EndpointImp.hpp:41
char profile_name[GEOPM_ENDPOINT_PROFILE_NAME_MAX]
Holds the profile name associated with the attached job.
Definition: EndpointImp.hpp:48
double values[(4096 - offsetof(struct geopm_endpoint_sample_shmem_header, values))/sizeof(double)]
Holds resource manager data.
Definition: EndpointImp.hpp:55
size_t count
Specifies the size of the following array.
Definition: EndpointImp.hpp:53
char agent[GEOPM_ENDPOINT_AGENT_NAME_MAX]
Holds the name of the Agent attached, if any.
Definition: EndpointImp.hpp:45
char hostlist_path[GEOPM_ENDPOINT_HOSTLIST_PATH_MAX]
Path to a file containing the list of hostnames in the attached job.
Definition: EndpointImp.hpp:51
geopm_time_s timestamp
Time that the memory was last updated.
Definition: EndpointImp.hpp:43