[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] Merged.
# HG changeset patch # User emellor@xxxxxxxxxxxxxxxxxxxxxx # Node ID bb0e5f7f94fd186868b68379aeb81938a1967d25 # Parent 60bf9aa39043681828eda93cf769d2c5208d6922 # Parent 4bdcb7f8c3d76dcdb7c67e996292fb3b2c8c483f Merged. diff -r 60bf9aa39043 -r bb0e5f7f94fd .hgignore --- a/.hgignore Tue Nov 15 14:56:47 2005 +++ b/.hgignore Tue Nov 15 15:24:31 2005 @@ -148,6 +148,8 @@ ^tools/vtpm_manager/manager/vtpm_managerd$ ^tools/xcutils/xc_restore$ ^tools/xcutils/xc_save$ +^tools/xenmon/setmask$ +^tools/xenmon/xenbaked$ ^tools/xenstat/xentop/xentop$ ^tools/xenstore/testsuite/tmp/.*$ ^tools/xenstore/xen$ diff -r 60bf9aa39043 -r bb0e5f7f94fd docs/man/xm.pod.1 --- a/docs/man/xm.pod.1 Tue Nov 15 14:56:47 2005 +++ b/docs/man/xm.pod.1 Tue Nov 15 15:24:31 2005 @@ -15,9 +15,9 @@ The basic structure of every xm command is almost always: - xm <SubCommand> <DomId> [OPTIONS] - -Where I<SubCommand> is one of the sub commands listed below, I<DomId> + xm <subcommand> <domain-id> [OPTIONS] + +Where I<subcommand> is one of the sub commands listed below, I<domain-id> is the numeric domain id, or the domain name (which will be internally translated to domain id), and I<OPTIONS> are sub command specific options. There are a few exceptions to this rule in the cases where @@ -46,13 +46,13 @@ =head1 DOMAIN SUBCOMMANDS The following sub commands manipulate domains directly, as stated -previously most commands take DomId as the first parameter. - -=over 4 - -=item I<console> <DomId> - -Attach to domain DomId's console. If you've set up your Domains to +previously most commands take domain-id as the first parameter. + +=over 4 + +=item B<console> I<domain-id> + +Attach to domain domain-id's console. If you've set up your Domains to have a traditional log in console this will look much like a normal text log in screen. @@ -63,15 +63,15 @@ so running curses based interfaces over the console B<is not advised>. Vi tends to get very odd when using it over this interface. -=item I<create> [-c] <ConfigFile> [Name=Value].. - -The create sub command requires a ConfigFile and can optional take a +=item B<create> I<[-c]> I<configfile> I<[name=value]>.. + +The create sub command requires a configfile and can optional take a series of name value pairs that add to or override variables defined in the config file. See L<xmdomain.cfg> for full details of that file -format, and possible options used in either the ConfigFile or +format, and possible options used in either the configfile or Name=Value combinations. -ConfigFile can either be an absolute path to a file, or a relative +Configfile can either be an absolute path to a file, or a relative path to a file located in /etc/xen. Create will return B<as soon> as the domain is started. This B<does @@ -82,7 +82,7 @@ =over 4 -=item I<-c> +=item B<-c> Attache console to the domain as soon as it has started. This is useful for determining issues with crashing domains. @@ -114,42 +114,42 @@ =back -=item I<destroy> <DomId> - -Immediately terminate the domain DomId. This doesn't give the domain +=item B<destroy> I<domain-id> + +Immediately terminate the domain domain-id. This doesn't give the domain OS any chance to react, and it the equivalent of ripping the power cord out on a physical machine. In most cases you will want to use the B<shutdown> command instead. -=item I<domid> <DomName> +=item B<domid> I<domain-name> Converts a domain name to a domain id using xend's internal mapping. -=item I<domname> <DomId> +=item B<domname> I<domain-id> Converts a domain id to a domain name using xend's internal mapping. -=item I<help> [--long] +=item B<help> I<[--long]> Displays the short help message (i.e. common commands). The I<--long> option prints out the complete set of B<xm> subcommands, grouped by function. -=item I<list> [--long] [DomId, ...] +=item B<list> I<[--long]> I<[domain-id, ...]> Prints information about one or more domains. If no domains are specified it prints out information about all domains. An example format for the list is as follows: - Name ID Mem(MiB) VCPUs State Time(s) - Domain-0 0 98 1 r----- 5068.6 - Fedora3 164 128 1 r----- 7.6 - Fedora4 165 128 1 ------ 0.6 - Mandrake2006 166 128 1 -b---- 3.6 - Mandrake10.2 167 128 1 ------ 2.5 - Suse9.2 168 100 1 ------ 1.8 + Name ID Mem(MiB) VCPUs State Time(s) + Domain-0 0 98 1 r----- 5068.6 + Fedora3 164 128 1 r----- 7.6 + Fedora4 165 128 1 ------ 0.6 + Mandrake2006 166 128 1 -b---- 3.6 + Mandrake10.2 167 128 1 ------ 2.5 + Suse9.2 168 100 1 ------ 1.8 Name is the name of the domain. ID the domain numeric id. Mem is the size of the memory allocated to the domain. VCPUS is the number of @@ -163,34 +163,34 @@ The State field lists 6 states for a Xen Domain, and which ones the current Domain is in. -=item I<r - running> +=item B<r - running> The domain is currently running on a CPU -=item I<b - blocked> +=item B<b - blocked> The domain is blocked, and not running or runable. This can be caused because the domain is waiting on IO (a traditional wait state) or has gone to sleep because there was nothing else for it to do. -=item I<p - paused> +=item B<p - paused> The domain has been paused, usually occurring through the administrator running B<xm pause>. When in a paused state the domain will still consume allocated resources like memory, but will not be eligible for scheduling by the Xen hypervisor. -=item I<s - shutdown> +=item B<s - shutdown> FIXME: Why would you ever see this state? -=item I<c - crashed> +=item B<c - crashed> The domain has crashed, which is always a violent ending. Usually this state can only occur if the domain has been configured not to restart on crash. See L<xmdomain.cfg> for more info. -=item I<d - dying> +=item B<d - dying> The domain is in process of dying, but hasn't completely shutdown or crashed. @@ -226,7 +226,7 @@ =back -=item I<mem-max> <DomId> <Mem> +=item B<mem-max> I<domain-id> I<mem> Specify the maximum amount of memory the Domain is able to use. Mem is specified in megabytes. @@ -234,7 +234,7 @@ The mem-max value may not correspond to the actual memory used in the Domain, as it may balloon down it's memory to give more back to the OS. -=item I<mem-set> <DomId> <Mem> +=item B<mem-set> I<domain-id> I<mem> Set the domain's used memory using the balloon driver. Because this operation requires cooperation from the domain operating system, there @@ -244,7 +244,7 @@ mem-set will make a domain unstable and cause it to crash. Be very careful when using this command on running domains. -=item I<migrate> <DomId> <Host> [Options] +=item B<migrate> I<domain-id> I<host> I<[options]> Migrate a domain to another Host machine. B<Xend> must be running on other host machine, it must be running the same version of xen, it @@ -261,13 +261,13 @@ =over 4 -=item I<-l, --live> +=item B<-l, --live> Use live migration. This will migrate the domain between hosts without shutting down the domain. See the Xen Users Guide for more information. -=item I<-r, --resource> Mbs +=item B<-r, --resource> I<Mbs> Set maximum Mbs allowed for migrating the domain. This ensures that the network link is not saturated with migration traffic while @@ -275,13 +275,13 @@ =back -=item I<pause> <DomId> +=item B<pause> I<domain-id> Pause a domain. When in a paused state the domain will still consume -allocated resources like memory, but will not be eligible for +allocated resources such as memory, but will not be eligible for scheduling by the Xen hypervisor. -=item I<reboot> [Options] <DomId> +=item B<reboot> I<[options]> I<domain-id> Reboot a domain. This acts just as if the domain had the B<reboot> command run from the console. The command returns as soon as it has @@ -289,66 +289,104 @@ domain actually reboots. The behavior of what happens to a domain when it reboots is set by the -B<on_reboot> parameter of the xmdomain.cfg file when the domain was +I<on_reboot> parameter of the xmdomain.cfg file when the domain was created. B<OPTIONS> =over 4 -=item I<-a, --all> +=item B<-a, --all> Reboot all domains -=item I<-w, --wait> +=item B<-w, --wait> Wait for reboot to complete before returning. This may take a while, as all services in the domain will have to be shut down cleanly. =back -=item I<restore> <File> - -Create a domain from saved state File. - -=item I<save> <DomId> <File> - -Save domain state to File. Saves domain configuration to File as well. - -=item I<shutdown> [Options] <DomId> - -Shutdown a domain. - -=over 4 - -Additional Options: - - -a, --all Shutdown all domains. - -H, --halt Shutdown domain without reboot. - -R, --reboot Shutdown and reboot domain. - -w, --wait Wait for shutdown to complete. - -=back - -=item I<sysrq> <DomId> <letter> - -Send a sysrq to a domain. - -=item I<unpause> <DomId> - -Unpause a paused domain. - -=item I<set-vcpus> <DomId> <VCPUs> - -Enable a specific number of VCPUs for a domain. Subcommand only enables or disables already configured VCPUs for domain. - -=item I<vpcu-list> [DomID] - -Lists VCPU information for a specific domain or all domains if DomID not given. - -=item I<vcpu-pin> <DomId> <VCPU> <CPUs> - -Sets VCPU to only run on specific CPUs. +=item B<restore> I<state-file> + +Build a domain from an B<xm save> state file. See I<save> for more info. + +=item B<save> I<domain-id> I<state-file> + +Saves a running domain to a state file so that it can be restored +later. Once saved, the domain will no longer be running on the +system, thus the memory allocated for the domain will be free for +other domains to use. B<xm restore> restores from this state file. + +This is roughly equivalent to doing a hibernate on a running computer, +with all the same limitations. Open network connections may be +severed upon restore, as TCP timeouts may have expired. + +=item B<shutdown> I<[options]> I<domain-id> + +Gracefully shuts down a domain. This coordinates with the domain OS +to perform graceful shutdown, so there is no guaruntee that it will +succeed, and may take a variable length of time depending on what +services must be shutdown in the domain. The command returns +immediately after signally the domain unless that I<-w> flag is used. + +The behavior of what happens to a domain when it reboots is set by the +I<on_shutdown> parameter of the xmdomain.cfg file when the domain was +created. + +B<OPTIONS> + +=over 4 + +=item B<-a> + +Shutdown B<all> domains. Often used when doing a complete shutdown of +a Xen system. + +=item B<-w> + +Wait for the domain to complete shutdown before returning. + +=back + +=item B<sysrq> I<domain-id> I<letter> + +Send a I<Magic System Request> signal to the domain. For more +information on available magic sys req operations, see sysrq.txt in +your Linux Kernel sources. + +=item B<unpause> I<domain-id> + +Moves a domain out of the paused state. This will allow a previously +paused domain to now be eligible for scheduling by the Xen hypervisor. + +=item B<set-vcpus> I<domain-id> I<vcpu-count> + +Enables the I<vcpu-count> virtual CPUs for the domain in question. +Like mem-set, this command can only allocate up to the maximum virtual +CPU count configured at boot for the domain. + +If the I<vcpu-count> is smaller than the current number of active +VCPUs, the highest number VCPUs will be hotplug removed. This may be +important for pinning purposes. + +Attempting to set-vcpus to a number larger than the initially +configured VCPU count is an error. Trying to set-vcpus to < 1 will be +quietly ignored. + +=item B<vpcu-list> I<[domain-id]> + +Lists VCPU information for a specific domain. If no domain is +specified, VCPU information for all domains will be provided. + +=item B<vcpu-pin> I<domain-id> I<vcpu> I<cpus> + +Pins the the VCPU to only run on the specific CPUs. + +Normally VCPUs can float between available CPUs whenever Xen deems a +different run state is appropriate. Pinning can be used to restrict +this, by ensuring certain VCPUs can only run on certain physical +CPUs. =back @@ -356,115 +394,286 @@ =over 4 -=item I<dmesg> [OPTION] - -Read or clear Xen's message buffer. The buffer contains Xen boot, warning, and error messages. - -=over 4 - -Additional Option: - - -c, --clear Clears Xen's message buffer. - -=back - -=item I<info> - -Get information about Xen host. - -=item I<log> - -Print B<xend> log. - -=item I<top> - -Monitor system and domains in real-time. +=item B<dmesg> I<[-c]> + +Reads the Xen message buffer, similar to dmesg on a Linux system. The +buffer contains informational, warning, and error messages created +during Xen's boot process. If you are having problems with Xen, this +is one of the first places to look as part of problem determination. + +B<OPTIONS> + +=over 4 + +=item B<-c, --clear> + +Clears Xen's message buffer. + +=back + +=item B<info> + +Print information about the Xen host in I<name : value> format. When +reporting a Xen bug, please provide this information as part of the +bug report. + +Sample xen domain info looks as follows (lines wrapped manually to +make the man page more readable): + + system : Linux + host : talon + release : 2.6.12.6-xen0 + version : #1 Mon Nov 14 14:26:26 EST 2005 + machine : i686 + nr_cpus : 2 + nr_nodes : 1 + sockets_per_node : 2 + cores_per_socket : 1 + threads_per_core : 1 + cpu_mhz : 696 + hw_caps : 0383fbff:00000000:00000000:00000040 + memory : 767 + free_memory : 37 + xen_major : 3 + xen_minor : 0 + xen_extra : -devel + xen_caps : xen-3.0-x86_32 + xen_params : virt_start=0xfc000000 + xen_changeset : Mon Nov 14 18:13:38 2005 +0100 + 7793:090e44133d40 + cc_compiler : gcc version 3.4.3 (Mandrakelinux + 10.2 3.4.3-7mdk) + cc_compile_by : sdague + cc_compile_domain : (none) + cc_compile_date : Mon Nov 14 14:16:48 EST 2005 + +B<FIELDS> + +=over 4 + +Not all fields will be explained here, but some of the less obvious +ones deserve explanation: + +=item I<hw_caps> + +A vector showing what hardware capabilities are supported by your +processor. This is equivalent to, though more cryptic, the flags +field in /proc/cpuinfo on a normal Linux machine. + +=item I<free_memory> + +Available memory (in MB) not allocated to Xen, or any other Domains. + +=item I<xen_caps> + +The xen version, architecture. Architecture values can be one of: +x86_32, x86_32p (i.e. PAE enabled), x86_64, ia64. + +=item I<xen_changeset> + +The xen mercurial changeset id. Very useful for determining exactly +what version of code your Xen system was built from. + +=back + +=item B<log> + +Print out the B<xend> log. This log file can be found in +/var/log/xend.log. + +=item B<top> + +Executes the xentop command, which provides real time monitoring of +domains. Xentop is a curses interface, and reasonably self +explanatory. =back =head1 SCHEDULER SUBCOMMANDS -=over 4 - -=item I<sched-bvt> <Parameters> - -Set Borrowed Virtual Time (BVT) scheduler parameters. There are five parameters, which are given in order below. - -=over 4 - -Parameters: - - mcuadv - Minimum Charging Unit (MCU) advance. - warpback - Warp back time allowed. - warpvalue - Warp value. - warpl - Warp maximum limit. - warpu - Unwarped minimum limit. +Xen ships with a number of domain schedulers, which can be set at boot +time with the I<sched=> parameter on the Xen command line. By +default I<sedf> is used for scheduling. + +FIXME: we really need a scheduler expert to write up this section. + +=over 4 + +=item B<sched-bvt> I<mcuadv> I<warpback> I<warpvalue> I<warpl> I<warpu> + +Performs runtime adjustments to the default parameters for the +Borrowed Virtual Time (BVT) scheduler. For full information on the +BVT concept, please consult the base paper listed in the B<SEE ALSO> +section. + +Set Borrowed Virtual Time (BVT) scheduler parameters. There are five +required parameters, which are given in order below. + +FIXME: what units are all the BVT params in? + +B<PARAMETERS> + +=over 4 + +=item I<mcuadv> + +The MCU (Minimum Charging Unit) advance determines the proportional +share of the CPU that a domain receives. It is set inversely +proportionally to a domain's sharing weight. + +=item I<warpback> + +The amount of `virtual time' the domain is allowed to warp backwards. + +=item I<warpvalue> + +Warp value (FIXME: what does this really mean?) + +=item I<warpl> + +The warp limit is the maximum time a domain can run warped for. + +=item I<warpu> + +The unwarp requirement is the minimum time a domain must run unwarped +for before it can warp again. =back -=item I<sched-bvt-ctxallow> <Allow> - -Sets the BVT scheduler's context switch allowance. Allow is the minimum time slice allowed to run before being pre-empted. - -=item I<sched-sedf> <Parameters> - -Set simple sEDF scheduler parameters. Use the following parametersin order. - -=over 4 - -Parameters: - - period - in nanoseconds - slice - in nanoseconds - latency-hint - scaled period if domain is doing heavy I/O - extratime - flag for allowing domain to run in extra time. - weight - another way of setting cpu slice. - -=back +=item B<sched-bvt-ctxallow> I<allow> + +Sets the BVT scheduler's context switch allowance. + +The context switch allowance is similar to the ``quantum'' in +traditional schedulers. It is the minimum time that a scheduled domain +will be allowed to run before being preempted. + +=item B<sched-sedf> I<period> I<slice> I<latency-hint> I<extratime> I<weight> + +Set Simple EDF scheduler parameters. This scheduler provides weighted +CPU sharing in an intuitive way and uses realtime-algorithms to ensure +time guarantees. For more information see +docs/misc/sedf_scheduler_mini-HOWTO.txt in the Xen distribution. + +B<PARAMETERS> + +=over 4 + +=item I<period> + +The normal EDF scheduling usage in nanosecs + +=item I<slice> + +The normal EDF scheduling usage in nanosecs + +FIXME: these are lame, should explain more. + +=item I<latency-hint> + +Scaled period if domain is doing heavy I/O. + +=item I<extratime> + +Flag for allowing domain to run in extra time. + +=item I<weight> + +Another way of setting cpu slice. + +=back + +B<EXAMPLES> + +I<normal EDF (20ms/5ms):> + + xm sched-sedf <dom-id> 20000000 5000000 0 0 0 + +I<best-effort domains (i.e. non-realtime):> + + xm sched-sedf <dom-id> 20000000 0 0 1 0 + +I<normal EDF (20ms/5ms) + share of extra-time:> + + xm sched-sedf <dom-id> 20000000 5000000 0 1 0 + +I<4 domains with weights 2:3:4:2> + + xm sched-sedf <d1> 0 0 0 0 2 + xm sched-sedf <d2> 0 0 0 0 3 + xm sched-sedf <d3> 0 0 0 0 4 + xm sched-sedf <d4> 0 0 0 0 2 + +I<1 fully-specified (10ms/3ms) domain, 3 other domains share available +rest in 2:7:3 ratio:> + + xm sched-sedf <d1> 10000000 3000000 0 0 0 + xm sched-sedf <d2> 0 0 0 0 2 + xm sched-sedf <d3> 0 0 0 0 7 + xm sched-sedf <d4> 0 0 0 0 3 =back =head1 VIRTUAL DEVICE COMMANDS -=over 4 - -=item I<block-attach <DomId> <BackDev> <FrontDev> <Mode> [BackDomId] - -Create a new virtual block device. - -=item I<block-detach> <DomId> <DevId> - -Destroy a domain's virtual block device. DevId may either be a device ID or the device name as mounted in the guest. - -=item I<block-list> <DomId> - -List virtual block devices for a domain. - -=item I<network-limit> <DomId> <Vif> <Credit> <Period> +Most virtual devices can be added and removed while guests are +running. The effect to the guest OS is much the same as any hotplug +event. + +=head2 BLOCK DEVICES + +=over 4 + +=item B<block-attach> I<domain-id> I<be-dev> I<fe-dev> I<mode> I<[bedomain-id]> + +Create a new virtual block device + +=item B<block-detach> I<domain-id> I<devid> + +Destroy a domain's virtual block device. DevId may either be a device +ID or the device name as mounted in the guest. + +=item B<block-list> I<domain-id> + +List virtual block devices for a domain. The returned output is +sexpression formatted. + +=head2 NETWORK DEVICES + +=item B<network-attach> I<domain-id> I<[script=script]> I<[ip=ipaddr]> +I<[mac=macaddr]> I<[bridge=bridge-name]> I<[backend=bedomain-id]> + +=item B<network-detach> I<domain-id> I<devid> + +=item B<network-limit> I<domain-id> I<vif> I<credit> I<period> Limit the transmission rate of a virtual network interface. -=item I<network-list> <DomId> - -List virtual network interfaces for a domain. +=item B<network-list> I<domain-id> + +List virtual network interfaces for a domain. The returned output is +sexpression formatted. =back =head1 VNET COMMANDS -The Virtual Network interfaces for Xen - -=over 4 - -=item I<vnet-list> [-l|--long] +The Virtual Network interfaces for Xen. + +FIXME: This needs a lot more explaination, or it needs to be ripped +out entirely. + +=over 4 + +=item B<vnet-list> I<[-l|--long]> List vnets. -=item I<vnet-create> <config> +=item B<vnet-create> I<config> Create a vnet from a config file. -=item I<vnet-delete> <vnetid> +=item B<vnet-delete> I<vnetid> Delete a vnet. @@ -475,6 +684,12 @@ =head1 SEE ALSO B<xmdomain.cfg>(5) + +BVT scheduling paper: K.J. Duda and D.R. Cheriton. Borrowed Virtual +Time (BVT) scheduling: supporting latency-sensitive threads in a +general purpose scheduler. In proceedings of the 17th ACM SIGOPS +Symposium on Operating Systems principles, volume 33(5) of ACM +Operating Systems Review, pages 261-267 =head1 AUTHOR diff -r 60bf9aa39043 -r bb0e5f7f94fd linux-2.6-xen-sparse/arch/xen/i386/kernel/cpu/common.c --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/cpu/common.c Tue Nov 15 14:56:47 2005 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/cpu/common.c Tue Nov 15 15:24:31 2005 @@ -572,7 +572,7 @@ va < gdt_descr->address + gdt_descr->size; va += PAGE_SIZE, f++) { frames[f] = virt_to_mfn(va); - make_page_readonly((void *)va); + make_lowmem_page_readonly((void *)va); } if (HYPERVISOR_set_gdt(frames, gdt_descr->size / 8)) BUG(); diff -r 60bf9aa39043 -r bb0e5f7f94fd linux-2.6-xen-sparse/arch/xen/i386/mm/init.c --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/init.c Tue Nov 15 14:56:47 2005 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/init.c Tue Nov 15 15:24:31 2005 @@ -68,7 +68,7 @@ #ifdef CONFIG_X86_PAE pmd_table = (pmd_t *) alloc_bootmem_low_pages(PAGE_SIZE); - make_page_readonly(pmd_table); + make_lowmem_page_readonly(pmd_table); set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT)); pud = pud_offset(pgd, 0); if (pmd_table != pmd_offset(pud, 0)) @@ -89,7 +89,7 @@ { if (pmd_none(*pmd)) { pte_t *page_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE); - make_page_readonly(page_table); + make_lowmem_page_readonly(page_table); set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE)); if (page_table != pte_offset_kernel(pmd, 0)) BUG(); diff -r 60bf9aa39043 -r bb0e5f7f94fd linux-2.6-xen-sparse/arch/xen/i386/mm/pgtable.c --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/pgtable.c Tue Nov 15 14:56:47 2005 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/pgtable.c Tue Nov 15 15:24:31 2005 @@ -199,7 +199,7 @@ { pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO); if (pte) - make_page_readonly(pte); + make_lowmem_page_readonly(pte); return pte; } @@ -336,7 +336,7 @@ spin_lock_irqsave(&pgd_lock, flags); memcpy(pmd, copy_pmd, PAGE_SIZE); spin_unlock_irqrestore(&pgd_lock, flags); - make_page_readonly(pmd); + make_lowmem_page_readonly(pmd); set_pgd(&pgd[USER_PTRS_PER_PGD], __pgd(1 + __pa(pmd))); } @@ -367,12 +367,12 @@ if (PTRS_PER_PMD > 1) { for (i = 0; i < USER_PTRS_PER_PGD; ++i) { pmd_t *pmd = (void *)__va(pgd_val(pgd[i])-1); - make_page_writable(pmd); + make_lowmem_page_writable(pmd); kmem_cache_free(pmd_cache, pmd); } if (!HAVE_SHARED_KERNEL_PMD) { pmd_t *pmd = (void *)__va(pgd_val(pgd[USER_PTRS_PER_PGD])-1); - make_page_writable(pmd); + make_lowmem_page_writable(pmd); memset(pmd, 0, PTRS_PER_PMD*sizeof(pmd_t)); kmem_cache_free(pmd_cache, pmd); } @@ -382,6 +382,7 @@ } #ifndef CONFIG_XEN_SHADOW_MODE +asmlinkage int xprintk(const char *fmt, ...); void make_lowmem_page_readonly(void *va) { pte_t *pte = virt_to_ptep(va); @@ -399,8 +400,7 @@ pte_t *pte = virt_to_ptep(va); set_pte(pte, pte_wrprotect(*pte)); if ((unsigned long)va >= (unsigned long)high_memory) { - unsigned long pfn; - pfn = pte_pfn(*pte); + unsigned long pfn = pte_pfn(*pte); #ifdef CONFIG_HIGHMEM if (pfn < highstart_pfn) #endif @@ -414,8 +414,7 @@ pte_t *pte = virt_to_ptep(va); set_pte(pte, pte_mkwrite(*pte)); if ((unsigned long)va >= (unsigned long)high_memory) { - unsigned long pfn; - pfn = pte_pfn(*pte); + unsigned long pfn = pte_pfn(*pte); #ifdef CONFIG_HIGHMEM if (pfn < highstart_pfn) #endif diff -r 60bf9aa39043 -r bb0e5f7f94fd linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c --- a/linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c Tue Nov 15 14:56:47 2005 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/smpboot.c Tue Nov 15 15:24:31 2005 @@ -344,7 +344,7 @@ return 0; } -subsys_initcall(setup_vcpu_hotplug_event); +arch_initcall(setup_vcpu_hotplug_event); int __cpu_disable(void) { diff -r 60bf9aa39043 -r bb0e5f7f94fd tools/Makefile --- a/tools/Makefile Tue Nov 15 14:56:47 2005 +++ b/tools/Makefile Tue Nov 15 15:24:31 2005 @@ -11,6 +11,7 @@ SUBDIRS += firmware SUBDIRS += security SUBDIRS += console +SUBDIRS += xenmon ifeq ($(VTPM_TOOLS),y) SUBDIRS += vtpm_manager SUBDIRS += vtpm diff -r 60bf9aa39043 -r bb0e5f7f94fd tools/ioemu/target-i386-dm/helper2.c --- a/tools/ioemu/target-i386-dm/helper2.c Tue Nov 15 14:56:47 2005 +++ b/tools/ioemu/target-i386-dm/helper2.c Tue Nov 15 15:24:31 2005 @@ -416,6 +416,7 @@ FD_ZERO(&wakeup_rfds); FD_SET(evtchn_fd, &wakeup_rfds); highest_fds = evtchn_fd; + env->send_event = 0; while (1) { if (vm_running) { if (shutdown_requested) { @@ -431,7 +432,6 @@ tv.tv_sec = 0; tv.tv_usec = 100000; - env->send_event = 0; retval = select(highest_fds+1, &wakeup_rfds, NULL, NULL, &tv); if (retval == -1) { perror("select"); @@ -447,12 +447,13 @@ #define ULONGLONG_MAX ULONG_MAX #endif - main_loop_wait(0); tun_receive_handler(&rfds); if ( FD_ISSET(evtchn_fd, &rfds) ) { cpu_handle_ioreq(env); } + main_loop_wait(0); if (env->send_event) { + env->send_event = 0; struct ioctl_evtchn_notify notify; notify.port = ioreq_local_port; (void)ioctl(evtchn_fd, IOCTL_EVTCHN_NOTIFY, ¬ify); diff -r 60bf9aa39043 -r bb0e5f7f94fd tools/xentrace/setsize.c --- a/tools/xentrace/setsize.c Tue Nov 15 14:56:47 2005 +++ b/tools/xentrace/setsize.c Tue Nov 15 15:24:31 2005 @@ -9,9 +9,9 @@ int xc_handle = xc_interface_open(); if (xc_tbuf_get_size(xc_handle, &size) != 0) { - perror("Failure to get tbuf info from Xen. Guess size is 0."); - printf("This may mean that tracing is not compiled into xen.\n"); - exit(1); + perror("Failure to get tbuf info from Xen. Guess size is 0"); + printf("This may mean that tracing is not enabled in xen.\n"); + // exit(1); } else printf("Current tbuf size: 0x%x\n", size); @@ -25,9 +25,10 @@ perror("set_size Hypercall failure"); exit(1); } + printf("set_size succeeded.\n"); if (xc_tbuf_get_size(xc_handle, &size) != 0) - perror("Failure to get tbuf info from Xen. Guess size is 0."); + perror("Failure to get tbuf info from Xen. Tracing must be enabled first"); else printf("New tbuf size: 0x%x\n", size); diff -r 60bf9aa39043 -r bb0e5f7f94fd tools/xm-test/lib/XmTestLib/Console.py --- a/tools/xm-test/lib/XmTestLib/Console.py Tue Nov 15 14:56:47 2005 +++ b/tools/xm-test/lib/XmTestLib/Console.py Tue Nov 15 15:24:31 2005 @@ -62,26 +62,37 @@ self.historySaveCmds = historySaveCmds self.debugMe = False self.limit = None + self.delay = 2 consoleCmd = ["/usr/sbin/xm", "xm", "console", domain] - if verbose: - print "Console executing: " + str(consoleCmd) - - pid, fd = pty.fork() - - if pid == 0: - os.execvp("/usr/sbin/xm", consoleCmd[1:]) - - self.consolePid = pid - self.consoleFd = fd - - tty.setraw(self.consoleFd, termios.TCSANOW) + start = time.time() + + while (time.time() - start) < self.TIMEOUT: + if verbose: + print "Console executing: %s" % str(consoleCmd) + + pid, fd = pty.fork() + + if pid == 0: + os.execvp("/usr/sbin/xm", consoleCmd[1:]) + + self.consolePid = pid + self.consoleFd = fd + + tty.setraw(self.consoleFd, termios.TCSANOW) - bytes = self.__chewall(self.consoleFd) - if bytes < 0: - raise ConsoleError("Console didn't respond") - + bytes = self.__chewall(self.consoleFd) + + if bytes > 0: + return + + if verbose: + print "Console didn't attach, waiting %i sec..." % self.delay + time.sleep(self.delay) + + raise ConsoleError("Console didn't respond after %i secs" % self.TIMEOUT) + def __addToHistory(self, line): self.historyBuffer.append(line) self.historyLines += 1 diff -r 60bf9aa39043 -r bb0e5f7f94fd tools/xm-test/lib/XmTestLib/XenDomain.py --- a/tools/xm-test/lib/XmTestLib/XenDomain.py Tue Nov 15 14:56:47 2005 +++ b/tools/xm-test/lib/XmTestLib/XenDomain.py Tue Nov 15 15:24:31 2005 @@ -228,7 +228,7 @@ # status, output = traceCommand("xm list") XenDomain.start(self) - waitForBoot() +# waitForBoot() def startNow(self): XenDomain.start(self) diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/arch/x86/domain.c --- a/xen/arch/x86/domain.c Tue Nov 15 14:56:47 2005 +++ b/xen/arch/x86/domain.c Tue Nov 15 15:24:31 2005 @@ -578,7 +578,7 @@ put_user(regs->rcx, rsp-11) ) { DPRINTK("Error while creating failsafe callback frame.\n"); - domain_crash(); + domain_crash(n->domain); } regs->entry_vector = TRAP_syscall; diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/arch/x86/mm.c --- a/xen/arch/x86/mm.c Tue Nov 15 14:56:47 2005 +++ b/xen/arch/x86/mm.c Tue Nov 15 15:24:31 2005 @@ -1461,6 +1461,22 @@ { if ( unlikely((x & PGT_type_mask) != (type & PGT_type_mask) ) ) { + if ( current->domain == page_get_owner(page) ) + { + /* + * This ensures functions like set_gdt() see up-to-date + * type info without needing to clean up writable p.t. + * state on the fast path. + */ + LOCK_BIGLOCK(current->domain); + cleanup_writable_pagetable(current->domain); + y = page->u.inuse.type_info; + UNLOCK_BIGLOCK(current->domain); + /* Can we make progress now? */ + if ( ((y & PGT_type_mask) == (type & PGT_type_mask)) || + ((y & PGT_count_mask) == 0) ) + goto again; + } if ( ((x & PGT_type_mask) != PGT_l2_page_table) || ((type & PGT_type_mask) != PGT_l1_page_table) ) MEM_LOG("Bad type (saw %" PRtype_info @@ -2529,7 +2545,7 @@ * not enough information in just a gpte to figure out how to * (re-)shadow this entry. */ - domain_crash(); + domain_crash(d); } rc = shadow_do_update_va_mapping(va, val, v); @@ -2918,7 +2934,6 @@ { l1_pgentry_t ol1e, nl1e; int modified = 0, i; - struct vcpu *v; for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) { @@ -2944,7 +2959,6 @@ if ( unlikely(!get_page_from_l1e(nl1e, d)) ) { - MEM_LOG("ptwr: Could not re-validate l1 page"); /* * Make the remaining p.t's consistent before crashing, so the * reference counts are correct. @@ -2953,9 +2967,8 @@ (L1_PAGETABLE_ENTRIES - i) * sizeof(l1_pgentry_t)); /* Crash the offending domain. */ - set_bit(_DOMF_ctrl_pause, &d->domain_flags); - for_each_vcpu ( d, v ) - vcpu_sleep_nosync(v); + MEM_LOG("ptwr: Could not revalidate l1 page"); + domain_crash(d); break; } @@ -3066,7 +3079,7 @@ unsigned int bytes, unsigned int do_cmpxchg) { - unsigned long pfn; + unsigned long pfn, l1va; struct pfn_info *page; l1_pgentry_t pte, ol1e, nl1e, *pl1e; struct domain *d = current->domain; @@ -3103,6 +3116,17 @@ old |= full; } + /* + * We must not emulate an update to a PTE that is temporarily marked + * writable by the batched ptwr logic, else we can corrupt page refcnts! + */ + if ( ((l1va = d->arch.ptwr[PTWR_PT_ACTIVE].l1va) != 0) && + (l1_linear_offset(l1va) == l1_linear_offset(addr)) ) + ptwr_flush(d, PTWR_PT_ACTIVE); + if ( ((l1va = d->arch.ptwr[PTWR_PT_INACTIVE].l1va) != 0) && + (l1_linear_offset(l1va) == l1_linear_offset(addr)) ) + ptwr_flush(d, PTWR_PT_INACTIVE); + /* Read the PTE that maps the page being updated. */ if (__copy_from_user(&pte, &linear_pg_table[l1_linear_offset(addr)], sizeof(pte))) @@ -3128,7 +3152,10 @@ /* Check the new PTE. */ nl1e = l1e_from_intpte(val); if ( unlikely(!get_page_from_l1e(nl1e, d)) ) + { + MEM_LOG("ptwr_emulate: could not get_page_from_l1e()"); return X86EMUL_UNHANDLEABLE; + } /* Checked successfully: do the update (write or cmpxchg). */ pl1e = map_domain_page(page_to_pfn(page)); @@ -3251,6 +3278,9 @@ goto emulate; #endif + PTWR_PRINTK("ptwr_page_fault on l1 pt at va %lx, pfn %lx, eip %lx\n", + addr, pfn, (unsigned long)regs->eip); + /* Get the L2 index at which this L1 p.t. is always mapped. */ l2_idx = page->u.inuse.type_info & PGT_va_mask; if ( unlikely(l2_idx >= PGT_va_unknown) ) @@ -3295,10 +3325,6 @@ goto emulate; } - PTWR_PRINTK("[%c] page_fault on l1 pt at va %lx, pt for %08lx, " - "pfn %lx\n", PTWR_PRINT_WHICH, - addr, l2_idx << L2_PAGETABLE_SHIFT, pfn); - /* * We only allow one ACTIVE and one INACTIVE p.t. to be updated at at * time. If there is already one, we must flush it out. @@ -3316,6 +3342,10 @@ d->arch.ptwr[which].prev_nr_updates = 1; goto emulate; } + + PTWR_PRINTK("[%c] batched ptwr_page_fault at va %lx, pt for %08lx, " + "pfn %lx\n", PTWR_PRINT_WHICH, addr, + l2_idx << L2_PAGETABLE_SHIFT, pfn); d->arch.ptwr[which].l1va = addr | 1; d->arch.ptwr[which].l2_idx = l2_idx; @@ -3348,7 +3378,7 @@ /* Toss the writable pagetable state and crash. */ unmap_domain_page(d->arch.ptwr[which].pl1e); d->arch.ptwr[which].l1va = 0; - domain_crash(); + domain_crash(d); return 0; } diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/arch/x86/shadow_public.c --- a/xen/arch/x86/shadow_public.c Tue Nov 15 14:56:47 2005 +++ b/xen/arch/x86/shadow_public.c Tue Nov 15 15:24:31 2005 @@ -239,13 +239,13 @@ l4page = alloc_domheap_page(NULL); if (l4page == NULL) - domain_crash(); + domain_crash(d); l4 = map_domain_page(page_to_pfn(l4page)); memset(l4, 0, PAGE_SIZE); l3page = alloc_domheap_page(NULL); if (l3page == NULL) - domain_crash(); + domain_crash(d); l3 = map_domain_page(page_to_pfn(l3page)); memset(l3, 0, PAGE_SIZE); diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/arch/x86/vmx.c --- a/xen/arch/x86/vmx.c Tue Nov 15 14:56:47 2005 +++ b/xen/arch/x86/vmx.c Tue Nov 15 15:24:31 2005 @@ -191,12 +191,12 @@ case MSR_FS_BASE: if (!(VMX_LONG_GUEST(vc))) /* XXX should it be GP fault */ - domain_crash(); + domain_crash(vc->domain); __vmread(GUEST_FS_BASE, &msr_content); break; case MSR_GS_BASE: if (!(VMX_LONG_GUEST(vc))) - domain_crash(); + domain_crash(vc->domain); __vmread(GUEST_GS_BASE, &msr_content); break; case MSR_SHADOW_GS_BASE: @@ -260,7 +260,7 @@ case MSR_FS_BASE: case MSR_GS_BASE: if (!(VMX_LONG_GUEST(vc))) - domain_crash(); + domain_crash(vc->domain); if (!IS_CANO_ADDRESS(msr_content)){ VMX_DBG_LOG(DBG_LEVEL_1, "Not cano address of msr write\n"); vmx_inject_exception(vc, TRAP_gp_fault, 0); @@ -273,7 +273,7 @@ case MSR_SHADOW_GS_BASE: if (!(VMX_LONG_GUEST(vc))) - domain_crash(); + domain_crash(vc->domain); vc->arch.arch_vmx.msr_content.shadow_gs = msr_content; wrmsrl(MSR_SHADOW_GS_BASE, msr_content); break; diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/arch/x86/vmx_vlapic.c --- a/xen/arch/x86/vmx_vlapic.c Tue Nov 15 14:56:47 2005 +++ b/xen/arch/x86/vmx_vlapic.c Tue Nov 15 15:24:31 2005 @@ -28,7 +28,7 @@ #include <asm/vmx.h> #include <asm/vmx_platform.h> #include <asm/vmx_vlapic.h> - +#include <asm/vmx_vioapic.h> #include <xen/lib.h> #include <xen/sched.h> #include <asm/current.h> @@ -322,10 +322,8 @@ vlapic_clear_isr(vlapic, vector); vlapic_update_ppr(vlapic); - if (test_and_clear_bit(vector, &vlapic->tmr[0])) { - extern void ioapic_update_EOI(struct domain *d, int vector); + if (test_and_clear_bit(vector, &vlapic->tmr[0])) ioapic_update_EOI(vlapic->domain, vector); - } } int vlapic_check_vector(struct vlapic *vlapic, diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/arch/x86/vmx_vmcs.c --- a/xen/arch/x86/vmx_vmcs.c Tue Nov 15 14:56:47 2005 +++ b/xen/arch/x86/vmx_vmcs.c Tue Nov 15 15:24:31 2005 @@ -157,13 +157,13 @@ mpfn = get_mfn_from_pfn(E820_MAP_PAGE >> PAGE_SHIFT); if (mpfn == INVALID_MFN) { printk("Can not find E820 memory map page for VMX domain.\n"); - domain_crash(); + domain_crash(d); } p = map_domain_page(mpfn); if (p == NULL) { printk("Can not map E820 memory map page for VMX domain.\n"); - domain_crash(); + domain_crash(d); } e820_map_nr = *(p + E820_MAP_NR_OFFSET); @@ -182,7 +182,7 @@ printk("Can not get io request shared page" " from E820 memory map for VMX domain.\n"); unmap_domain_page(p); - domain_crash(); + domain_crash(d); } unmap_domain_page(p); @@ -190,13 +190,13 @@ mpfn = get_mfn_from_pfn(gpfn); if (mpfn == INVALID_MFN) { printk("Can not find io request shared page for VMX domain.\n"); - domain_crash(); + domain_crash(d); } p = map_domain_page(mpfn); if (p == NULL) { printk("Can not map io request shared page for VMX domain.\n"); - domain_crash(); + domain_crash(d); } d->arch.vmx_platform.shared_page_va = (unsigned long)p; diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/common/domain.c --- a/xen/common/domain.c Tue Nov 15 14:56:47 2005 +++ b/xen/common/domain.c Tue Nov 15 15:24:31 2005 @@ -125,18 +125,27 @@ } -void domain_crash(void) -{ - printk("Domain %d (vcpu#%d) crashed on cpu#%d:\n", - current->domain->domain_id, current->vcpu_id, smp_processor_id()); - show_registers(guest_cpu_user_regs()); - domain_shutdown(SHUTDOWN_crash); +void domain_crash(struct domain *d) +{ + if ( d == current->domain ) + { + printk("Domain %d (vcpu#%d) crashed on cpu#%d:\n", + d->domain_id, current->vcpu_id, smp_processor_id()); + show_registers(guest_cpu_user_regs()); + } + else + { + printk("Domain %d reported crashed by domain %d on cpu#%d:\n", + d->domain_id, current->domain->domain_id, smp_processor_id()); + } + + domain_shutdown(d, SHUTDOWN_crash); } void domain_crash_synchronous(void) { - domain_crash(); + domain_crash(current->domain); for ( ; ; ) do_softirq(); } @@ -178,10 +187,9 @@ __initcall(domain_shutdown_finaliser_init); -void domain_shutdown(u8 reason) -{ - struct domain *d = current->domain; - struct vcpu *v; +void domain_shutdown(struct domain *d, u8 reason) +{ + struct vcpu *v; if ( d->domain_id == 0 ) { diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/common/grant_table.c --- a/xen/common/grant_table.c Tue Nov 15 14:56:47 2005 +++ b/xen/common/grant_table.c Tue Nov 15 15:24:31 2005 @@ -29,6 +29,7 @@ #include <xen/shadow.h> #include <xen/mm.h> #include <acm/acm_hooks.h> +#include <xen/trace.h> #if defined(CONFIG_X86_64) #define GRANT_PTE_FLAGS (_PAGE_PRESENT|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER) @@ -379,6 +380,8 @@ } } + TRACE_1D(TRC_MEM_PAGE_GRANT_MAP, dom); + ld->grant_table->maptrack[handle].domid = dom; ld->grant_table->maptrack[handle].ref_and_flags = (ref << MAPTRACK_REF_SHIFT) | @@ -462,6 +465,8 @@ (void)__put_user(GNTST_bad_domain, &uop->status); return GNTST_bad_domain; } + + TRACE_1D(TRC_MEM_PAGE_GRANT_UNMAP, dom); act = &rd->grant_table->active[ref]; sha = &rd->grant_table->shared[ref]; @@ -802,6 +807,8 @@ page_set_owner(page, e); spin_unlock(&e->page_alloc_lock); + + TRACE_1D(TRC_MEM_PAGE_GRANT_TRANSFER, e->domain_id); /* Tell the guest about its new page frame. */ sha = &e->grant_table->shared[gop->ref]; diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/common/schedule.c --- a/xen/common/schedule.c Tue Nov 15 14:56:47 2005 +++ b/xen/common/schedule.c Tue Nov 15 15:24:31 2005 @@ -12,15 +12,6 @@ * implements support functionality for the Xen scheduler API. * */ - -/*#define WAKE_HISTO*/ -/*#define BLOCKTIME_HISTO*/ - -#if defined(WAKE_HISTO) -#define BUCKETS 31 -#elif defined(BLOCKTIME_HISTO) -#define BUCKETS 200 -#endif #include <xen/config.h> #include <xen/init.h> @@ -45,6 +36,8 @@ static char opt_sched[10] = "sedf"; string_param("sched", opt_sched); +/*#define WAKE_HISTO*/ +/*#define BLOCKTIME_HISTO*/ #if defined(WAKE_HISTO) #define BUCKETS 31 #elif defined(BLOCKTIME_HISTO) @@ -205,9 +198,7 @@ if ( likely(domain_runnable(v)) ) { SCHED_OP(wake, v); -#ifdef WAKE_HISTO v->wokenup = NOW(); -#endif } clear_bit(_VCPUF_cpu_migrated, &v->vcpu_flags); spin_unlock_irqrestore(&schedule_data[v->processor].schedule_lock, flags); @@ -267,7 +258,7 @@ { TRACE_3D(TRC_SCHED_SHUTDOWN, current->domain->domain_id, current->vcpu_id, arg); - domain_shutdown((u8)arg); + domain_shutdown(current->domain, (u8)arg); break; } @@ -416,10 +407,25 @@ return continue_running(prev); } + TRACE_2D(TRC_SCHED_SWITCH_INFPREV, + prev->domain->domain_id, now - prev->lastschd); + TRACE_3D(TRC_SCHED_SWITCH_INFNEXT, + next->domain->domain_id, now - next->wokenup, r_time); + clear_bit(_VCPUF_running, &prev->vcpu_flags); set_bit(_VCPUF_running, &next->vcpu_flags); perfc_incrc(sched_ctx); + + /* + * Logic of wokenup field in domain struct: + * Used to calculate "waiting time", which is the time that a domain + * spends being "runnable", but not actually running. wokenup is set + * set whenever a domain wakes from sleeping. However, if wokenup is not + * also set here then a preempted runnable domain will get a screwed up + * "waiting time" value next time it is scheduled. + */ + prev->wokenup = NOW(); #if defined(WAKE_HISTO) if ( !is_idle_task(next->domain) && next->wokenup ) diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/include/asm-ia64/vmx_vpd.h --- a/xen/include/asm-ia64/vmx_vpd.h Tue Nov 15 14:56:47 2005 +++ b/xen/include/asm-ia64/vmx_vpd.h Tue Nov 15 15:24:31 2005 @@ -122,7 +122,7 @@ do { \ printk("__vmx_bug at %s:%d\n", __FILE__, __LINE__); \ show_registers(regs); \ - domain_crash(); \ + domain_crash(current->domain); \ } while (0) #endif //__ASSEMBLY__ diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/include/asm-x86/vmx_vioapic.h --- a/xen/include/asm-x86/vmx_vioapic.h Tue Nov 15 14:56:47 2005 +++ b/xen/include/asm-x86/vmx_vioapic.h Tue Nov 15 15:24:31 2005 @@ -114,6 +114,8 @@ int vmx_vioapic_add_lapic(struct vlapic *vlapic, struct vcpu *v); +void ioapic_update_EOI(struct domain *d, int vector); + #ifdef VMX_DOMAIN_SAVE_RESTORE void ioapic_save(QEMUFile* f, void* opaque); int ioapic_load(QEMUFile* f, void* opaque, int version_id); diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/include/public/trace.h --- a/xen/include/public/trace.h Tue Nov 15 14:56:47 2005 +++ b/xen/include/public/trace.h Tue Nov 15 15:24:31 2005 @@ -14,6 +14,7 @@ #define TRC_SCHED 0x0002f000 /* Xen Scheduler trace */ #define TRC_DOM0OP 0x0004f000 /* Xen DOM0 operation trace */ #define TRC_VMX 0x0008f000 /* Xen VMX trace */ +#define TRC_MEM 0x000af000 /* Xen memory trace */ #define TRC_ALL 0xfffff000 /* Trace subclasses */ @@ -40,6 +41,12 @@ #define TRC_SCHED_S_TIMER_FN (TRC_SCHED + 11) #define TRC_SCHED_T_TIMER_FN (TRC_SCHED + 12) #define TRC_SCHED_DOM_TIMER_FN (TRC_SCHED + 13) +#define TRC_SCHED_SWITCH_INFPREV (TRC_SCHED + 14) +#define TRC_SCHED_SWITCH_INFNEXT (TRC_SCHED + 15) + +#define TRC_MEM_PAGE_GRANT_MAP (TRC_MEM + 1) +#define TRC_MEM_PAGE_GRANT_UNMAP (TRC_MEM + 2) +#define TRC_MEM_PAGE_GRANT_TRANSFER (TRC_MEM + 3) /* trace events per subclass */ #define TRC_VMX_VMEXIT (TRC_VMXEXIT + 1) diff -r 60bf9aa39043 -r bb0e5f7f94fd xen/include/xen/sched.h --- a/xen/include/xen/sched.h Tue Nov 15 14:56:47 2005 +++ b/xen/include/xen/sched.h Tue Nov 15 15:24:31 2005 @@ -220,14 +220,15 @@ struct domain *find_domain_by_id(domid_t dom); extern void domain_destruct(struct domain *d); extern void domain_kill(struct domain *d); -extern void domain_shutdown(u8 reason); +extern void domain_shutdown(struct domain *d, u8 reason); extern void domain_pause_for_debugger(void); /* - * Mark current domain as crashed. This function returns: the domain is not - * synchronously descheduled from any processor. - */ -extern void domain_crash(void); + * Mark specified domain as crashed. This function always returns, even if the + * caller is the specified domain. The domain is not synchronously descheduled + * from any processor. + */ +extern void domain_crash(struct domain *d); /* * Mark current domain as crashed and synchronously deschedule from the local diff -r 60bf9aa39043 -r bb0e5f7f94fd tools/xenmon/COPYING --- /dev/null Tue Nov 15 14:56:47 2005 +++ b/tools/xenmon/COPYING Tue Nov 15 15:24:31 2005 @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff -r 60bf9aa39043 -r bb0e5f7f94fd tools/xenmon/Makefile --- /dev/null Tue Nov 15 14:56:47 2005 +++ b/tools/xenmon/Makefile Tue Nov 15 15:24:31 2005 @@ -0,0 +1,51 @@ +# Copyright (C) HP Labs, Palo Alto and Fort Collins, 2005 +# Author: Diwaker Gupta <diwaker.gupta@xxxxxx> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; under version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +INSTALL = install +INSTALL_PROG = $(INSTALL) -m0755 +INSTALL_DIR = $(INSTALL) -d -m0755 +INSTALL_DATA = $(INSTALL) -m064 + +prefix=/usr/local +mandir=$(prefix)/share/man +man1dir=$(mandir)/man1 +sbindir=$(prefix)/sbin + +XEN_ROOT=../.. +include $(XEN_ROOT)/tools/Rules.mk + +CFLAGS += -Wall -Werror -g +CFLAGS += -I $(XEN_XC) +CFLAGS += -I $(XEN_LIBXC) +LDFLAGS += -L $(XEN_LIBXC) + +BIN = setmask xenbaked +SCRIPTS = xenmon.py + +all: build + +build: $(BIN) + +install: xenbaked setmask + [ -d $(DESTDIR)$(sbindir) ] || $(INSTALL_DIR) $(DESTDIR)$(sbindir) + $(INSTALL_PROG) xenbaked $(DESTDIR)$(sbindir)/xenbaked + $(INSTALL_PROG) setmask $(DESTDIR)$(sbindir)/setmask + $(INSTALL_PROG) xenmon.py $(DESTDIR)$(sbindir)/xenmon.py + +clean: + rm -f $(BIN) + + +%: %.c Makefile + $(CC) $(CFLAGS) $(LDFLAGS) -lxenctrl -o $@ $< + + diff -r 60bf9aa39043 -r bb0e5f7f94fd tools/xenmon/README --- /dev/null Tue Nov 15 14:56:47 2005 +++ b/tools/xenmon/README Tue Nov 15 15:24:31 2005 @@ -0,0 +1,104 @@ +Xen Performance Monitor +----------------------- + +The xenmon tools make use of the existing xen tracing feature to provide fine +grained reporting of various domain related metrics. It should be stressed that +the xenmon.py script included here is just an example of the data that may be +displayed. The xenbake demon keeps a large amount of history in a shared memory +area that may be accessed by tools such as xenmon. + +For each domain, xenmon reports various metrics. One part of the display is a +group of metrics that have been accumulated over the last second, while another +part of the display shows data measured over 10 seconds. Other measurement +intervals are possible, but we have just chosen 1s and 10s as an example. + + +Execution Count +--------------- + o The number of times that a domain was scheduled to run (ie, dispatched) over + the measurement interval + + +CPU usage +--------- + o Total time used over the measurement interval + o Usage expressed as a percentage of the measurement interval + o Average cpu time used during each execution of the domain + + +Waiting time +------------ +This is how much time the domain spent waiting to run, or put another way, the +amount of time the domain spent in the "runnable" state (or on the run queue) +but not actually running. Xenmon displays: + + o Total time waiting over the measurement interval + o Wait time expressed as a percentage of the measurement interval + o Average waiting time for each execution of the domain + +Blocked time +------------ +This is how much time the domain spent blocked (or sleeping); Put another way, +the amount of time the domain spent not needing/wanting the cpu because it was +waiting for some event (ie, I/O). Xenmon reports: + + o Total time blocked over the measurement interval + o Blocked time expressed as a percentage of the measurement interval + o Blocked time per I/O (see I/O count below) + +Allocation time +--------------- +This is how much cpu time was allocated to the domain by the scheduler; This is +distinct from cpu usage since the "time slice" given to a domain is frequently +cut short for one reason or another, ie, the domain requests I/O and blocks. +Xenmon reports: + + o Average allocation time per execution (ie, time slice) + o Min and Max allocation times + +I/O Count +--------- +This is a rough measure of I/O requested by the domain. The number of page +exchanges (or page "flips") between the domain and dom0 are counted. The +number of pages exchanged may not accurately reflect the number of bytes +transferred to/from a domain due to partial pages being used by the network +protocols, etc. But it does give a good sense of the magnitude of I/O being +requested by a domain. Xenmon reports: + + o Total number of page exchanges during the measurement interval + o Average number of page exchanges per execution of the domain + + +Usage Notes and issues +---------------------- + - Start xenmon by simply running xenmon.py; The xenbake demon is started and + stopped automatically by xenmon. + - To see the various options for xenmon, run xenmon -h. Ditto for xenbaked. + - xenmon also has an option (-n) to output log data to a file instead of the + curses interface. + - NDOMAINS is defined to be 32, but can be changed by recompiling xenbaked + - Xenmon.py appears to create 1-2% cpu overhead; Part of this is just the + overhead of the python interpreter. Part of it may be the number of trace + records being generated. The number of trace records generated can be + limited by setting the trace mask (with a dom0 Op), which controls which + events cause a trace record to be emitted. + - To exit xenmon, type 'q' + - To cycle the display to other physical cpu's, type 'c' + +Future Work +----------- +o RPC interface to allow external entities to programmatically access processed data +o I/O Count batching to reduce number of trace records generated + +Case Study +---------- +We have written a case study which demonstrates some of the usefulness of +this tool and the metrics reported. It is available at: +http://www.hpl.hp.com/techreports/2005/HPL-2005-187.html + +Authors +------- +Diwaker Gupta <diwaker.gupta@xxxxxx> +Rob Gardner <rob.gardner@xxxxxx> +Lucy Cherkasova <lucy.cherkasova.hp.com> + diff -r 60bf9aa39043 -r bb0e5f7f94fd tools/xenmon/setmask.c --- /dev/null Tue Nov 15 14:56:47 2005 +++ b/tools/xenmon/setmask.c Tue Nov 15 15:24:31 2005 @@ -0,0 +1,90 @@ +/****************************************************************************** + * tools/xenmon/setmask.c + * + * Simple utility for getting/setting the event mask + * + * Copyright (C) 2005 by Hewlett-Packard, Palo Alto and Fort Collins + * + * Authors: Lucy Cherkasova, lucy.cherkasova.hp.com + * Rob Gardner, rob.gardner@xxxxxx + * Diwaker Gupta, diwaker.gupta@xxxxxx + * Date: August, 2005 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <stdlib.h> +#include <stdio.h> +#include <sys/types.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <getopt.h> +#include <xenctrl.h> +#include <xen/xen.h> +typedef struct { int counter; } atomic_t; +#include <xen/trace.h> + +#define XENMON (TRC_SCHED_DOM_ADD | TRC_SCHED_DOM_REM | TRC_SCHED_SWITCH_INFPREV | TRC_SCHED_SWITCH_INFNEXT | TRC_SCHED_BLOCK | TRC_SCHED_SLEEP | TRC_SCHED_WAKE | TRC_MEM_PAGE_GRANT_TRANSFER) + +int main(int argc, char * argv[]) +{ + + dom0_op_t op; + int ret; + + int xc_handle = xc_interface_open(); + op.cmd = DOM0_TBUFCONTROL; + op.interface_version = DOM0_INTERFACE_VERSION; + op.u.tbufcontrol.op = DOM0_TBUF_GET_INFO; + ret = xc_dom0_op(xc_handle, &op); + if ( ret != 0 ) + { + perror("Failure to get event mask from Xen"); + exit(1); + } + else + { + printf("Current event mask: 0x%.8x\n", op.u.tbufcontrol.evt_mask); + } + + op.cmd = DOM0_TBUFCONTROL; + op.interface_version = DOM0_INTERFACE_VERSION; + op.u.tbufcontrol.op = DOM0_TBUF_SET_EVT_MASK; + op.u.tbufcontrol.evt_mask = XENMON; + + ret = xc_dom0_op(xc_handle, &op); + printf("Setting mask to 0x%.8x\n", op.u.tbufcontrol.evt_mask); + if ( ret != 0 ) + { + perror("Failure to get scheduler ID from Xen"); + exit(1); + } + + op.cmd = DOM0_TBUFCONTROL; + op.interface_version = DOM0_INTERFACE_VERSION; + op.u.tbufcontrol.op = DOM0_TBUF_GET_INFO; + ret = xc_dom0_op(xc_handle, &op); + if ( ret != 0 ) + { + perror("Failure to get event mask from Xen"); + exit(1); + } + else + { + printf("Current event mask: 0x%.8x\n", op.u.tbufcontrol.evt_mask); + } + xc_interface_close(xc_handle); + return 0; +} diff -r 60bf9aa39043 -r bb0e5f7f94fd tools/xenmon/xenbaked.c --- /dev/null Tue Nov 15 14:56:47 2005 +++ b/tools/xenmon/xenbaked.c Tue Nov 15 15:24:31 2005 @@ -0,0 +1,1029 @@ +/****************************************************************************** + * tools/xenbaked.c + * + * Tool for collecting raw trace buffer data from Xen and + * performing some accumulation operations and other processing + * on it. + * + * Copyright (C) 2004 by Intel Research Cambridge + * Copyright (C) 2005 by Hewlett Packard, Palo Alto and Fort Collins + * + * Authors: Diwaker Gupta, diwaker.gupta@xxxxxx + * Rob Gardner, rob.gardner@xxxxxx + * Lucy Cherkasova, lucy.cherkasova.hp.com + * Much code based on xentrace, authored by Mark Williamson, mark.a.williamson@xxxxxxxxx + * Date: November, 2005 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <time.h> +#include <stdlib.h> +#include <stdio.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <argp.h> +#include <signal.h> +#include <xenctrl.h> +#include <xen/xen.h> +#include <string.h> + +#include "xc_private.h" +typedef struct { int counter; } atomic_t; +#define _atomic_read(v) ((v).counter) + +#include <xen/trace.h> +#include "xenbaked.h" + +extern FILE *stderr; + +/***** Compile time configuration of defaults ********************************/ + +/* when we've got more records than this waiting, we log it to the output */ +#define NEW_DATA_THRESH 1 + +/* sleep for this long (milliseconds) between checking the trace buffers */ +#define POLL_SLEEP_MILLIS 100 + +/* Size of time period represented by each sample */ +#define MS_PER_SAMPLE 100 + +/* CPU Frequency */ +#define MHZ +#define CPU_FREQ 2660 MHZ + +/***** The code **************************************************************/ + +typedef struct settings_st { + char *outfile; + struct timespec poll_sleep; + unsigned long new_data_thresh; + unsigned long ms_per_sample; + double cpu_freq; +} settings_t; + +settings_t opts; + +int interrupted = 0; /* gets set if we get a SIGHUP */ +int rec_count = 0; +time_t start_time; +int dom0_flips = 0; + +_new_qos_data *new_qos; +_new_qos_data **cpu_qos_data; + + +#define ID(X) ((X>NDOMAINS-1)?(NDOMAINS-1):X) + +// array of currently running domains, indexed by cpu +int *running = NULL; + +// number of cpu's on this platform +int NCPU = 0; + + +void init_current(int ncpu) +{ + running = calloc(ncpu, sizeof(int)); + NCPU = ncpu; + printf("Initialized with %d %s\n", ncpu, (ncpu == 1) ? "cpu" : "cpu's"); +} + +int is_current(int domain, int cpu) +{ + // int i; + + // for (i=0; i<NCPU; i++) + if (running[cpu] == domain) + return 1; + return 0; +} + + +// return the domain that's currently running on the given cpu +int current(int cpu) +{ + return running[cpu]; +} + +void set_current(int cpu, int domain) +{ + running[cpu] = domain; +} + + + +void close_handler(int signal) +{ + interrupted = 1; +} + +#if 0 +void dump_record(int cpu, struct t_rec *x) +{ + printf("record: cpu=%x, tsc=%lx, event=%x, d1=%lx\n", + cpu, x->cycles, x->event, x->data[0]); +} +#endif + +/** + * millis_to_timespec - convert a time in milliseconds to a struct timespec + * @millis: time interval in milliseconds + */ +struct timespec millis_to_timespec(unsigned long millis) +{ + struct timespec spec; + + spec.tv_sec = millis / 1000; + spec.tv_nsec = (millis % 1000) * 1000; + + return spec; +} + + +typedef struct +{ + int event_count; + int event_id; + char *text; +} stat_map_t; + +stat_map_t stat_map[] = { + { 0, 0, "Other" }, + { 0, TRC_SCHED_DOM_ADD, "Add Domain" }, + { 0, TRC_SCHED_DOM_REM, "Remove Domain" }, + { 0, TRC_SCHED_SLEEP, "Sleep" }, + { 0, TRC_SCHED_WAKE, "Wake" }, + { 0, TRC_SCHED_BLOCK, "Block" }, + { 0, TRC_SCHED_SWITCH, "Switch" }, + { 0, TRC_SCHED_S_TIMER_FN, "Timer Func"}, + { 0, TRC_SCHED_SWITCH_INFPREV, "Switch Prev" }, + { 0, TRC_SCHED_SWITCH_INFNEXT, "Switch Next" }, + { 0, TRC_MEM_PAGE_GRANT_MAP, "Page Map" }, + { 0, TRC_MEM_PAGE_GRANT_UNMAP, "Page Unmap" }, + { 0, TRC_MEM_PAGE_GRANT_TRANSFER, "Page Transfer" }, + { 0, 0, 0 } +}; + + +void check_gotten_sum(void) +{ +#if 0 + uint64_t sum, ns; + extern uint64_t total_ns_gotten(uint64_t*); + double percent; + int i; + + for (i=0; i<NCPU; i++) { + new_qos = cpu_qos_data[i]; + ns = billion; + sum = total_ns_gotten(&ns); + + printf("[cpu%d] ns_gotten over all domains = %lldns, over %lldns\n", + i, sum, ns); + percent = (double) sum; + percent = (100.0*percent) / (double)ns; + printf(" ==> ns_gotten = %7.3f%%\n", percent); + } +#endif +} + + + +void dump_stats(void) +{ + stat_map_t *smt = stat_map; + time_t end_time, run_time; + + time(&end_time); + + run_time = end_time - start_time; + + printf("Event counts:\n"); + while (smt->text != NULL) { + printf("%08d\t%s\n", smt->event_count, smt->text); + smt++; + } + + printf("processed %d total records in %d seconds (%ld per second)\n", + rec_count, (int)run_time, rec_count/run_time); + + check_gotten_sum(); +} + +void log_event(int event_id) +{ + stat_map_t *smt = stat_map; + + // printf("event_id = 0x%x\n", event_id); + + while (smt->text != NULL) { + if (smt->event_id == event_id) { + smt->event_count++; + return; + } + smt++; + } + if (smt->text == NULL) + stat_map[0].event_count++; // other +} + + + +/** + * get_tbufs - get pointer to and size of the trace buffers + * @mfn: location to store mfn of the trace buffers to + * @size: location to store the size of a trace buffer to + * + * Gets the machine address of the trace pointer area and the size of the + * per CPU buffers. + */ +void get_tbufs(unsigned long *mfn, unsigned long *size) +{ + int ret; + dom0_op_t op; /* dom0 op we'll build */ + int xc_handle = xc_interface_open(); /* for accessing control interface */ + + op.cmd = DOM0_TBUFCONTROL; + op.interface_version = DOM0_INTERFACE_VERSION; + op.u.tbufcontrol.op = DOM0_TBUF_GET_INFO; + + ret = do_dom0_op(xc_handle, &op); + + xc_interface_close(xc_handle); + + if ( ret != 0 ) + { + PERROR("Failure to get trace buffer pointer from Xen"); + exit(EXIT_FAILURE); + } + + *mfn = op.u.tbufcontrol.buffer_mfn; + *size = op.u.tbufcontrol.size; +} + +/** + * map_tbufs - memory map Xen trace buffers into user space + * @tbufs_mfn: mfn of the trace buffers + * @num: number of trace buffers to map + * @size: size of each trace buffer + * + * Maps the Xen trace buffers them into process address space. + */ +struct t_buf *map_tbufs(unsigned long tbufs_mfn, unsigned int num, + unsigned long size) +{ + int xc_handle; /* file descriptor for /proc/xen/privcmd */ + struct t_buf *tbufs_mapped; + + xc_handle = xc_interface_open(); + + if ( xc_handle < 0 ) + { + PERROR("Open /proc/xen/privcmd when mapping trace buffers\n"); + exit(EXIT_FAILURE); + } + + tbufs_mapped = xc_map_foreign_range(xc_handle, 0 /* Dom 0 ID */, + size * num, PROT_READ | PROT_WRITE, + tbufs_mfn); + + xc_interface_close(xc_handle); + + if ( tbufs_mapped == 0 ) + { + PERROR("Failed to mmap trace buffers"); + exit(EXIT_FAILURE); + } + + return tbufs_mapped; +} + +/** + * init_bufs_ptrs - initialises an array of pointers to the trace buffers + * @bufs_mapped: the userspace address where the trace buffers are mapped + * @num: number of trace buffers + * @size: trace buffer size + * + * Initialises an array of pointers to individual trace buffers within the + * mapped region containing all trace buffers. + */ +struct t_buf **init_bufs_ptrs(void *bufs_mapped, unsigned int num, + unsigned long size) +{ + int i; + struct t_buf **user_ptrs; + + user_ptrs = (struct t_buf **)calloc(num, sizeof(struct t_buf *)); + if ( user_ptrs == NULL ) + { + PERROR( "Failed to allocate memory for buffer pointers\n"); + exit(EXIT_FAILURE); + } + + /* initialise pointers to the trace buffers - given the size of a trace + * buffer and the value of bufs_maped, we can easily calculate these */ + for ( i = 0; i<num; i++ ) + user_ptrs[i] = (struct t_buf *)((unsigned long)bufs_mapped + size * i); + + return user_ptrs; +} + + +/** + * init_rec_ptrs - initialises data area pointers to locations in user space + * @tbufs_mfn: base mfn of the trace buffer area + * @tbufs_mapped: user virtual address of base of trace buffer area + * @meta: array of user-space pointers to struct t_buf's of metadata + * @num: number of trace buffers + * + * Initialises data area pointers to the locations that data areas have been + * mapped in user space. Note that the trace buffer metadata contains machine + * pointers - the array returned allows more convenient access to them. + */ +struct t_rec **init_rec_ptrs(struct t_buf **meta, unsigned int num) +{ + int i; + struct t_rec **data; + + data = calloc(num, sizeof(struct t_rec *)); + if ( data == NULL ) + { + PERROR("Failed to allocate memory for data pointers\n"); + exit(EXIT_FAILURE); + } + + for ( i = 0; i < num; i++ ) + data[i] = (struct t_rec *)(meta[i] + 1); + + return data; +} + + + +/** + * get_num_cpus - get the number of logical CPUs + */ +unsigned int get_num_cpus() +{ + dom0_op_t op; + int xc_handle = xc_interface_open(); + int ret; + + op.cmd = DOM0_PHYSINFO; + op.interface_version = DOM0_INTERFACE_VERSION; + + ret = xc_dom0_op(xc_handle, &op); + + if ( ret != 0 ) + { + PERROR("Failure to get logical CPU count from Xen"); + exit(EXIT_FAILURE); + } + + xc_interface_close(xc_handle); + opts.cpu_freq = (double)op.u.physinfo.cpu_khz/1000.0; + + return (op.u.physinfo.threads_per_core * + op.u.physinfo.cores_per_socket * + op.u.physinfo.sockets_per_node * + op.u.physinfo.nr_nodes); +} + + +/** + * monitor_tbufs - monitor the contents of tbufs + */ +int monitor_tbufs() +{ + int i; + extern void process_record(int, struct t_rec *); + extern void alloc_qos_data(int ncpu); + + void *tbufs_mapped; /* pointer to where the tbufs are mapped */ + struct t_buf **meta; /* pointers to the trace buffer metadata */ + struct t_rec **data; /* pointers to the trace buffer data areas + * where they are mapped into user space. */ + unsigned long tbufs_mfn; /* mfn of the tbufs */ + unsigned int num; /* number of trace buffers / logical CPUS */ + unsigned long size; /* size of a single trace buffer */ + + int size_in_recs; + + /* get number of logical CPUs (and therefore number of trace buffers) */ + num = get_num_cpus(); + + init_current(num); + alloc_qos_data(num); + + printf("CPU Frequency = %7.2f\n", opts.cpu_freq); + + /* setup access to trace buffers */ + get_tbufs(&tbufs_mfn, &size); + + // printf("from dom0op: %ld, t_buf: %d, t_rec: %d\n", + // size, sizeof(struct t_buf), sizeof(struct t_rec)); + + tbufs_mapped = map_tbufs(tbufs_mfn, num, size); + + size_in_recs = (size - sizeof(struct t_buf)) / sizeof(struct t_rec); + // fprintf(stderr, "size_in_recs = %d\n", size_in_recs); + + /* build arrays of convenience ptrs */ + meta = init_bufs_ptrs (tbufs_mapped, num, size); + data = init_rec_ptrs(meta, num); + + /* now, scan buffers for events */ + while ( !interrupted ) + { + for ( i = 0; ( i < num ) && !interrupted; i++ ) + while ( meta[i]->cons != meta[i]->prod ) + { + rmb(); /* read prod, then read item. */ + process_record(i, data[i] + meta[i]->cons % size_in_recs); + mb(); /* read item, then update cons. */ + meta[i]->cons++; + } + + nanosleep(&opts.poll_sleep, NULL); + } + + /* cleanup */ + free(meta); + free(data); + /* don't need to munmap - cleanup is automatic */ + + return 0; +} + + +/****************************************************************************** + * Various declarations / definitions GNU argp needs to do its work + *****************************************************************************/ + + +/* command parser for GNU argp - see GNU docs for more info */ +error_t cmd_parser(int key, char *arg, struct argp_state *state) +{ + settings_t *setup = (settings_t *)state->input; + + switch ( key ) + { + case 't': /* set new records threshold for logging */ + { + char *inval; + setup->new_data_thresh = strtol(arg, &inval, 0); + if ( inval == arg ) + argp_usage(state); + } + break; + + case 's': /* set sleep time (given in milliseconds) */ + { + char *inval; + setup->poll_sleep = millis_to_timespec(strtol(arg, &inval, 0)); + if ( inval == arg ) + argp_usage(state); + } + break; + + case 'm': /* set ms_per_sample */ + { + char *inval; + setup->ms_per_sample = strtol(arg, &inval, 0); + if ( inval == arg ) + argp_usage(state); + } + break; + + case ARGP_KEY_ARG: + { + if ( state->arg_num == 0 ) + setup->outfile = arg; + else + argp_usage(state); + } + break; + + default: + return ARGP_ERR_UNKNOWN; + } + + return 0; +} + +#define SHARED_MEM_FILE "/tmp/xenq-shm" +void alloc_qos_data(int ncpu) +{ + int i, n, pgsize, off=0; + char *dummy; + int qos_fd; + void advance_next_datapoint(uint64_t); + + cpu_qos_data = (_new_qos_data **) calloc(ncpu, sizeof(_new_qos_data *)); + + + qos_fd = open(SHARED_MEM_FILE, O_RDWR|O_CREAT|O_TRUNC, 0777); + if (qos_fd < 0) { + PERROR(SHARED_MEM_FILE); + exit(2); + } + pgsize = getpagesize(); + dummy = malloc(pgsize); + + for (n=0; n<ncpu; n++) { + + for (i=0; i<sizeof(_new_qos_data); i=i+pgsize) + write(qos_fd, dummy, pgsize); + + new_qos = (_new_qos_data *) mmap(0, sizeof(_new_qos_data), PROT_READ|PROT_WRITE, + MAP_SHARED, qos_fd, off); + off += i; + if (new_qos == NULL) { + PERROR("mmap"); + exit(3); + } + // printf("new_qos = %p\n", new_qos); + memset(new_qos, 0, sizeof(_new_qos_data)); + new_qos->next_datapoint = 0; + advance_next_datapoint(0); + new_qos->structlen = i; + new_qos->ncpu = ncpu; + // printf("structlen = 0x%x\n", i); + cpu_qos_data[n] = new_qos; + } + free(dummy); + new_qos = NULL; +} + + +#define xstr(x) str(x) +#define str(x) #x + +const struct argp_option cmd_opts[] = +{ + { .name = "log-thresh", .key='t', .arg="l", + .doc = + "Set number, l, of new records required to trigger a write to output " + "(default " xstr(NEW_DATA_THRESH) ")." }, + + { .name = "poll-sleep", .key='s', .arg="p", + .doc = + "Set sleep time, p, in milliseconds between polling the trace buffer " + "for new data (default " xstr(POLL_SLEEP_MILLIS) ")." }, + + { .name = "ms_per_sample", .key='m', .arg="MS", + .doc = + "Specify the number of milliseconds per sample " + " (default " xstr(MS_PER_SAMPLE) ")." }, + + {0} +}; + +const struct argp parser_def = +{ + .options = cmd_opts, + .parser = cmd_parser, + // .args_doc = "[output file]", + .doc = + "Tool to capture and partially process Xen trace buffer data" + "\v" + "This tool is used to capture trace buffer data from Xen. The data is " + "saved in a shared memory structure to be further processed by xenmon." +}; + + +const char *argp_program_version = "xenbaked v1.3"; +const char *argp_program_bug_address = "<rob.gardner@xxxxxx>"; + + +int main(int argc, char **argv) +{ + int ret; + struct sigaction act; + + time(&start_time); + opts.outfile = 0; + opts.poll_sleep = millis_to_timespec(POLL_SLEEP_MILLIS); + opts.new_data_thresh = NEW_DATA_THRESH; + opts.ms_per_sample = MS_PER_SAMPLE; + opts.cpu_freq = CPU_FREQ; + + argp_parse(&parser_def, argc, argv, 0, 0, &opts); + fprintf(stderr, "ms_per_sample = %ld\n", opts.ms_per_sample); + + + /* ensure that if we get a signal, we'll do cleanup, then exit */ + act.sa_handler = close_handler; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + sigaction(SIGHUP, &act, NULL); + sigaction(SIGTERM, &act, NULL); + sigaction(SIGINT, &act, NULL); + + ret = monitor_tbufs(); + + dump_stats(); + msync(new_qos, sizeof(_new_qos_data), MS_SYNC); + + return ret; +} + +int domain_runnable(int domid) +{ + return new_qos->domain_info[ID(domid)].runnable; +} + + +void update_blocked_time(int domid, uint64_t now) +{ + uint64_t t_blocked; + int id = ID(domid); + + if (new_qos->domain_info[id].blocked_start_time != 0) { + if (now >= new_qos->domain_info[id].blocked_start_time) + t_blocked = now - new_qos->domain_info[id].blocked_start_time; + else + t_blocked = now + (~0ULL - new_qos->domain_info[id].blocked_start_time); + new_qos->qdata[new_qos->next_datapoint].ns_blocked[id] += t_blocked; + } + + if (domain_runnable(id)) + new_qos->domain_info[id].blocked_start_time = 0; + else + new_qos->domain_info[id].blocked_start_time = now; +} + + +// advance to next datapoint for all domains +void advance_next_datapoint(uint64_t now) +{ + int new, old, didx; + + old = new_qos->next_datapoint; + new = QOS_INCR(old); + new_qos->next_datapoint = new; + // memset(&new_qos->qdata[new], 0, sizeof(uint64_t)*(2+5*NDOMAINS)); + for (didx = 0; didx < NDOMAINS; didx++) { + new_qos->qdata[new].ns_gotten[didx] = 0; + new_qos->qdata[new].ns_allocated[didx] = 0; + new_qos->qdata[new].ns_waiting[didx] = 0; + new_qos->qdata[new].ns_blocked[didx] = 0; + new_qos->qdata[new].switchin_count[didx] = 0; + new_qos->qdata[new].io_count[didx] = 0; + } + new_qos->qdata[new].ns_passed = 0; + new_qos->qdata[new].lost_records = 0; + new_qos->qdata[new].flip_free_periods = 0; + + new_qos->qdata[new].timestamp = now; +} + + + +void qos_update_thread(int cpu, int domid, uint64_t now) +{ + int n, id; + uint64_t last_update_time, start; + int64_t time_since_update, run_time = 0; + + id = ID(domid); + + n = new_qos->next_datapoint; + last_update_time = new_qos->domain_info[id].last_update_time; + + time_since_update = now - last_update_time; + + if (time_since_update < 0) { + // what happened here? either a timestamp wraparound, or more likely, + // a slight inconsistency among timestamps from various cpu's + if (-time_since_update < billion) { + // fairly small difference, let's just adjust 'now' to be a little + // beyond last_update_time + time_since_update = -time_since_update; + } + else if ( ((~0ULL - last_update_time) < billion) && (now < billion) ) { + // difference is huge, must be a wraparound + // last_update time should be "near" ~0ULL, + // and now should be "near" 0 + time_since_update = now + (~0ULL - last_update_time); + printf("time wraparound\n"); + } + else { + // none of the above, may be an out of order record + // no good solution, just ignore and update again later + return; + } + } + + new_qos->domain_info[id].last_update_time = now; + + if (new_qos->domain_info[id].runnable_at_last_update && is_current(domid, cpu)) { + start = new_qos->domain_info[id].start_time; + if (start > now) { // wrapped around + run_time = now + (~0ULL - start); + printf("warning: start > now\n"); + } + else + run_time = now - start; + // if (run_time < 0) // should not happen + // printf("warning: run_time < 0; start = %lld now= %lld\n", start, now); + new_qos->domain_info[id].ns_oncpu_since_boot += run_time; + new_qos->domain_info[id].start_time = now; + new_qos->domain_info[id].ns_since_boot += time_since_update; +#if 1 + new_qos->qdata[n].ns_gotten[id] += run_time; + if (domid == 0 && cpu == 1) + printf("adding run time for dom0 on cpu1\r\n"); +#endif + } + + new_qos->domain_info[id].runnable_at_last_update = domain_runnable(domid); + + update_blocked_time(domid, now); + + // how much time passed since this datapoint was updated? + if (now >= new_qos->qdata[n].timestamp) { + // all is right with the world, time is increasing + new_qos->qdata[n].ns_passed += (now - new_qos->qdata[n].timestamp); + } + else { + // time wrapped around + //new_qos->qdata[n].ns_passed += (now + (~0LL - new_qos->qdata[n].timestamp)); + // printf("why timewrap?\r\n"); + } + new_qos->qdata[n].timestamp = now; +} + + +// called by dump routines to update all structures +void qos_update_all(uint64_t now, int cpu) +{ + int i; + + for (i=0; i<NDOMAINS; i++) + if (new_qos->domain_info[i].in_use) + qos_update_thread(cpu, i, now); +} + + +void qos_update_thread_stats(int cpu, int domid, uint64_t now) +{ + if (new_qos->qdata[new_qos->next_datapoint].ns_passed > (million*opts.ms_per_sample)) { + qos_update_all(now, cpu); + advance_next_datapoint(now); + return; + } + qos_update_thread(cpu, domid, now); +} + + +void qos_init_domain(int cpu, int domid, uint64_t now) +{ + int i, id; + + id = ID(domid); + + if (new_qos->domain_info[id].in_use) + return; + + + memset(&new_qos->domain_info[id], 0, sizeof(_domain_info)); + new_qos->domain_info[id].last_update_time = now; + // runnable_start_time[id] = 0; + new_qos->domain_info[id].runnable_start_time = 0; // invalidate + new_qos->domain_info[id].in_use = 1; + new_qos->domain_info[id].blocked_start_time = 0; + new_qos->domain_info[id].id = id; + if (domid == IDLE_DOMAIN_ID) + sprintf(new_qos->domain_info[id].name, "Idle Task%d", cpu); + else + sprintf(new_qos->domain_info[id].name, "Domain#%d", domid); + + for (i=0; i<NSAMPLES; i++) { + new_qos->qdata[i].ns_gotten[id] = 0; + new_qos->qdata[i].ns_allocated[id] = 0; + new_qos->qdata[i].ns_waiting[id] = 0; + new_qos->qdata[i].ns_blocked[id] = 0; + new_qos->qdata[i].switchin_count[id] = 0; + new_qos->qdata[i].io_count[id] = 0; + } +} + + +// called when a new thread gets the cpu +void qos_switch_in(int cpu, int domid, uint64_t now, unsigned long ns_alloc, unsigned long ns_waited) +{ + int id = ID(domid); + + new_qos->domain_info[id].runnable = 1; + update_blocked_time(domid, now); + new_qos->domain_info[id].blocked_start_time = 0; // invalidate + new_qos->domain_info[id].runnable_start_time = 0; // invalidate + //runnable_start_time[id] = 0; + + new_qos->domain_info[id].start_time = now; + new_qos->qdata[new_qos->next_datapoint].switchin_count[id]++; + new_qos->qdata[new_qos->next_datapoint].ns_allocated[id] += ns_alloc; + new_qos->qdata[new_qos->next_datapoint].ns_waiting[id] += ns_waited; + qos_update_thread_stats(cpu, domid, now); + set_current(cpu, id); + + // count up page flips for dom0 execution + if (id == 0) + dom0_flips = 0; +} + +// called when the current thread is taken off the cpu +void qos_switch_out(int cpu, int domid, uint64_t now, unsigned long gotten) +{ + int id = ID(domid); + int n; + + if (!is_current(id, cpu)) { + // printf("switching out domain %d but it is not current. gotten=%ld\r\n", id, gotten); + } + + if (gotten == 0) { + printf("gotten==0 in qos_switchout(domid=%d)\n", domid); + } + + if (gotten < 100) { + printf("gotten<100ns in qos_switchout(domid=%d)\n", domid); + } + + + n = new_qos->next_datapoint; +#if 0 + new_qos->qdata[n].ns_gotten[id] += gotten; + if (gotten > new_qos->qdata[n].ns_passed) + printf("inconsistency #257, diff = %lld\n", + gotten - new_qos->qdata[n].ns_passed ); +#endif + new_qos->domain_info[id].ns_oncpu_since_boot += gotten; + new_qos->domain_info[id].runnable_start_time = now; + // runnable_start_time[id] = now; + qos_update_thread_stats(cpu, id, now); + + // process dom0 page flips + if (id == 0) + if (dom0_flips == 0) + new_qos->qdata[n].flip_free_periods++; +} + +// called when domain is put to sleep, may also be called +// when thread is already asleep +void qos_state_sleeping(int cpu, int domid, uint64_t now) +{ + int id = ID(domid); + + if (!domain_runnable(id)) // double call? + return; + + new_qos->domain_info[id].runnable = 0; + new_qos->domain_info[id].blocked_start_time = now; + new_qos->domain_info[id].runnable_start_time = 0; // invalidate + // runnable_start_time[id] = 0; // invalidate + qos_update_thread_stats(cpu, domid, now); +} + + + +void qos_kill_thread(int domid) +{ + new_qos->domain_info[ID(domid)].in_use = 0; +} + + +// called when thread becomes runnable, may also be called +// when thread is already runnable +void qos_state_runnable(int cpu, int domid, uint64_t now) +{ + int id = ID(domid); + + if (domain_runnable(id)) // double call? + return; + new_qos->domain_info[id].runnable = 1; + update_blocked_time(domid, now); + + qos_update_thread_stats(cpu, domid, now); + + new_qos->domain_info[id].blocked_start_time = 0; /* invalidate */ + new_qos->domain_info[id].runnable_start_time = now; + // runnable_start_time[id] = now; +} + + +void qos_count_packets(domid_t domid, uint64_t now) +{ + int i, id = ID(domid); + _new_qos_data *cpu_data; + + for (i=0; i<NCPU; i++) { + cpu_data = cpu_qos_data[i]; + if (cpu_data->domain_info[id].in_use) { + cpu_data->qdata[cpu_data->next_datapoint].io_count[id]++; + } + } + + new_qos->qdata[new_qos->next_datapoint].io_count[0]++; + dom0_flips++; +} + + +int domain_ok(int cpu, int domid, uint64_t now) +{ + if (domid == IDLE_DOMAIN_ID) + domid = NDOMAINS-1; + if (domid < 0 || domid >= NDOMAINS) { + printf("bad domain id: %d\n", domid); + return 0; + } + if (new_qos->domain_info[domid].in_use == 0) + qos_init_domain(cpu, domid, now); + return 1; +} + + +void process_record(int cpu, struct t_rec *r) +{ + uint64_t now; + + + new_qos = cpu_qos_data[cpu]; + + rec_count++; + + now = ((double)r->cycles) / (opts.cpu_freq / 1000.0); + + log_event(r->event); + + switch (r->event) { + + case TRC_SCHED_SWITCH_INFPREV: + // domain data[0] just switched out and received data[1] ns of cpu time + if (domain_ok(cpu, r->data[0], now)) + qos_switch_out(cpu, r->data[0], now, r->data[1]); + // printf("ns_gotten %ld\n", r->data[1]); + break; + + case TRC_SCHED_SWITCH_INFNEXT: + // domain data[0] just switched in and + // waited data[1] ns, and was allocated data[2] ns of cpu time + if (domain_ok(cpu, r->data[0], now)) + qos_switch_in(cpu, r->data[0], now, r->data[2], r->data[1]); + break; + + case TRC_SCHED_DOM_ADD: + if (domain_ok(cpu, r->data[0], now)) + qos_init_domain(cpu, r->data[0], now); + break; + + case TRC_SCHED_DOM_REM: + if (domain_ok(cpu, r->data[0], now)) + qos_kill_thread(r->data[0]); + break; + + case TRC_SCHED_SLEEP: + if (domain_ok(cpu, r->data[0], now)) + qos_state_sleeping(cpu, r->data[0], now); + break; + + case TRC_SCHED_WAKE: + if (domain_ok(cpu, r->data[0], now)) + qos_state_runnable(cpu, r->data[0], now); + break; + + case TRC_SCHED_BLOCK: + if (domain_ok(cpu, r->data[0], now)) + qos_state_sleeping(cpu, r->data[0], now); + break; + + case TRC_MEM_PAGE_GRANT_TRANSFER: + if (domain_ok(cpu, r->data[0], now)) + qos_count_packets(r->data[0], now); + break; + + default: + break; + } + new_qos = NULL; +} + + + diff -r 60bf9aa39043 -r bb0e5f7f94fd tools/xenmon/xenbaked.h --- /dev/null Tue Nov 15 14:56:47 2005 +++ b/tools/xenmon/xenbaked.h Tue Nov 15 15:24:31 2005 @@ -0,0 +1,101 @@ +/****************************************************************************** + * tools/xenbaked.h + * + * Header file for xenbaked + * + * Copyright (C) 2005 by Hewlett Packard, Palo Alto and Fort Collins + * + * Authors: Diwaker Gupta, diwaker.gupta@xxxxxx + * Rob Gardner, rob.gardner@xxxxxx + * Lucy Cherkasova, lucy.cherkasova.hp.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __QOS_H__ +#define __QOS_H__ + +///// qos stuff +#define million 1000000LL +#define billion 1000000000LL + +#define QOS_ADD(N,A) ((N+A)<(NSAMPLES-1) ? (N+A) : A) +#define QOS_INCR(N) ((N<(NSAMPLES-2)) ? (N+1) : 0) +#define QOS_DECR(N) ((N==0) ? (NSAMPLES-1) : (N-1)) + +#define MAX_NAME_SIZE 32 +#define IDLE_DOMAIN_ID 32767 + +/* Number of domains we can keep track of in memory */ +#define NDOMAINS 32 + +/* Number of data points to keep */ +#define NSAMPLES 100 + + +// per domain stuff +typedef struct +{ + uint64_t last_update_time; + uint64_t start_time; // when the thread started running + uint64_t runnable_start_time; // when the thread became runnable + uint64_t blocked_start_time; // when the thread became blocked + uint64_t ns_since_boot; // time gone by since boot + uint64_t ns_oncpu_since_boot; // total cpu time used by thread since boot + // uint64_t ns_runnable_since_boot; + int runnable_at_last_update; // true if the thread was runnable last time we checked. + int runnable; // true if thread is runnable right now + // tells us something about what happened during the + // sample period that we are analysing right now + int in_use; // + domid_t id; + char name[MAX_NAME_SIZE]; +} _domain_info; + + + +typedef struct +{ + struct + { +// data point: +// stuff that is recorded once for each measurement interval + uint64_t ns_gotten[NDOMAINS]; // ns used in the last sample period + uint64_t ns_allocated[NDOMAINS]; // ns allocated by scheduler + uint64_t ns_waiting[NDOMAINS]; // ns spent waiting to execute, ie, time from + // becoming runnable until actually running + uint64_t ns_blocked[NDOMAINS]; // ns spent blocked + uint64_t switchin_count[NDOMAINS]; // number of executions of the domain + uint64_t io_count[NDOMAINS]; + uint64_t ns_passed; // ns gone by on the wall clock, ie, the sample period + uint64_t timestamp; + uint64_t lost_records; // # of lost trace records this time period + uint64_t flip_free_periods; // # of executions of dom0 in which no page flips happened + } qdata[NSAMPLES]; + + _domain_info domain_info[NDOMAINS]; + + // control information + int next_datapoint; + int ncpu; + int structlen; + + // parameters + int measurement_frequency; // for example + +} _new_qos_data; + + + +#endif diff -r 60bf9aa39043 -r bb0e5f7f94fd tools/xenmon/xenmon.py --- /dev/null Tue Nov 15 14:56:47 2005 +++ b/tools/xenmon/xenmon.py Tue Nov 15 15:24:31 2005 @@ -0,0 +1,578 @@ +#!/usr/bin/env python + +##################################################################### +# xenmon is a front-end for xenbaked. +# There is a curses interface for live monitoring. XenMon also allows +# logging to a file. For options, run python xenmon.py -h +# +# Copyright (C) 2005 by Hewlett Packard, Palo Alto and Fort Collins +# Authors: Lucy Cherkasova, lucy.cherkasova@xxxxxx +# Rob Gardner, rob.gardner@xxxxxx +# Diwaker Gupta, diwaker.gupta@xxxxxx +##################################################################### +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; under version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +##################################################################### + +import mmap +import struct +import os +import time +import optparse as _o +import curses as _c +import math +import sys + +# constants +NSAMPLES = 100 +NDOMAINS = 32 + +# the struct strings for qos_info +ST_DOM_INFO = "6Q4i32s" +ST_QDATA = "%dQ" % (6*NDOMAINS + 4) + +# size of mmaped file +QOS_DATA_SIZE = struct.calcsize(ST_QDATA)*NSAMPLES + struct.calcsize(ST_DOM_INFO)*NDOMAINS + struct.calcsize("4i") + +# location of mmaped file, hard coded right now +SHM_FILE = "/tmp/xenq-shm" + +# format strings +TOTALS = 15*' ' + "%6.2f%%" + 35*' ' + "%6.2f%%" + +ALLOCATED = "Allocated" +GOTTEN = "Gotten" +BLOCKED = "Blocked" +WAITED = "Waited" +IOCOUNT = "I/O Count" +EXCOUNT = "Exec Count" + +# globals +# our curses screen +stdscr = None + +# parsed options +options, args = None, None + +# the optparse module is quite smart +# to see help, just run xenmon -h +def setup_cmdline_parser(): + parser = _o.OptionParser() + parser.add_option("-l", "--live", dest="live", action="store_true", + default=True, help = "show the ncurses live monitoring frontend (default)") + parser.add_option("-n", "--notlive", dest="live", action="store_false", + default="True", help = "write to file instead of live monitoring") + parser.add_option("-p", "--prefix", dest="prefix", + default = "log", help="prefix to use for output files") + parser.add_option("-t", "--time", dest="duration", + action="store", type="int", default=10, + help="stop logging to file after this much time has elapsed (in seconds). set to 0 to keep logging indefinitely") + parser.add_option("-i", "--interval", dest="interval", + action="store", type="int", default=1000, + help="interval for logging (in ms)") + parser.add_option("--ms_per_sample", dest="mspersample", + action="store", type="int", default=100, + help = "determines how many ms worth of data goes in a sample") + return parser + +# encapsulate information about a domain +class DomainInfo: + def __init__(self): + self.allocated_samples = [] + self.gotten_samples = [] + self.blocked_samples = [] + self.waited_samples = [] + self.execcount_samples = [] + self.iocount_samples = [] + self.ffp_samples = [] + + def gotten_stats(self, passed): + total = float(sum(self.gotten_samples)) + per = 100*total/passed + exs = sum(self.execcount_samples) + if exs > 0: + avg = total/exs + else: + avg = 0 + return [total/(float(passed)/10**9), per, avg] + + def waited_stats(self, passed): + total = float(sum(self.waited_samples)) + per = 100*total/passed + exs = sum(self.execcount_samples) + if exs > 0: + avg = total/exs + else: + avg = 0 + return [total/(float(passed)/10**9), per, avg] + + def blocked_stats(self, passed): + total = float(sum(self.blocked_samples)) + per = 100*total/passed + ios = sum(self.iocount_samples) + if ios > 0: + avg = total/float(ios) + else: + avg = 0 + return [total/(float(passed)/10**9), per, avg] + + def allocated_stats(self, passed): + total = sum(self.allocated_samples) + exs = sum(self.execcount_samples) + if exs > 0: + return float(total)/exs + else: + return 0 + + def ec_stats(self, passed): + total = float(sum(self.execcount_samples))/(float(passed)/10**9) + return total + + def io_stats(self, passed): + total = float(sum(self.iocount_samples)) + exs = sum(self.execcount_samples) + if exs > 0: + avg = total/exs + else: + avg = 0 + return [total/(float(passed)/10**9), avg] + + def stats(self, passed): + return [self.gotten_stats(passed), self.allocated_stats(passed), self.blocked_stats(passed), + self.waited_stats(passed), self.ec_stats(passed), self.io_stats(passed)] + +# report values over desired interval +def summarize(startat, endat, duration, samples): + dominfos = {} + for i in range(0, NDOMAINS): + dominfos[i] = DomainInfo() + + passed = 1 # to prevent zero division + curid = startat + numbuckets = 0 + lost_samples = [] + ffp_samples = [] + + while passed < duration: + for i in range(0, NDOMAINS): + dominfos[i].gotten_samples.append(samples[curid][0*NDOMAINS + i]) + dominfos[i].allocated_samples.append(samples[curid][1*NDOMAINS + i]) + dominfos[i].waited_samples.append(samples[curid][2*NDOMAINS + i]) + dominfos[i].blocked_samples.append(samples[curid][3*NDOMAINS + i]) + dominfos[i].execcount_samples.append(samples[curid][4*NDOMAINS + i]) + dominfos[i].iocount_samples.append(samples[curid][5*NDOMAINS + i]) + + passed += samples[curid][6*NDOMAINS] + lost_samples.append(samples[curid][6*NDOMAINS + 2]) + ffp_samples.append(samples[curid][6*NDOMAINS + 3]) + + numbuckets += 1 + + if curid > 0: + curid -= 1 + else: + curid = NSAMPLES - 1 + if curid == endat: + break + + lostinfo = [min(lost_samples), sum(lost_samples), max(lost_samples)] + ffpinfo = [min(ffp_samples), sum(ffp_samples), max(ffp_samples)] + ldoms = map(lambda x: dominfos[x].stats(passed), range(0, NDOMAINS)) + + return [ldoms, lostinfo, ffpinfo] + +# scale microseconds to milliseconds or seconds as necessary +def time_scale(ns): + if ns < 1000: + return "%4.2f ns" % float(ns) + elif ns < 1000*1000: + return "%4.2f us" % (float(ns)/10**3) + elif ns < 10**9: + return "%4.2f ms" % (float(ns)/10**6) + else: + return "%4.2f s" % (float(ns)/10**9) + +# paint message on curses screen, but detect screen size errors +def display(scr, row, col, str, attr=0): + try: + scr.addstr(row, col, str, attr) + except: + scr.erase() + _c.nocbreak() + scr.keypad(0) + _c.echo() + _c.endwin() + print "Your terminal screen is not big enough; Please resize it." + print "row=%d, col=%d, str='%s'" % (row, col, str) + sys.exit(1) + + +# the live monitoring code +def show_livestats(): + cpu = 0 # cpu of interest to display data for + ncpu = 1 # number of cpu's on this platform + slen = 0 # size of shared data structure, incuding padding + + # mmap the (the first chunk of the) file + shmf = open(SHM_FILE, "r+") + shm = mmap.mmap(shmf.fileno(), QOS_DATA_SIZE) + + samples = [] + doms = [] + + # initialize curses + stdscr = _c.initscr() + _c.noecho() + _c.cbreak() + + stdscr.keypad(1) + stdscr.timeout(1000) + [maxy, maxx] = stdscr.getmaxyx() + + + + # display in a loop + while True: + + for cpuidx in range(0, ncpu): + + # calculate offset in mmap file to start from + idx = cpuidx * slen + + + samples = [] + doms = [] + + # read in data + for i in range(0, NSAMPLES): + len = struct.calcsize(ST_QDATA) + sample = struct.unpack(ST_QDATA, shm[idx:idx+len]) + samples.append(sample) + idx += len + + for i in range(0, NDOMAINS): + len = struct.calcsize(ST_DOM_INFO) + dom = struct.unpack(ST_DOM_INFO, shm[idx:idx+len]) + doms.append(dom) + idx += len + + len = struct.calcsize("4i") + oldncpu = ncpu + (next, ncpu, slen, freq) = struct.unpack("4i", shm[idx:idx+len]) + idx += len + + # xenbaked tells us how many cpu's it's got, so re-do + # the mmap if necessary to get multiple cpu data + if oldncpu != ncpu: + shm = mmap.mmap(shmf.fileno(), ncpu*slen) + + # if we've just calculated data for the cpu of interest, then + # stop examining mmap data and start displaying stuff + if cpuidx == cpu: + break + + # calculate starting and ending datapoints; never look at "next" since + # it represents live data that may be in transition. + startat = next - 1 + if next + 10 < NSAMPLES: + endat = next + 10 + else: + endat = 10 + + # get summary over desired interval + [h1, l1, f1] = summarize(startat, endat, 10**9, samples) + [h2, l2, f2] = summarize(startat, endat, 10 * 10**9, samples) + + # the actual display code + row = 0 + display(stdscr, row, 1, "CPU = %d" % cpu, _c.A_STANDOUT) + + display(stdscr, row, 10, "%sLast 10 seconds%sLast 1 second" % (6*' ', 30*' '), _c.A_BOLD) + row +=1 + display(stdscr, row, 1, "%s" % ((maxx-2)*'=')) + + total_h1_cpu = 0 + total_h2_cpu = 0 + + for dom in range(0, NDOMAINS): + if h1[dom][0][1] > 0 or dom == NDOMAINS - 1: + # display gotten + row += 1 + col = 2 + display(stdscr, row, col, "%d" % dom) + col += 4 + display(stdscr, row, col, "%s" % time_scale(h2[dom][0][0])) + col += 12 + display(stdscr, row, col, "%3.2f%%" % h2[dom][0][1]) + col += 12 + display(stdscr, row, col, "%s/ex" % time_scale(h2[dom][0][2])) + col += 18 + display(stdscr, row, col, "%s" % time_scale(h1[dom][0][0])) + col += 12 + display(stdscr, row, col, "%3.2f%%" % h1[dom][0][1]) + col += 12 + display(stdscr, row, col, "%s/ex" % time_scale(h1[dom][0][2])) + col += 18 + display(stdscr, row, col, "Gotten") + + # display allocated + row += 1 + col = 2 + display(stdscr, row, col, "%d" % dom) + col += 28 + display(stdscr, row, col, "%s/ex" % time_scale(h2[dom][1])) + col += 42 + display(stdscr, row, col, "%s/ex" % time_scale(h1[dom][1])) + col += 18 + display(stdscr, row, col, "Allocated") + + # display blocked + row += 1 + col = 2 + display(stdscr, row, col, "%d" % dom) + col += 4 + display(stdscr, row, col, "%s" % time_scale(h2[dom][2][0])) + col += 12 + display(stdscr, row, col, "%3.2f%%" % h2[dom][2][1]) + col += 12 + display(stdscr, row, col, "%s/io" % time_scale(h2[dom][2][2])) + col += 18 + display(stdscr, row, col, "%s" % time_scale(h1[dom][2][0])) + col += 12 + display(stdscr, row, col, "%3.2f%%" % h1[dom][2][1]) + col += 12 + display(stdscr, row, col, "%s/io" % time_scale(h1[dom][2][2])) + col += 18 + display(stdscr, row, col, "Blocked") + + # display waited + row += 1 + col = 2 + display(stdscr, row, col, "%d" % dom) + col += 4 + display(stdscr, row, col, "%s" % time_scale(h2[dom][3][0])) + col += 12 + display(stdscr, row, col, "%3.2f%%" % h2[dom][3][1]) + col += 12 + display(stdscr, row, col, "%s/ex" % time_scale(h2[dom][3][2])) + col += 18 + display(stdscr, row, col, "%s" % time_scale(h1[dom][3][0])) + col += 12 + display(stdscr, row, col, "%3.2f%%" % h1[dom][3][1]) + col += 12 + display(stdscr, row, col, "%s/ex" % time_scale(h1[dom][3][2])) + col += 18 + display(stdscr, row, col, "Waited") + + # display ex count + row += 1 + col = 2 + display(stdscr, row, col, "%d" % dom) + + col += 28 + display(stdscr, row, col, "%d/s" % h2[dom][4]) + col += 42 + display(stdscr, row, col, "%d" % h1[dom][4]) + col += 18 + display(stdscr, row, col, "Execution count") + + # display io count + row += 1 + col = 2 + display(stdscr, row, col, "%d" % dom) + col += 4 + display(stdscr, row, col, "%d/s" % h2[dom][5][0]) + col += 24 + display(stdscr, row, col, "%d/ex" % h2[dom][5][1]) + col += 18 + display(stdscr, row, col, "%d" % h1[dom][5][0]) + col += 24 + display(stdscr, row, col, "%3.2f/ex" % h1[dom][5][1]) + col += 18 + display(stdscr, row, col, "I/O Count") + + #row += 1 + #stdscr.hline(row, 1, '-', maxx - 2) + total_h1_cpu += h1[dom][0][1] + total_h2_cpu += h2[dom][0][1] + + + row += 1 + display(stdscr, row, 2, TOTALS % (total_h2_cpu, total_h1_cpu)) + row += 1 +# display(stdscr, row, 2, +# "\tFFP: %d (Min: %d, Max: %d)\t\t\tFFP: %d (Min: %d, Max %d)" % +# (math.ceil(f2[1]), f2[0], f2[2], math.ceil(f1[1]), f1[0], f1[2]), _c.A_BOLD) + + if l1[1] > 1 : + row += 1 + display(stdscr, row, 2, + "\tRecords lost: %d (Min: %d, Max: %d)\t\t\tRecords lost: %d (Min: %d, Max %d)" % + (math.ceil(l2[1]), l2[0], l2[2], math.ceil(l1[1]), l1[0], l1[2]), _c.A_BOLD) + + # grab a char from tty input; exit if interrupt hit + try: + c = stdscr.getch() + except: + break + + # q = quit + if c == ord('q'): + break + + # c = cycle to a new cpu of interest + if c == ord('c'): + cpu = (cpu + 1) % ncpu + + stdscr.erase() + + _c.nocbreak() + stdscr.keypad(0) + _c.echo() + _c.endwin() + shm.close() + shmf.close() + + +# simple functions to allow initialization of log files without actually +# physically creating files that are never used; only on the first real +# write does the file get created +class Delayed(file): + def __init__(self, filename, mode): + self.filename = filename + self.saved_mode = mode + self.delay_data = "" + self.opened = 0 + + def delayed_write(self, str): + self.delay_data = str + + def write(self, str): + if not self.opened: + self.file = open(self.filename, self.saved_mode) + self.opened = 1 + self.file.write(self.delay_data) + self.file.write(str) + + def flush(self): + if self.opened: + self.file.flush() + + def close(self): + if self.opened: + self.file.close() + + +def writelog(): + global options + + ncpu = 1 # number of cpu's + slen = 0 # size of shared structure inc. padding + + shmf = open(SHM_FILE, "r+") + shm = mmap.mmap(shmf.fileno(), QOS_DATA_SIZE) + + interval = 0 + outfiles = {} + for dom in range(0, NDOMAINS): + outfiles[dom] = Delayed("%s-dom%d.log" % (options.prefix, dom), 'w') + outfiles[dom].delayed_write("# passed cpu dom cpu(tot) cpu(%) cpu/ex allocated/ex blocked(tot) blocked(%) blocked/io waited(tot) waited(%) waited/ex ex/s io(tot) io/ex\n") + + while options.duration == 0 or interval < (options.duration * 1000): + for cpuidx in range(0, ncpu): + idx = cpuidx * slen # offset needed in mmap file + + + samples = [] + doms = [] + + for i in range(0, NSAMPLES): + len = struct.calcsize(ST_QDATA) + sample = struct.unpack(ST_QDATA, shm[idx:idx+len]) + samples.append(sample) + idx += len + + for i in range(0, NDOMAINS): + len = struct.calcsize(ST_DOM_INFO) + dom = struct.unpack(ST_DOM_INFO, shm[idx:idx+len]) + doms.append(dom) + idx += len + + len = struct.calcsize("4i") + oldncpu = ncpu + (next, ncpu, slen, freq) = struct.unpack("4i", shm[idx:idx+len]) + idx += len + + if oldncpu != ncpu: + shm = mmap.mmap(shmf.fileno(), ncpu*slen) + + startat = next - 1 + if next + 10 < NSAMPLES: + endat = next + 10 + else: + endat = 10 + + [h1,l1, f1] = summarize(startat, endat, options.interval * 10**6, samples) + for dom in range(0, NDOMAINS): + if h1[dom][0][1] > 0 or dom == NDOMAINS - 1: + outfiles[dom].write("%.3f %d %d %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n" % + (interval, cpuidx, dom, + h1[dom][0][0], h1[dom][0][1], h1[dom][0][2], + h1[dom][1], + h1[dom][2][0], h1[dom][2][1], h1[dom][2][2], + h1[dom][3][0], h1[dom][3][1], h1[dom][3][2], + h1[dom][4], + h1[dom][5][0], h1[dom][5][1])) + outfiles[dom].flush() + + interval += options.interval + time.sleep(1) + + for dom in range(0, NDOMAINS): + outfiles[dom].close() + +# start xenbaked +def start_xenbaked(): + global options + global args + + os.system("killall -9 xenbaked") + # assumes that xenbaked is in your path + os.system("xenbaked --ms_per_sample=%d &" % + options.mspersample) + time.sleep(1) + +# stop xenbaked +def stop_xenbaked(): + os.system("killall -s INT xenbaked") + +def main(): + global options + global args + global domains + + parser = setup_cmdline_parser() + (options, args) = parser.parse_args() + + start_xenbaked() + if options.live: + show_livestats() + else: + try: + writelog() + except: + print 'Quitting.' + stop_xenbaked() + +if __name__ == "__main__": + main() _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |