Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Cheng A.Real-time systems.Scheduling,analysis,and verification.2002.pdf
Скачиваний:
58
Добавлен:
23.08.2013
Размер:
3.68 Mб
Скачать

388 TIMING ANALYSIS OF PREDICATE-LOGIC RULE-BASED SYSTEMS

This cycle contains only the fourth rule. It implies the other rules can terminate in finite firings. The fourth rule is

(p check-group

(device ^mode { <x> <> void } ^domain <y>

^compnt <z1> ^desc { <w> << open closed >> }) (device ^mode <x> ^domain <y> ^compnt <z2> ^desc <w>) (valve_groups ^vtype <v> ^valve_a <z1> ^valve_b <z2>)

-->

(modify 1 ^compnt <v>) (modify 2 ^mode void))

We then examine the non-terminating rule with the enabling condition of the cycle. We find that the program flow can enter the cycle when variable <z1> is equal to variable <z2> in the rule check-group. This situation is not expected as a normal execution flow. Hence, we modify the LHS of this rule such that variable <z1> is not equal to variable <z2>.

(p check-group

(device ^mode { <x> <> void } ^domain <y>

^compnt <z1> ^desc { <w> << open closed >> })

(device ^mode <x> ^domain <y> ^compnt { <z2> <> <z1> } ^desc <w>) (valve_groups ^vtype <v> ^valve_a <z1> ^valve_b <z2>)

-->

(modify 1 ^compnt <v>) (modify 2 ^mode void))

This modification breaks the cycle, thus guaranteeing the termination of this rule and the program. In the next section, we introduce techniques for determining the execution time of OPS5 programs.

11.2.3 Timing Analysis

Now we introduce techniques for analyzing the timing properties of OPS5 programs and discuss a static-analytic method to predict the timing bound on program execution time. The ER graph is the basic structure of our static analysis. We predict the timing in terms of the number of rule firings. Similar work has been done for MRL in [Wang and Mok, 1993]. We will indicate the problems of static analysis and describe a tool to facilitate the timing analysis and to assist programmers in analyzing run-time performance.

Before we analyze the problem, we need to make the following assumptions:

The program can terminate.

The data domains of all attributes are finite.

No duplicate WMEs are in the WM.

The first assumption is obvious since no timing bound can be found for a program with infinite firings. The second assumption is based on the fact that the analysis

CHENG–TSAI TIMING ANALYSIS METHODOLOGY

389

problem is in general undecidable for programs with infinite domains. The third assumption is actually an extension of the second assumption. Unlike MRL, OPS5’s WMEs are identified not only by their contents but also by their time tags. Thus, the following two WMEs are identified as different items in OPS5; the first WME is generated earlier than the second WME. However, identical WMEs cannot co-exist in the WM in MRL.

time tag

WMEs

___________________________________

#3 (class ^a1 3 ^a2 4)

#6 (class ^a1 3 ^a2 4)

An OPS5 system can use a hash table to quickly locate the duplicate WMEs in the WM and prevent redundancy in every cycle. If a set of WMEs satisfies the enabling condition of the first firing rule, we can generate the same WMEs as many times as we want. In other words, we can fire the first-firing rule as many times as we want. This indicates that no upper bound exists for this rule’s firings, and thus the program cannot terminate in a finite number of rule firings. Therefore, we need to enforce the third assumption to facilitate our analysis.

11.2.4 Static Analysis

Prediction of the Number of Rule Firings Since the execution of rule-based programs is data-driven, the WM is used to predict the number of rule firings. To predict the number of each rule’s firings, we estimate the number of instantiations in the conflict set. The maximum number of instantiations of a rule can be estimated, as in example 10.

Example 10. An example with a maximum number of instantiations.

(p a

(class_a ^a1 <x> ^a2 <y>) (class_b ^b1 <x> ^b2 <z>) (class_c ^c1 <z>)

-->

action without changing the instantiations of rule a ...

Assume the domains of <x>,<y>, and <z> contain at most x, y, and z instances, respectively. Then, we have at most x yz instantiations of rule a in the conflict set. Suppose the action of rule a does not remove any instantiations of rule a. There are two situations in which rule a can be fired: (1) the initial WM contains rule a’s instantiations, or (2) rule a is triggered by other rules.

In the first situation, we have at most x yz instantiations in the initial WM. Thus rule a can fire at most x yz times before rule a is triggered by other rules.

In the second situation, another rule creates or modifies WME w which matches one or more enabling condition elements of rule a. If the WME w matches the first condition element, (class a ^a1 <x> ^a2 <y>), at most z of rule a instantiations will

390 TIMING ANALYSIS OF PREDICATE-LOGIC RULE-BASED SYSTEMS

be added into the conflict set because variables <x> and <y> are bound with the values of w’s attributes. Thus rule a can fire at most z times before it is again triggered by other rules. Similarly, if w matches (class b ^b1 <x> ^b2 <z>) or (class c ^c1 <z>), rule a can fire at most y or x y times, respectively, before another rule triggers rule a again.

Also, the action part of a rule can affect the rule’s instantiations. For example, the rule in example 10 can be

(p a

(class_a ^a1 <x> ^a2 <y>) (class_b ^b1 <x> ^b2 <z>) (class_c ^c1 <z>)

-->

(modify 3 ^c1 <y>))

Once the value of attribute ^c1 is changed, the instantiations associated with the third condition element, (class c ^c1 <z>), will be removed. Thus the maximum number of firings is the number of instances of <z>, that is, z. Also, we reduce the maximum number of firings from x yz to z. If rule a is triggered with the match of the third condition element, (class c ^c1 <z>), rule a can fire at most once before another trigger.

Algorithm 2. Detection of the upper bound on the number of firings of rule r.

Premise: rule r can be detected to terminate in bounded time by using the termination detection algorithm 1.

Suppose we have up to Ir instantiations of rule r in the initial WM. The upper bound on the firings of rule r can be estimated according to the following conditions.

1.Rule r satisfies condition 1 of theorem 1: the upper bound on the firings of rule r is Ir . The maximum number of the initial WMEs is bounded by the domain size of each attribute.

2.Rule r satisfies condition 2 of theorem 1: rules r1, r2, . . . , rn are enabling rules of the matched condition elements of rule r. These rules can terminate in f1, f2, . . . , fn firings, respectively. Rule r has at most I1, I2, . . . , In instantiations when triggered by r1, r2, . . . , rn . The upper bound on the number of firings of rule r is

n

Ir + ( f j × I j )

j=1

3.Rule r satisfies condition 3 of theorem 1: rules r1, r2, . . . , rm , which point to rule r in the ER graph can terminate in f1, f2, . . . , fm firings, respectively. Rule r has at most I1, I2, . . . , Im instantiations when triggered by

CHENG–TSAI TIMING ANALYSIS METHODOLOGY

391

r1, r2, . . . , rm . The upper bound on the number of firings of rule r is

m

Ir + ( f j × I j )

j=1

Example 3 illustrates condition 1 of this algorithm. Example 11 illustrates condition 2 of this algorithm.

Example 11. A rule satisfying condition 2 of algorithm 2.

(p a

(c1 ^a1 1 ^a2 <y>)

(c2 ^a1 <x> ^a2 <y>)

-->

(modify 2 ^a2 <x>))

Suppose variables <x> and <y> have x and y items. The second condition element, (c2 ^a1 <x> ^a2 <y>), is the matched condition element. The enabling rules of this condition element can terminate in f1, f2, . . . , fm firings, respectively. We have up to Ia instantiations of rule a in the initial WM. Since the action does not affect the WMEs that satisfy the first condition element, (c1 ^a1 1 ^a2 <y>), there would be at most y instantiations when this rule is triggered by one of the enabling rules. The upper bound on the number of firings of rule a is

n

Ia + ( f j × y)

j=1

Problems Algorithm 2 is based on the ER graph. However, in the ER graph, we use the symbolic matching method to detect the enabling relations. Since the contents and interrelationship of WMEs cannot be determined statically, it is likely to cause a pessimistic prediction, as in example 12.

Example 12. A rule with pessimistic estimation.

(p a

(class_a ^a1 7 ^a2 <x>) (class_b ^b1 <x> ^b2 6)

-->

(make class_b ^b1 5 ^b2 4)) (p b

(class_a ^a1 { <x> <> <y> } ^a2 <y>) -(class_a ^a1 <y> ^a2 <x>)

(class_b ^b1 <x> ^b2 <y>) (class_b ^b1 <y> ^b2 <x>)

-->

(modify 3 ^b2 <x>))

392 TIMING ANALYSIS OF PREDICATE-LOGIC RULE-BASED SYSTEMS

First, the enabling conditions of rule b are quite restricted. They actually imply tight relationships among the WMEs of class a and class b. The probability of firing this rule is relatively low compared to other rules. However, we still need to say that rule a potentially enables rule b since rule a creates a WME (class b ^b1 5 ^b2 4), which can individually match the third and fourth condition elements of rule b.

Second, it is unlikely that the WME modified by rule a can match the second condition element of rule b, (class b ^b1 <x> ^b2 6), because of the constant restriction on attribute ^b2. However, since variable <x> in rule a is not semantically bounded, the enabling relation still weakly holds.

In addition, algorithm 2 does not take the control strategies (LEX or MEA) into consideration. These control strategies require the time tag of each WME in the WM to determine the priorities of each instantiation in the conflict set. The time tags of WMEs are hard to predict before run-time. Without knowing the time tag of the WMEs, it is difficult to predict the interference among instantiations. Thus we must assume no interference among instantiations to make a conservative estimation. If the domain is too large, our estimation becomes pessimistic. Figure 11.3 illustrates the situation. For example, rule c can be triggered by rules e, f , g, and h. It is rare or even impossible that instantiations of these four rules triggering rule c co-exist in the conflict set because firing one of these rules may prevent other rules from firing. For example, firing instantiations of rule e may remove the instantiations of rule f . Since we cannot predict the interference relation among rules e, f , g, and h, we must assume all instantiations of these four rules can be executed. The same condition applies to rules a, b, and d. As we can see, rule b inherits the firing bounds of rules

e

f

g

h

i

c

d

b

a

Figure 11.3 Enabling relation with pessimistic estimation.

Соседние файлы в предмете Электротехника