1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #ifndef CHANNEL_MANAGER_H_
6 #define CHANNEL_MANAGER_H_
12 #include <linux/limits.h>
16 /* Maximum name length including '\0' terminator */
17 #define CHANNEL_MGR_MAX_NAME_LEN 64
19 /* Hypervisor Path for libvirt(qemu/KVM) */
20 #define CHANNEL_MGR_DEFAULT_HV_PATH "qemu:///system"
22 /* File socket directory */
23 #define CHANNEL_MGR_SOCKET_PATH "/tmp/powermonitor/"
25 /* FIFO file name template */
26 #define CHANNEL_MGR_FIFO_PATTERN_NAME "fifo"
28 #define MAX_CLIENTS 64
32 struct libvirt_vm_info {
34 unsigned int pcpus[MAX_VCPUS];
38 extern struct libvirt_vm_info lvm_info[MAX_CLIENTS];
39 /* Communication Channel Status */
40 enum channel_status { CHANNEL_MGR_CHANNEL_DISCONNECTED = 0,
41 CHANNEL_MGR_CHANNEL_CONNECTED,
42 CHANNEL_MGR_CHANNEL_DISABLED,
43 CHANNEL_MGR_CHANNEL_PROCESSING};
45 /* Communication Channel Type */
47 CHANNEL_TYPE_BINARY = 0,
52 /* VM libvirt(qemu/KVM) connection status */
53 enum vm_status { CHANNEL_MGR_VM_INACTIVE = 0, CHANNEL_MGR_VM_ACTIVE};
56 * Represents a single and exclusive VM channel that exists between a guest and
60 char channel_path[UNIX_PATH_MAX]; /**< Path to host socket */
61 volatile uint32_t status; /**< Connection status(enum channel_status) */
62 int fd; /**< AF_UNIX socket fd */
63 unsigned channel_num; /**< CHANNEL_MGR_SOCKET_PATH/<vm_name>.channel_num */
64 enum channel_type type; /**< Binary, ini, json, etc. */
65 void *priv_info; /**< Pointer to private info, do not modify */
68 /* Represents a single VM instance used to return internal information about
71 char name[CHANNEL_MGR_MAX_NAME_LEN]; /**< VM name */
72 enum vm_status status; /**< libvirt status */
73 uint16_t pcpu_map[RTE_MAX_LCORE]; /**< pCPU map to vCPU */
74 unsigned num_vcpus; /**< number of vCPUS */
75 struct channel_info channels[RTE_MAX_LCORE]; /**< channel_info array */
76 unsigned num_channels; /**< Number of channels */
77 int allow_query; /**< is query allowed */
81 * Initialize the Channel Manager resources and connect to the Hypervisor
83 * This must be successfully called first before calling any other functions.
84 * It must only be call once;
87 * Must be a local path, e.g. qemu:///system.
91 * - Negative on error.
93 int channel_manager_init(const char *path);
96 * Free resources associated with the Channel Manager.
99 * Must be a local path, e.g. qemu:///system.
104 void channel_manager_exit(void);
107 * Get the Physical CPU for VM lcore channel(vcpu).
108 * It is not thread-safe.
111 * Pointer to struct channel_info
114 * The virtual CPU to query.
121 uint16_t get_pcpu(struct channel_info *chan_info, unsigned int vcpu);
124 * Set the Physical CPU for the specified vCPU.
125 * It is not thread-safe.
128 * Virtual Machine name to lookup
131 * The virtual CPU to set.
134 * The core number of the physical CPU(s) to bind the vCPU
138 * - Negative on error.
140 int set_pcpu(char *vm_name, unsigned int vcpu, unsigned int pcpu);
143 * Allow or disallow queries for specified VM.
147 * Virtual Machine name to lookup.
150 * Query status to be set.
154 * - Negative on error.
156 int set_query_status(char *vm_name, bool allow_query);
159 * Add a VM as specified by name to the Channel Manager. The name must
160 * correspond to a valid libvirt domain name.
161 * This is required prior to adding channels.
162 * It is not thread-safe.
165 * Virtual Machine name to lookup.
169 * - Negative on error.
171 int add_vm(const char *name);
174 * Remove a previously added Virtual Machine from the Channel Manager
175 * It is not thread-safe.
178 * Virtual Machine name to lookup.
182 * - Negative on error.
184 int remove_vm(const char *name);
187 * Add all available channels to the VM as specified by name.
188 * Channels in the form of paths
189 * (CHANNEL_MGR_SOCKET_PATH/<vm_name>.<channel_number>) will only be parsed.
190 * It is not thread-safe.
193 * Virtual Machine name to lookup.
196 * - N the number of channels added for the VM
198 int add_all_channels(const char *vm_name);
201 * Add the channel numbers in channel_list to the domain specified by name.
202 * Channels in the form of paths
203 * (CHANNEL_MGR_SOCKET_PATH/<vm_name>.<channel_number>) will only be parsed.
204 * It is not thread-safe.
207 * Virtual Machine name to add channels.
209 * @param channel_list
210 * Pointer to list of unsigned integers, representing the channel number to add
211 * It must be allocated outside of this function.
213 * @param num_channels
214 * The amount of channel numbers in channel_list
217 * - N the number of channels added for the VM
220 int add_channels(const char *vm_name, unsigned *channel_list,
221 unsigned num_channels);
224 * Set up fifos by which host applications can send command an policies
225 * through a fifo to the vm_power_manager
230 int add_host_channels(void);
233 * Remove a channel definition from the channel manager. This must only be
234 * called from the channel monitor thread.
237 * Pointer to a valid struct channel_info.
241 * - Negative on error.
243 int remove_channel(struct channel_info **chan_info_dptr);
246 * For all channels associated with a Virtual Machine name, update the
247 * connection status. Valid states are CHANNEL_MGR_CHANNEL_CONNECTED or
248 * CHANNEL_MGR_CHANNEL_DISABLED only.
252 * Virtual Machine name to modify all channels.
255 * The status to set each channel
257 * @param num_channels
258 * The amount of channel numbers in channel_list
261 * - N the number of channels added for the VM
264 int set_channel_status_all(const char *name, enum channel_status status);
267 * For all channels in channel_list associated with a Virtual Machine name
268 * update the connection status of each.
269 * Valid states are CHANNEL_MGR_CHANNEL_CONNECTED or
270 * CHANNEL_MGR_CHANNEL_DISABLED only.
271 * It is not thread-safe.
274 * Virtual Machine name to add channels.
276 * @param channel_list
277 * Pointer to list of unsigned integers, representing the channel numbers to
279 * It must be allocated outside of this function.
281 * @param num_channels
282 * The amount of channel numbers in channel_list
285 * - N the number of channels modified for the VM
288 int set_channel_status(const char *vm_name, unsigned *channel_list,
289 unsigned len_channel_list, enum channel_status status);
292 * Populates a pointer to struct vm_info associated with vm_name.
295 * The name of the virtual machine to lookup.
298 * Pointer to a struct vm_info, this must be allocated prior to calling this
303 * - Negative on error.
305 int get_info_vm(const char *vm_name, struct vm_info *info);
308 * Populates a table with all domains running and their physical cpu.
309 * All information is gathered through libvirt api.
312 * modified to store number of active VMs
315 modified to store number of vcpus active
320 void get_all_vm(int *num_vm, int *num_vcpu);
325 #endif /* CHANNEL_MANAGER_H_ */