geopm 3.1.1.dev410+g40bf96ed
GEOPM - Global Extensible Open Power Manager
Loading...
Searching...
No Matches
Profile.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 PROFILE_HPP_INCLUDE
7#define PROFILE_HPP_INCLUDE
8
9#include <cstdint>
10#include <map>
11#include <memory>
12#include <set>
13#include <stack>
14#include <string>
15#include <vector>
16
17#include "geopm_hash.h"
18#include "geopm_hint.h"
19#include "geopm_public.h"
20#include "geopm_time.h"
21
22/****************************************/
23/* Encode/decode function for region_id */
24/****************************************/
25
27 GEOPM_REGION_ID_EPOCH = 1ULL << 63, /* Signaling the start of an epoch, no associated Region */
28 GEOPM_REGION_ID_MPI = 1ULL << 62, /* Execution of MPI calls */
29};
30
31static inline uint64_t geopm_region_id_hash(uint64_t region_id)
32{
33 uint64_t ret = ((region_id << 32) >> 32);
34
35 if (GEOPM_REGION_HASH_INVALID == ret) {
36 ret = GEOPM_REGION_HASH_UNMARKED;
37 }
38 return ret;
39}
40
41static inline int geopm_region_id_is_mpi(uint64_t region_id)
42{
43 return (region_id & GEOPM_REGION_ID_MPI) ? 1 : 0;
44}
45
46static inline geopm_region_hint_e geopm_region_id_hint(uint64_t region_id)
47{
48 geopm_region_hint_e ret;
49 if (GEOPM_REGION_HASH_UNMARKED == region_id) {
50 ret = GEOPM_REGION_HINT_UNKNOWN;
51 }
52 else if (geopm_region_id_is_mpi(region_id)) {
53 ret = GEOPM_REGION_HINT_NETWORK;
54 }
55 else {
56 ret = (geopm_region_hint_e)(region_id >> 32);
57 if (!ret || ret >= GEOPM_NUM_REGION_HINT) {
58 ret = GEOPM_REGION_HINT_UNKNOWN;
59 }
60 }
61 return ret;
62}
63
64static inline uint64_t geopm_region_id_set_hint(uint64_t hint_type, uint64_t region_id)
65{
66 return (region_id | (hint_type << 32));
67}
68
69static inline int geopm_region_id_hint_is_equal(uint64_t hint_type, uint64_t region_id)
70{
71 return (region_id & (hint_type << 32)) ? 1 : 0;
72}
73
74
75namespace geopm
76{
112 class GEOPM_PUBLIC Profile
113 {
114 public:
115 Profile() = default;
116 virtual ~Profile() = default;
117 static Profile &default_profile(void);
118
143 virtual uint64_t region(const std::string &region_name, long hint) = 0;
155 virtual void enter(uint64_t region_id) = 0;
168 virtual void exit(uint64_t region_id) = 0;
177 virtual void epoch(void) = 0;
178 virtual void shutdown(void) = 0;
186 virtual void thread_init(uint32_t num_work_unit) = 0;
189 //
192 virtual void thread_post(int cpu) = 0;
193
194 virtual std::vector<std::string> region_names(void) = 0;
195
196 virtual void reset_cpu_set(void) = 0;
197 virtual void overhead(double overhead_sec) = 0;
198 virtual void connect(void) = 0;
204 static int get_cpu(void);
205 };
206
207 class SharedMemory;
209 class ApplicationStatus;
210 class ServiceProxy;
211 class Scheduler;
212
213 class GEOPM_PUBLIC ProfileImp : public Profile
214 {
215 public:
222 ProfileImp();
236 ProfileImp(const std::string &prof_name,
237 const std::string &report,
238 int num_cpu,
239 std::set<int> cpu_set,
240 std::shared_ptr<ApplicationStatus> app_status,
241 std::shared_ptr<ApplicationRecordLog> app_record_log,
242 bool do_profile,
243 std::shared_ptr<ServiceProxy> service_proxy,
244 std::shared_ptr<Scheduler> scheduler,
245 int registered_pid);
246 ProfileImp(const ProfileImp &other) = delete;
247 ProfileImp operator=(const ProfileImp &other) = delete;
249 virtual ~ProfileImp();
250 uint64_t region(const std::string &region_name, long hint) override;
251 void enter(uint64_t region_id) override;
252 void exit(uint64_t region_id) override;
253 void epoch(void) override;
254 void shutdown(void) override;
255 void thread_init(uint32_t num_work_unit) override;
256 void thread_post(int cpu) override;
257 std::vector<std::string> region_names(void) override;
258 void reset_cpu_set(void) override;
259 void overhead(double overhead_sec) override;
260 void connect(void) override;
261 protected:
263 private:
264 void GEOPM_PRIVATE
265 init_app_status(void);
266 void GEOPM_PRIVATE
267 init_app_record_log(void);
269 void GEOPM_PRIVATE
270 set_hint(uint64_t hint);
271
273 std::string m_prof_name;
274 std::string m_report;
277 uint64_t m_curr_region_id;
278 uint64_t m_current_hash;
282 int m_num_cpu;
285 std::set<int> m_cpu_set;
286
287 std::shared_ptr<ApplicationStatus> m_app_status;
288 std::shared_ptr<ApplicationRecordLog> m_app_record_log;
289 std::stack<geopm_region_hint_e> m_hint_stack;
290
291 double m_overhead_time;
292 double m_overhead_time_startup;
293 double m_overhead_time_shutdown;
294 bool m_do_profile;
295 std::map<std::string, uint64_t> m_region_names;
296
297 std::shared_ptr<ServiceProxy> m_service_proxy;
298 std::shared_ptr<Scheduler> m_scheduler;
299 int m_pid_registered;
300
301 enum m_profile_const_e {
302 M_PID_INIT = -1,
303 M_PID_TEST = -2,
304 };
305
307 std::set<uint64_t> m_region_ids;
308 };
309}
310
311#endif
geopm_region_id_e
Definition Profile.hpp:26
@ GEOPM_REGION_ID_MPI
Definition Profile.hpp:28
@ GEOPM_REGION_ID_EPOCH
Definition Profile.hpp:27
Provides an abstraction for a shared memory buffer that can be used to pass entry,...
Definition ApplicationRecordLog.hpp:57
Object that encapsulates application process information such as the process ID, region hash,...
Definition ApplicationStatus.hpp:27
Enables application profiling and application feedback to the control algorithm.
Definition Profile.hpp:113
virtual uint64_t region(const std::string &region_name, long hint)=0
Register a region of code to be profiled.
virtual void exit(uint64_t region_id)=0
Mark a region exit point.
virtual void overhead(double overhead_sec)=0
virtual std::vector< std::string > region_names(void)=0
virtual void enter(uint64_t region_id)=0
Mark a region entry point.
virtual void reset_cpu_set(void)=0
virtual void epoch(void)=0
Signal pass through outer loop.
Profile()=default
virtual ~Profile()=default
virtual void thread_init(uint32_t num_work_unit)=0
Update the total work for all CPUs. This method should be called by one thread in the same parallel r...
virtual void connect(void)=0
virtual void shutdown(void)=0
virtual void thread_post(int cpu)=0
Mark one unit of work completed by the thread on this CPU.
Definition Profile.hpp:214
ProfileImp(const ProfileImp &other)=delete
bool m_is_enabled
Definition Profile.hpp:262
ProfileImp operator=(const ProfileImp &other)=delete
Definition Scheduler.hpp:16
Definition Accumulator.cpp:12