inha university incheon, korea tossti: saving time and energy in tinyos with software thread...

26
INHA UNIVERSITY INCHEON, KOREA http:// eslab.inha.ac.kr/ TOSSTI: Saving Time and Energy in TinyOS with Software Thread Integration Zane D. Purvis and Alexander G. Dean IEEE Real-Time and Embedded Technology and Application Symposium, 2008 Intelligent E-Commerce System Lab. Aettie Ji

Upload: anthony-logan

Post on 27-Dec-2015

219 views

Category:

Documents


2 download

TRANSCRIPT

INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

TOSSTI: Saving Time and Energy in TinyOS with Software Thread

IntegrationZane D. Purvis and Alexander G. Dean

IEEE Real-Time and Embedded Technology and Application Sym-posium, 2008

Intelligent E-Commerce System Lab.Aettie Ji

- 2 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

OUTLINE IntroductionRelated Work

Mote Systems Software Thread Integration(STI)

TOSSTI: TinyOS with Software Thread Integra-tion Support TinyOS Scheduler vs. TOSSTI Scheduler Declaring & Posting Merged Tasks in nesC

Experiments and Analysis Sample TOSSTI Application & Analysis

Conclusions

- 3 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

INTRODUCTION(1/3)

Motivation Motes have frequent periods of busy-waiting for com-

municating with slow peripherals. Waiting times are so short that the cost of context switch

is prohibitive.Using STI (Software Thread Integration), useful works

could be performed during the wait times.

- 4 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

INTRODUCTION(2/3)Mote Application

Transmit

Transmit integrated with Processing

Mote Application with STI

Time ▶

Sensing Processing Transmit Idle Integrated Code

Figure 1. Sample mote application timeline without and with STI

- 5 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

INTRODUCTION(3/3)

Benefits of STI The processor can switch to a low power mode sooner. Completing the work early benefits real-time systems. STI enhances the concurrency model of the scheduler.

Contributions This paper introduces TOSSTI, a software system, which

uses STI with the common WSN operating system TinyOS.

And demonstrates TOSSTI by applying it to a micro-phone array sampling application.

The integrated tasks finish 17.7% faster, reducing appli-cation active time by 6.3%.

- 6 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Related Works(1/2)Mote System

Power & energy management for motes applica-tion.

• Analysis of power management facilities provided by mi-croprocessor [14].

• Various non-battery energy source for WSNs [23].• ICEM for power management in TinyOS [15].

Energy-mindful MAC & routing algorithm.• SEESAW MAC [2].• X-MAC [3].

Operating System for WSNs.• MANTIS [20].• Contiki [7].• TinyOS [10].

- 7 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Related Work(2/2)Software Thread Integration (STI)

Is a compiler technique which provides fine-grained con-currency on processor.

The assembly-language-level compile-time interleaving of multiple functions.

Duplicates and moves instructions to maintain control-flow and data-flow semantics. weightless context switching.

Can be used to reclaim processor idle time which would be too short to use with traditional context switching.

This paper describes a system for incorporating STI into TinyOS applications relatively easily for reducing energy consumption and increasing performance.

- 8 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/TOSSTI: TinyOS with Soft-ware Thread Integration Support

TISSTI is a tool set for easily adding facilities for STI to TinyOS. Replacing the default TinyOS

1.1.x scheduler, Declaring nesC tasks that may

be integrated with other nesC tasks,

Processing a TinyOS applica-tion’s code to add STI func-tionality.

http://www.cesr.ncsu.edu/adgean/tossti Figure 2. Interaction of tools used

when building a TOSSTI application

- 9 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

TinyOS Scheduler(1/2) FIFO queue. No priority, no preemption. ISR is the only form of concurrency. To support STI in TinyOS,

There must be a way to recognize the integrated tasks. Task scheduler must be modified to identify when the in-

tegrated tasks are available and run it.

TOSSTI: TinyOS with STI Support

- 10 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

TinyOS Scheduler(2/2)

TOSSTI: TinyOS with STI Support

*task

*task

*task

Figure 3. TinyOS scheduler queue

C function, both the argument and return type are void.

TOSH_sched_free, the index of the first free entry in the queue. If TOS_queue[TOSH_sched_free].tp != null then the queue is full.Otherwise, a new task is added.TOS_queue[TOSH_sched_free].tp = function

TOSH_sched_full, the index of the first used position of the queue. TOSH_run_next_task() executes and removes TOS_queue[TOSH_sched_full].

0

1

2

3

4

5

6

TOS_queue, implemented as an ar-ray of C structs with a pointer to a task, tp.The size of queue, TOSH_MAX_TASKS, must be a power of two for efficient modulo arithmetic.

7

- 11 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

TOSSTI Schedulers(1/5)

In order to run integrated threads in TinyOS, the scheduler must be modified to determine when an integrated version of multiple tasks is avail-able.

Previously, STI utilized two queue, and only the head of them would be examined. A multiple scheduling system would break TinyOS’s single-priority scheduling semantics.

In TOSSTI, like the TinyOS, a single queue is used for all tasks. Dynamic & Static scheduler

TOSSTI: TinyOS with STI Support

- 12 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

TOSSTI Schedulers(2/5)

Dynamic TOSSTI Scheduler

TOSSTI: TinyOS with STI Support

*task

*task

*task 0

1

2

3

4

5

6

7

2

0

1

tid

*task_1_2 3

2

1

0

Figure 4. Dynamic TOSSTI scheduler queue and table

TOSSTI_queue, an array of typedef struct TOSSTI_sched_entry_t{

void (*tp)(void);uint8_t tid;bool has_run;

} TOSSTI_sched_entry_t;

tid, a unique identifier for each integrated

task.

TOSSTI_sched_free

TOSSTI_sched_full

TOSSTI_integrated_threads array

TOSSTI_sched_full

has_run flag is set

callTOSSIT_run_next_task()

callTOSSIT_run_next_task()

Tasks which al-ready had been executed are re-

moved

- 13 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

TOSSTI Schedulers(3/5)

TOSSTI_locator: bit-map Indicating the relative position of TOSSTI-tasks in the queue. If Bit 0, the head of the queue is an integrated task. If the task is removed from the queue, one right shift. If the task is added to the queue and has non-zero tid, the bit corre-

sponding to the position is set. If TOSSTI_locator is 0, no need to search the integrated task. O(n) complexity. The scheduler does not waste time searching.

Compared to TinyOS schduler, when using queue size of 8 2 * more RAM for queue storage on AVR architecture. 2 byte per queue entry of TinyOS vs. only 4 bytes of TOSSTI and one

additional byte for TOSSTI_locator The lookup table using 2 bytes per entry can be stored ROM.

- 14 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

TOSSTI Schedulers(4/5)

Static TOSSTI Scheduler

TOSSTI: TinyOS with STI Support

*task-C

*task-B

*task-A 0

1

2

3

4

5

6

7

TOS_queue

TOSH_sched_free

TOSH_sched_full

D

Bpost() D

Figure 5. Scheduler queue before (a) and after (b) posting an integrated task, task−D, to the static TOSSTI scheduler

sti-B, D is the integrated version of task-B, D.task-A, B, C are already posted.

where

*sti-BD

The integrated task informa-tion is specified as such in the integrated tasks file.

- 15 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

TOSSTI Schedulers(5/5)

Scheduler Response Times TinyOS scheduler

TOSSTI scheduler

TOSSTI: TinyOS with STI Support

n

iiTTnR

10)(

SI

n

ii TTTTnR

10)(

- 16 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Declaring & Posting (1/3)

#<include> TOSSTI.h //must be added.task void TOSSTI(myReallySweetTask){ //definition

// a fun mix of C and nesC code} myReallySweetTask must be wrapped in a call of the TOSSTI

macro. TOSSTI macro mangles the name of the task. The other TOSSTI tools can pick up the integrated task and as-

sign unique tid. Non-TOSSTI task is assigned a tid of 0.

//all posts of tasks become post TOSSTI(myReallySweetTask);//adds task to the queue and tid.

TOSSTI: TinyOS with STI Support

- 17 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Declaring & Posting (2/3)

Processing the Application’s C Code and Generat-ing TIDs TOSSTI script makes - MyModule$mySweetTask MyModule$___TOSSTI___mySweetTask___ - TOSH_post(ModuleName$workerTask)

TOSSTI_post(ModuleName$workerTask, tid) - TOSH_init_sched() TOSSTI_init_sched() - TOSH_run_next_task() TOSSTI_run_next_task() TOSSTI script adds - C preprocessor liner number directives to output source code

to aid in debugging.

TOSSTI: TinyOS with STI Support

- 18 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Declaring & Posting (3/3)

Declaring Integrated Tasks TOSSTI script must define the TOSSTI_integrated_tasks

array. An integrated threads files used for indicating which

tasks have been merged to form integrated threads. - task01 = {ModA$task0, ModB$task1} - task03 = {ModA$task0, ModB$task3}

Building the TOSSTI Application After the integrated tasks file is created the, TOSSTI

script is used to insert an appropriate scheduler into the source code.

The resulting code is compiled using gcc, along with the integrated function bodies, using the same compiler op-timization flags that the nesC compiler passes to gcc,

And then can be loaded onto the mote.

TOSSTI: TinyOS with STI Support

- 19 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Sample TOSSTI Applica-tion(1/2)

A TinyOS application named “MicSampler [17]” has been devised to demonstrate using STI in TinyOS with TOSSTI.

Sampling 8 microphones attached a mote’s analog to digital converter and sending samples to PC.

PC calculates the direction of sound detected.

Figure 6. Components used in MicSampler as generated using nesdoc

Experiment & Analysis

- 20 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Sample TOSSTI Applica-tion(2/2)

Sampling all eight channels from the AVR’s ADC. get-SamplesTask()

Transmitting the eight ADC samples over the mote’s CC2420 radio. startSent()

The sample and transmit tasks were integrated using thrint.

Experiment & Analysis

Figure 7. CDG of Integrated getSamplesTask() and startSend()

- 21 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Analysis(1/5)

Run Time Reduction (a) without STI: getSamplesTask() 77.7 μs + startSent() 200.5 μs =

278.2 μs (b) with STI static scheduler: getSamplesTask() + startSent() =

200.5 μs 17.7% reduction in run time

Experiment & Analysis

Figure 8. Oscilloscope screenshots showing task exe-cution time (a) without and (b) with STI, using static scheduler

- 22 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Analysis(2/5)

Active Time Analysis: using dynamic scheduler (a) without STI: 514.0 μs (b) with STI dynamic scheduler: 566.5 μs Increase!! it takes too long to search the next task to execute.

Experiment & Analysis

Figure 9. Oscilloscope screenshots showing active time (a) without and (b) with STI using dynamic TOSSTI scheduler

In an application with longer tasks, this overhead may be negligible.The systems where new tasks may be introduced to the system at run time, the dynamic scheduler could be useful.

- 23 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Analysis(3/5)

Active Time Analysis: using static scheduler Fig 9. (a) without STI: 514.0 μs Fig. 10 with STI static scheduler: 481.5 μs Time savings of 32.5 μs or a decrease of 6.3 %

Experiment & Analysis

Figure 10. Oscilloscope screenshot showing Mic-Sampler application using static TOSSTI scheduler

- 24 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Analysis(4/5)

Power and Energy MicaZ power model[22] assumption

- Processor is standby if not waking up or in active mode.- Radio is active for same amount of time to send 12 bytes data(mote ID, packet number, 8 data samples) and 17 bytes of B-MAC protocol overhead

Applying TOSSTI cuts processor active time by 6.3%,- MCU power is reduced from 7.54mW to 7.19 mW.- MCU + radio power is reduced from 38.92 mW to 38.57 mW.

Experiment & Analysis

- 25 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Analysis(5/5)

Response Time The response time for getSamplesTask is unchanged here, but the

response time for startSend gets reduced. R(startSend) = (TgetSamplesTask + TstartSend)− (TgetSamplesTask + TstartSend)

+ TsendAndSample

Program Memory Usage

Experiment & Analysis

Case Memory Usage

Non-STI App 11,130 bytes

App with Dynamic TOSSTI Scheduler 13,166 bytes

App Static TOSSTI Scheduler 12,948 bytes

sendAndSample function 1,168 bytes

Table 1. Program memory usage for ver-sionsof MicSampler application.

- 26 -INHA UNIVERSITYINCHEON, KOREA

http://eslab.inha.ac.kr/

Conclusion

This work has shown that using software thread integration with TinyOS, TOSSTI.

It also shows an example application that uses TOSSTI to reclaim busy-wait time.

During what was previously busy-wait time, the mote can now perform useful operations, com-pleting its active cycle sooner, going back a low-power mode sooner, reducing energy consump-tion.

In the future, TOSSTI can be ported to the new TinyOS 2.0, which provides a more easily accessi-ble method of utilizing a custom scheduler [16].