ia64/xen-unstable

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