• No results found

The HSASC Algorithm for RTSC

As a reminder, the RTSC problem addresses system-wide energy optimiza-tion for hard real-time tasks running on a single-core processor. The main objective is to find the optimal speed assignment assign, which ensures sys-tem schedulability while minimizing the syssys-tem-wide energy consumption over one hyper period. Therefore, the solution space ΩRT SCis defined as the set of all possible speed assignments.

RT SC= {assign1, assign2, ..., assign|S|n} (4.7) Clearly, the size of solution space is |S|n, where |S| is the number of available P-states and n is the number of tasks. For instance, if a processor supports 5 operating speeds and 10 real-time tasks need to be scheduled, there exist 510= 9765625 possible speed assignments in total. Moreover, two solutions assigniand assignj are said to be neighbors, i.e.,

(assigni∈ N(assignj)) ∧ (assignj∈ N(assigni)) (4.8) if they exactly differ in the speed assignment of one task, i.e.,

∃τ ∈ Γ : assigni(τ) 6= assignj(τ) (4.9) and

∀τ0∈ Γ \ {τ} : assigni0) = assignj0) (4.10) One of the most important procedures in the SA algorithm is neighbor selec-tion. Naively, a uniform distribution can be applied to select neighbors, how-ever, by considering problem specific information, some neighbors might be

Task τ1 τ2 τ3 τ4 τ5

SC S3 S3 S3 S3 S3

assign S1 S3 S3 S2 S1

pen 1.8 1 1 1.3 1.8

prob 0.26 0.14 0.14 0.20 0.26

Table 4.1: An example computation of the task penalty value and the task selection probability

more superior than the others in terms of energy consumption. For the RTSC problem, this process is performed by selecting a neighbor in two steps as shown in Figure 4.1. In the first step a task is selected, for which its fre-quency is to be changed in the second step. For the first step, each task is associated with a so-called penalty value pen(τi), which is defined in (4.11).

∀τi∈ Γ : pen(τi) = λ1· |F(assign(τi)) − F(SC(τi))| + λ2 (4.11)

Intuitively, the penalty value of a task shows the distance between the cur-rently assigned P-state and the P-state with critical speed. By definition, the critical speed of a task is the optimal speed when its AEC is concerned. Ob-viously, if the task is not running at the optimal speed, then there is some wasted energy. Therefore, the task is to be penalized according to its dif-ference to the optimal speed. The parameter λ1 is a coefficient to adjust the weight of the speed difference and λ2is a technical parameter preventing the penalty value from being zero. After establishing the penalty value, the task selection probability prob(τi) in the first step is defined.

∀τi∈ Γ : prob(τi) = pen(τi)

τj∈Γ

pen(τj) (4.12)

It is not hard to see that the more penalized task is to be selected more likely, because in this way, hopefully, its change is more beneficial with regard to energy saving. Table 4.1 shows a simple example with 5 real-time tasks. It is assumed that the processor supports 3 P-states with F(S1) = 1, F(S2) = 0.5 and F(S3) = 0.2. The critical speed for each task is assumed to be computed and shown in the second row. Though all the tasks have the same critical speed here, it may not be the case for other examples. Furthermore, the example assumes assign as the current solution shown in the third row of the table. The corresponding task penalty values can be easily obtained by applying (4.11), provided that λ1and λ2 are set to be 1. In accordance with (4.12), the calculated selection probability for each task is shown in the fifth row.

After a task τi is selected, a new speed has to be assigned to it. Hereby the critical speed is selected with the probability 0.5 and the remaining probabil-ity is uniformly distributed to the other available speeds. Algorithm 2 shows an overview of the proposed heuristic search algorithm. The initial solution is simply generated by assigning all the tasks with the maximal speed.

Algorithm 2 Heuristic Search Algorithm for RTSC (HSASC) Input: A solution space Ω = {assign1, assign2, ..., assign|S|n} Output: A solution assignbest

1: Generate assigninitwith ∀τ ∈ Γ : assigninit(τ) = S1 2: assignbest ← assigninit, assigncurr ← assigninit, i ← 1

3: while termination criterion is not met do

4: Select a τ according to the selection probability prob (4.12)

5: Generate assign0by changing assigncurr(τ)

6: Generate a random number r ∈ [0, 1]

7: if r ≤ Praccept(assigncurr, assign0, i) then

8: assigncurr ← assign0

9: if J(assigncurr) < J(assignbest) then

10: assignbest ← assigncurr

11: end if

12: end if

13: i← i + 1

14: end while

In Algorithm 2, the initial and current solution are denoted by assigninit and assigncurr, respectively. assign0 denotes the generated neighbor solution in each iteration. Except the neighbor selection process, another important dif-ference between the HSASC Algorithm and the generalized SA algorithm (Algorithm 1) is that the HSASC algorithm always remembers the best so-lution, denoted by assignbest, ever found and produces it as the final output.

This modification further improves the performance of the original SA algo-rithm, which outputs the current solution.

Moreover, J(assign) expresses the cost or value of the solution assign, which is the system-wide energy consumption over a hyper period. If a speed assignment results in an invalid solution, i.e., the real-time system is not feasible under the speed assignment, the HSASC algorithm assumes that J(assign) = +∞. As a result, the unschedulable solutions will never be ac-cepted. In general, the evaluation of a solution is a non-trivial job. At this moment, one assumes that the value of a solution can be obtained in some way. However, more details are explained in Chapter 6.

Table 4.2 shows a possible series of solutions that are visited by the HSASC algorithm for the example shown in Table 4.1.

Task τ1 τ2 τ3 τ4 τ5 1st assign S1 S1 S1 S1 S1 2nd assign S2 S1 S1 S1 S1 3rd assign S2 S3 S1 S1 S1 4th assign S3 S3 S1 S1 S1 5th assign S3 S3 S1 S3 S1 6th assign S3 S3 S2 S3 S1 7th assign S3 S3 S2 S3 S2 Table 4.2: A series of possible solutions