Journal/Paper.thy
changeset 76 b6ea51cd2e88
parent 75 2aa37de77f31
child 82 c0a4e840aefe
equal deleted inserted replaced
75:2aa37de77f31 76:b6ea51cd2e88
    21   preced ("prec") and
    21   preced ("prec") and
    22 (*  preceds ("precs") and*)
    22 (*  preceds ("precs") and*)
    23   cpreced ("cprec") and
    23   cpreced ("cprec") and
    24   cp ("cprec") and
    24   cp ("cprec") and
    25   holdents ("resources") and
    25   holdents ("resources") and
    26   DUMMY  ("\<^raw:\mbox{$\_\!\_$}>")
    26   DUMMY  ("\<^raw:\mbox{$\_\!\_$}>") and
       
    27   cntP ("c\<^bsub>P\<^esub>") and
       
    28   cntV ("c\<^bsub>V\<^esub>")
    27  
    29  
    28 (*>*)
    30 (*>*)
    29 
    31 
    30 section {* Introduction *}
    32 section {* Introduction *}
    31 
    33 
   176   example on Page 254 the authors write: ``{\it Upon releasing the
   178   example on Page 254 the authors write: ``{\it Upon releasing the
   177   lock, the [low-priority] thread will revert to its original
   179   lock, the [low-priority] thread will revert to its original
   178   priority.}'' The same error is also repeated later in this textbook.
   180   priority.}'' The same error is also repeated later in this textbook.
   179 
   181 
   180   
   182   
   181   While \cite{Laplante11,Liu00,book,Sha90,Silberschatz13} are the only formal publications we have 
   183   While \cite{Laplante11,Liu00,book,Sha90,Silberschatz13} are the only
   182   found that specify the incorrect behaviour, it seems also many
   184   formal publications we have found that specify the incorrect
   183   informal descriptions of PIP overlook the possibility that another
   185   behaviour, it seems also many informal descriptions of PIP overlook
   184   high-priority might wait for a low-priority process to finish.
   186   the possibility that another high-priority might wait for a
   185   A notable exception is the texbook \cite{buttazzo}, which gives the correct 
   187   low-priority process to finish.  A notable exception is the texbook
   186   behaviour of resetting the priority of a thread to the highest remaining priority of the 
   188   \cite{buttazzo}, which gives the correct behaviour of resetting the
   187   threads it blocks. This textbook also gives an informal proof for 
   189   priority of a thread to the highest remaining priority of the
   188   the correctness of PIP in the style of Sha et al. Unfortunately, this informal 
   190   threads it blocks. This textbook also gives an informal proof for
   189   proof is too vague to be useful for formalising the correctness of PIP
   191   the correctness of PIP in the style of Sha et al. Unfortunately,
   190   and the specification leaves out nearly all details in order 
   192   this informal proof is too vague to be useful for formalising the
   191   to implement PIP efficiently.\medskip\smallskip
   193   correctness of PIP and the specification leaves out nearly all
       
   194   details in order to implement PIP efficiently.\medskip\smallskip
   192   %
   195   %
   193   %The advantage of formalising the
   196   %The advantage of formalising the
   194   %correctness of a high-level specification of PIP in a theorem prover
   197   %correctness of a high-level specification of PIP in a theorem prover
   195   %is that such issues clearly show up and cannot be overlooked as in
   198   %is that such issues clearly show up and cannot be overlooked as in
   196   %informal reasoning (since we have to analyse all possible behaviours
   199   %informal reasoning (since we have to analyse all possible behaviours
   197   %of threads, i.e.~\emph{traces}, that could possibly happen).
   200   %of threads, i.e.~\emph{traces}, that could possibly happen).
   198 
   201 
   199   \noindent
   202   \noindent {\bf Contributions:} There have been earlier formal
   200   {\bf Contributions:} There have been earlier formal investigations
   203   investigations into PIP \cite{Faria08,Jahier09,Wellings07}, but they
   201   into PIP \cite{Faria08,Jahier09,Wellings07}, but they employ model
   204   employ model checking techniques. This paper presents a formalised
   202   checking techniques. This paper presents a formalised and
   205   and mechanically checked proof for the correctness of PIP. For this
   203   mechanically checked proof for the correctness of PIP. For this we 
   206   we needed to design a new correctness criterion for PIP. In contrast
   204   needed to design a new correctness criterion for PIP. In contrast to model checking, our
   207   to model checking, our formalisation provides insight into why PIP
   205   formalisation provides insight into why PIP is correct and allows us
   208   is correct and allows us to prove stronger properties that, as we
   206   to prove stronger properties that, as we will show, can help with an
   209   will show, can help with an efficient implementation of PIP. We
   207   efficient implementation of PIP in the educational PINTOS operating
   210   illustrate this with an implementation of PIP in the educational
   208   system \cite{PINTOS}.  For example, we found by ``playing'' with the
   211   PINTOS operating system \cite{PINTOS}.  For example, we found by
   209   formalisation that the choice of the next thread to take over a lock
   212   ``playing'' with the formalisation that the choice of the next
   210   when a resource is released is irrelevant for PIP being correct---a
   213   thread to take over a lock when a resource is released is irrelevant
   211   fact that has not been mentioned in the literature and not been used
   214   for PIP being correct---a fact that has not been mentioned in the
   212   in the reference implementation of PIP in PINTOS.  This fact, however, is important
   215   literature and not been used in the reference implementation of PIP
   213   for an efficient implementation of PIP, because we can give the lock
   216   in PINTOS.  This fact, however, is important for an efficient
   214   to the thread with the highest priority so that it terminates more
   217   implementation of PIP, because we can give the lock to the thread
   215   quickly.  We were also being able to generalise the scheduler of Sha
   218   with the highest priority so that it terminates more quickly.  We
   216   et al.~\cite{Sha90} to the practically relevant case where critical 
   219   were also being able to generalise the scheduler of Sha et
   217   sections can overlap; see Figure~\ref{overlap} \emph{a)} below for an example of 
   220   al.~\cite{Sha90} to the practically relevant case where critical
   218   this restriction. %In the existing literature there is no 
   221   sections can overlap; see Figure~\ref{overlap} \emph{a)} below for
   219   %proof and also no proving method that cover this generalised case.
   222   an example of this restriction. In the existing literature there is
       
   223   no proof and also no proving method that cover this generalised
       
   224   case.
   220 
   225 
   221   \begin{figure}
   226   \begin{figure}
   222   \begin{center}
   227   \begin{center}
   223   \begin{tikzpicture}[scale=1]
   228   \begin{tikzpicture}[scale=1]
   224   %%\draw[step=2mm] (0,0) grid (10,2);
   229   %%\draw[step=2mm] (0,0) grid (10,2);
   379   ``time-slicing'' threads with equal priority, but found that it does not lead to 
   384   ``time-slicing'' threads with equal priority, but found that it does not lead to 
   380   advantages in practice. On the contrary, according to their work having a policy 
   385   advantages in practice. On the contrary, according to their work having a policy 
   381   like our FIFO-scheduling of threads with equal priority reduces the number of
   386   like our FIFO-scheduling of threads with equal priority reduces the number of
   382   tasks involved in the inheritance process and thus minimises the number
   387   tasks involved in the inheritance process and thus minimises the number
   383   of potentially expensive thread-switches. 
   388   of potentially expensive thread-switches. 
       
   389 
       
   390   We will also need counters for @{term P} and @{term V} events of a thread @{term th}
       
   391   in a state @{term s}. This can be straightforwardly defined in Isabelle as
       
   392 
       
   393   \begin{isabelle}\ \ \ \ \ %%%
       
   394   \mbox{\begin{tabular}{@ {}l}
       
   395   @{thm cntP_def}\\
       
   396   @{thm cntV_def}
       
   397   \end{tabular}}
       
   398   \end{isabelle}
       
   399 
       
   400   \noindent using the predefined function @{const count} for lists.
   384 
   401 
   385   Next, we introduce the concept of \emph{waiting queues}. They are
   402   Next, we introduce the concept of \emph{waiting queues}. They are
   386   lists of threads associated with every resource. The first thread in
   403   lists of threads associated with every resource. The first thread in
   387   this list (i.e.~the head, or short @{term hd}) is chosen to be the one 
   404   this list (i.e.~the head, or short @{term hd}) is chosen to be the one 
   388   that is in possession of the
   405   that is in possession of the
   941   To see what kind of thread can block @{term th}.
   958   To see what kind of thread can block @{term th}.
   942 
   959 
   943   From these two lemmas we can see the correctness of PIP, which is
   960   From these two lemmas we can see the correctness of PIP, which is
   944   that: the blockage of th is reasonable and under control.
   961   that: the blockage of th is reasonable and under control.
   945 
   962 
       
   963   Lemmas we want to describe:
       
   964 
       
   965   \begin{lemma}
       
   966   @{thm eq_pv_persist}
       
   967   \end{lemma}
       
   968 
       
   969   \begin{lemma}
       
   970   @{thm eq_pv_blocked}
       
   971   \end{lemma}
       
   972 
       
   973   \begin{lemma}
       
   974   @{thm runing_cntP_cntV_inv}
       
   975   \end{lemma}
       
   976 
       
   977   \noindent
       
   978   Remember we do not have the well-nestedness restriction in our
       
   979   proof, which means the difference between the counters @{const cntV}
       
   980   and @{const cntP} can be larger than @{term 1}.
       
   981 
       
   982   \begin{lemma}
       
   983   @{thm runing_inversion}
       
   984   \end{lemma}
       
   985   
       
   986 
       
   987   \begin{lemma}
       
   988   @{thm th_blockedE}
       
   989   \end{lemma}
       
   990 
   946   \subsection*{END OUTLINE}
   991   \subsection*{END OUTLINE}
       
   992 
       
   993 
       
   994 
   947 
   995 
   948   In what follows we will describe properties of PIP that allow us to prove 
   996   In what follows we will describe properties of PIP that allow us to prove 
   949   Theorem~\ref{mainthm} and, when instructive, briefly describe our argument. 
   997   Theorem~\ref{mainthm} and, when instructive, briefly describe our argument. 
   950   It is relatively easy to see that:
   998   It is relatively easy to see that:
   951 
   999 
   955   @{thm[mode=IfThen]  finite_threads}
  1003   @{thm[mode=IfThen]  finite_threads}
   956   \end{tabular}
  1004   \end{tabular}
   957   \end{isabelle}
  1005   \end{isabelle}
   958 
  1006 
   959   \noindent
  1007   \noindent
   960   The second property is by induction of @{term vt}. The next three
  1008   The second property is by induction on @{term vt}. The next three
   961   properties are: 
  1009   properties are: 
   962 
  1010 
   963   \begin{isabelle}\ \ \ \ \ %%%
  1011   \begin{isabelle}\ \ \ \ \ %%%
   964   \begin{tabular}{@ {}l}
  1012   \begin{tabular}{@ {}l}
   965   HERE??
  1013   HERE??