geopm  3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
BatchServer.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 BATCHSERVER_HPP_INCLUDE
7 #define BATCHSERVER_HPP_INCLUDE
8 
9 #include <memory>
10 #include <vector>
11 #include <string>
12 #include <functional>
13 #include <signal.h>
14 
15 
16 struct geopm_request_s;
17 
18 namespace geopm
19 {
20  class PlatformIO;
21  class SharedMemory;
22  class BatchStatus;
23  class POSIXSignal;
24 
26  {
27  public:
30  BatchServer() = default;
31  virtual ~BatchServer() = default;
68  static std::unique_ptr<BatchServer> make_unique(int client_pid,
69  const std::vector<geopm_request_s> &signal_config,
70  const std::vector<geopm_request_s> &control_config);
73  static std::string get_signal_shmem_key(
74  const std::string &server_key);
77  static std::string get_control_shmem_key(
78  const std::string &server_key);
81  virtual int server_pid(void) const = 0;
85  virtual std::string server_key(void) const = 0;
92  virtual void stop_batch(void) = 0;
94  virtual bool is_active(void) = 0;
95 
96  protected:
97  static constexpr const char* M_SHMEM_PREFIX =
98  "/run/geopm/batch-buffer-";
99  };
100 
102  {
103  public:
104  BatchServerImp(int client_pid,
105  const std::vector<geopm_request_s> &signal_config,
106  const std::vector<geopm_request_s> &control_config);
107  BatchServerImp(int client_pid,
108  const std::vector<geopm_request_s> &signal_config,
109  const std::vector<geopm_request_s> &control_config,
110  const std::string &signal_shmem_key,
111  const std::string &control_shmem_key,
112  PlatformIO &pio,
113  std::shared_ptr<BatchStatus> batch_status,
114  std::shared_ptr<POSIXSignal> posix_signal,
115  std::shared_ptr<SharedMemory> signal_shmem,
116  std::shared_ptr<SharedMemory> control_shmem,
117  int server_pid);
118  BatchServerImp(const BatchServerImp &other) = delete;
119  BatchServerImp &operator=(const BatchServerImp &other) = delete;
120  virtual ~BatchServerImp();
121  int server_pid(void) const override;
122  std::string server_key(void) const override;
123  void stop_batch(void) override;
124  bool is_active(void) override;
125  void run_batch(void);
126  void create_shmem(void);
129  int fork_with_setup(std::function<char(void)> setup,
130  std::function<void(void)> run);
131  void child_register_handler(void);
132  void parent_register_handler(void);
133 
134  private:
135  void push_requests(void);
136  void read_and_update(void);
137  void update_and_write(void);
138  void check_invalid_signal(void);
139  void check_return(int ret, const std::string &func_name) const;
140  char read_message(void);
141  void write_message(char message);
142  void event_loop(void);
143 
144  const int m_client_pid;
145  const std::string m_server_key;
146  const std::vector<geopm_request_s> m_signal_config;
147  const std::vector<geopm_request_s> m_control_config;
148  const std::string m_signal_shmem_key;
149  const std::string m_control_shmem_key;
150  PlatformIO &m_pio;
151  std::shared_ptr<SharedMemory> m_signal_shmem;
152  std::shared_ptr<SharedMemory> m_control_shmem;
153  std::shared_ptr<BatchStatus> m_batch_status;
154  std::shared_ptr<POSIXSignal> m_posix_signal;
155  int m_server_pid;
156  bool m_is_active;
157  bool m_is_client_attached;
158  bool m_is_client_waiting;
161  std::vector<int> m_signal_handle;
164  std::vector<int> m_control_handle;
165  };
166 }
167 
168 #endif
Definition: BatchServer.hpp:26
static std::unique_ptr< BatchServer > make_unique(int client_pid, const std::vector< geopm_request_s > &signal_config, const std::vector< geopm_request_s > &control_config)
Supports the D-Bus interface for starting a batch server.
Definition: BatchServer.cpp:59
static std::string get_control_shmem_key(const std::string &server_key)
Definition: BatchServer.cpp:73
virtual void stop_batch(void)=0
Supports the D-Bus interface for stopping a batch server.
virtual std::string server_key(void) const =0
static std::string get_signal_shmem_key(const std::string &server_key)
Definition: BatchServer.cpp:67
static constexpr const char * M_SHMEM_PREFIX
Definition: BatchServer.hpp:97
BatchServer()=default
Interface called by geopmd to create the server for batch commands.
virtual int server_pid(void) const =0
virtual bool is_active(void)=0
Returns true if the batch server is running.
virtual ~BatchServer()=default
Definition: BatchServer.hpp:102
void parent_register_handler(void)
Definition: BatchServer.cpp:402
void child_register_handler(void)
Definition: BatchServer.cpp:391
bool is_active(void) override
Returns true if the batch server is running.
Definition: BatchServer.cpp:304
virtual ~BatchServerImp()
Definition: BatchServer.cpp:152
BatchServerImp & operator=(const BatchServerImp &other)=delete
void stop_batch(void) override
Supports the D-Bus interface for stopping a batch server.
Definition: BatchServer.cpp:184
void run_batch(void)
Definition: BatchServer.cpp:246
BatchServerImp(const BatchServerImp &other)=delete
int server_pid(void) const override
Definition: BatchServer.cpp:174
std::string server_key(void) const override
Definition: BatchServer.cpp:179
int fork_with_setup(std::function< char(void)> setup, std::function< void(void)> run)
Fork a process that runs two functions and block until the first function completes.
Definition: BatchServer.cpp:413
BatchServerImp(int client_pid, const std::vector< geopm_request_s > &signal_config, const std::vector< geopm_request_s > &control_config)
Definition: BatchServer.cpp:79
void create_shmem(void)
Definition: BatchServer.cpp:370
Class which is a collection of all valid control and signal objects for a platform.
Definition: PlatformIO.hpp:26
Definition: Agg.cpp:20
Definition: geopm_pio.h:387