diff options
author | Ian Jackson <Ian.Jackson@eu.citrix.com> | 2012-03-01 16:48:36 +0000 |
---|---|---|
committer | Ian Jackson <Ian.Jackson@eu.citrix.com> | 2012-03-01 16:48:36 +0000 |
commit | ff7c56c82c6f58d201c0bfcf57f58f574de7a57e (patch) | |
tree | 7e7859a9350125b56b6058821aaf9dbc6cf9b6b4 /tools | |
parent | e44490b9a512b955fcaf4dea3c35382990549e72 (diff) | |
parent | c933085d093fe64a08a6b86829015e9788192d64 (diff) | |
download | xen-ff7c56c82c6f58d201c0bfcf57f58f574de7a57e.tar.gz xen-ff7c56c82c6f58d201c0bfcf57f58f574de7a57e.tar.bz2 xen-ff7c56c82c6f58d201c0bfcf57f58f574de7a57e.zip |
Merge
Diffstat (limited to 'tools')
-rw-r--r-- | tools/libxc/xc_cpufeature.h | 2 | ||||
-rw-r--r-- | tools/libxc/xc_cpuid_x86.c | 4 | ||||
-rw-r--r-- | tools/misc/Makefile | 8 | ||||
-rw-r--r-- | tools/misc/xen-lowmemd.c | 148 |
4 files changed, 160 insertions, 2 deletions
diff --git a/tools/libxc/xc_cpufeature.h b/tools/libxc/xc_cpufeature.h index ff7c3d0042..e1772337ad 100644 --- a/tools/libxc/xc_cpufeature.h +++ b/tools/libxc/xc_cpufeature.h @@ -129,10 +129,12 @@ /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx) */ #define X86_FEATURE_FSGSBASE 0 /* {RD,WR}{FS,GS}BASE instructions */ #define X86_FEATURE_BMI1 3 /* 1st group bit manipulation extensions */ +#define X86_FEATURE_HLE 4 /* Hardware Lock Elision */ #define X86_FEATURE_AVX2 5 /* AVX2 instructions */ #define X86_FEATURE_SMEP 7 /* Supervisor Mode Execution Protection */ #define X86_FEATURE_BMI2 8 /* 2nd group bit manipulation extensions */ #define X86_FEATURE_ERMS 9 /* Enhanced REP MOVSB/STOSB */ #define X86_FEATURE_INVPCID 10 /* Invalidate Process Context ID */ +#define X86_FEATURE_RTM 11 /* Restricted Transactional Memory */ #endif /* __LIBXC_CPUFEATURE_H */ diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index d8a910a6e4..0882ce6554 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -363,11 +363,13 @@ static void xc_cpuid_hvm_policy( case 0x00000007: /* Intel-defined CPU features */ if ( input[1] == 0 ) { regs[1] &= (bitmaskof(X86_FEATURE_BMI1) | + bitmaskof(X86_FEATURE_HLE) | bitmaskof(X86_FEATURE_AVX2) | bitmaskof(X86_FEATURE_SMEP) | bitmaskof(X86_FEATURE_BMI2) | bitmaskof(X86_FEATURE_ERMS) | bitmaskof(X86_FEATURE_INVPCID) | + bitmaskof(X86_FEATURE_RTM) | bitmaskof(X86_FEATURE_FSGSBASE)); } else regs[1] = 0; @@ -496,9 +498,11 @@ static void xc_cpuid_pv_policy( case 0x00000007: if ( input[1] == 0 ) regs[1] &= (bitmaskof(X86_FEATURE_BMI1) | + bitmaskof(X86_FEATURE_HLE) | bitmaskof(X86_FEATURE_AVX2) | bitmaskof(X86_FEATURE_BMI2) | bitmaskof(X86_FEATURE_ERMS) | + bitmaskof(X86_FEATURE_RTM) | bitmaskof(X86_FEATURE_FSGSBASE)); else regs[1] = 0; diff --git a/tools/misc/Makefile b/tools/misc/Makefile index 817398bc9b..2c691a4329 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -5,11 +5,12 @@ CFLAGS += -Werror CFLAGS += $(CFLAGS_libxenctrl) CFLAGS += $(CFLAGS_xeninclude) +CFLAGS += $(CFLAGS_libxenstore) HDRS = $(wildcard *.h) TARGETS-y := xenperf xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xenwatchdogd -TARGETS-$(CONFIG_X86) += xen-detect xen-hvmctx xen-hvmcrash +TARGETS-$(CONFIG_X86) += xen-detect xen-hvmctx xen-hvmcrash xen-lowmemd TARGETS-$(CONFIG_MIGRATE) += xen-hptool TARGETS := $(TARGETS-y) @@ -21,7 +22,7 @@ INSTALL_BIN-y := xencons INSTALL_BIN-$(CONFIG_X86) += xen-detect INSTALL_BIN := $(INSTALL_BIN-y) -INSTALL_SBIN-y := xm xen-bugtool xen-python-path xend xenperf xsview xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xenwatchdogd xen-ringwatch +INSTALL_SBIN-y := xm xen-bugtool xen-python-path xend xenperf xsview xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xenwatchdogd xen-ringwatch xen-lowmemd INSTALL_SBIN-$(CONFIG_X86) += xen-hvmctx xen-hvmcrash INSTALL_SBIN-$(CONFIG_MIGRATE) += xen-hptool INSTALL_SBIN := $(INSTALL_SBIN-y) @@ -70,6 +71,9 @@ xen-hptool: xen-hptool.o xenwatchdogd: xenwatchdogd.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) +xen-lowmemd: xen-lowmemd.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) + gtraceview: gtraceview.o $(CC) $(LDFLAGS) -o $@ $< $(CURSES_LIBS) $(APPEND_LDFLAGS) diff --git a/tools/misc/xen-lowmemd.c b/tools/misc/xen-lowmemd.c new file mode 100644 index 0000000000..42098e4d6f --- /dev/null +++ b/tools/misc/xen-lowmemd.c @@ -0,0 +1,148 @@ +/* + * xen-lowmemd: demo VIRQ_ENOMEM + * Andres Lagar-Cavilla (GridCentric Inc.) + */ + +#include <stdio.h> +#include <xenctrl.h> +#include <xs.h> +#include <stdlib.h> +#include <string.h> + +static evtchn_port_t virq_port = -1; +static xc_evtchn *xce_handle = NULL; +static xc_interface *xch = NULL; +static struct xs_handle *xs_handle = NULL; + +void cleanup(void) +{ + if (virq_port > -1) + xc_evtchn_unbind(xce_handle, virq_port); + if (xce_handle) + xc_evtchn_close(xce_handle); + if (xch) + xc_interface_close(xch); + if (xs_handle) + xs_daemon_close(xs_handle); +} + +/* Never shrink dom0 below 1 GiB */ +#define DOM0_FLOOR (1 << 30) +#define DOM0_FLOOR_PG ((DOM0_FLOOR) >> 12) + +/* Act if free memory is less than 92 MiB */ +#define THRESHOLD (92 << 20) +#define THRESHOLD_PG ((THRESHOLD) >> 12) + +#define BUFSZ 512 +void handle_low_mem(void) +{ + xc_dominfo_t dom0_info; + xc_physinfo_t info; + unsigned long long free_pages, dom0_pages, diff, dom0_target; + char data[BUFSZ], error[BUFSZ]; + + if (xc_physinfo(xch, &info) < 0) + { + perror("Getting physinfo failed"); + return; + } + + free_pages = (unsigned long long) info.free_pages; + printf("Available free pages: 0x%llx:%llux\n", + free_pages, free_pages); + + /* Don't do anything if we have more than the threshold free */ + if ( free_pages >= THRESHOLD_PG ) + return; + diff = THRESHOLD_PG - free_pages; + + if (xc_domain_getinfo(xch, 0, 1, &dom0_info) < 1) + { + perror("Failed to get dom0 info"); + return; + } + + dom0_pages = (unsigned long long) dom0_info.nr_pages; + printf("Dom0 pages: 0x%llx:%llu\n", dom0_pages, dom0_pages); + dom0_target = dom0_pages - diff; + if (dom0_target <= DOM0_FLOOR_PG) + return; + + printf("Shooting for dom0 target 0x%llx:%llu\n", + dom0_target, dom0_target); + + snprintf(data, BUFSZ, "%llu", dom0_target); + if (!xs_write(xs_handle, XBT_NULL, + "/local/domain/0/memory/target", data, strlen(data))) + { + snprintf(error, BUFSZ,"Failed to write target %s to xenstore", data); + perror(error); + } +} + +int main(int argc, char *argv[]) +{ + int rc; + + atexit(cleanup); + + xch = xc_interface_open(NULL, NULL, 0); + if (xch == NULL) + { + perror("Failed to open xc interface"); + return 1; + } + + xce_handle = xc_evtchn_open(NULL, 0); + if (xce_handle == NULL) + { + perror("Failed to open evtchn device"); + return 2; + } + + xs_handle = xs_daemon_open(); + if (xs_handle == NULL) + { + perror("Failed to open xenstore connection"); + return 3; + } + + if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_ENOMEM)) == -1) + { + perror("Failed to bind to domain exception virq port"); + return 4; + } + + virq_port = rc; + + while(1) + { + evtchn_port_t port; + + if ((port = xc_evtchn_pending(xce_handle)) == -1) + { + perror("Failed to listen for pending event channel"); + return 5; + } + + if (port != virq_port) + { + char data[BUFSZ]; + snprintf(data, BUFSZ, "Wrong port, got %d expected %d", port, virq_port); + perror(data); + return 6; + } + + if (xc_evtchn_unmask(xce_handle, port) == -1) + { + perror("Failed to unmask port"); + return 7; + } + + printf("Got a virq kick, time to get work\n"); + handle_low_mem(); + } + + return 0; +} |