geopm  3.1.1.dev214+gba4f9f6d
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 #include <limits.h>
11 
12 #include "geopm_endpoint.h"
13 #include "geopm_time.h"
14 #include "geopm/Endpoint.hpp"
15 
16 namespace geopm
17 {
19  geopm_time_s timestamp; // 16 bytes
20  size_t count; // 8 bytes
21  double values; // 8 bytes
22  };
23 
25  geopm_time_s timestamp; // 16 bytes
26  char agent[GEOPM_ENDPOINT_AGENT_NAME_MAX]; // 256 bytes
27  char profile_name[GEOPM_ENDPOINT_PROFILE_NAME_MAX]; // 256 bytes
28  char hostlist_path[GEOPM_ENDPOINT_HOSTLIST_PATH_MAX]; // 512 bytes
29  size_t count; // 8 bytes
30  double values; // 8 bytes
31  };
32 
35  geopm_time_s timestamp;
37  size_t count;
39  double values[(4096 - offsetof(struct geopm_endpoint_policy_shmem_header, values)) / sizeof(double)];
40  };
41 
44  geopm_time_s timestamp;
46  char agent[GEOPM_ENDPOINT_AGENT_NAME_MAX];
49  char profile_name[GEOPM_ENDPOINT_PROFILE_NAME_MAX];
52  char hostlist_path[GEOPM_ENDPOINT_HOSTLIST_PATH_MAX];
54  size_t count;
56  double values[(4096 - offsetof(struct geopm_endpoint_sample_shmem_header, values)) / sizeof(double)];
57  };
58 
59  static_assert(sizeof(struct geopm_endpoint_policy_shmem_s) == 4096, "Alignment issue with geopm_endpoint_policy_shmem_s.");
60  static_assert(sizeof(struct geopm_endpoint_sample_shmem_s) == 4096, "Alignment issue with geopm_endpoint_sample_shmem_s.");
61 
62  class SharedMemory;
63 
64  class EndpointImp : public Endpoint
65  {
66  public:
67  EndpointImp() = delete;
68  EndpointImp(const EndpointImp &other) = delete;
69  EndpointImp &operator=(const EndpointImp &other) = delete;
70 
71  EndpointImp(const std::string &data_path);
72  EndpointImp(const std::string &data_path,
73  std::shared_ptr<SharedMemory> policy_shmem,
74  std::shared_ptr<SharedMemory> sample_shmem,
75  size_t num_policy,
76  size_t num_sample);
77  virtual ~EndpointImp();
78 
79  void open(void) override;
80  void close(void) override;
81  void write_policy(const std::vector<double> &policy) override;
82  double read_sample(std::vector<double> &sample) override;
83  std::string get_agent(void) override;
84  void wait_for_agent_attach(double timeout) override;
85  void wait_for_agent_detach(double timeout) override;
86  void stop_wait_loop(void) override;
87  void reset_wait_loop(void) override;
88  std::string get_profile_name(void) override;
89  std::set<std::string> get_hostnames(void) override;
90  static std::string shm_policy_postfix(void);
91  static std::string shm_sample_postfix(void);
92  private:
93  std::string m_path;
94  std::shared_ptr<SharedMemory> m_policy_shmem;
95  std::shared_ptr<SharedMemory> m_sample_shmem;
96  size_t m_num_policy;
97  size_t m_num_sample;
98  bool m_is_open;
99  volatile bool m_continue_loop;
100  };
101 }
102 
103 #endif
Definition: Endpoint.hpp:20
Definition: EndpointImp.hpp:65
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:18
size_t count
Definition: EndpointImp.hpp:20
geopm_time_s timestamp
Definition: EndpointImp.hpp:19
double values
Definition: EndpointImp.hpp:21
Definition: EndpointImp.hpp:33
double values[(4096 - offsetof(struct geopm_endpoint_policy_shmem_header, values))/sizeof(double)]
Holds resource manager data.
Definition: EndpointImp.hpp:39
geopm_time_s timestamp
Time that the memory was last updated.
Definition: EndpointImp.hpp:35
size_t count
Specifies the size of the following array.
Definition: EndpointImp.hpp:37
Definition: EndpointImp.hpp:24
double values
Definition: EndpointImp.hpp:30
geopm_time_s timestamp
Definition: EndpointImp.hpp:25
char hostlist_path[GEOPM_ENDPOINT_HOSTLIST_PATH_MAX]
Definition: EndpointImp.hpp:28
char profile_name[GEOPM_ENDPOINT_PROFILE_NAME_MAX]
Definition: EndpointImp.hpp:27
char agent[GEOPM_ENDPOINT_AGENT_NAME_MAX]
Definition: EndpointImp.hpp:26
size_t count
Definition: EndpointImp.hpp:29
Definition: EndpointImp.hpp:42
char profile_name[GEOPM_ENDPOINT_PROFILE_NAME_MAX]
Holds the profile name associated with the attached job.
Definition: EndpointImp.hpp:49
double values[(4096 - offsetof(struct geopm_endpoint_sample_shmem_header, values))/sizeof(double)]
Holds resource manager data.
Definition: EndpointImp.hpp:56
size_t count
Specifies the size of the following array.
Definition: EndpointImp.hpp:54
char agent[GEOPM_ENDPOINT_AGENT_NAME_MAX]
Holds the name of the Agent attached, if any.
Definition: EndpointImp.hpp:46
char hostlist_path[GEOPM_ENDPOINT_HOSTLIST_PATH_MAX]
Path to a file containing the list of hostnames in the attached job.
Definition: EndpointImp.hpp:52
geopm_time_s timestamp
Time that the memory was last updated.
Definition: EndpointImp.hpp:44