Journal/Paper.thy
changeset 142 10c16b85a839
parent 141 f70344294e99
child 143 c5a65d98191a
equal deleted inserted replaced
141:f70344294e99 142:10c16b85a839
   422   advantages in practice. On the contrary, according to their work having a policy 
   422   advantages in practice. On the contrary, according to their work having a policy 
   423   like our FIFO-scheduling of threads with equal priority reduces the number of
   423   like our FIFO-scheduling of threads with equal priority reduces the number of
   424   tasks involved in the inheritance process and thus minimises the number
   424   tasks involved in the inheritance process and thus minimises the number
   425   of potentially expensive thread-switches. 
   425   of potentially expensive thread-switches. 
   426 
   426 
   427   {\bf NEEDED?} We will also need counters for @{term P} and @{term V} events of a thread @{term th}
   427   \endnote{{\bf NEEDED?} We will also need counters for @{term P} and @{term V} events of a thread @{term th}
   428   in a state @{term s}. This can be straightforwardly defined in Isabelle as
   428   in a state @{term s}. This can be straightforwardly defined in Isabelle as
   429 
   429 
   430   \begin{isabelle}\ \ \ \ \ %%%
   430   \begin{isabelle}\ \ \ \ \ %%%
   431   \mbox{\begin{tabular}{@ {}l}
   431   \mbox{\begin{tabular}{@ {}l}
   432   @{thm cntP_def}\\
   432   @{thm cntP_def}\\
   433   @{thm cntV_def}
   433   @{thm cntV_def}
   434   \end{tabular}}
   434   \end{tabular}}
   435   \end{isabelle}
   435   \end{isabelle}
   436 
   436 
   437   \noindent using the predefined function @{const count} for lists.
   437   \noindent using the predefined function @{const count} for lists.}
   438 
   438 
   439   Next, we introduce the concept of \emph{waiting queues}. They are
   439   Next, we introduce the concept of \emph{waiting queues}. They are
   440   lists of threads associated with every resource. The first thread in
   440   lists of threads associated with every resource. The first thread in
   441   this list (i.e.~the head, or short @{term hd}) is chosen to be the one 
   441   this list (i.e.~the head, or short @{term hd}) is chosen to be the one 
   442   that is in possession of the
   442   that is in possession of the
   567   \noindent Note that forests can have trees with infinte depth and
   567   \noindent Note that forests can have trees with infinte depth and
   568   containing nodes with infinitely many children.  A \emph{finite
   568   containing nodes with infinitely many children.  A \emph{finite
   569   forrest} is a forest which is well-founded and every node has 
   569   forrest} is a forest which is well-founded and every node has 
   570   finitely many children (is only finitely branching).
   570   finitely many children (is only finitely branching).
   571 
   571 
       
   572   \endnote{
   572   \begin{isabelle}\ \ \ \ \ %%%
   573   \begin{isabelle}\ \ \ \ \ %%%
   573   @{thm rtrancl_path.intros}
   574   @{thm rtrancl_path.intros}
   574   \end{isabelle} 
   575   \end{isabelle} 
   575 
   576 
   576   \begin{isabelle}\ \ \ \ \ %%%
   577   \begin{isabelle}\ \ \ \ \ %%%
   577   @{thm rpath_def}
   578   @{thm rpath_def}
   578   \end{isabelle}
   579   \end{isabelle}}
   579 
   580 
   580 
   581 
   581   {\bf Lemma about overlapping paths}
   582   \endnote{{\bf Lemma about overlapping paths}}
   582   
   583   
   583 
   584 
   584   We will design our PIP-scheduler  
   585   We will design our PIP-scheduler  
   585   so that every thread can be in the possession of several resources, that is 
   586   so that every thread can be in the possession of several resources, that is 
   586   it has potentially several incoming holding edges in the RAG, but has at most one outgoing  
   587   it has potentially several incoming holding edges in the RAG, but has at most one outgoing  
   617 
   618 
   618   \begin{isabelle}\ \ \ \ \ %%%
   619   \begin{isabelle}\ \ \ \ \ %%%
   619   @{thm cpreced_def}\hfill\numbered{cpreced}
   620   @{thm cpreced_def}\hfill\numbered{cpreced}
   620   \end{isabelle}
   621   \end{isabelle}
   621 
   622 
       
   623   \endnote{
   622   \begin{isabelle}\ \ \ \ \ %%%
   624   \begin{isabelle}\ \ \ \ \ %%%
   623   @{thm cp_alt_def cp_alt_def1}
   625   @{thm cp_alt_def cp_alt_def1}
   624   \end{isabelle}
   626   \end{isabelle}}
   625 
   627 
   626   \noindent
   628   \noindent
   627   where the dependants of @{text th} are given by the waiting queue function.
   629   where the dependants of @{text th} are given by the waiting queue function.
   628   While the precedence @{term prec} of any thread is determined statically 
   630   While the precedence @{term prec} of any thread is determined statically 
   629   (for example when the thread is
   631   (for example when the thread is
   879 context valid_trace
   881 context valid_trace
   880 begin
   882 begin
   881 (*>*)
   883 (*>*)
   882 text {*
   884 text {*
   883 
   885 
   884   In this section we prove facts that immediately follow from
   886   \endnote{In this section we prove facts that immediately follow from
   885   our definitions of valid traces.
   887   our definitions of valid traces.
   886 
   888 
   887   \begin{lemma}??\label{precedunique}
   889   \begin{lemma}??\label{precedunique}
   888   @{thm [mode=IfThen] preced_unique[where ?th1.0=th\<^sub>1 and ?th2.0=th\<^sub>2]} 
   890   @{thm [mode=IfThen] preced_unique[where ?th1.0=th\<^sub>1 and ?th2.0=th\<^sub>2]} 
   889   \end{lemma}
   891   \end{lemma}
   915   That means the precedences of @{text "th'\<^sub>1"} and @{text "th'\<^sub>2"}
   917   That means the precedences of @{text "th'\<^sub>1"} and @{text "th'\<^sub>2"}
   916   must be the same (they are the maxima in the respective RAG-subtrees). From this we can
   918   must be the same (they are the maxima in the respective RAG-subtrees). From this we can
   917   infer by Lemma~\ref{precedunique} that @{text "th'\<^sub>1"}
   919   infer by Lemma~\ref{precedunique} that @{text "th'\<^sub>1"}
   918   and @{text "th'\<^sub>2"} are the same threads. However, this also means the
   920   and @{text "th'\<^sub>2"} are the same threads. However, this also means the
   919   roots @{text "th\<^sub>1"} and @{text "th\<^sub>2"} must be the same.\qed
   921   roots @{text "th\<^sub>1"} and @{text "th\<^sub>2"} must be the same.\qed
   920   \end{proof}
   922   \end{proof}}
   921 
   923 
   922   *}
   924   *}
   923 (*<*)end(*>*)
   925 (*<*)end(*>*)
   924 
   926 
   925 section {* The Correctness Proof *}
   927 section {* The Correctness Proof *}
  1028 
  1030 
  1029   \begin{theorem}\label{mainthm}
  1031   \begin{theorem}\label{mainthm}
  1030   Given the assumptions about states @{text "s"} and @{text "s' @ s"},
  1032   Given the assumptions about states @{text "s"} and @{text "s' @ s"},
  1031   the thread @{text th} and the events in @{text "s'"}, then either
  1033   the thread @{text th} and the events in @{text "s'"}, then either
  1032   \begin{itemize}
  1034   \begin{itemize}
  1033   \item @{term "th \<in> running (s' @ s)"} or\medskip
  1035   \item[$\bullet$] @{term "th \<in> running (s' @ s)"} or\medskip
  1034 
  1036 
  1035   \item there exists a thread @{term "th'"} with @{term "th' \<noteq> th"}
  1037   \item[$\bullet$] there exists a thread @{term "th'"} with @{term "th' \<noteq> th"}
  1036   and @{term "th' \<in> running (s' @ s)"} such that @{text "th' \<in> threads
  1038   and @{term "th' \<in> running (s' @ s)"} such that @{text "th' \<in> threads
  1037   s"}, @{text "\<not> detached s th'"} and @{term "cp (s' @ s) th' = prec
  1039   s"}, @{text "\<not> detached s th'"} and @{term "cp (s' @ s) th' = prec
  1038   th s"}.
  1040   th s"}.
  1039   \end{itemize}
  1041   \end{itemize}
  1040   \end{theorem}
  1042   \end{theorem}
  1072 
  1074 
  1073 %% HERE
  1075 %% HERE
  1074 
  1076 
  1075   Given our assumptions (on @{text th}), the first property we can
  1077   Given our assumptions (on @{text th}), the first property we can
  1076   show is that any running thread, say @{text "th'"}, has the same
  1078   show is that any running thread, say @{text "th'"}, has the same
  1077   precedence of @{text th}:
  1079   precedence as @{text th}:
  1078 
  1080 
  1079   \begin{lemma}\label{runningpreced}
  1081   \begin{lemma}\label{runningpreced}
  1080   @{thm [mode=IfThen] running_preced_inversion}
  1082   @{thm [mode=IfThen] running_preced_inversion}
  1081   \end{lemma}
  1083   \end{lemma}
  1082 
  1084 
  1083   \begin{proof}
  1085   \begin{proof}
  1084   By definition the running thread has as current precedence the maximum of
  1086   By definition, the running thread has as current precedence the maximum of
  1085   all ready threads, that is
  1087   all ready threads, that is
  1086 
  1088 
  1087   \begin{center}
  1089   \begin{center}
  1088   @{term "cp (t @ s) th' = Max (cp (t @ s) ` readys (t @ s))"}
  1090   @{term "cp (t @ s) th' = Max (cp (t @ s) ` readys (t @ s))"}
  1089   \end{center}
  1091   \end{center}
  1090 
  1092 
  1091   \noindent
  1093   \noindent
  1092   We also know that this is equal to all threads, that is
  1094   We also know that this is equal to the current precedences of all threads,
       
  1095   that is
  1093 
  1096 
  1094   \begin{center}
  1097   \begin{center}
  1095   @{term "cp (t @ s) th' = Max (cp (t @ s) ` treads (t @ s))"}
  1098   @{term "cp (t @ s) th' = Max (cp (t @ s) ` treads (t @ s))"}
  1096   \end{center}
  1099   \end{center}
  1097 
  1100 
  1098   \noindent
  1101   \noindent
       
  1102   This is because each ready thread, say @{text "th\<^sub>r"}, has the maximum
       
  1103   current precedence of the subtree located at @{text "th\<^sub>r"}. All these
       
  1104   subtrees together form the set of threads.
  1099   But the maximum of all threads is the @{term "cp"} of @{text "th"},
  1105   But the maximum of all threads is the @{term "cp"} of @{text "th"},
  1100   which is the @{term preced} of @{text th}.
  1106   which is equal to the @{term preced} of @{text th}.\qed
  1101   \end{proof}
  1107   \end{proof}
  1102 
  1108 
       
  1109   \endnote{
  1103   @{thm "th_blockedE_pretty"} -- thm-blockedE??
  1110   @{thm "th_blockedE_pretty"} -- thm-blockedE??
  1104   
  1111   
  1105 
       
  1106   @{text "th_kept"} shows that th is a thread in s'-s
  1112   @{text "th_kept"} shows that th is a thread in s'-s
  1107 
  1113   }
  1108 
  1114 
  1109 
  1115   Next we show that a running thread @{text "th'"} must either wait for or
  1110 
  1116   hold a resource in state @{text s}.
  1111   \begin{proof}[of Theorem 1]
  1117 
  1112   If @{term "th \<in> running (s' @ s)"}, then there is nothing to show. So let us
  1118   \begin{lemma}\label{notdetached}
  1113   assume otherwise. By Lem.~\ref{thblockedE} we know there exists a thread
  1119   If @{term "th' \<in> running (s' @ s)"} then @{term "\<not>detached s th'"}.
  1114   @{text "th'"} that is an acestor of @{text th} in the @{text "RAG"}
  1120   \end{lemma}
  1115   and @{text "th'"} is running, that is we know
  1121 
  1116 
  1122   \begin{proof} Let us assume @{text "th'"} is detached in state
  1117   \begin{center}
  1123   @{text "s"}, then, according to the definition of detached, @{text
  1118   @{term "th' \<in> nancestors (tG (s' @ s)) th"} \quad and \quad
  1124   "th’"} does not hold or wait for any resource. Hence the @{text
  1119   @{term "th' \<in> running (s' @ s)"}
  1125   cp}-value of @{text "th'"} in @{text s} is not boosted, that is
  1120   \end{center}
  1126   @{term "cp s th' = prec th s"}, and is therefore lower than the
  1121 
  1127   precedence (as well as the @{text "cp"}-value) of @{term "th"}. This
  1122   \noindent We have that @{term "th \<noteq> th'"} since we assumed
  1128   means @{text "th'"} will not run as long as @{text "th"} is a
  1123   @{text th} is not running.  By Lem.~\ref{thkept}, we know that
  1129   live thread. In turn this means @{text "th'"} cannot acquire a reseource
  1124   @{text "th'"} is also running in state @{text s} and by
  1130   and is still detached in state @{text "s' @ s"}.  Consequently
  1125   Lem.~\ref{detached} that @{term "\<not>detached s th'"}.
  1131   @{text "th'"} is also not boosted in state @{text "s' @ s"} and
  1126   By Lem.~\ref{runningpreced} we have
  1132   would not run. This contradicts our assumption.\qed
       
  1133   \end{proof}
       
  1134 
       
  1135 
       
  1136   \begin{proof}[of Theorem 1] If @{term "th \<in> running (s' @ s)"},
       
  1137   then there is nothing to show. So let us assume otherwise. Since the
       
  1138   @{text "RAG"} is well-founded, we know there exists an ancestor of
       
  1139   @{text "th"} that is the root of the corrsponding subtree and
       
  1140   therefore is ready. Let us call this thread @{text "th'"}. We know
       
  1141   that @{text "th'"} has the highest precedence of all ready threads.
       
  1142   Therefore it is running.  We have that @{term "th \<noteq> th'"}
       
  1143   since we assumed @{text th} is not running.  By
       
  1144   Lem.~\ref{notdetached} we have that @{term "\<not>detached s th'"}.
       
  1145   If @{text "th'"} is not detached in @{text s}, that is either
       
  1146   holding or waiting for a resource, it must be that @{term "th' \<in>
       
  1147   threads s"}.  By Lem.~\ref{runningpreced} we have
  1127 
  1148 
  1128   \begin{center}
  1149   \begin{center}
  1129   @{term "cp (t @ s) th' = preced th s"}
  1150   @{term "cp (t @ s) th' = preced th s"}
  1130   \end{center}
  1151   \end{center}
  1131 
  1152 
  1132   \noindent
  1153   \noindent
  1133   This concludes the proof of Theorem 1.
  1154   This concludes the proof of Theorem 1.\qed
  1134   \end{proof}
  1155   \end{proof}
  1135 
  1156 
  1136 
  1157 
  1137 
  1158   \endnote{
  1138 
       
  1139   In what follows we will describe properties of PIP that allow us to
  1159   In what follows we will describe properties of PIP that allow us to
  1140   prove Theorem~\ref{mainthm} and, when instructive, briefly describe
  1160   prove Theorem~\ref{mainthm} and, when instructive, briefly describe
  1141   our argument. Recall we want to prove that in state @{term "s' @ s"}
  1161   our argument. Recall we want to prove that in state @{term "s' @ s"}
  1142   either @{term th} is either running or blocked by a thread @{term
  1162   either @{term th} is either running or blocked by a thread @{term
  1143   "th'"} (@{term "th \<noteq> th'"}) which was alive in state @{term s}. We
  1163   "th'"} (@{term "th \<noteq> th'"}) which was alive in state @{term s}. We
  1144   can show that
  1164   can show that
  1145 
  1165 
  1146   
       
  1147 
  1166 
  1148   \begin{lemma}
  1167   \begin{lemma}
  1149   If @{thm (prem 2) eq_pv_blocked}
  1168   If @{thm (prem 2) eq_pv_blocked}
  1150   then @{thm (concl) eq_pv_blocked}
  1169   then @{thm (concl) eq_pv_blocked}
  1151   \end{lemma}
  1170   \end{lemma}
  1152 
  1171 
  1153   \begin{lemma}
  1172   \begin{lemma}
  1154   If @{thm (prem 2) eq_pv_persist}
  1173   If @{thm (prem 2) eq_pv_persist}
  1155   then @{thm (concl) eq_pv_persist}
  1174   then @{thm (concl) eq_pv_persist}
  1156   \end{lemma}
  1175   \end{lemma}}
  1157 
  1176 
  1158   \subsection*{\bf OUTLINE}
  1177   \endnote{{\bf OUTLINE}
  1159 
  1178 
  1160   Since @{term "th"} is the most urgent thread, if it is somehow
  1179   Since @{term "th"} is the most urgent thread, if it is somehow
  1161   blocked, people want to know why and wether this blocking is
  1180   blocked, people want to know why and wether this blocking is
  1162   reasonable.
  1181   reasonable.
  1163 
  1182 
  1216   \begin{lemma}\label{runninginversion}
  1235   \begin{lemma}\label{runninginversion}
  1217   @{thm running_inversion}
  1236   @{thm running_inversion}
  1218   \end{lemma}
  1237   \end{lemma}
  1219   
  1238   
  1220   explain tRAG
  1239   explain tRAG
  1221   \bigskip
  1240   \bigskip}
  1222 
  1241 
  1223   
  1242   
  1224   Suppose the thread @{term th} is \emph{not} running in state @{term
  1243   Suppose the thread @{term th} is \emph{not} running in state @{term
  1225   "t @ s"}, meaning that it should be blocked by some other thread.
  1244   "t @ s"}, meaning that it should be blocked by some other thread.
  1226   It is first shown that there is a path in the RAG leading from node
  1245   It is first shown that there is a path in the RAG leading from node
  1270 
  1289 
  1271   \begin{corollary}  
  1290   \begin{corollary}  
  1272   Using the lemma \ref{runninginversion} we can say more about the thread th'
  1291   Using the lemma \ref{runninginversion} we can say more about the thread th'
  1273   \end{corollary}
  1292   \end{corollary}
  1274 
  1293 
  1275   \subsection*{END OUTLINE}
  1294   \endnote{\subsection*{END OUTLINE}}
  1276 
       
  1277 
       
  1278 
       
  1279 
  1295 
  1280   In what follows we will describe properties of PIP that allow us to prove 
  1296   In what follows we will describe properties of PIP that allow us to prove 
  1281   Theorem~\ref{mainthm} and, when instructive, briefly describe our argument. 
  1297   Theorem~\ref{mainthm} and, when instructive, briefly describe our argument. 
  1282   It is relatively easy to see that:
  1298   It is relatively easy to see that:
  1283 
  1299 
  2007   %We are grateful for the comments we received from anonymous
  2023   %We are grateful for the comments we received from anonymous
  2008   %referees.
  2024   %referees.
  2009 
  2025 
  2010   \bibliographystyle{plain}
  2026   \bibliographystyle{plain}
  2011   \bibliography{root}
  2027   \bibliography{root}
       
  2028 
       
  2029   \theendnotes
  2012 *}
  2030 *}
  2013 
  2031 
  2014 
  2032 
  2015 (*<*)
  2033 (*<*)
  2016 end
  2034 end