Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeContact

The text of a manual · part 9 of 14

Feasibility of formal model checking in the Vitatron environment: Chapter 5Formal modeling of pacemakerfirmware, pages 49 to 54

Pages 49 to 54 of 91, from Feasibility of formal model checking in the Vitatron environment

The original document is the PDF (6.4 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

Filed in the catalog under the Vitatron EE244

Page 49

Chapter 5

Formal modeling of pacemaker firmware During the project several formal models have been constructed to investigate the feasibility of model checking on the firmware designs of Vitatron. These models differ in which firmware components are contained in the model and in which environmental processes are modeled besides the firmware processes. For example, we initially started with a model that contained only a small part of the firmware, a simple process simulating the behavior of the hardware module PG (see chapter 4), and a group of processes simulating some basic heart behavior. In this model, the firmware process was a model of some core functionality to deliver paces at a certain rate. Later on, we added more firmware functionality to the models and concurrently also the PG process and the heart processes were extended to support the firmware extensions in the formal models. This chapter gives a description of some technical details of the formal models and of the design decisions that were made during the formal modeling of the pacemaker firmware. These design decisions mainly concern the translation of the H&P model constructs into the formal languages of the model checking tools. The described choices and modeling techniques slowly emerged during the construction and the verification of the models; they are described in this report because they form the basis of the models. By keeping these choices and techniques in mind, the construction of the models was actually just a matter of straightforward translation of the H&P model. During this translation we tried to deviate as little as possible from the H&P model; the only necessary deviations that were made are described in this chapter. Because we think all these deviations are justified, we have high confidence that the level of conformance between the H&P model and the formal model is rather high. Section 5.1 describes the design decisions and technical details that are applicable on all formal models of the pacemaker firmware. Because some technical aspects of the models are dependent of the model checking tool that is used, sections 5.2 and 5.3 describe the tool specific technical aspects of the models. Section 5.4 describes the design of the heart simulation processes and the PG process, because they form the environment in which the firmware model is verified in some models. Finally in section 5.5 we mention some techniques that have been applied to reduce the state space of the models. Note that these state space reducing techniques decrease the level of conformance between the H&P model and the formal model, but this is inevitable if we want

48

Page 50

to make model checking possible. The actual model checking approaches and their results will not be described in this chapter, but in chapter 6.

5.1

General aspects of the formal models

When translating (a part of) a Hatley and Pirbhai system requirements model to a formal model, the first design decision concerns the grouping of the H&P processes (DFDs and PSPECs) into concurrent processes in the formal model. If this grouping is chosen too coarsegrained, i.e. too much H&P processes are put in one formal concurrent process, the concurrent processes become too complex and also the benefits that concurrency in the formal model gives are lost. If for example a concurrent process is created that represents two different (but related) DFDs with corresponding STDs, the concurrent process must take all state combinations of these two STDs into account. Modeling the two DFDs each as a concurrent process avoids this and makes the modeling easier, because each process only has to bother about the state of its own STD, thus resulting in a decrease of the total number of ‘state handling routines’. On the other hand, in a too fine-grained grouping, the overhead of communication becomes large which is also undesirable. These considerations lead to the decision that each DFD that does not contain child diagrams (but only PSPECs) is modeled as a separate concurrent process. The formal process description defines the actions that are performed on receipt of an event from each incoming control flow to the diagram. Usually the diagram’s CSPEC is the basis of the process description; it executes the pseudo-code of the PSPECs that are called by the CSPEC. Besides the concurrent processes for these lowest level H&P DFDs, the formal models also contain concurrent processes for most intermediate level H&P diagrams. Often such an intermediate level diagram does not contain any PSPECs and its function is only the redirection of incoming events to its child diagrams. Then the diagram’s CSPEC, which manages these redirections, is directly translated to a concurrent process. If an intermediate level diagram also contains some PSPECs, the functionality from these PSPECs is combined with the redirection of the incoming control flows. However, to this latter statement there is one exception in the DFD Atrial Monitor which contains a relatively complex PSPEC Atrial Rate Classifier. This PSPEC performs a calculation on receipt of an event; the possible incoming events are not only coming from higher level diagrams but also from child diagrams of the Atrial Monitor. Modeling this PSPEC as a separate concurrent process is more straightforward since this creates a more clear interface to the processes that must send an event to the PSPEC. In the H&P model all communications between DFDs, PSPECs and CSPECs run via data flows and control flows. The way the data flows are modeled happens to be tool dependent, hence we describe this aspect in the tool specific sections 5.2 and 5.3. On the contrary, for the control flows a modeling construct is designed that is used in the models for both tools. To motivate this control flow modeling construct, we consider the following example: Consider a system, consisting of two concurrent processes A and B that can interact by synchronous communication. Process A sends an event to process B, then performs n local actions and then terminates. Process B waits on any incoming event; on receipt of an event it processes this event by performing m local actions. 49

Page 51

When process A after sending the event to process B, simply continues its action sequence and ignores the behavior of process B, the resulting system state space will contain states for all combinations of internal states of process A and B. So in this case the order of magnitude of the model state space would be n ∗ m, meaning that the state space size is quadratic in n and m. Because the firmware design contains many such situations, we had to invent an event passing mechanism that avoids an explosion of the state space as described in the example. When we look at the implementation code of the pacemaker firmware, we see that event sending in the H&P model is actually implemented as doing a function call. Because the pacemaker firmware has no parallel threads, a component that calls a function must wait on execution of the function and can only resume its behavior when the program counter is set back to its address on termination of the called function. Back to the example this corresponds to the behavior in which process A performs its local actions after process B has finished processing the received event. If this behavior should be modeled, the order of magnitude of the model state space would be n + m, meaning that the state space size is only linear in n and m. So to conform the formal models to the firmware design and for performance reasons, the sending of events is formally modeled as follows. Every process has its own unique ID and a process always sends its own ID and the ID of the recipient along with an event. After sending an event, the sending process waits on a special acknowledgment message that contains the ID of the event recipient and its own ID. The event recipient sends this acknowledgment message as soon as it finishes the processing of the received event. In this way, function calling and returning are modeled as separate events in the formal model. The event and acknowledgment messages with their arguments are modeled in mCRL2 and Uppaal as synchronizing parameterized actions or synchronizations over channels from an array, respectively. An event from the PG that reaches the firmware system is firstly processed by the highest level process (corresponding to the highest level H&P diagram). This process sends the incoming event consecutively to one or more child processes as defined in the CSPEC of the highest level diagram. Each time the highest level process waits on acknowledgment while its child diagram processes the event. This behavior repeats itself on lower levels and usually the real processing of the event is mainly done in the lowest level processes by the PSPECs. This typical behavior is visualized in a message sequence chart (MSC) of an imaginary system in figure 5.1. In this MSC we see that process Root and process A just redirect the event to child processes and wait for acknowledgment. Process B and C do some processing on receipt of the event and send an acknowledgment to the process that sent the event. On processing the event, process B sends an output to the environment. Of course such modeling can be improved by for instance dropping process A as intermediate process in sending an event from Root to C, but in many cases we have not done this to stay close to the H&P model and to provide a clear interface to processes that must send an event to process A. In other cases we have applied this improvement; for example when a certain process always redirects all incoming event to one particular subprocess. However this mechanism can cause problems if a certain process during processing of a received event sends an event to a higher level process that is currently waiting on an acknowledgment. The waiting process only accepts an acknowledgment from the process to 50

Page 52

Figure 5.1: Message sequence chart of typical event passing in firmware system which it has sent an event and thus will not be able to receive any events. This scenario will most likely cause a deadlock in the complete system, because the root process also does not get an acknowledgment and will not be able to receive any events from the environment anymore. During construction of the models in this project, such scenarios did indeed cause a deadlock to occur when trying to generate the state space of the model. By inspecting the trace to the found deadlock, the scenario could be explored and the problem could be solved. Because the problem does not occur too often, it was possible to solve them by explicitly modeling the possible incoming events during waiting for an acknowledgment. When process A is waiting for an acknowledgment from process B and it receives an event from process C, it postpones processing of the event until the acknowledgment from process B is received. This prevents that process A and process B will be concurrently processing an event which can have bad consequences on the state space as we have seen above. An H&P system requirements model can contain state transition diagrams (STD) in the context of a CSPEC (see section 4.1). These STDs differ from common state transition diagrams in the sense that they implicitly ignore events from incoming control flows if the STD does not include an outgoing transition from the current state for this control flow. So if an event is received when the STD resides in a state without an outgoing transition for this event, the STD just stays in this state. In the formal models this aspect is also modeled. In mCRL2 this was just a matter of adding an else-branch to each process that sends an acknowledgment to the sender of an event for which no outgoing transition is defined in the current state. But Uppaal does not support such an else-branch construct so we had to add all non-defined transitions as loop transitions that send an acknowledgment to the event sender.

51

Page 53

5.2

Technical aspects of the mCRL2 models

As described in section 4.1, data flows in an H&P model are time continuous and can be read and reread any number of times by a receiving process until the source of the data flow stops generating it. To model this aspect in mCRL2, for each data flow x of type T three parameterized actions (r x, s x, c x : T ) are declared. By means of the mCRL2 communication and restriction operators, it is specified that these three actions communicate and that only the action c x is allowed to occur. The source process A of x contains a parameter representing the current value of x and A’s process expression contains an alternative that performs the action s x(“value of x”). This enables each process that needs the value of x to perform P y:T r x(y) and use the value of y in subsequent actions and conditions as the value of the data flow x. This modeling of the data flows only causes some problems when the source process is performing a series of actions in collaboration with other processes. During the execution the process is not able to perform the s x action. An example of this problem is the situation in which process A has sent an event to one of its child processes B and waits on acknowledgment of B. While the event is being processed in lower level processes, the value of A’s data flow may be needed. But A is waiting on acknowledgment and can not send the data flow value. This is a typical deadlock situation in which process A waits on the lower level processes and one of the lower level processes waits on process A. One nasty solution for this problem could be enabling A to perform the data flow send action during waiting on an acknowledgment. But we have chosen to create a co-process in such cases that is responsible for storing the values of the data flows of process A, i.e. the data flows are modeled as a process. When for example, a calculation in process A results in a change of its data flow x, A performs a s set x(“new value of x”) action that communicates with a r set x action in A’s co-process which stores the new value. The co-process only contains alternatives for receiving changes in A’s data flows and for sending the current values to other processes. Because these are all unit-actions, the co-process can never be busy executing a series of actions and causing a deadlock situation as described above. Next we discuss the modeling of time in the mCRL2 models. In the H&P firmware requirements model time is present through the minute passed events from the hardware module Timer (see figure 4.2). In the part of the model that is formally modeled, these minute passed events are actually only used in the process Band Update that updates the physiological band (see section 4.2) at least every minute. In the processes that simulate the heart and PG behavior time is a more crucial factor, but here time steps of one minute are far too large. Because the PG does some processing every 5 ms, special tick-actions are introduced that represent a time passage of 5 ms. All processes that use time (i.e. the heart and PG processes, the Band Update process and also the root process of the firmware (see below)) can perform their own tick-action if their local state allows it. For example, if t represents the current time and the PG must deliver a pace to the heart if t = 15 then when t = 15 the PG may only perform its tick-action after delivering the pace. All the tick-actions communicate to one global tick-action which represents a global time passage of 5 ms. Because individual tick-actions are not allowed to occur independently of all others, global time can only pass if the states of all time dependent processes allow it. As said above, the root process of the formal model also participates in performing the 52

Page 54

tick-action. Not the fact that this process is time dependent is the reason for this, but this models the property that all processing in an H&P model is infinitely fast. All external events enter the formal model via this root process which redirects them to its subprocesses. Hence, the root process is always waiting for an acknowledgment of one of its subprocesses during processing of an event. When the root process is waiting until the event is entirely processed, it can not perform its tick-action. Therefore time can not pass during processing of an event in the formal model which means that this processing is modeled infinitely fast. It must be noted that because event handling is modeled like this to conform to the H&P principle of infinitely fast event processing, flaws in the firmware implementation can potentially remain undiscovered. During processing of an external event, the firmware implementation of course spends runtime which could influence the later external behavior of the system. Since we only verify the firmware design, we stick to the infinitely fast modeling of event handling, but one has to be aware of the risk of missing flaws that are caused by spent runtime. Modeling this spent runtime will certainly not result in a feasible model checking approach, because this introduces too much non-determinism into the model.

5.3

Technical aspects of the Uppaal models

In Uppaal time is explicitly present through clock variables. All time dependent processes in the formal Uppaal model are equipped with one or more clock variables. Because these clock variables automatically show synchronous progress, the only concern is to restrict this progress when time is not allowed to pass. In the previous section we described two situations in which time is not allowed to pass, i.e. if a process must perform some action sequence on a specific moment in time or when an external event is being processed in the model. In the first situation the passage of time is restricted by a combination of a guard on the first transition of the action sequence and an invariant on the state wherein the process waits until it may perform the action sequence. The guard is a clock constraint which controls that performing the action sequence is not allowed before the clock reaches the time on which the action sequence must occur. On the other hand, the invariant is a clock constraint which specifies that the same clock may not be greater than the time on which the action sequence must occur. The invariant makes sure that the model can not reside in the corresponding state after the action sequence must have been performed. Hence the guard and the invariant together imply that the action sequence starts exactly on the specified moment in time and is performed infinitely fast. To disallow passage of time during processing of an event, we make use of the notion of the committed locations (see section 2.2). Event processing is just an action sequence which includes redirection of events to other processes and waiting for acknowledgments. By making all intermediate locations in such action sequences committed, the action sequence must be finished once it is started before time can pass again. The same effect would be reached when we made all these locations urgent, but this would leave the option open to perform other (non time passing) actions during the processing of an event. This would affect the model state space size negatively and furthermore it could cause interference in the model when these other actions affect variables on which decision are made in processing the event.

53