Installation instructions for PowerTOSSIM

NOTE: If you find something unclear or incorrect on this page, please email me. Also email if you find bugs in the code :)

Basic instructions

The first step is to get the code. If you have a recent version of TinyOS (after 1.1.10 I think), you already have it, as that's when it was moved into the main tree in the sourceforge TinyOS repository. If you're using an older version of TinyOS, you should upgrade :)

Once you have the code, do the following:

  1. recompile your app:

    $ make pc

  2. make sure DBG includes POWER. If you don't need any other debugging messages, this reduces to (for the appropriate shell):

    bash$ export DBG=power

    tcsh% setenv DBG power

  3. run main.exe with the -p flag and save the output to a file. For example

    ./build/pc/main.exe -t=60 -p 10 > myapp.trace

  4. run postprocess.py on the resulting trace:

    $TOSROOT/tools/scripts/PowerTOSSIM/postprocess.py --sb=0 --em $TOSROOT/tools/scripts/PowerTOSSIM/mica2_energy_model.txt myapp.trace

    The --sb parameter specifies whether to assume that the motes have a sensor board attached. The --em parameter specifies the energy model. Run postprocess.py --help for details on other options.

    Here's the output we get for the trace of a CntToLedsAndRfm run with main.exe -t=60 -p 2:

    Mote 0, cpu total: 719.503906
    Mote 0, radio total: 1235.255862
    Mote 0, adc total: 0.000000
    Mote 0, leds total: 571.570576
    Mote 0, sensor total: 0.000000
    Mote 0, eeprom total: 0.000000
    Mote 0, cpu_cycle total: 0.000000
    Mote 0, Total energy: 2526.330344
    
    Mote 1, cpu total: 635.394462
    Mote 1, radio total: 1090.990102
    Mote 1, adc total: 0.000000
    Mote 1, leds total: 504.416514
    Mote 1, sensor total: 0.000000
    Mote 1, eeprom total: 0.000000
    Mote 1, cpu_cycle total: 0.000000
    Mote 1, Total energy: 2230.801078
    
    By default, the postprocessor prints the total energy used by each component on each mote. The --detail flag can be used to generate current vs time data files, one per simulated mote.

Using the mica2 radio stack

By default, TOSSIM uses an old version of the mica radio stack, which does not support power management and tuning transmission power. PowerTOSSIM includes a port of the mica2 radio stack, so it is now possible to run programs that take advantage of the CC1000's power management features. To use it include

PFLAGS += -I%T/platform/pc/CC1000Radio

in your application Makefile.

Using the TinyViz plugin

The TinyViz plugin allows you to see the power state of the you application as it's running. It is in the main tree, so run

$ cd $TOSROOT/tools/java/net/tinyos/sim/plugins
$ cvs update
$ cd $TOSROOT/tools/java/net/tinyos/sim/
$ make

To use the plugin, run the simulation as usual, making sure to include the -p flag and have POWER as part of DBG. For example:

$ setenv DBG power
$ tinyviz -run 'main.exe -p' 5

Using the CPU cycle counting code

Disclaimer: This code is currently made up of a bunch of hacks, mostly due to the fact that I don't really know ML

The main component that actually does the transformation is currently provided as an x86 linux binary (cilly.asm.exe). This is a compiled version of CIL with a module to add a counter to every basic block. The module code is in scripts/counter.ml, so if x86 linux doesn't work for you, install CIL, add in the counter.ml module, and generate your own cilly program :)

Note: Read if you're compiling your own version of CIL: Getting CIL to process the output of the nesC compiler requires a small modification to make it recognize '$' as a valid character for identifiers. Namely, you have to modify the following two lines in src/frontc/clexer.mll to add the '$':

let ident = (letter|'_')(letter|decdigit|'_'|'$')* 
let attribident = (letter|'_')(letter|decdigit|'_'|':'|'$')

Once you have a version of cilly that works on your machine, make sure that: (This assumes that you already have basic PowerTOSSIM set up as described above.)

Then, to set up cpu cycle counting for MyApp, run:
$ cd $TOSROOT/apps/MyApp
$ $TOSROOT/tools/scripts/PowerTOSSIM/compile.pl
... lots of silly warnings here ...  But there shouldn't be any errors.
$ cd build/pc
$ ./a.out -cpuprof 1
...
0: POWER: Mote 0 CPU_CYCLES 5985780.5 at 38191327
0: POWER: Mote 0 CPU_CYCLES 6059924.0 at 38591427
0: POWER: Mote 0 CPU_CYCLES 6133961.0 at 38991527
0: POWER: Mote 0 CPU_CYCLES 6209839.5 at 39391627
...

When the run finishes (use -t=TIME), the bb_exec_cnt file will have execution counts for each basic block. The basic block to line number mapping is in bb_linenum_map, and the basic block to cycle count in bb_cycle_map. The cpuprof.py script can do some processing of these files to give sorted basic block or cycle execution counts.

Using the CPU cycle counting code in Cygwin

If you're trying to use the CPU cycle counting code on Cygwin, you'll need to compile your own version of cilly and potentially make some other changes. Turkmen Canli wrote up a page with the steps he followed to get it to work.

Email me if/when something breaks, or if you have questions. Patches are also appreciated :)