Introduction
Libxc is the name in/xen/tools/. In many addresses, libxenctrl is actually a meaning, but it is different from libxen.. Libxc is a C language library that provides some easy-to-use APIs, allowing your programs to easily communicate with hypervisor.
Its working principle is very simple. It mainly encapsulates/proc/xen/privcmd,/dev/xen/evtchn in dom0 and IOCTL interfaces provided by/dev/xen/gntdev. That is to say, we can directly use these kernel-level device drivers for relevant operation control, but with libxc, we only need to call the corresponding interface functions, it is responsible for parsing/encapsulating the data structure and then communicating with the underlying hypervisor. This is why xend is reached after XM sends the command, and xend needs to call libxc for further processing before communicating with the underlying hypervisor: libxc is an interface library.
Libxenctrl is a C library that provides some easy-to-use APIs, allowing your programs to easily communicate with hypervisor.
Its working principle is very simple. It encapsulates/proc/xen/privcmd,/dev/xen/evtchn in dom0 and IOCTL interfaces provided by/dev/xen/gntdev.
Ø programming steps:
2/proc/xen/privcmd
1.
Xc_interface_open ()
Open/proc/xen/privcmd to obtain the file descriptor.
2.
Xc_sysctl ()
Fill in the xen_sysctl struct and send the ioctl request.
3.
Xc_interface_close ()
Disable the file descriptor opened in 1.
2/dev/xen/evtchn
1.
Xc_evtchn_open
2.
Xc_evtchn_policy and other functions
The evtchn operation is relatively simple. You do not need to fill in the struct. Generally, you can specify the remote Dom ID and port.
3.
Xc_evtchn_close
2/dev/xen/gntdev
1.
Xc_gnttab_open
2.
Xc_gnttab_map_grant_ref
3.
Xc_gnttab_close
Ø programming example
Take the interface provided by/proc/xen/privcmd as an example, excerpted from tools/xenmon/setmask. c
Int main (INT argc, char * argv [])
{
Struct xen_sysctl sysctl;
Int ret;
Int xc_handle = xc_interface_open ();
Sysctl. cmd = xen_sysctl_tbuf_op; // the Union in sysctl (structxen_sysctl) is determined by CMD.
Sysctl. interface_version = xen_sysctl_interface_version;
Sysctl. U. tbuf_op.cmd = xen_sysctl_tbufop_get_info;
Ret = xc_sysctl (xc_handle, & sysctl );
If (Ret! = 0)
{
Perror ("failure to get event mask from xen ");
Exit (1 );
}
Else
{
Printf ("current event mask: 0x %. 8x \ n", sysctl. U. tbuf_op.evt_mask );
}
... Snip...
Xc_interface_close (xc_handle );
Return 0;
}
2. xen_sysctl command (the main IOCTL command isIoctl_private_hypercall)
No. |
Command |
Comment |
Struct |
1 |
Xen_sysctl_readconsole |
Read console content from xen buffer ring. |
Xen_sysctl_readconsole |
2 |
Xen_sysctl_tbuf_op |
Get trace buffers machine base address |
Xen_sysctl_tbuf_op |
3 |
Xen_sysctl_physinfo |
Get physical information about the host machine |
Xen_sysctl_physinfo |
4 |
Xen_sysctl_sched_id |
Get the ID of the current scheduler. |
Xen_sysctl_sched_id |
5 |
Xen_sysctl_perfc_op |
Interface for controlling xen software performance counters. |
Xen_sysctl_perfc_op |
6 |
Xen_sysctl_getdomaininfolist |
- |
Xen_sysctl_getdomaininfolist |
7 |
Xen_sysctl_debug_keys |
Inject debug keys into xen. |
Xen_sysctl_debug_keys |
8 |
Xen_sysctl_getcpuinfo |
Get Physical CPU information. |
Xen_sysctl_getcpuinfo |
9 |
Xen_sysctl_availheap |
- |
Xen_sysctl_availheap |
10 |
Xen_sysctl_get_pmstat |
- |
Xen_sysctl_get_pmstat |
11 |
Xen_sysctl_cpu_hotplug |
- |
Xen_sysctl_cpu_hotplug |
12 |
Xen_sysctl_pm_op |
GET/set xen power management, include cpufreq governors and Related Parameters |
Xen_sysctl_page_offline_op |
13 |
- |
- |
- |
14 |
Xen_sysctl_page_offline_op |
- |
Xen_sysctl_page_offline_op |
15 |
Xen_sysctl_lockprof_op |
- |
Xen_sysctl_lockprof_op |
Struct xen_sysctl {
Uint32_t cmd;
Uint32_t interface_version;/* xen_sysctl_interface_version */
Union {
Struct xen_sysctl_readconsole readconsole;
Struct xen_sysctl_tbuf_op tbuf_op;
Struct xen_sysctl_physinfo physinfo;
Struct xen_sysctl_sched_id sched_id;
Struct xen_sysctl_perfc_op perfc_op;
Struct xen_sysctl_getdomaininfolist getdomaininfolist;
Struct xen_sysctl_debug_keys debug_keys;
Struct xen_sysctl_getcpuinfo getcpuinfo;
Struct xen_sysctl_availheap availheap;
Struct xen_sysctl_get_pmstat get_pmstat;
Struct xen_sysctl_cpu_hotplug cpu_hotplug;
Struct xen_sysctl_pm_op pm_op;
Struct xen_sysctl_page_offline_op page_offline;
Struct xen_sysctl_lockprof_op lockprof_op;
Uint8_t pad [128];
} U;
};
Typedef struct xen_sysctl xen_sysctl_t;