Beruflich Dokumente
Kultur Dokumente
CHAPTER 1 INTRODUCTION
A typical Wireless Sensor Network (WSN) consists of a large number of small-sized, battery-powered sensor nodes that are limited in battery energy, CPU power, and communication capability. Recently, WSN has witnessed an explosive growth in both academia and industry, attracting a great deal of research attention in the past few years. WSNs are envisioned to support a variety of applications, including military surveillance, habitat monitoring, and infrastructure protection, etc. Being simple in terms of hardware, WSN applications are diverse and demanding. The infrastructural support for such applications in the form of operating systems (OS) is becoming increasingly important. The basic functionalities of an OS include resource abstractions for various hardware devices, interrupt management, task scheduling, concurrency control, and networking support. Numerous applications are built on top of the OS. A sensor networkOS(hereafter, sensorOSfor short) bridges the gap between the hardware simplicity and the application complexity. It plays a central role in providing a flexible environment for building predictable and efficient services. Over the years, we have seen various OSs emerging in the sensor network community. While they address various challenging issues by adopting different approaches in the design spectrum, two important issues, i.e., predictability assurance and programming flexibility, are still not well addressed. Predictability. As sensor nodes are usually deployed in inaccessible areas, operating in an unattended manner for a long lifetime, system predictability is highly desirable. The OS should provide mechanisms to ensure the overall system performance. First, the OS should provide a level of separation between the OS and applications, e.g., the OS should remain responsive irrespective of the application behaviors. Second, the OS should provide a level of separation between different tasks, e.g., a critical task should not be blocked indefinitely by noncritical tasks or locks hold by a group of tasks. Flexibility. Since WSN applications have diverse requirements, system flexibility to facilitate application programming is desirable. The OS should provide many choices to meet requirements of specific application scenarios and programmers preference. A hybrid model combining both event-driven programming and multithreaded programming is highly preferred. Specific challenges should be addressed to design a hybrid system while retaining
Dept of CS&E, PESITM 1
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
predictability and efficiency at the same time. Sensor nodes are usually equipped with low-power microcontrollers with stringent resource constraints. The OS should optimize CPU utilization and memory consumption for high efficiency. Moreover, as sensor nodes are usually deployed in hostile environment in a large scale, the OS should also support efficient network reprogramming to allow updating the WSN software.
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
It perfoms sensitive and critical tasks with all interrupts disabled. In contrast, the bottom half can be deferred to a more suitable point in time to complete servicing of a prior interrupt. It allows top halves to preempt its execution by enabling interrupts. Fig. 2 shows the code snippets for the SenseTask application for both TinyOS-1.x and SenSpire OS (hereafter, we will use T1 to refer to TinyOS-1.x and T2 to refer to TinyOS-2.x when different TinyOS versions matter). The code for SenSpire OS is written in CSpire, which will be introduced in Section 2.5. In CSpire, the bh keyword is used to indicate a bottom half while thetaskkeyword is used to indicate a run-to-completion task (a run-to-completion task cannot block or self-suspend, e.g., TinyOS tasks are run-tocompletion). In the code for T1, the atomic keyword is used to protect the shared data by disabling global interrupts. Hence, within the atomic section, the OS is not responsive toany other interrupts. In contrast, in the code for SenSpire OS, the ADC completion event is notified in the context of a bottom half, and the critical primitive is used to protect the shared data. The critical primitive differs from the atomic primitive in that it only defers the execution of bottom halves. Hence top halves can still be serviced immediately once interrupts trigger. Note that the critical primitive is used to protect shared data between tasks and bottom halves. To protect shared data between bottom halves and top halves, we should use the atomic keyword (which disables all interrupts) instead. In this case, top halves cannot interrupt the execution of bottom halves. Interrupt latency depends on the length of time top halves execute
Dept of CS&E, PESITM 5
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
and the rate of interrupts. In TinyOS, the interrupt latency also depends on the atomic section length because the atomic keyword disables all interrupts from execution. As the atomic keyword is exposed to application programmers, the application code does affect the interrupt latency. On the other hand, in SenSpire OS, the critical keyword disables bottom halves (but not top halves) and top halves can always be serviced irrespective of the critical section size. Hence, SenSpire OS achieves a more predictable interrupt latency.
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
In this example, we would expect that T1, being the highest priority thread, will be blocked no longer than the time for T3 to complete its execution in the critical section, i.e., (t6 t5). However, the duration of blocking is, in fact, (t6 - t5) + (t5 - t4), which is unpredictable because the execution time of T2 (= t5 - t4) and any other pending intermediate threads can be sufficiently long SenSpire OS hence adopts the priority ceiling protocol to address this issue. It works as follows:
In SenSpire OS, each thread has a static priority and a dynamic priority. Each shared resource has a static priority ceiling, which equals to the highest static priority of the thread that uses it. Thanks to the CSpire language, we are able to obtain the priority ceiling by program code analysis.
The dynamic priority of a thread equals the maximum of its static priority and priority ceiling of the shared resource it currently uses. A ready thread can preempt the current thread only when its static priority is higher than the dynamic priority of the current thread.
It is formally proved in that the priority ceiling protocol reduces the worst-case blocking time to at most the duration of execution of a single critical section of a lower priority thread. In addition, it prevents the formation of deadlocks. In the example shown in Fig. 3, if the priority ceiling protocol is used, at time t4, T3 will continue because it has a higher dynamic priority than T2s static priority.
Dept of CS&E, PESITM 7
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
by natively supporting hybrid scheduling in the kernel scheduler, SenSpire OS is able to exploit stack sharing in order to reduce the stack memory consumption.
Events are scheduled by Event Schedulers (ESs) which in turn are scheduled by the Kernel Scheduler (KS). SenSpire OSs event-driven subsystem is different from TinyOS, in that we can support multiple preemption levels by the use of multiple ESs. Events in different ESs can preempt one another. In contrast, the TinyOS core has only one preemption level within the task context. Some critical system events (e.g., packet reception) are executed in the task context, sharing the same context as other noncritical tasks (e.g., compression). Therefore, a critical task can be interfered by the execution of other noncritical tasks ahead of it. The multithreaded subsystem consists of multiple threads which are directly scheduled by our KS along with ESs. It is different from Mantis OS, in that we do not employ time-sliced scheduling, instead, preemption occurs when a high priority thread (or ES) is ready or when the currently running thread calls a blocking I/O or gives up its CPU cycles voluntarily by calling sleep( ) or yield( ). Hence the number of context switches can be reduced. In SenSpire OS, the event-driv-
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
en subsystem takes a higher priority than the multithreaded subsystem because it is more suitable for time-sensitive operations. We have introduced the design of SenSpire OSs thread synchronization primitives in Section 2.1.2. In the following section, we will describe SenSpire OSs novel differentiated kernel scheduling scheme which implements the hybrid model while reduces memory consumption by stack sharing at the same time.
10
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
Note that, events, being run-to-completion, are not allowed to block. This means that events cannot block on synchronization primitives such as mutexes. In order to achieve synchronization between events of different priorities, or events and threads, we need to manually check for the resource availability in the event, and need to repost the event if the resource is unavailable at the current time. The KS employs preemptive scheduling in accordance with the priorities of ESs and threads. The priorities of ESs must be different while the priorities of threads can be the same. Within the same priority, the KS schedules threads in an FIFO manner. Each ES uses a nonpreemptive scheduling scheme. Within each ES, events share a common execution context and are scheduled by a certain nonpreemptive policy (e.g., FIFO, or nonpreemptive priority based). Hence, to execute an event, two levels of scheduling are involved: first, the KS schedules the corresponding ES (which the event is assigned to), then the ES schedules the event to run. The scheduling system can be viewed as a hierarchy of execution contexts . As shown in Figure 5, the Kernel Scheduler schedules two ESs and two threads in a prioritypreemption manner. The ES-NPPS has the highest priority. Thus any event assigned to it can preempt other tasks. The scheduling policy is Non-Preemptive Priority Scheduling (NPPS). The ES-FIFO has an intermediate priority. Any event assigned to it can preempt threads, but not events assigned to ES-NPPS. It schedules events assigned to it in an FIFO manner. Two threads have the same lowest priority and can be preempted by any events in the system. They are scheduled by our KS in an FIFO manner.
11
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
TinyThreads, also built on TinyOS, implements a cooperative thread mechanism. In the cooperative thread model, a thread must explicitly yield the CPU to other runnable threads. The problem with cooperative threads is the correctness of the system depends on application code voluntarily yielding the CPU at specific intervals. If a thread does not relinquish the CPU for a long time, then other threads may be unable to make progress. The same issue exists for event-driven systems. Therefore, TinyOS Preemptive Level Scheduler (PL) supports preemptive events based on TinyOS, but it does not support thread-like programming. The Contiki preemptive library, and TOSThreads, support true preemptive multithreading on eventdriven kernels; TinyMOS supports events in a multithreaded kernel (Mantis OS). SenSpire OS advances these three works in three aspects. First, SenSpire OS supports preemption in both
Dept of CS&E, PESITM 12
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
event-driven subsystem and multithreaded subsystem. Event preemption is important for ensuring system predictability in the event-driven subsystem. Second, SenSpire OS supports customizing different scheduling policies with the help of the CSpire language compiler (which will be further discussed in Section 4.5). Third, by directly supporting hybrid scheduling in the kernel scheduler, SenSpire OS is able to employ stack sharing for optimizing resource utilization (see Section 2.3.1).
Stack for ES-NPPS; all tasks within ES-NPPS are nonpreemptive, hence share this common stack.
13
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks 2.
Stack for ES-FIFO; all tasks within ES-FIFO are nonpreemptive, hence share this common stack.
3. Stack for thread1 (the primary thread). 4. Stack for thread2. This is a relative costly scheme for implementing the hybrid model on resource constrained sensor nodes. In SenSpire OS, a common system stack is shared among ESs and the primary thread. Considering an additional stack for thread2, the system consumes two stacks, reducing two stacks compared to prior approaches.
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
tion by using relocatable code. Second, SOS module does not allow to define global variables because data relocation is not performed. SenSpire OS does not have this limitation.
The radio layer provided by device driver developers. It implements device specific MAC protocols.
2)
The unified resource layer provided by OS kernel developers. It virtualizes the radio hardware, scheduling concurrent requests. On top of it, different applications can use the hardware radio without interfering each other.
3)
The sensornet layer provided by network service developers. It implements neighborhood management and link estimations, which can be shared among different upperlayer networking routing protocols.
15
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
Function polymorphism. CSpire allows a common name to be shared among multiple functions as long as their signatures are different. Note that CSpire does not allow dynamic polymorphism as it will incur a large runtime overhead.
Object manipulation. CSpire supports invoking methods of an object. However, CSpire does not manage object lifetime. Support for the hybrid model. CSpire supports the keywords of task, thread, bh, etc., to simply programming on top of SenSpire OSs hybrid model. Annotations. CSpire supports specifying annotations to objects, e.g., task[period=1000] denotes a periodic task with a one second period. Compile-time verification. CSpire verifies whether the application code conforms to the requirements of SenSpire OS. For example, blocking is not allowed in events (or bottom halves).
Compile-time optimization and customization. CSpire is able to analyze application resource requirements and customize the OS kernel. Currently, CSpire supports for customization of the scheduling hierarchy, e.g., the multithreaded system can be excluded if the application never uses. CSpire also supports stack size estimation by differentiating different execution contexts and analyzing at the assembly level.
CHAPTER 3 IMPLEMENTATION
We have implemented SenSpire OS on three commonly deployed sensor node platformsMica2, MicaZ, and TelosB.
16
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
The SenSpire OS kernel is written in C. As shown in Fig. 7, The SenSpire OS mainly consists of the following components:
Hardware drivers. They are further classified into onchip device drivers (such as hardware timers, UART, and ADC) and off-chip device drivers (such as MTS300/MTS310 sensorboards, Chipcon CC1000/ CC2420 radios). We port parts of this code from SOS and Mantis OS.
Interrupt system. It contains the two-phase interrupt handling code. Task scheduling system. It implements the differentiated kernel scheduling algorithm and a set of synchronization primitives. Module manager. It extends SenSpire OS for handling modules. It is responsible for module placement, loading, and execution. Network protocols. They include the sensornet layer and illustrative network routing protocols such as the tree routing protocol. Programming environment. Applications based on SenSpireOSare written in CSpire,weexpose SenSpire OS kernel services to application programmers via the CSpire native classes which are thin wrappers around their C implementations. We implement the CSpire compiler with JavaCC. It compiles user applications together with SenSpire OS native classes into C. Then it invokes the corresponding C cross-compiler (e.g., avr-gcc or msp-gcc) to compile the converted C code into the binary code.
17
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
The kernel scheduler is the core of SenSpire OS. The SenSpire OS kernel scheduler maintains a priority queue. As shown in Fig. 8, the kernel scheduler fetches the highest priority task from the queue. If there is no task in the queue, the kernel scheduler puts the CPU into the sleep state to
save energy. Otherwise the kernel scheduler switches the register files. After that, the kernel scheduler switches the stack only when necessary (according to Table 1).
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
another component; also, one component can signal events to another component. The execution model of TinyOS consists of interrupts and tasks. Interrupts execute at a higher priority and can preempt the execution of tasks. Tasks execute at a lower priority and are scheduled in a FIFO manner. Tasks in TinyOS are written in a run-to-completion manner, and they cannot be preempted or self-suspended. For this reason, I/Os are done in splitphases, i.e., a request is issued before a signal invokes the start of the next task. Contiki, developed at Swedish Institute of Computer Science, is a sensor OS that supports dynamically loadable modules. Contiki supports multithreading via libraries to address the programming inconvenience of event-based programming (e.g., in TinyOS). Contiki also supports a lightweight threading mechanism, i.e., protothreads . SOS, developed at the University of California, Los Angeles, also supports dynamically loadable modules. It adopts a module-based architecture which allows dynamically loading and unloading modules. The SOS execution model is only slightly more complex than TinyOS: SOS message handlers (similar to TinyOS tasks) are dispatched according to three different priorities, but preemption is not allowed between two message handlers. Mantis OS, developed at Colorado University, implements a traditional preemptive time-sliced multithreading on sensor nodes. The Mantis kernel supports synchronous I/Os (as opposed to split-phase I/Os), and a set of concurrency control primitives, e.g., binary semaphores (mutex) and counting semaphores. Nano-RK, developed at Carnegie Mellon University, implements a reservation-based real-time OS for WSNs. Nano-RK supports fixed-priority preemptive multitasking for guaranteeing that task deadlines are met. It also supports CPU and network bandwidth reservations, i.e., tasks can specify their resource demands and the OS provides timely, guaranteed and controlled access to CPU cycles and network packets. RETOS, developed at Yonsei University, Korea, is designed to improve several aspects of prior work. It improves system resilience by supporting dual mode operation (i.e., kernel mode and user mode) as well as application code checking at design-time and runtime. It optimizes multithreading implementation and provides support for POSIX 1003.1b real-time scheduling. It also supports loadable modules and provides multihop networking services. LiteOS, developed at the University of Illinois at Urbana Champaign, is designed to provide a traditional Unix-like environments for programming WSN applications. It includes:
1)
A built-in hierarchical file system and a wireless shell for user interaction using Unixlike commands.
19
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks 1) 2)
Kernel support for dynamic loading native execution of multithreaded applications. An object oriented programming language (LiteC++) that uses a subset of C++ as its syntax with class library support.
Pixie OS, developed at Harvard University, is designed to enables resource-aware programming. In Pixie, a sensor node has direct knowledge of available resources, such as energy, radio bandwidth, and storage space, and can control resource consumption at a fine granularity. The Pixie OS is based on a dataflow programming model based on the concept of resource tickets, a core abstraction for representing resource availability and reservations. By giving the system visibility and fine-grained control over resource management, a broad range of policies can be implemented. Aside from the basic system implementations mentioned above, there is a large body of work devoted to improving OS capabilities in different dimensions, e.g., improving OS reliability (e.g., t-kernel, Harbor, and Neutron ), providing real-time support (e.g., FIT ), extending the programming model (e.g., protothreads , TOSThreads), and providing reprogramming support (e.g., Deluge, Stream, and Elon ). For a more complete review in the areas of sensor OS design.
20
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks
ability and programming convenience. Having implemented SenSpire OS on three most commonly used sensor node platforms, we evaluate its performance extensively. While we have shown that SenSpire OS is promising in providing a flexible environment for building predictable and efficient sensor network applications. There is much future work to consider. In particular, we would like to examine how SenSpire OSs design principles will enhance the performance of large-scale complex WSN applications.
REFERENCES
1.
I.F. Akyildiz, W. Su, Y. Sankarasubramaniam, and E. Cayirci, Wireless Sensor Networks: A Survey, Computer Networks, vol. 38, pp. 393-422, 2002.
2. TinyOS, http://www.tinyos.net,
3.
A. Dunkels, B. Gro nvall, and T. Voigt, ContikiA Lightweight and Flexible Operating System for Tiny Networked Sensors, Proc. 29th Ann. IEEE Intl Conf. Local Computer Networks (LCN 04), 2004.
21
SenSpire OS: A Predictable,Flexible and Efficient Operating System for Wireless Sensor Networks 4.
C.-C. Han, R. Kumar, R. Shea, E. Kohler, and M. Srivastava, A Dynamic Operating System for Sensor Nodes, Proc. Third Intl Conf. Mobile Systems, Applications, and Services (MobiSys), 2005.
5.
S. Bhatti, J. Carlson, H. Dai, J. Deng, J. Rose, A. Sheth, B. Shucker, C. Gruenwald, A. Torgerson, and R. Han, MANTIS OS: An Embedded Multithreaded Operating System for Wireless Micro Sensor Platforms, J. Mobile Networks and Applications, vol. 10, pp. 563-579, 2005.
6.
A. Eswaran, A. Rowe, and R. Rajkumar, Nano-RK: An Energy- Aware Resource-Centric RTOS for Sensor Networks, Proc. 26th IEEE Intl Real-Time Systems Symp. (RTSS), 2005.
7.
H. Cha, S. Choi, I. Jung, H. Kim, and H. Shin, RETOS: Resilient, Expandable, and Threaded Operating System for Wireless Sensor Networks, Proc. Sixth Intl Conf. Information Processing in Sensor Networks (IPSN 07), 2007.
8.
Q. Cao, T.F. Adbelzaher, and J.A. Stankovic, The LiteOS Operating System: Towards Unix-Like Abstractions for Wireless Sensor Networks, Proc. Seventh Intl Conf. Information Processing in Sensor Networks (IPSN 08), 2008.
9.
K. Lorincz, B. rong Chen, J. Waterman, G. Werner-Allen, and M. Welsh, Resource Aware Programming in the Pixie OS, Proc. Sixth ACM Conf. Embedded Network Sensor Systems (SenSys), 2008.
10.
Q. Wang, Y. Zhu, and L. Cheng, Reprogramming Wireless Sensor Networks: Challenges and Approaches, IEEE Network Magazine, vol. 20, no. 3, pp. 48-55, May/June 2006.
22