prio/Paper/Paper.thy
changeset 304 bd05c5011c0f
parent 301 e820ee5f76f7
child 305 463bed130705
equal deleted inserted replaced
303:d9b0a2fd0db7 304:bd05c5011c0f
   101   \end{quote}
   101   \end{quote}
   102 
   102 
   103   \noindent
   103   \noindent
   104   He suggests to avoid PIP altogether by not allowing critical
   104   He suggests to avoid PIP altogether by not allowing critical
   105   sections to be preempted. Unfortunately, this solution does not
   105   sections to be preempted. Unfortunately, this solution does not
   106   help in real-time systems with low latency \emph{requirements}.
   106   help in real-time systems with hard deadlines for high-priority 
       
   107   threads.
   107 
   108 
   108   In our opinion, there is clearly a need for investigating correct
   109   In our opinion, there is clearly a need for investigating correct
   109   algorithms for PIP. A few specifications for PIP exist (in English)
   110   algorithms for PIP. A few specifications for PIP exist (in English)
   110   and also a few high-level descriptions of implementations (e.g.~in
   111   and also a few high-level descriptions of implementations (e.g.~in
   111   the textbook \cite[Section 5.6.5]{Vahalia96}), but they help little
   112   the textbook \cite[Section 5.6.5]{Vahalia96}), but they help little
   148   informal reasoning (since we have to analyse all possible behaviours
   149   informal reasoning (since we have to analyse all possible behaviours
   149   of threads, i.e.~\emph{traces}, that could possibly happen).\medskip
   150   of threads, i.e.~\emph{traces}, that could possibly happen).\medskip
   150 
   151 
   151   \noindent
   152   \noindent
   152   {\bf Contributions:} There have been earlier formal investigations
   153   {\bf Contributions:} There have been earlier formal investigations
   153   into PIP \cite{conf/fase/JahierHR09,WellingsBSB07,Faria08}, but they
   154   into PIP \cite{Faria08,Jahier09,Wellings07}, but they employ model
   154   are using model checking technology. As far as we are aware, this is
   155   checking techniques. This paper presents a formalised and
   155   the first formalised proof for the correctness of PIP. In contrast
   156   mechanically checked proof for the correctness of PIP (to our
   156   to model checking, our formalisation provides insight into why PIP
   157   knowledge the first one; an earlier informal proof by Sha et
   157   is correct and allows us to prove stronger properties. For this Isar
   158   al.~\cite{Sha90} is flawed).  In contrast to model checking, our
   158   and Isabelle/HOL is an attractive tool for exploring definitions and
   159   formalisation provides insight into why PIP is correct and allows us
   159   keeping proofs consistent.
   160   to prove stronger properties that, as we will show, inform an
   160 
   161   implementation.  For example, we found by ``playing'' with the formalisation
   161   For example, we find through formalization that the choice of next 
   162   that the choice of the next thread to take over a lock when a
   162   thread to take a lock when a resource is released is irrelevant for 
   163   resource is released is irrelevant for PIP being correct.
   163   the very basic property of PIP to hold.
       
   164 
       
   165   Despite the wide use of Priority Inheritance Protocol in real time
       
   166   operating system, it’s correctness has never been formally proved
       
   167   and mechanically checked. All existing verification are based on
       
   168   model checking technology. Full automatic verification gives little
       
   169   help to understand why the protocol is correct. And results such
       
   170   obtained only apply to models of limited size. This paper presents a
       
   171   formal verification based on theorem proving. Machine checked formal
       
   172   proof does help to get deeper understanding. We found the fact which
       
   173   is not mentioned in the literature, that the choice of next thread
       
   174   to take over when an critical resource is release does not affect
       
   175   the correctness of the protocol. The paper also shows how formal
       
   176   proof can help to construct correct and efficient implementation.
       
   177 
       
   178   vt (valid trace) was introduced earlier, cite
       
   179   
       
   180   
       
   181   Paulson's method has not been used outside security field, except
       
   182   work by Zhang et al.
       
   183 
       
   184   How did Sha et al prove it....they did not use Paulson's method.
       
   185 *}
   164 *}
   186 
   165 
   187 section {* Formal Model of the Priority Inheritance Protocol *}
   166 section {* Formal Model of the Priority Inheritance Protocol *}
   188 
   167 
   189 text {*
   168 text {*
   526   function @{text f}. 
   505   function @{text f}. 
   527   Note that in the initial case, that is where the list of events is empty, the set 
   506   Note that in the initial case, that is where the list of events is empty, the set 
   528   @{term threads} is empty and therefore there is no thread ready nor a running.
   507   @{term threads} is empty and therefore there is no thread ready nor a running.
   529   If there is one or more threads ready, then there can only be \emph{one} thread
   508   If there is one or more threads ready, then there can only be \emph{one} thread
   530   running, namely the one whose current precedence is equal to the maximum of all ready 
   509   running, namely the one whose current precedence is equal to the maximum of all ready 
   531   threads. We use the set-comprehension to capture both possibilites.
   510   threads. We use the set-comprehension to capture both possibilities.
   532   We can now also define the set of resources that are locked by a thread in any
   511   We can now also define the set of resources that are locked by a thread in any
   533   given state.
   512   given state.
   534 
   513 
   535   \begin{isabelle}\ \ \ \ \ %%%
   514   \begin{isabelle}\ \ \ \ \ %%%
   536   @{thm holdents_def}
   515   @{thm holdents_def}
   537   \end{isabelle}
   516   \end{isabelle}
   538 
   517 
   539   \noindent
   518   \noindent
   540   These resources are given by the holding edges in the RAG.
   519   These resources are given by the holding edges in the RAG.
   541 
   520 
   542   Finally we can define what a \emph{valid state} is in our PIP. For example we cannot exptect to
   521   Finally we can define what a \emph{valid state} is in our PIP. For
   543   be able to exit a thread, if it was not created yet. These validity constraints
   522   example we cannot expect to be able to exit a thread, if it was not
   544   are characterised by the inductive predicate @{term "step"}. We give five 
   523   created yet. These validity constraints are characterised by the
   545   inference rules relating a state and an event that can happen next.
   524   inductive predicate @{term "step"}. We give five inference rules
       
   525   relating a state and an event that can happen next.
   546 
   526 
   547   \begin{center}
   527   \begin{center}
   548   \begin{tabular}{c}
   528   \begin{tabular}{c}
   549   @{thm[mode=Rule] thread_create[where thread=th]}\hspace{1cm}
   529   @{thm[mode=Rule] thread_create[where thread=th]}\hspace{1cm}
   550   @{thm[mode=Rule] thread_exit[where thread=th]}
   530   @{thm[mode=Rule] thread_exit[where thread=th]}
   620     @{thm threads_s}.
   600     @{thm threads_s}.
   621   \item @{term "th"} has the highest precedence in @{term "s"} (@{text "highest"}):
   601   \item @{term "th"} has the highest precedence in @{term "s"} (@{text "highest"}):
   622     @{thm highest}.
   602     @{thm highest}.
   623   \item The precedence of @{term "th"} is @{term "Prc prio tm"} (@{text "preced_th"}):
   603   \item The precedence of @{term "th"} is @{term "Prc prio tm"} (@{text "preced_th"}):
   624     @{thm preced_th}.
   604     @{thm preced_th}.
   625   \end{enumerate}
   605  
   626 
   606   \item @{term "t"} is a valid extension of @{term "s"} (@{text "vt_t"}): @{thm vt_t}.
       
   607   \item Any thread created in @{term "t"} has priority no higher than @{term "prio"}, therefore
       
   608     its precedence can not be higher than @{term "th"},  therefore
       
   609     @{term "th"} remain to be the one with the highest precedence
       
   610     (@{text "create_low"}):
       
   611     @{thm [display] create_low}
       
   612   \item Any adjustment of priority in 
       
   613     @{term "t"} does not happen to @{term "th"} and 
       
   614     the priority set is no higher than @{term "prio"}, therefore
       
   615     @{term "th"} remain to be the one with the highest precedence (@{text "set_diff_low"}):
       
   616     @{thm [display] set_diff_low}
       
   617   \item Since we are investigating what happens to @{term "th"}, it is assumed 
       
   618     @{term "th"} does not exit during @{term "t"} (@{text "exit_diff"}):
       
   619     @{thm [display] exit_diff}
       
   620   \end{enumerate}
   627 
   621 
   628   \begin{lemma}
   622   \begin{lemma}
   629   @{thm[mode=IfThen] moment_blocked}
   623   @{thm[mode=IfThen] moment_blocked}
   630   \end{lemma}
   624   \end{lemma}
   631 
   625 
   632   \begin{theorem}
   626   \begin{theorem}
   633   @{thm[mode=IfThen] runing_inversion_2}
   627   @{thm[mode=IfThen] runing_inversion_2}
   634   \end{theorem}
   628   \end{theorem}
   635 
   629 
       
   630   \begin{theorem}
       
   631   @{thm[mode=IfThen] runing_inversion_3}
       
   632   \end{theorem}
   636   
   633   
   637 
   634 
   638 
   635 
   639 TO DO 
   636 TO DO 
   640 
   637 
   657 
   654 
   658   A clear and simple understanding of the problem at hand is both a
   655   A clear and simple understanding of the problem at hand is both a
   659   prerequisite and a byproduct of such an effort, because everything
   656   prerequisite and a byproduct of such an effort, because everything
   660   has finally be reduced to the very first principle to be checked
   657   has finally be reduced to the very first principle to be checked
   661   mechanically.
   658   mechanically.
       
   659 
       
   660   Our formalisation and the one presented
       
   661   in \cite{Wang09} are the only ones that employ Paulson's method for
       
   662   verifying protocols which are \emph{not} security related. 
   662 
   663 
   663   TO DO 
   664   TO DO 
   664 
   665 
   665   no clue about multi-processor case according to \cite{Steinberg10} 
   666   no clue about multi-processor case according to \cite{Steinberg10} 
   666 
   667 
   677   practice\cite{locke-july02}. However, as pointed out in the
   678   practice\cite{locke-july02}. However, as pointed out in the
   678   literature, the analysis of priority inheritance protocol is quite
   679   literature, the analysis of priority inheritance protocol is quite
   679   subtle\cite{yodaiken-july02}.  A formal analysis will certainly be
   680   subtle\cite{yodaiken-july02}.  A formal analysis will certainly be
   680   helpful for us to understand and correctly implement PI. All
   681   helpful for us to understand and correctly implement PI. All
   681   existing formal analysis of PI
   682   existing formal analysis of PI
   682   \cite{conf/fase/JahierHR09,WellingsBSB07,Faria08} are based on the
   683   \cite{Jahier09,Wellings07,Faria08} are based on the
   683   model checking technology. Because of the state explosion problem,
   684   model checking technology. Because of the state explosion problem,
   684   model check is much like an exhaustive testing of finite models with
   685   model check is much like an exhaustive testing of finite models with
   685   limited size.  The results obtained can not be safely generalized to
   686   limited size.  The results obtained can not be safely generalized to
   686   models with arbitrarily large size. Worse still, since model
   687   models with arbitrarily large size. Worse still, since model
   687   checking is fully automatic, it give little insight on why the
   688   checking is fully automatic, it give little insight on why the
  1036   the fundamental requirement of Priority Inheritance protocol. Another purpose of this paper 
  1037   the fundamental requirement of Priority Inheritance protocol. Another purpose of this paper 
  1037   is to show how this model can be used to guide a concrete implementation. As discussed in
  1038   is to show how this model can be used to guide a concrete implementation. As discussed in
  1038   Section 5.6.5 of \cite{Vahalia96}, the implementation of Priority Inheritance in Solaris 
  1039   Section 5.6.5 of \cite{Vahalia96}, the implementation of Priority Inheritance in Solaris 
  1039   uses sophisticated linking data structure. Except discussing two scenarios to show how
  1040   uses sophisticated linking data structure. Except discussing two scenarios to show how
  1040   the data structure should be manipulated, a lot of details of the implementation are missing. 
  1041   the data structure should be manipulated, a lot of details of the implementation are missing. 
  1041   In \cite{Faria08,conf/fase/JahierHR09,WellingsBSB07} the protocol is described formally 
  1042   In \cite{Faria08,Jahier09,Wellings07} the protocol is described formally 
  1042   using different notations, but little information is given on how this protocol can be 
  1043   using different notations, but little information is given on how this protocol can be 
  1043   implemented efficiently, especially there is no information on how these data structure 
  1044   implemented efficiently, especially there is no information on how these data structure 
  1044   should be manipulated. 
  1045   should be manipulated. 
  1045 
  1046 
  1046   Because the scheduling of threads is based on current precedence, 
  1047   Because the scheduling of threads is based on current precedence, 
  1305 section {* Related works \label{related} *}
  1306 section {* Related works \label{related} *}
  1306 
  1307 
  1307 text {*
  1308 text {*
  1308   \begin{enumerate}
  1309   \begin{enumerate}
  1309   \item {\em Integrating Priority Inheritance Algorithms in the Real-Time Specification for Java}
  1310   \item {\em Integrating Priority Inheritance Algorithms in the Real-Time Specification for Java}
  1310     \cite{WellingsBSB07} models and verifies the combination of Priority Inheritance (PI) and 
  1311     \cite{Wellings07} models and verifies the combination of Priority Inheritance (PI) and 
  1311     Priority Ceiling Emulation (PCE) protocols in the setting of Java virtual machine 
  1312     Priority Ceiling Emulation (PCE) protocols in the setting of Java virtual machine 
  1312     using extended Timed Automata(TA) formalism of the UPPAAL tool. Although a detailed 
  1313     using extended Timed Automata(TA) formalism of the UPPAAL tool. Although a detailed 
  1313     formal model of combined PI and PCE is given, the number of properties is quite 
  1314     formal model of combined PI and PCE is given, the number of properties is quite 
  1314     small and the focus is put on the harmonious working of PI and PCE. Most key features of PI 
  1315     small and the focus is put on the harmonious working of PI and PCE. Most key features of PI 
  1315     (as well as PCE) are not shown. Because of the limitation of the model checking technique
  1316     (as well as PCE) are not shown. Because of the limitation of the model checking technique
  1318     convincing way.  
  1319     convincing way.  
  1319   \item {\em Formal Development of Solutions for Real-Time Operating Systems with TLA+/TLC}
  1320   \item {\em Formal Development of Solutions for Real-Time Operating Systems with TLA+/TLC}
  1320     \cite{Faria08}. A formal model of PI is given in TLA+. Only 3 properties are shown 
  1321     \cite{Faria08}. A formal model of PI is given in TLA+. Only 3 properties are shown 
  1321     for PI using model checking. The limitation of model checking is intrinsic to the work.
  1322     for PI using model checking. The limitation of model checking is intrinsic to the work.
  1322   \item {\em Synchronous modeling and validation of priority inheritance schedulers}
  1323   \item {\em Synchronous modeling and validation of priority inheritance schedulers}
  1323     \cite{conf/fase/JahierHR09}. Gives a formal model
  1324     \cite{Jahier09}. Gives a formal model
  1324     of PI and PCE in AADL (Architecture Analysis \& Design Language) and checked 
  1325     of PI and PCE in AADL (Architecture Analysis \& Design Language) and checked 
  1325     several properties using model checking. The number of properties shown there is 
  1326     several properties using model checking. The number of properties shown there is 
  1326     less than here and the scale is also limited by the model checking technique. 
  1327     less than here and the scale is also limited by the model checking technique. 
  1327   \item {\em The Priority Ceiling Protocol: Formalization and Analysis Using PVS}
  1328   \item {\em The Priority Ceiling Protocol: Formalization and Analysis Using PVS}
  1328     \cite{dutertre99b}. Formalized another protocol for Priority Inversion in the 
  1329     \cite{dutertre99b}. Formalized another protocol for Priority Inversion in the