Abstract

Wireless sensor network (WSN) has been already widely used in many fields in terms of industry, agriculture, and military, and so forth. The basic composition is WSN nodes that are capable of performing processing, gathering information, and communicating with other connected nodes in the network. The main components of a WSN node are microcontroller, transceiver, and some sensors. Undoubtedly, it also can be added with some actuators to form a tiny mechanical system. Under this case, the existence of task preemption while executing operating system will not only cost more energy for WSN nodes themselves, but also bring unacceptable system states caused by vibrations. However for these nodes, task I/O delays are inevitable due to the existence of task preemption, which will bring extra overhead for the whole system, and even bring unacceptable system states caused by vibrations. This paper mainly considers the earliest deadline first (EDF) task preemption algorithm executed in WSN OS and proposes an improved task preemption algorithm so as to lower the preemption overhead and I/O delay and then improve the system performance. The experimental results show that the improved task preemption algorithm can reduce the I/O delay effectively, so the real-time processing ability of the system is enhanced.

1. Introduction

WSN consists of spatially distributed autonomous sensors to monitor physical or environmental conditions, such as temperature, sound, and pressure. These WSN nodes cooperatively pass their data through the network to a main location. Energy issue and system performance of WSN have always been considered because WSN nodes always work in some harsh environment. Energy is the scarcest resource for WSN nodes, and it finally determines the lifetime of WSNs. Energy consumption of the sensor nodes should be minimized since their limited energy resource determines their lifetime [1]. For the WSN OS used in some practical application of connecting some actuators, the task preemption will inevitably bring I/O delay and even unacceptable system states caused by the vibrations [2]. Nowadays, while WSN nodes formed a tiny mechanical system by adding actuators, how to decrease the system extra overhead and improve the system performance caused by the vibrations becomes very important.

Currently, there are many researches about improving system performance for WSN nodes; for example, [3] used error and kernel density approach of sleeping nodes in cluster-based WSNs; [4] used low energy online self-test of embedded processor in dependable WSN nodes. Reference [5] studied low-energy symmetric key distribution in WSN; [6] used a dynamic programming approach for QoS-aware power management in wireless video sensor. Reference [7] used virtual backbone scheduling to maximize the lifetime of WSNs. Reference [8] used hybrid-storage units to extend runtime of low-power WSN nodes. Reference [9] studied distributed tracking with energy management in wireless sensor networks. Reference [10] used joint routing and sleep scheduling to maximize lifetime of WSN. Thus it can be seen that most solutions are implemented by the way of utilizing extra resources. But the innovation for this paper is to improve the lifetime of WSN nodes in terms of real-time operating system itself and the task scheduling algorithm to be exact. The decrease of system overhead and the improvement of system performance are implemented by reducing the overhead of task preemptions. The most important is that this method can be combined with all of the others to achieve better system performance in tiny mechanical system composed of WSN nodes, as this improvement is focused on the real-time operating system itself.

2. EDF Task Scheduling Analysis

Compared with fixed priority task scheduling algorithm, dynamic priority algorithm allocates different priorities to every period task, so the task priority is constantly changing. EDF task scheduling algorithm has already been widely used as a classic dynamic priority scheduling algorithm in WSN [11].

EDF task scheduling algorithm assigns tasks with different priority according to execution deadline of task, the earlier task execution deadline, and the higher task priority. In a word, system allocates the highest priority to task having the earliest task execution.

2.1. Judging Whether the System Is Schedulable

Supposing that system has independent and preemptive period tasks (). , , and represent the execution time, relative deadline, and period of task , respectively. The sufficient condition for EDF task scheduling algorithm in single processor is given by

While task () has max block time , the above sufficient condition will be expressed as

If this formula can be met for all tasks, the system is regarded as schedulable. The all below discussions are all based on formula (2).

2.2. Task Preemption Optimization about EDF Task Scheduling Algorithm

Use the attribute set to describe a period task, where is the period of task and is the execution time of the task, while using to describe one specific job in a task, which means that the task has jobs totally. For example, supposing that there are three jobs in the task , the first one is , the second one is , and the last one is .

Suppose that there are three period tasks (2, 0.8), (3, 0.4), and (5, 2.1) in the single processor system. For these three tasks, their super period is 30.

As Figure 1(a) shows, task , , and are all released at time 0, but their execution deadline is 2, 3, and 5, so task has the highest priority and it begins to run firstly. At time 0.8, task begins to run as it has higher priority than task . Till time 1.2, task begins to run. While at time 2, task is released again, task is preempted by task then. Figure 1(a) shows the whole execution case before optimization for these three tasks during the time period .

Figure 1(a) shows that the beginning time for jobs on task , , and is , , and , respectively. We can see from the results that the jobs of task are preempted 4 times totally, and each time point of preemption is shown as in Figure 1(a).

Figure 1(b) shows the execution case after optimization during the time period ; the beginning time for jobs of tasks , , and becomes , , and , respectively. Under this case, task is preempted 2 times totally, and in the meanwhile, task and do not exceed their deadline. This is implemented by postponing the execution of some jobs for task and , which means that nonpreemptive scopes are added for some jobs in task , and the below discussion will describe the process of implementation in detail.

2.3. Extra Overhead Caused by Task Preemption

is a task preemptive set, which describes that task is executed times totally. The number of elements for is signed as , which means the times that task is preempted totally, so the total amount for all these tasks are given by

If a low priority task is preempted by another one, then the extra cost for the preemption is . While there is no preemption exists and then the extra cost is , for any task, no matter whether it is preempted, the total extra cost for the system is [11].

If the phase position is for the real-time task set , the extra overhead caused by task preemption during the time period is described as

So we can know that the task preemption will bring extra overhead for the whole system. As saving energy is very important for WSN nodes that formed a tiny mechanism system, how to reduce the task preemption becomes very necessary.

3. Analysis of I/O Delay for EDF Task Scheduling

For the release time of all jobs in set , there exists a max I/O delay for certain job [11, 12].

3.1. Analysis of I/O Delay Caused by Task Preemption

Supposing that allocated preemptive threshold equals and ignoring the restrain of preemptive threshold time, then according to the analysis of time requirement, the max I/O delay for preemptive task scheduling of is given by where is the release time of job; then, can be calculated by

While , the above iterative calculation will end.

For task , while the release time of its one job is , the job load of higher priority can be represented as

A preemptive threshold () is assigned to task , and the I/O delay should be calculated by the preemptive part and nonpreemptive part, respectively, as below [11].

The max I/O delay of preemptive part for task is given by where is the max value of formula (9), and it can be calculated by the initialization value .

The max I/O delay of nonpreemptive part for task is represented as

so the max I/O delay for task based on EDF scheduling algorithm is described as

While , then

Under this case, the I/O delay is a constant value, and it is irrelevant to task attribute.

While ,

From the above formulas, we can know that is the main factor for , and the next section will describe how to assign for jobs.

3.2. Improved Task Preemption Scheduling Algorithm

In the EDF task scheduling algorithm, task is indexed by the relative time slice. For task , the bigger the index, the bigger relative time slice. So only the task with big relative time slice can block the task with smaller one and the time requirement of preemptive part for task having below restriction of preemptive time threshold [11]. Consider

The max execution time of nonpreemptive part is for task , so the necessary condition that task can be schedulable is there is existing   , which meets the below formula:

as is the detecting set, and it is given by where , and it meets the following formula:

The necessary and sufficient condition for EDF task scheduling is described as

Then can be calculated by

To make the task schedulable, the min value of is given by So to make all tasks schedulable, the min value of is represented as

From the above analyses, system allocates the to the task that has the smallest relative deadline. The value of other jobs will also be allocated by formula (21).

The system obtains block time for every task and calculates threshold of tasks whose relative time slices are larger than according to and then allocates threshold to task by Algorithm 1.

(1) Input: ;
(2) = , and allocating preemptive threshold to task .
(3) Initializing ;
(4) Calculating by formula (19);
(5) Assigning to separately;
(6) , returning to Step (4) till all are calculated.
(7) for ,
(8) Obtaining all preemptive time threshold by formula (20) and (21).
(9) endfor
(10) for tasks
(11) Calculating max delay , and min delay min delay.
(12) endfor
(13) Output: and .

Algorithm 1 implements an optimization allocation of preemptive time threshold for each job. From the above formula (18) and (19), we can know that the time complexity of this algorithm is .

which corresponds to task release time. If several tasks are released at the same time, then the system uses the task TID having the highest priority.

At any given time , is used to express the time difference between system supplying and finishing the all jobs whose priority is no less than job during time period .

For any one task set based on EDF task scheduling algorithm, system can calculate the amount of task preemption by task attribute during the time period according to Algorithm 2.

(1) Input: ;
(2) Initializing ; ;
(3) Constructing TID = and Set ; // N
(4) for to ;
(5) Detecting release time of all tasks;
(6)  ; ;
(7) if then
(8) Ending this loop, and detecting next release time;
(9) endif
(10) if then
(11) Refreshing ;
(12) Ending this loop, and detecting next release time;
(13) endif
(14) System finds the index in , and makes and
     ;
(15) if then
(16)  ;
(17) endif
(18) Refreshing ;
(19) endfor
(20) Output: ; the amount of task is preempted
   ; the amount of all preemptions

The above algorithms describe the implementation of postponing the execution of some jobs for some tasks; at the meanwhile, nonpreemptive scope is added for some jobs in others tasks, and the below discussion will describe the experiments about the performance test.

4. Experimental Platform

In order to test the performance of the improved task scheduling algorithm, we used the hardware platform of Webit&NEU [13] and its operating system Webit&NEU OS which were implemented by our China Liaoning Province Embedded Technique Key Laboratory.

4.1. Hardware Platform

Webit&NEU (Atmega128L Processor) uses the basic structure of Webit2.0. It can collect and handle the data collected from the CC2520 and store the core data to data memory.

Webit2.0 (AT90S8515 Processor) is an embedded Internet device that has implemented the function about making the standard industry device that can access the Internet. Webit2.0 has successfully been developed by our China Liaoning Province Embedded Technique Key Laboratory and has been manufactured by our China Shenyang Neu-Era Information Technology Stock CO., LTD. The most important is that Webit2.0 has also achieved the China’s product patent (numbers ZL 00 2 52482.1 and ZL 01 2 29725.9) [14].

4.2. Software Platform

A real-time operating system must have the ability to respond to external events fast. In order to coordinate and execute tasks effectively, Webit&NEU OS system provides the following services: interrupt handlers, intertask communication facilities, task synchronization, internal memory management, timing services, task priority assignment, and so on as Table 1 shows [15, 16]. Webit&NEU OS supports up to 16 tasks, which is committed to achieve low cost application in the IoT. These tasks have 8 different priorities of 0–7. The bigger the value, and higher the priority.

All of these functions implemented by the unique design of system call can easily execute real-time applications. System call is a program supported to user by operating system, while users need to implement certain system function; then, what they need to do is to call the accordingly system call in the application program; thus, it is very convenient for users to use the system kernel.

All the system calls are written in AVR assembly language. One of the important advantage for AVR assembly language is that it can flexibly and easily manage a certain storage location in memory, even its certain bit of the storage location, so system can effectively handle task, interruption, message, timing, and so on.

All of these functions can easily implement real-time applications, so the Webit&NEU OS system can well be used to effectively manage data collection, wireless communication in the field of WSN, and it has successfully been developed by our China Liaoning Province Embedded Technique Key Laboratory.

5. Performance Analysis of Improved EDF Scheduling Algorithm

For system load , the system generates 18 period task sets totally, and each set includes 6 period tasks generated at random. Table 2 shows the case of task preemption comparison before and after algorithm optimization.

From the experimental results, we can know that the optimization scope ranges from 50.0% to 33.3%; with the increase of system load, the preemption optimization rate decreases correspondingly, which means that system can get better optimization while system load is lower [1719].

We used the tools of logic analyzer (TLA603), arbitrary waveform generator (AWG2021), and digital storage oscilloscope (TDS1012). In the test programs, we added some control codes by transforming the value of high and low levels of pulses through I/O pin while task is preempted.

The I/O pin of Webit&NEU is connected to the digital storage oscilloscope (TDS1012). While there are the task preemptions happening, the system will alter the current value of pulses when certain task is about to be preempted; accordingly, the system will also change the current value of pulses again while the preempted task begins to execute again. So from the waveform of the experimental results in the digital storage oscilloscope, we can obtain the whole time for the whole process. Besides, we can also get the whole execution time of the preemption task . So I/O delay time can be calculated by .

Under the case of different system load, we obtained the I/O delay according to the above method, and the experimental results are shown in Figure 2.

As Figure 2 shows, while the system load is 0.05, system can achieve the best optimization rate of 50.8%; however, even the system load is 0.9 and the optimization rate can still reach 31.6%. Obviously, the proposed improved task scheduling algorithm can well decrease the I/O delay for the real-time operating system. The system I/O delay is obviously reduced because of the decrease of task preemption, which also means that the system overhead is also reduced. Consequently system real-time ability is enhanced, and at the meanwhile, energy consumption is also obviously decreased [20].

Table 3 shows the system kernel code size of Webit5.0 OS (the fifth version operation system for Webit2.0), Webit&NEU OS, and μC/OS-II separately. Because Webit&NEU OS supports only up to 16 tasks, it is committed to low cost application in the IoT, so its kernel code size is smaller than μC/OS-II who manages up to 64 tasks. This is just the design goal of light-weight operating systems for Webit&NEU OS.

As the code memory of Atmega128L is 128 KB, the code size of Webit&NEU OS with improved algorithm (4.031 KB) is 4.34% larger than Webit&NEU OS’s (3.856 KB); its size only occupies 3.15% of the whole code memory, so it still leaves enough space for user applications.

6. Conclusions

Compared with other current common solutions to increase the lifetime of WSN nodes, this paper aims to improve the lifetime and system performance by optimizing task scheduling algorithm when WSN nodes are applied to actuator applications. On the premise that these jobs can be executed within their execution deadline, system postpones executing some jobs to ensure that more jobs can better be executed, which can reduce task preemption greatly. By executing the improved task scheduling algorithm in the platform of Webit&NEU and Webit&NEU OS both designed and implemented by our laboratory, the experimental results show that the system I/O delay and overhead are decreased effectively and the occurrences of unacceptable system states caused by vibrations are also reduced, due to the reduction of task preemption in tiny mechanical system composed of WSN nodes.

Conflict of Interests

The authors declare that there is no conflict of interests regarding the publication of this paper.

Acknowledgments

This work is partly supported by National Natural Science Foundation of China (no. 61101121), National High Technology Research and Development Program (863 Program) (no. 2013AA102505), Key Laboratory Project Funds of Shenyang Ligong University under Grant (no. 4771004kfs03), and Educational Committee of Liaoning Province Science and Technology Research Projects under Grant (no. L2013096). The authors thank Jan Vitek, Ales Plsek, and Lei Zhao for their help during their studying at Purdue University in USA from September 2010 to September 2012. They also thank the anonymous reviewers for their valuable comments.