4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef CHANNEL_MANAGER_H_
35 #define CHANNEL_MANAGER_H_
41 #include <linux/limits.h>
42 #include <rte_atomic.h>
43 #include "channel_commands.h"
45 /* Maximum name length including '\0' terminator */
46 #define CHANNEL_MGR_MAX_NAME_LEN 64
48 /* Maximum number of channels to each Virtual Machine */
49 #define CHANNEL_MGR_MAX_CHANNELS 64
51 /* Hypervisor Path for libvirt(qemu/KVM) */
52 #define CHANNEL_MGR_DEFAULT_HV_PATH "qemu:///system"
54 /* File socket directory */
55 #define CHANNEL_MGR_SOCKET_PATH "/tmp/powermonitor/"
57 /* Communication Channel Status */
58 enum channel_status { CHANNEL_MGR_CHANNEL_DISCONNECTED = 0,
59 CHANNEL_MGR_CHANNEL_CONNECTED,
60 CHANNEL_MGR_CHANNEL_DISABLED,
61 CHANNEL_MGR_CHANNEL_PROCESSING};
63 /* VM libvirt(qemu/KVM) connection status */
64 enum vm_status { CHANNEL_MGR_VM_INACTIVE = 0, CHANNEL_MGR_VM_ACTIVE};
67 * Represents a single and exclusive VM channel that exists between a guest and
71 char channel_path[PATH_MAX]; /**< Path to host socket */
72 volatile uint32_t status; /**< Connection status(enum channel_status) */
73 int fd; /**< AF_UNIX socket fd */
74 unsigned channel_num; /**< CHANNEL_MGR_SOCKET_PATH/<vm_name>.channel_num */
75 void *priv_info; /**< Pointer to private info, do not modify */
78 /* Represents a single VM instance used to return internal information about
81 char name[CHANNEL_MGR_MAX_NAME_LEN]; /**< VM name */
82 enum vm_status status; /**< libvirt status */
83 uint64_t pcpu_mask[CHANNEL_CMDS_MAX_CPUS]; /**< pCPU mask for each vCPU */
84 unsigned num_vcpus; /**< number of vCPUS */
85 struct channel_info channels[CHANNEL_MGR_MAX_CHANNELS]; /**< Array of channel_info */
86 unsigned num_channels; /**< Number of channels */
90 * Initialize the Channel Manager resources and connect to the Hypervisor
92 * This must be successfully called first before calling any other functions.
93 * It must only be call once;
96 * Must be a local path, e.g. qemu:///system.
100 * - Negative on error.
102 int channel_manager_init(const char *path);
105 * Free resources associated with the Channel Manager.
108 * Must be a local path, e.g. qemu:///system.
113 void channel_manager_exit(void);
116 * Get the Physical CPU mask for VM lcore channel(vcpu), result is assigned to
118 * It is not thread-safe.
121 * Pointer to struct channel_info
124 * The virtual CPU to query.
131 uint64_t get_pcpus_mask(struct channel_info *chan_info, unsigned vcpu);
134 * Set the Physical CPU mask for the specified vCPU.
135 * It is not thread-safe.
138 * Virtual Machine name to lookup
141 * The virtual CPU to set.
144 * The core mask of the physical CPU(s) to bind the vCPU
148 * - Negative on error.
150 int set_pcpus_mask(char *vm_name, unsigned vcpu, uint64_t core_mask);
153 * Set the Physical CPU for the specified vCPU.
154 * It is not thread-safe.
157 * Virtual Machine name to lookup
160 * The virtual CPU to set.
163 * The core number of the physical CPU(s) to bind the vCPU
167 * - Negative on error.
169 int set_pcpu(char *vm_name, unsigned vcpu, unsigned core_num);
171 * Add a VM as specified by name to the Channel Manager. The name must
172 * correspond to a valid libvirt domain name.
173 * This is required prior to adding channels.
174 * It is not thread-safe.
177 * Virtual Machine name to lookup.
181 * - Negative on error.
183 int add_vm(const char *name);
186 * Remove a previously added Virtual Machine from the Channel Manager
187 * It is not thread-safe.
190 * Virtual Machine name to lookup.
194 * - Negative on error.
196 int remove_vm(const char *name);
199 * Add all available channels to the VM as specified by name.
200 * Channels in the form of paths
201 * (CHANNEL_MGR_SOCKET_PATH/<vm_name>.<channel_number>) will only be parsed.
202 * It is not thread-safe.
205 * Virtual Machine name to lookup.
208 * - N the number of channels added for the VM
210 int add_all_channels(const char *vm_name);
213 * Add the channel numbers in channel_list to the domain specified by name.
214 * Channels in the form of paths
215 * (CHANNEL_MGR_SOCKET_PATH/<vm_name>.<channel_number>) will only be parsed.
216 * It is not thread-safe.
219 * Virtual Machine name to add channels.
221 * @param channel_list
222 * Pointer to list of unsigned integers, representing the channel number to add
223 * It must be allocated outside of this function.
225 * @param num_channels
226 * The amount of channel numbers in channel_list
229 * - N the number of channels added for the VM
232 int add_channels(const char *vm_name, unsigned *channel_list,
233 unsigned num_channels);
236 * Remove a channel definition from the channel manager. This must only be
237 * called from the channel monitor thread.
240 * Pointer to a valid struct channel_info.
244 * - Negative on error.
246 int remove_channel(struct channel_info **chan_info_dptr);
249 * For all channels associated with a Virtual Machine name, update the
250 * connection status. Valid states are CHANNEL_MGR_CHANNEL_CONNECTED or
251 * CHANNEL_MGR_CHANNEL_DISABLED only.
255 * Virtual Machine name to modify all channels.
258 * The status to set each channel
260 * @param num_channels
261 * The amount of channel numbers in channel_list
264 * - N the number of channels added for the VM
267 int set_channel_status_all(const char *name, enum channel_status status);
270 * For all channels in channel_list associated with a Virtual Machine name
271 * update the connection status of each.
272 * Valid states are CHANNEL_MGR_CHANNEL_CONNECTED or
273 * CHANNEL_MGR_CHANNEL_DISABLED only.
274 * It is not thread-safe.
277 * Virtual Machine name to add channels.
279 * @param channel_list
280 * Pointer to list of unsigned integers, representing the channel numbers to
282 * It must be allocated outside of this function.
284 * @param num_channels
285 * The amount of channel numbers in channel_list
288 * - N the number of channels modified for the VM
291 int set_channel_status(const char *vm_name, unsigned *channel_list,
292 unsigned len_channel_list, enum channel_status status);
295 * Populates a pointer to struct vm_info associated with vm_name.
298 * The name of the virtual machine to lookup.
301 * Pointer to a struct vm_info, this must be allocated prior to calling this
306 * - Negative on error.
308 int get_info_vm(const char *vm_name, struct vm_info *info);
314 #endif /* CHANNEL_MANAGER_H_ */