7 declare [[show_question_marks = false]] |
7 declare [[show_question_marks = false]] |
8 |
8 |
9 |
9 |
10 notation (latex output) |
10 notation (latex output) |
11 Cons ("_::_" [78,77] 73) and |
11 Cons ("_::_" [78,77] 73) and |
|
12 If ("(\<^raw:\textrm{>if\<^raw:}> (_)/ \<^raw:\textrm{>then\<^raw:}> (_)/ \<^raw:\textrm{>else\<^raw:}> (_))" 10) and |
12 vt ("valid'_state") and |
13 vt ("valid'_state") and |
13 runing ("running") and |
14 runing ("running") and |
14 If ("(\<^raw:\textrm{>if\<^raw:}> (_)/ \<^raw:\textrm{>then\<^raw:}> (_)/ \<^raw:\textrm{>else\<^raw:}> (_))" 10) and |
|
15 Prc ("'(_, _')") and |
15 Prc ("'(_, _')") and |
16 holding ("holds") and |
16 holding ("holds") and |
17 waiting ("waits") and |
17 waiting ("waits") and |
18 Th ("T") and |
18 Th ("T") and |
19 Cs ("C") and |
19 Cs ("C") and |
20 readys ("ready") and |
20 readys ("ready") and |
21 depend ("RAG") and |
|
22 preced ("prec") and |
21 preced ("prec") 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{$\_\!\_$}>") |
27 |
27 |
28 |
|
29 (*>*) |
28 (*>*) |
30 |
29 |
31 section {* Introduction *} |
30 section {* Introduction *} |
32 |
31 |
33 text {* |
32 text {* |
184 to the thread with the highest priority so that it terminates more |
183 to the thread with the highest priority so that it terminates more |
185 quickly. We were also being able to generalise the scheduler of Sha |
184 quickly. We were also being able to generalise the scheduler of Sha |
186 et al.~\cite{Sha90} to the practically relevant case where critical |
185 et al.~\cite{Sha90} to the practically relevant case where critical |
187 sections can overlap; see Figure~\ref{overlap} below for an example of |
186 sections can overlap; see Figure~\ref{overlap} below for an example of |
188 this restriction. In the existing literature there is no |
187 this restriction. In the existing literature there is no |
189 proof and also no prove method that cover this generalised case. |
188 proof and also no proving method that cover this generalised case. |
190 |
189 |
191 \begin{figure} |
190 \begin{figure} |
192 \begin{center} |
191 \begin{center} |
193 \begin{tikzpicture}[scale=1] |
192 \begin{tikzpicture}[scale=1] |
194 %%\draw[step=2mm] (0,0) grid (10,2); |
193 %%\draw[step=2mm] (0,0) grid (10,2); |
326 \begin{isabelle}\ \ \ \ \ %%% |
325 \begin{isabelle}\ \ \ \ \ %%% |
327 @{thm preced_def[where thread="th"]} |
326 @{thm preced_def[where thread="th"]} |
328 \end{isabelle} |
327 \end{isabelle} |
329 |
328 |
330 \noindent |
329 \noindent |
|
330 We also use the abbreviation |
|
331 |
|
332 \begin{isabelle}\ \ \ \ \ %%% |
|
333 @{abbrev "preceds s ths"} |
|
334 \end{isabelle} |
|
335 |
|
336 \noindent |
|
337 for the set of precedences of threads @{text ths} in state @{text s}. |
331 The point of precedences is to schedule threads not according to priorities (because what should |
338 The point of precedences is to schedule threads not according to priorities (because what should |
332 we do in case two threads have the same priority), but according to precedences. |
339 we do in case two threads have the same priority), but according to precedences. |
333 Precedences allow us to always discriminate between two threads with equal priority by |
340 Precedences allow us to always discriminate between two threads with equal priority by |
334 taking into account the time when the priority was last set. We order precedences so |
341 taking into account the time when the priority was last set. We order precedences so |
335 that threads with the same priority get a higher precedence if their priority has been |
342 that threads with the same priority get a higher precedence if their priority has been |
476 @{thm cpreced_def2}\hfill\numbered{cpreced} |
483 @{thm cpreced_def2}\hfill\numbered{cpreced} |
477 \end{isabelle} |
484 \end{isabelle} |
478 |
485 |
479 \noindent |
486 \noindent |
480 where the dependants of @{text th} are given by the waiting queue function. |
487 where the dependants of @{text th} are given by the waiting queue function. |
481 While the precedence @{term prec} of a thread is determined statically |
488 While the precedence @{term prec} of any thread is determined statically |
482 (for example when the thread is |
489 (for example when the thread is |
483 created), the point of the current precedence is to let the scheduler increase this |
490 created), the point of the current precedence is to let the scheduler increase this |
484 precedence, if needed according to PIP. Therefore the current precedence of @{text th} is |
491 precedence, if needed according to PIP. Therefore the current precedence of @{text th} is |
485 given as the maximum of the precedence @{text th} has in state @{text s} \emph{and} all |
492 given as the maximum of the precedence @{text th} has in state @{text s} \emph{and} all |
486 threads that are dependants of @{text th}. Since the notion @{term "dependants"} is |
493 threads that are dependants of @{text th}. Since the notion @{term "dependants"} is |
487 defined as the transitive closure of all dependent threads, we deal correctly with the |
494 defined as the transitive closure of all dependent threads, we deal correctly with the |
488 problem in the informal algorithm by Sha et al.~\cite{Sha90} where a priority of a thread is |
495 problem in the informal algorithm by Sha et al.~\cite{Sha90} where a priority of a thread is |
489 lowered prematurely. |
496 lowered prematurely. We again introduce an abbreviation for current precedeces of |
|
497 a set of threads, written @{term "cprecs wq s ths"}. |
490 |
498 |
491 The next function, called @{term schs}, defines the behaviour of the scheduler. It will be defined |
499 The next function, called @{term schs}, defines the behaviour of the scheduler. It will be defined |
492 by recursion on the state (a list of events); this function returns a \emph{schedule state}, which |
500 by recursion on the state (a list of events); this function returns a \emph{schedule state}, which |
493 we represent as a record consisting of two |
501 we represent as a record consisting of two |
494 functions: |
502 functions: |
595 \hspace{5mm}@{text "let"} @{text "new_wq = wq(cs := release (wq cs))"} @{text "in"}\\ |
603 \hspace{5mm}@{text "let"} @{text "new_wq = wq(cs := release (wq cs))"} @{text "in"}\\ |
596 \hspace{8mm}@{term "(|wq_fun = new_wq, cprec_fun = cpreced new_wq (V th cs # s)|)"} |
604 \hspace{8mm}@{term "(|wq_fun = new_wq, cprec_fun = cpreced new_wq (V th cs # s)|)"} |
597 \end{tabular} |
605 \end{tabular} |
598 \end{isabelle} |
606 \end{isabelle} |
599 |
607 |
600 Having the scheduler function @{term schs} at our disposal, we can ``lift'', or |
608 Having the scheduler function @{term schs} at our disposal, we can |
601 overload, the notions |
609 ``lift'', or overload, the notions @{term waiting}, @{term holding}, |
602 @{term waiting}, @{term holding}, @{term depend} and @{term cp} to operate on states only. |
610 @{term RAG}, @{term dependants} and @{term cp} to operate on states |
|
611 only. |
603 |
612 |
604 \begin{isabelle}\ \ \ \ \ %%% |
613 \begin{isabelle}\ \ \ \ \ %%% |
605 \begin{tabular}{@ {}rcl} |
614 \begin{tabular}{@ {}rcl} |
606 @{thm (lhs) s_holding_abv} & @{text "\<equiv>"} & @{thm (rhs) s_holding_abv}\\ |
615 @{thm (lhs) s_holding_abv} & @{text "\<equiv>"} & @{thm (rhs) s_holding_abv}\\ |
607 @{thm (lhs) s_waiting_abv} & @{text "\<equiv>"} & @{thm (rhs) s_waiting_abv}\\ |
616 @{thm (lhs) s_waiting_abv} & @{text "\<equiv>"} & @{thm (rhs) s_waiting_abv}\\ |
608 @{thm (lhs) s_depend_abv} & @{text "\<equiv>"} & @{thm (rhs) s_depend_abv}\\ |
617 @{thm (lhs) s_RAG_abv} & @{text "\<equiv>"} & @{thm (rhs) s_RAG_abv}\\ |
609 @{thm (lhs) cp_def} & @{text "\<equiv>"} & @{thm (rhs) cp_def} |
618 @{thm (lhs) s_dependants_abv}& @{text "\<equiv>"} & @{thm (rhs) s_dependants_abv}\\ |
|
619 @{thm (lhs) cp_def} & @{text "\<equiv>"} & @{thm (rhs) cp_def}\\ |
610 \end{tabular} |
620 \end{tabular} |
611 \end{isabelle} |
621 \end{isabelle} |
612 |
622 |
613 \noindent |
623 \noindent |
614 With these abbreviations in place we can introduce |
624 With these abbreviations in place we can introduce |
623 @{thm runing_def} |
633 @{thm runing_def} |
624 \end{tabular} |
634 \end{tabular} |
625 \end{isabelle} |
635 \end{isabelle} |
626 |
636 |
627 \noindent |
637 \noindent |
628 In the second definition @{term "DUMMY ` DUMMY"} stands for the image of a set under a function. |
638 %%In the second definition @{term "DUMMY ` DUMMY"} stands for the image of a set under a function. |
629 Note that in the initial state, that is where the list of events is empty, the set |
639 Note that in the initial state, that is where the list of events is empty, the set |
630 @{term threads} is empty and therefore there is neither a thread ready nor running. |
640 @{term threads} is empty and therefore there is neither a thread ready nor running. |
631 If there is one or more threads ready, then there can only be \emph{one} thread |
641 If there is one or more threads ready, then there can only be \emph{one} thread |
632 running, namely the one whose current precedence is equal to the maximum of all ready |
642 running, namely the one whose current precedence is equal to the maximum of all ready |
633 threads. We use sets to capture both possibilities. |
643 threads. We use sets to capture both possibilities. |
834 one resource---that means the thread was not \emph{detached} in @{text s}. |
844 one resource---that means the thread was not \emph{detached} in @{text s}. |
835 As we shall see shortly, that means there are only finitely |
845 As we shall see shortly, that means there are only finitely |
836 many threads that can block @{text th} in this way and then they |
846 many threads that can block @{text th} in this way and then they |
837 need to run with the same precedence as @{text th}. |
847 need to run with the same precedence as @{text th}. |
838 |
848 |
839 Like in the argument by Sha et al.~our |
849 Like in the argument by Sha et al.~our finite bound does not |
840 finite bound does not guarantee absence of indefinite Priority |
850 guarantee absence of indefinite Priority Inversion. For this we |
841 Inversion. For this we further have to assume that every thread |
851 further have to assume that every thread gives up its resources |
842 gives up its resources after a finite amount of time. We found that |
852 after a finite amount of time. We found that this assumption is |
843 this assumption is awkward to formalise in our model. There are mainly |
853 awkward to formalise in our model. There are mainly two reasons: |
844 two reasons: First, we do not specify what ``running'' the code of a |
854 First, we do not specify what ``running'' the code of a thread |
845 thread means, for example by giving an operational semantics for |
855 means, for example by giving an operational semantics for machine |
846 machine instructions. Therefore we cannot characterise what are ``good'' |
856 instructions. Therefore we cannot characterise what are ``good'' |
847 programs that contain for every looking request also a corresponding |
857 programs that contain for every looking request also a corresponding |
848 unlocking request for a resource. |
858 unlocking request for a resource. Second, we would need to specify a |
849 % |
859 kind of global clock that tracks the time how long a thread locks a |
850 %(HERE) |
860 resource. But this seems difficult, because how do we conveninet |
851 % |
861 distinguish between a thread that ``just'' lock a resource for a |
852 Therefore we |
862 very long time and one that locks it forever. Therefore we decided |
853 leave it out and let the programmer assume the responsibility to |
863 to leave it out this property and let the programmer assume the |
854 program threads in such a benign manner (in addition to causing no |
864 responsibility to program threads in such a benign manner (in |
855 circularity in the RAG). In this detail, we do not |
865 addition to causing no circularity in the RAG). In this detail, we |
856 make any progress in comparison with the work by Sha et al. |
866 do not make any progress in comparison with the work by Sha et al. |
857 However, we are able to combine their two separate bounds into a |
867 However, we are able to combine their two separate bounds into a |
858 single theorem improving their bound. |
868 single theorem improving their bound. |
859 |
869 |
860 In what follows we will describe properties of PIP that allow us to prove |
870 In what follows we will describe properties of PIP that allow us to prove |
861 Theorem~\ref{mainthm} and, when instructive, briefly describe our argument. |
871 Theorem~\ref{mainthm} and, when instructive, briefly describe our argument. |
862 It is relatively easy to see that |
872 It is relatively easy to see that: |
863 |
873 |
864 \begin{isabelle}\ \ \ \ \ %%% |
874 \begin{isabelle}\ \ \ \ \ %%% |
865 \begin{tabular}{@ {}l} |
875 \begin{tabular}{@ {}l} |
866 @{text "running s \<subseteq> ready s \<subseteq> threads s"}\\ |
876 @{text "running s \<subseteq> ready s \<subseteq> threads s"}\\ |
867 @{thm[mode=IfThen] finite_threads} |
877 @{thm[mode=IfThen] finite_threads} |
868 \end{tabular} |
878 \end{tabular} |
869 \end{isabelle} |
879 \end{isabelle} |
870 |
880 |
871 \noindent |
881 \noindent |
872 The second property is by induction of @{term vt}. The next three |
882 The second property is by induction of @{term vt}. The next three |
873 properties are |
883 properties are: |
874 |
884 |
875 \begin{isabelle}\ \ \ \ \ %%% |
885 \begin{isabelle}\ \ \ \ \ %%% |
876 \begin{tabular}{@ {}l} |
886 \begin{tabular}{@ {}l} |
877 @{thm[mode=IfThen] waiting_unique[of _ _ "cs\<^sub>1" "cs\<^sub>2"]}\\ |
887 @{thm[mode=IfThen] waiting_unique[of _ _ "cs\<^sub>1" "cs\<^sub>2"]}\\ |
878 @{thm[mode=IfThen] held_unique[of _ "th\<^sub>1" _ "th\<^sub>2"]}\\ |
888 @{thm[mode=IfThen] held_unique[of _ "th\<^sub>1" _ "th\<^sub>2"]}\\ |
888 at most one running thread. We can also show the following properties |
898 at most one running thread. We can also show the following properties |
889 about the @{term RAG} in @{text "s"}. |
899 about the @{term RAG} in @{text "s"}. |
890 |
900 |
891 \begin{isabelle}\ \ \ \ \ %%% |
901 \begin{isabelle}\ \ \ \ \ %%% |
892 \begin{tabular}{@ {}l} |
902 \begin{tabular}{@ {}l} |
893 @{text If}~@{thm (prem 1) acyclic_depend}~@{text "then"}:\\ |
903 @{text If}~@{thm (prem 1) acyclic_RAG}~@{text "then"}:\\ |
894 \hspace{5mm}@{thm (concl) acyclic_depend}, |
904 \hspace{5mm}@{thm (concl) acyclic_RAG}, |
895 @{thm (concl) finite_depend} and |
905 @{thm (concl) finite_RAG} and |
896 @{thm (concl) wf_dep_converse},\\ |
906 @{thm (concl) wf_dep_converse},\\ |
897 \hspace{5mm}@{text "if"}~@{thm (prem 2) dm_depend_threads}~@{text "then"}~@{thm (concl) dm_depend_threads} |
907 \hspace{5mm}@{text "if"}~@{thm (prem 2) dm_RAG_threads}~@{text "then"}~@{thm (concl) dm_RAG_threads} |
898 and\\ |
908 and\\ |
899 \hspace{5mm}@{text "if"}~@{thm (prem 2) range_in}~@{text "then"}~@{thm (concl) range_in}. |
909 \hspace{5mm}@{text "if"}~@{thm (prem 2) range_in}~@{text "then"}~@{thm (concl) range_in}. |
900 \end{tabular} |
910 \end{tabular} |
901 \end{isabelle} |
911 \end{isabelle} |
902 |
912 |
1111 \end{center} |
1121 \end{center} |
1112 \end{lemma} |
1122 \end{lemma} |
1113 |
1123 |
1114 \noindent |
1124 \noindent |
1115 That means the current precedence of a thread @{text th} can be |
1125 That means the current precedence of a thread @{text th} can be |
1116 computed locally by considering only the children of @{text th}. In |
1126 computed locally by considering only the current precedences of the children of @{text th}. In |
1117 effect, it only needs to be recomputed for @{text th} when one of |
1127 effect, it only needs to be recomputed for @{text th} when one of |
1118 its children changes its current precedence. Once the current |
1128 its children changes its current precedence. Once the current |
1119 precedence is computed in this more efficient manner, the selection |
1129 precedence is computed in this more efficient manner, the selection |
1120 of the thread with highest precedence from a set of ready threads is |
1130 of the thread with highest precedence from a set of ready threads is |
1121 a standard scheduling operation implemented in most operating |
1131 a standard scheduling operation implemented in most operating |
1122 systems. |
1132 systems. |
|
1133 |
|
1134 \begin{proof}[of Lemma~\ref{childrenlem}] |
|
1135 Test |
|
1136 \end{proof} |
1123 |
1137 |
1124 Of course the main work for implementing PIP involves the |
1138 Of course the main work for implementing PIP involves the |
1125 scheduler and coding how it should react to events. Below we |
1139 scheduler and coding how it should react to events. Below we |
1126 outline how our formalisation guides this implementation for each |
1140 outline how our formalisation guides this implementation for each |
1127 kind of events.\smallskip |
1141 kind of events.\smallskip |