geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
ApplicationStatus.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 APPLICATIONSTATUS_HPP_INCLUDE
7 #define APPLICATIONSTATUS_HPP_INCLUDE
8 
9 #include <cstdint>
10 
11 #include <memory>
12 #include <vector>
13 #include <set>
14 
15 #include "geopm/Helper.hpp"
16 
17 namespace geopm
18 {
19  class SharedMemory;
20 
27  {
28  public:
29  virtual ~ApplicationStatus() = default;
30 
36  virtual void set_hint(int cpu_idx, uint64_t hint) = 0;
40  virtual uint64_t get_hint(int cpu_idx) const = 0;
43  virtual void set_hash(int cpu_idx, uint64_t hash, uint64_t hint) = 0;
46  virtual uint64_t get_hash(int cpu_idx) const = 0;
47  virtual void reset_work_units(int cpu_idx) = 0;
53  virtual void set_total_work_units(int cpu_idx, int work_units) = 0;
56  virtual void increment_work_unit(int cpu_idx) = 0;
63  virtual double get_progress_cpu(int cpu_idx) const = 0;
67  virtual void update_cache(void) = 0;
68 
77  static std::unique_ptr<ApplicationStatus> make_unique(int num_cpu,
78  std::shared_ptr<SharedMemory> shmem);
84  static size_t buffer_size(int num_cpu);
85 
86  protected:
87  static constexpr size_t M_STATUS_SIZE = geopm::hardware_destructive_interference_size;
88  };
89 
91  {
92  public:
93  ApplicationStatusImp(int num_cpu,
94  std::shared_ptr<SharedMemory> shmem);
95  virtual ~ApplicationStatusImp() = default;
96  void set_hint(int cpu_idx, uint64_t hint) override;
97  uint64_t get_hint(int cpu_idx) const override;
98  void set_hash(int cpu_idx, uint64_t hash, uint64_t hint) override;
99  uint64_t get_hash(int cpu_idx) const override;
100  void reset_work_units(int cpu_idx) override;
101  void set_total_work_units(int cpu_idx, int work_units) override;
102  void increment_work_unit(int cpu_idx) override;
103  double get_progress_cpu(int cpu_idx) const override;
104  void update_cache(void) override;
105  private:
106  // These fields must all be 32-bit int
107  struct m_app_status_s
108  {
109  int32_t process; // can be negative, indicating unset process
110  uint32_t hint;
111  uint32_t hash;
112  uint32_t total_work;
113  uint32_t completed_work;
114  char padding[44];
115  };
116  static_assert((sizeof(ApplicationStatusImp::m_app_status_s) % geopm::hardware_destructive_interference_size) == 0,
117  "m_app_status_s not aligned to cache lines");
118  static_assert(sizeof(ApplicationStatusImp::m_app_status_s) == ApplicationStatus::M_STATUS_SIZE,
119  "M_STATUS_SIZE does not match size of m_app_status_s");
120 
121  int m_num_cpu;
122  std::shared_ptr<SharedMemory> m_shmem;
123  m_app_status_s *m_buffer;
124  std::vector<m_app_status_s> m_cache;
125  };
126 }
127 
128 #endif
Object that encapsulates application process information such as the process ID, region hash,...
Definition: ApplicationStatus.hpp:27
virtual void increment_work_unit(int cpu_idx)=0
Mark a unit of work completed for this CPU.
virtual void update_cache(void)=0
Updates the local memory with the latest values from the shared memory. Any calls to get methods will...
static size_t buffer_size(int num_cpu)
Return the required size of the shared memory region used by the ApplicationStatus for the given numb...
Definition: ApplicationStatus.cpp:26
virtual void reset_work_units(int cpu_idx)=0
virtual void set_hint(int cpu_idx, uint64_t hint)=0
Set the current hint bits for a CPU.
virtual void set_total_work_units(int cpu_idx, int work_units)=0
Reset the total work units for all threads to be completed as part of a parallel region....
virtual ~ApplicationStatus()=default
virtual double get_progress_cpu(int cpu_idx) const =0
Get the current progress for this CPU. Progress is the fraction of the total work units that have bee...
virtual uint64_t get_hash(int cpu_idx) const =0
Get the hash of the region currently running on a CPU.
virtual uint64_t get_hint(int cpu_idx) const =0
Get the current hint bits for a CPU.
static std::unique_ptr< ApplicationStatus > make_unique(int num_cpu, std::shared_ptr< SharedMemory > shmem)
Create an ApplicationStatus object using the given SharedMemory. The caller is responsible for callin...
Definition: ApplicationStatus.cpp:20
static constexpr size_t M_STATUS_SIZE
Definition: ApplicationStatus.hpp:87
virtual void set_hash(int cpu_idx, uint64_t hash, uint64_t hint)=0
Set the hash and hint of the region currently running on a CPU.
Definition: ApplicationStatus.hpp:91
ApplicationStatusImp(int num_cpu, std::shared_ptr< SharedMemory > shmem)
Definition: ApplicationStatus.cpp:31
void set_hint(int cpu_idx, uint64_t hint) override
Set the current hint bits for a CPU.
Definition: ApplicationStatus.cpp:51
uint64_t get_hash(int cpu_idx) const override
Get the hash of the region currently running on a CPU.
Definition: ApplicationStatus.cpp:92
void reset_work_units(int cpu_idx) override
Definition: ApplicationStatus.cpp:103
uint64_t get_hint(int cpu_idx) const override
Get the current hint bits for a CPU.
Definition: ApplicationStatus.cpp:63
void update_cache(void) override
Updates the local memory with the latest values from the shared memory. Any calls to get methods will...
Definition: ApplicationStatus.cpp:159
virtual ~ApplicationStatusImp()=default
void set_total_work_units(int cpu_idx, int work_units) override
Reset the total work units for all threads to be completed as part of a parallel region....
Definition: ApplicationStatus.cpp:114
double get_progress_cpu(int cpu_idx) const override
Get the current progress for this CPU. Progress is the fraction of the total work units that have bee...
Definition: ApplicationStatus.cpp:143
void set_hash(int cpu_idx, uint64_t hash, uint64_t hint) override
Set the hash and hint of the region currently running on a CPU.
Definition: ApplicationStatus.cpp:76
void increment_work_unit(int cpu_idx) override
Mark a unit of work completed for this CPU.
Definition: ApplicationStatus.cpp:130
Definition: Accumulator.cpp:12