next up previous contents
Next: PTLsim/X Architecture Details Up: PTLsim/X: Full System SMP/SMT Previous: Background   Contents

Subsections

Getting Started with PTLsim/X

NOTE: This part of the manual is relevant only if you are using the full-system PTLsim/X. If you are looking for the userspace-only version, please skip this entire part and read Part II instead.

1]1WARNING: PTLsim/X assumes fairly high level of familiarity with Xen and the Linux kernel. If you have never compiled your own Linux kernel or if you are not yet running Xen or are unsure how to create and use domains, STOP NOW and become familiar with Xen itself before attempting to use PTLsim/X. The following sections all assume you are familiar with Xen, at least from a system administration perspective. We cannot provide support for Xen-related issues unless they are caused by PTLsim.

Building PTLsim/X

Prerequisites:

Quick Start Steps:

All files listed below can be downloaded from https://ptlsim.org/download.php.

1]1IMPORTANT: The instructions below refer to specific versions of various files (i.e., Xen hypervisor, Linux kernel, etc.). We regularly update the versions of these files, and newer PTLsim/X versions may not work correctly with older kernel and/or hypervisor versions (i.e. the versions should be matching). The following instructions are therefore for informational purposes only; always check the PTLsim web site's download page for the latest versions of these files. The following versions are correct as of September 20th, 2007

  1. Set up Xen with PTLsim/X extensions:

  2. Set up sample virtual machine and disk images:

  3. Setup PTLsim itself:


Running PTLsim

PTLsim is run in domain 0 as root, for instance by using the ``sudo ptlsim ...'' command. The -domainN option is used to specify the domain to access. The following scenarios show by example how this is done.

Booting Linux under PTLsim

In the following examples, we will assume the target domain is called ptlvm.

Start your domain as follows:

sudo xm create domainname -paused

sudo xm list

sudo xm console domainname

The -paused option tells Xen to pause the domain as soon as it's created, so we can run the entire boot process under PTLsim.

The xm list command will print the domain ID assigned to ptlvm. On our test machine, the output looks like:

yourst [typhoon /project/ptlsim] sudo xm create ptlvm -paused; sudo xm list; sudo xm console ptlvm;

Using config file "ptlvm".

Started domain ptlvm

Name                                      ID Mem(MiB) VCPUs State   Time(s)

Domain-0                                   0     7877     4 r---    137.9

ptlvm                                     21      128     1 -p--      0.0

You may also want to give the PTLsim domain a low priority; otherwise it may cause the system to respond slowly. This can be done by adding:

sudo xm sched-credit -d ptlvm -w 16

Open another console and start PTLsim on this domain (using the domain ID ``21'' given in the example above):

sudo ./ptlsim -domain ptlvm -logfile ptlsim.log -native

The resulting output:

//

//  PTLsim: Cycle Accurate x86-64 Full System Simulator

//  Copyright 1999-2007 Matt T. Yourst <>

//

//  Revision 225 (2007-09-21)

//  Built Sep  21 2007 16:21:36 on tidalwave.lab.ptlsim.org using gcc-4.2

//  Running on typhoon.lab.ptlsim.org

//

Processing -domain 21 -logfile ptlsim.log -native

System Information:

  Running on hypervisor version xen-3.0-x86_64-ptlsim

  Xen is mapped at virtual address 0xffff800000000000

  PTLsim is running across 1 VCPUs:

    VCPU 0: 2202 MHz

Memory Layout:

  System:                 524208 pages,    2096832 KB

  Domain:                  32768 pages,     131072 KB

  PTLsim reserved:          8192 pages,      32768 KB

  Page Tables:               275 pages,       1100 KB

  PTLsim image:              407 pages,       1628 KB

  Heap:                     7510 pages,      30040 KB

  Stack:                     256 pages,       1024 KB

Interfaces:

  PTLsim page table:      282898

  Shared info mfn:          4056

  Shadow shinfo mfn:      295164

  PTLsim hostcall:                event channel    3

  PTLsim upcall:                  event channel    4

  Switched to native mode

Back in the Xen console for the domain, you'll see the familiar Linux boot messages:

Bootdata ok (command line is  nousb noide root=/dev/hda1 xencons=ttyS console=ttyS0)

Linux version 2.6.18-mtyrel-k8-64bit-xen (yourst@tidalwave) (gcc version 4.1.0 (SUSE Linux)) #2 Sun Oct 8 02:29:10 EDT 2006

BIOS-provided physical RAM map:

 Xen: 0000000000000000 - 0000000008800000 (usable)

No mptable found.

Built 1 zonelists.  Total pages: 34816

Kernel command line:  nousb noide root=/dev/hda1 xencons=ttyS console=ttyS0

Initializing CPU#0

PID hash table entries: 1024 (order: 10, 8192 bytes)

Xen reported: 2202.808 MHz processor.

Console: colour dummy device 80x25

Dentry cache hash table entries: 32768 (order: 6, 262144 bytes)

Inode-cache hash table entries: 16384 (order: 5, 131072 bytes)

Software IO TLB disabled

Memory: 123180k/139264k available (2783k kernel code, 7728k reserved, 959k data, 184k init)

Calibrating delay using timer specific routine.. 4407.14 BogoMIPS (lpj=2203570)

...

NET: Registered protocol family 1

NET: Registered protocol family 17

VFS: Mounted root (ext2 filesystem) readonly.

Welcome to the PTLsim demo machine!

root [ptlsim /] cat /proc/cpuinfo

You'll notice how we specified the ``-native'' option to speed up the boot process by running all code on the real CPU rather than PTLsim's synthetic CPU model. Booting Linux within PTLsim is slow since the kernel often executes several billion instructions before finally presenting a command line.

Running Simulations: PTLctl

At this point, we would like to start an actual simulation run. For purposes of illustration, this run is composed of three actions:

In the first example, we will start this run from within the running domain using ptlctl (PTLsim controller), a program supplied with PTLsim. PTLctl is actually an example program showing the use of PTLsim hypercalls (``PTL calls''), special x86 instructions that can be used to control a domain's own simulation. More information on the PTLcall API is in Section 14.4.

To conduct this simulation, the ptlctlcommand is used within the running virtual machine (by typing it at the domain's console); it is not run on the host system at all:

root [ptlsim /] tar zc usr lib | tar ztv > /tmp/allfiles.txt &

[1] 775

root [ptlsim /] ptlctl -core ooo -stopinsns 100m -run : -core seq -stopinsns 200m -run : -native

Sending flush and command list to PTLsim hypervisor:

  -core ooo -stopinsns 100m -run

  -core seq -stopinsns 200m -run

  -native

PTLsim returned rc 0

root [ptlsim /] 

The first command simply runs several CPU-intensive multi-threaded processes in the background for simulation purposes (in this case, compressing and uncompressing files in the virtual machine's filesystem).

The second ptlctl command submits the three simulation actions to PTLsim, separated by colons (``:'').

At the PTLsim console, the following output is produced (the cycle counters will update regularly):

...

Breakout request received from native mode

  Switched to simulation mode

Returned from switch to native: now back in sim

Processing -core ooo -stopinsns 100m -run

  Completed       75258330 cycles,      100000000 commits:    461819 cycles/sec,    795201, insns/sec

Processing -core seq -stopinsns 200m -run

  Completed      200000000 cycles,      200000000 commits:   6941302 cycles/sec,   6941302, insns/sec

Processing -native

  Switched to native mode

Notice how the command list is always terminated by a final simulation action (in this case, -native). If the command list only had one simulation run with a fixed duration, once that simulation ended, the domain would freeze, since PTLsim would pause until another command arrived. However, since the domain is frozen, the next command would never arrive: there is no way to execute the ptlctl program a second time if the domain is stopped. To avoid this sort of deadlock, ptlctllets the user atomically submit batches of multiple commands as shown ahove.

This powerful capability allows ``self-directed'' simulation scripts (i.e. standard shell scripts), in which ptlctlis run immediately before starting a benchmark program, then ptlctlis run again after the program exits to end the simulation and switch back to native mode.

PTLsim/X Options

In Section 10.3, the configuration options common to both userspace PTLsim and full system PTLsim/X wer listed. PTLsim/X also introduces a number of special options only applicable to full system simulation:

Actions:


Live Updates of Configuration Options

PTLsim/X provides the ability to send commands and modify configuration options in the running simulation from another console on the host system. This is different from how the ptlctl program is used inside the target domain to script simulations: in this case, the commands are submitted asynchronously from the host system.

For instance,

sudo ptlsim -native -domain ptlvm

will immediately switch the target domain back to native mode.

To reset the log level in the middle of a simulation run, use the following:

sudo ptlsim -domain ptlvm -loglevel 99 : -run

ptlsim: Sending request '-domain ptlvm -loglevel 99 : -run' to domain 12...OK

(This is an example only! Using -loglevel 99 will create huge log files).

Most options (such as -loglevel, -stoprip, etc.) can be updated at any time in this manner.

To end a simulation currently in progress, use this:

sudo ptlsim -domain ptlvm -kill

This will force PTLsim to cleanly exit.


Command Scripts

PTLsim supports command scripts, in which a file containing a list of commands is passed on the PTLsim command line as follows:

sudo ./ptlsim -domain name @ptlvm.cmd

where ptlvm.cmd (specified following the ``@'' operator) contains the example lines:

# Configuration options:

-logfile ptlsim.log -loglevel 4 -stats ptlsim.stats -snapshot-cycles 10m

# Run the simulation

-core seq -run -stopinsns 20m

-core ooo -run -stopinsns 100m

-native      # All done (switch to native mode)

These commands are executed by PTLsim one at a time, waiting until the previous command completes before starting the next. Notice the use of comments (starting with ``#''), and how configuration options can be spread across lines if desired. This mode is very useful for specifying breakpoints using -stoprip and similar options; when the target RIP is reached, the simulation stops and the next command in the command list is executed.

Command scripts can be nested (i.e. a script can itself include other scripts using @scriptname). When multiple commands are given on the command line separated by colons (``:''), any @scriptname clauses are processed after all other commands on the command line.

Working with Checkpoints

1]1We maintain a tutorial on how to set up checkpoints and perform advanced checkpointing techniques at https://ptlsim.org/capswiki/index.php/SPEC_2006. Note that this address is subject to change.

Xen provides the ability to capture the state of a domain into a checkpoint file stored on disk. PTLsim can leverage this capability to start simulation from a checkpoint, avoiding the need to go through the entire boot process, and allowing precisely reproducable results across multiple simulation runs.

To create a checkpoint, boot the domain in native mode without PTLsim running, and bring the domain to the point where you would like to begin simulation. Then, in another console, run:

sudo xm save ptlvm /tmp/ptlvm.img

If you're using our sample disk images, this command will pause until you do the following from within the domain:

echo checkpoint > /proc/xen/checkpoint

This facility allows very precise checkpoint placement, even by writing to this special file from within a benchmark.

To restore the domain to that checkpoint, run:

sudo xm restore /tmp/ptlvm.img -paused

sudo xm list

sudo xm console ptlvm

PTLsim can then be started in the normal manner, by specifying -domain domainname. If the checkpoint was made while the domain waited for input (e.g. at a shell command line), you may have to press a few keys to get any response from its console.

To exit PTLsim, use ``sudo ptlsim -kill -domain X'' from another console. To abort PTLsim immediately, use Ctrl+C on the ptlsim process, then type ``xm kill ptlvm'' to destroy the domain.


The Nature of Time

Full system simulation poses some difficult philosophical questions about the nature of time itself and the relativistic phenomenon of ``time dilation''. Specifically, if a simulator runs X times slower than the native CPU, both external interrupts and timer interrupts should theoretically be generated X times slower than in the real world. This is critical for obtaining accurate simulation results: for events like network traffic, if a real network device fed interrupts into the domain in realtime, and the simulator injected these interrupts into the simulation at the same rate, they would appear to arrive thousands of times faster than any physical network interface could deliver them. This can easily result in a livelock situation not possible in a real machine; at the very least it will deliver misleading performance results.

On the other hand, interacting with a domain running at the ``correct'' rate according to its own simulated clock can be unpleasant for users. For instance, if the ``sleep 1'' command is run in a Linux domain under PTLsim, instead of sleeping for 1 second of wall clock time (as perceived by the user), the domain will wait until 1 billion cycles have been fully simulated (assuming the simulated processor frequency is 1 GHz). This is because PTLsim keys interrupt delivery and all timers to the simulated cycle number in which the interrupt should arrive (based on the core clock frequency). In addition to being annoying, this behavior will massively confuse network applications that rely on precise timing information: a TCP/IP endpoint outside the domain will not expect packets to arrive thousands of times slower than its own realtime clock expects, resulting in retransmissions and timeouts that would never occur if both endpoints were inside the same ``time dilated'' domain.

Rather than attempt to solve this philosophical dilemma, PTLsim allows users to choose the options that best suit their simulation accuracy needs. The following options control the notion of time inside the simulation:

Other Options

PTLsim/X has a few additional options related to full system simulation:

All other options in Section 10.3 (unless otherwise noted) are common to both userspace PTLsim and full system PTLsim/X.


next up previous contents
Next: PTLsim/X Architecture Details Up: PTLsim/X: Full System SMP/SMT Previous: Background   Contents
Matt T Yourst 2007-09-26