ia64/xen-unstable

view tools/libxc/xc_private.h @ 14114:59b8d5168cc1

Reduce impact of saving/restoring/dumping large domains on Dom0 memory
usage by means of fadvise64() to tell the OS to discard the cache
pages used for the save/dump file.

Signed-off-by: Simon Graham <Simon.Graham@stratus.com>
author Keir Fraser <keir@xensource.com>
date Sat Feb 24 14:48:17 2007 +0000 (2007-02-24)
parents cd532c9351fc
children d66dff09338a
line source
2 #ifndef XC_PRIVATE_H
3 #define XC_PRIVATE_H
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <string.h>
10 #include <sys/mman.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <stdlib.h>
14 #include <sys/ioctl.h>
16 #include "xenctrl.h"
18 #include <xen/sys/privcmd.h>
20 /* valgrind cannot see when a hypercall has filled in some values. For this
21 reason, we must zero the privcmd_hypercall_t or domctl/sysctl instance
22 before a call, if using valgrind. */
23 #ifdef VALGRIND
24 #define DECLARE_HYPERCALL privcmd_hypercall_t hypercall = { 0 }
25 #define DECLARE_DOMCTL struct xen_domctl domctl = { 0 }
26 #define DECLARE_SYSCTL struct xen_sysctl sysctl = { 0 }
27 #else
28 #define DECLARE_HYPERCALL privcmd_hypercall_t hypercall
29 #define DECLARE_DOMCTL struct xen_domctl domctl
30 #define DECLARE_SYSCTL struct xen_sysctl sysctl
31 #endif
33 #undef PAGE_SHIFT
34 #undef PAGE_SIZE
35 #undef PAGE_MASK
36 #define PAGE_SHIFT XC_PAGE_SHIFT
37 #define PAGE_SIZE (1UL << PAGE_SHIFT)
38 #define PAGE_MASK (~(PAGE_SIZE-1))
40 #define DEBUG 1
41 #define INFO 1
42 #define PROGRESS 0
44 /*
45 ** Define max dirty page cache to permit during save/restore -- need to balance
46 ** keeping cache usage down with CPU impact of invalidating too often.
47 ** (Currently 16MB)
48 */
49 #define MAX_PAGECACHE_USAGE (4*1024)
51 #if INFO
52 #define IPRINTF(_f, _a...) printf(_f , ## _a)
53 #else
54 #define IPRINTF(_f, _a...) ((void)0)
55 #endif
57 #if DEBUG
58 #define DPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
59 #else
60 #define DPRINTF(_f, _a...) ((void)0)
61 #endif
63 #if PROGRESS
64 #define PPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
65 #else
66 #define PPRINTF(_f, _a...)
67 #endif
69 char *safe_strerror(int errcode);
70 void xc_set_error(int code, const char *fmt, ...);
72 #define ERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m , ## _a )
73 #define PERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m " (%d = %s)", \
74 ## _a , errno, safe_strerror(errno))
76 int lock_pages(void *addr, size_t len);
77 void unlock_pages(void *addr, size_t len);
79 static inline void safe_munlock(const void *addr, size_t len)
80 {
81 int saved_errno = errno;
82 (void)munlock(addr, len);
83 errno = saved_errno;
84 }
86 int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall);
88 static inline int do_xen_version(int xc_handle, int cmd, void *dest)
89 {
90 DECLARE_HYPERCALL;
92 hypercall.op = __HYPERVISOR_xen_version;
93 hypercall.arg[0] = (unsigned long) cmd;
94 hypercall.arg[1] = (unsigned long) dest;
96 return do_xen_hypercall(xc_handle, &hypercall);
97 }
99 static inline int do_domctl(int xc_handle, struct xen_domctl *domctl)
100 {
101 int ret = -1;
102 DECLARE_HYPERCALL;
104 domctl->interface_version = XEN_DOMCTL_INTERFACE_VERSION;
106 hypercall.op = __HYPERVISOR_domctl;
107 hypercall.arg[0] = (unsigned long)domctl;
109 if ( lock_pages(domctl, sizeof(*domctl)) != 0 )
110 {
111 PERROR("Could not lock memory for Xen hypercall");
112 goto out1;
113 }
115 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
116 {
117 if ( errno == EACCES )
118 DPRINTF("domctl operation failed -- need to"
119 " rebuild the user-space tool set?\n");
120 }
122 unlock_pages(domctl, sizeof(*domctl));
124 out1:
125 return ret;
126 }
128 static inline int do_sysctl(int xc_handle, struct xen_sysctl *sysctl)
129 {
130 int ret = -1;
131 DECLARE_HYPERCALL;
133 sysctl->interface_version = XEN_SYSCTL_INTERFACE_VERSION;
135 hypercall.op = __HYPERVISOR_sysctl;
136 hypercall.arg[0] = (unsigned long)sysctl;
138 if ( lock_pages(sysctl, sizeof(*sysctl)) != 0 )
139 {
140 PERROR("Could not lock memory for Xen hypercall");
141 goto out1;
142 }
144 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
145 {
146 if ( errno == EACCES )
147 DPRINTF("sysctl operation failed -- need to"
148 " rebuild the user-space tool set?\n");
149 }
151 unlock_pages(sysctl, sizeof(*sysctl));
153 out1:
154 return ret;
155 }
157 int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
158 privcmd_mmap_entry_t *entries, int nr);
160 void *map_domain_va_core(unsigned long domfd, int cpu, void *guest_va,
161 vcpu_guest_context_t *ctxt);
162 int xc_waitdomain_core(int xc_handle, int domain, int *status,
163 int options, vcpu_guest_context_t *ctxt);
165 void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits);
166 void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);
168 /* Optionally flush file to disk and discard page cache */
169 int discard_file_cache(int fd, int flush);
171 #endif /* __XC_PRIVATE_H__ */