geopm  3.1.1.dev214+gba4f9f6d
GEOPM - Global Extensible Open Power Manager
MSRIOImp.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 MSRIOIMP_HPP_INCLUDE
7 #define MSRIOIMP_HPP_INCLUDE
8 
9 #include <string>
10 #include <map>
11 
12 #include "IOUring.hpp"
13 #include "MSRIO.hpp"
14 
15 namespace geopm
16 {
17  class MSRPath;
18 
19  class MSRIOImp : public MSRIO
20  {
21  public:
22  MSRIOImp() = delete;
23  MSRIOImp(std::shared_ptr<MSRPath> path);
24  MSRIOImp(int num_cpu, std::shared_ptr<MSRPath> path,
25  std::shared_ptr<IOUring> batch_reader,
26  std::shared_ptr<IOUring> batch_writer);
27  MSRIOImp(const MSRIOImp &other) = delete;
28  MSRIOImp &operator=(const MSRIOImp &other) = delete;
29  virtual ~MSRIOImp();
30  uint64_t read_msr(int cpu_idx,
31  uint64_t offset) override;
32  void write_msr(int cpu_idx,
33  uint64_t offset,
34  uint64_t raw_value,
35  uint64_t write_mask) override;
36  int create_batch_context(void) override;
37  int add_read(int cpu_idx, uint64_t offset) override;
38  int add_read(int cpu_idx, uint64_t offset, int batch_ctx) override;
39  void read_batch() override;
40  void read_batch(int batch_ctx) override;
41  uint64_t sample(int batch_idx) const override;
42  uint64_t sample(int batch_idx, int batch_ctx) const override;
43  void write_batch() override;
44  void write_batch(int batch_ctx) override;
45  int add_write(int cpu_idx, uint64_t offset) override;
46  int add_write(int cpu_idx, uint64_t offset, int batch_ctx) override;
47  void adjust(int batch_idx, uint64_t value, uint64_t write_mask) override;
48  void adjust(int batch_idx, uint64_t value, uint64_t write_mask, int batch_ctx) override;
49  uint64_t system_write_mask(uint64_t offset) override;
50  private:
51  struct m_msr_batch_op_s {
52  uint16_t cpu;
53  uint16_t isrdmsr;
54  int32_t err;
55  uint32_t msr;
56  uint64_t msrdata;
57  uint64_t wmask;
58  };
59 
60  struct m_msr_batch_array_s {
61  uint32_t numops;
62  struct m_msr_batch_op_s *ops;
63  };
64 
65  struct m_batch_context_s {
66  m_batch_context_s(int num_cpu)
67  : m_is_batch_read(false)
68  , m_read_batch({0, nullptr})
69  , m_write_batch({0, nullptr})
70  , m_read_batch_op(0)
71  , m_write_batch_op(0)
72  , m_read_batch_idx_map(num_cpu)
73  , m_write_batch_idx_map(num_cpu)
74  {}
75 
76  bool m_is_batch_read;
77  struct m_msr_batch_array_s m_read_batch;
78  struct m_msr_batch_array_s m_write_batch;
79  std::vector<struct m_msr_batch_op_s> m_read_batch_op;
80  std::vector<struct m_msr_batch_op_s> m_write_batch_op;
81  std::vector<std::map<uint64_t, int> > m_read_batch_idx_map;
82  std::vector<std::map<uint64_t, int> > m_write_batch_idx_map;
83  std::vector<uint64_t> m_write_val;
84  std::vector<uint64_t> m_write_mask;
85  };
86 
87  void open_all(void);
88  void open_msr(int cpu_idx);
89  void open_msr_batch(void);
90  void close_all(void);
91  void close_msr(int cpu_idx);
92  void close_msr_batch(void);
93  int msr_desc(int cpu_idx);
94  int msr_batch_desc(void);
95  void msr_ioctl(struct m_msr_batch_array_s &batch);
96  void msr_ioctl_read(struct m_batch_context_s &ctx);
97  void msr_ioctl_write(struct m_batch_context_s &ctx);
98  void msr_batch_io(IOUring &batcher, struct m_msr_batch_array_s &batch);
99  void msr_read_files(int batch_ctx);
100  void msr_rmw_files(int batch_ctx);
101 
102  const int m_num_cpu;
103  std::vector<int> m_file_desc;
104  std::vector<struct m_batch_context_s> m_batch_context;
105  bool m_is_batch_enabled;
106  std::map<uint64_t, uint64_t> m_offset_mask_map;
107  bool m_is_open;
108  std::shared_ptr<MSRPath> m_path;
109  std::shared_ptr<IOUring> m_batch_reader;
110  std::shared_ptr<IOUring> m_batch_writer;
111  };
112 }
113 
114 #endif
Definition: MSRIO.hpp:16
Definition: MSRIOImp.hpp:20
MSRIOImp & operator=(const MSRIOImp &other)=delete
void write_batch() override
Write all adjusted values. Note: uses the default batch context.
Definition: MSRIO.cpp:448
MSRIOImp()=delete
uint64_t sample(int batch_idx) const override
Read the full 64-bit value of the MSR that was previously added to the MSRIO with add_read()....
Definition: MSRIO.cpp:248
void adjust(int batch_idx, uint64_t value, uint64_t write_mask) override
Adjust a value that was previously added with the add_write() method. Note: uses the default batch co...
Definition: MSRIO.cpp:194
MSRIOImp(const MSRIOImp &other)=delete
int add_write(int cpu_idx, uint64_t offset) override
Add another offset to the list of MSRs to be written in batch. Note: uses the default batch context.
Definition: MSRIO.cpp:162
void read_batch() override
Batch read a set of MSRs configured by a previous call to the batch_config() method....
Definition: MSRIO.cpp:426
void write_msr(int cpu_idx, uint64_t offset, uint64_t raw_value, uint64_t write_mask) override
Write to a single MSR on a CPU.
Definition: MSRIO.cpp:97
int create_batch_context(void) override
Add a new batch context to the set of managed contexts.
Definition: MSRIO.cpp:155
uint64_t read_msr(int cpu_idx, uint64_t offset) override
Read from a single MSR on a CPU.
Definition: MSRIO.cpp:83
int add_read(int cpu_idx, uint64_t offset) override
Extend the set of MSRs for batch read with a single offset. Note: uses the default batch context.
Definition: MSRIO.cpp:226
uint64_t system_write_mask(uint64_t offset) override
Return the system write mask for a given offset.
Definition: MSRIO.cpp:121
virtual ~MSRIOImp()
Definition: MSRIO.cpp:56
Definition: Agg.cpp:20