PIPDefs.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 02 Jun 2016 13:15:03 +0100
changeset 125 95e7933968f8
parent 118 a4bb5525b7b6
child 126 a88af0e4731f
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
(*<*)
64
b4bcd1edbb6d renamed files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 53
diff changeset
     2
theory PIPDefs
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
     3
imports Precedence_ord Moment RTree Max
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
(*>*)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
94
44df6ac30bd2 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
     7
chapter {* Definitions *}
44df6ac30bd2 some small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
     8
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
text {*
48
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    10
  In this section, the formal model of  Priority Inheritance Protocol (PIP) is presented. 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
  The model is based on Paulson's inductive protocol verification method, where 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
  the state of the system is modelled as a list of events happened so far with the latest 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
  event put at the head. 
48
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    14
*}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
48
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    16
text {*
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
  To define events, the identifiers of {\em threads},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
  {\em priority} and {\em critical resources } (abbreviated as @{text "cs"}) 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
  need to be represented. All three are represetned using standard 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
  Isabelle/HOL type @{typ "nat"}:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
*}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
type_synonym thread = nat -- {* Type for thread identifiers. *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
type_synonym priority = nat  -- {* Type for priorities. *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
type_synonym cs = nat -- {* Type for critical sections (or critical resources). *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
text {*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
  \noindent
48
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    29
  The abstraction of Priority Inheritance Protocol (PIP) is set at the system call level.
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    30
  Every system call is represented as an event. The format of events is defined 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  defined as follows:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
datatype event = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  Create thread priority | -- {* Thread @{text "thread"} is created with priority @{text "priority"}. *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
  Exit thread | -- {* Thread @{text "thread"} finishing its execution. *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
  P thread cs | -- {* Thread @{text "thread"} requesting critical resource @{text "cs"}. *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
  V thread cs | -- {* Thread @{text "thread"}  releasing critical resource @{text "cs"}. *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
  Set thread priority -- {* Thread @{text "thread"} resets its priority to @{text "priority"}. *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 118
diff changeset
    41
fun actor  where
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    42
  "actor (Exit th) = th" |
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    43
  "actor (P th cs) = th" |
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    44
  "actor (V th cs) = th" |
125
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 118
diff changeset
    45
  "actor (Set th pty) = th" |
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 118
diff changeset
    46
  "actor (Create th prio) = th"
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 118
diff changeset
    47
95e7933968f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 118
diff changeset
    48
definition "actions_of ths s = filter (\<lambda> e. actor e \<in> ths) s"
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    49
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    50
fun isCreate :: "event \<Rightarrow> bool" where
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    51
  "isCreate (Create th pty) = True" |
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    52
  "isCreate _ = False"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    53
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    54
fun isP :: "event \<Rightarrow> bool" where
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    55
  "isP (P th cs) = True" |
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    56
  "isP _ = False"
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    57
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    58
fun isV :: "event \<Rightarrow> bool" where
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    59
  "isV (V th cs) = True" |
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 65
diff changeset
    60
  "isV _ = False"
48
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    61
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    62
text {* 
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    63
  As mentioned earlier, in Paulson's inductive method, the states of system are represented as lists of events,
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    64
  which is defined by the following type @{text "state"}:
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    65
  *}
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    66
type_synonym state = "event list"
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    67
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    68
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
text {* 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
  Resource Allocation Graph (RAG for short) is used extensively in our formal analysis. 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
  The following type @{text "node"} is used to represent nodes in RAG.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
datatype node = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
   Th "thread" | -- {* Node for thread. *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
   Cs "cs" -- {* Node for critical resource. *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
text {*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
  \noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
  The following function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
  @{text "threads"} is used to calculate the set of live threads (@{text "threads s"})
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
  in state @{text "s"}.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
fun threads :: "state \<Rightarrow> thread set"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
  where 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
  -- {* At the start of the system, the set of threads is empty: *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
  "threads [] = {}" | 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
  -- {* New thread is added to the @{text "threads"}: *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
  "threads (Create thread prio#s) = {thread} \<union> threads s" | 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
  -- {* Finished thread is removed: *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
  "threads (Exit thread # s) = (threads s) - {thread}" | 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
  -- {* Other kind of events does not affect the value of @{text "threads"}: *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
  "threads (e#s) = threads s" 
48
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
    94
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
    95
text {* 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
    96
  \noindent
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
    97
  The function @{text "threads"} defined above is one of 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
    98
  the so called {\em observation function}s which forms 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
    99
  the very basis of Paulson's inductive protocol verification method.
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   100
  Each observation function {\em observes} one particular aspect (or attribute)
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   101
  of the system. For example, the attribute observed by  @{text "threads s"}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   102
  is the set of threads living in state @{text "s"}. 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   103
  The protocol being modelled 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   104
  The decision made the protocol being modelled is based on the {\em observation}s
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   105
  returned by {\em observation function}s. Since {\observation function}s forms 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   106
  the very basis on which Paulson's inductive method is based, there will be 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   107
  a lot of such observation functions introduced in the following. In fact, any function 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   108
  which takes event list as argument is a {\em observation function}.
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   109
  *}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   110
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
text {* \noindent
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   112
  Observation @{text "priority th s"} is
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   113
  the {\em original priority} of thread @{text "th"} in state @{text "s"}. 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   114
  The {\em original priority} is the priority 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
  assigned to a thread when it is created or when it is reset by system call 
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   116
  (represented by event @{text "Set thread priority"}).
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
*}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   119
fun priority :: "thread \<Rightarrow> state \<Rightarrow> priority"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
  where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
  -- {* @{text "0"} is assigned to threads which have never been created: *}
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   122
  "priority thread [] = 0" |
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   123
  "priority thread (Create thread' prio#s) = 
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   124
     (if thread' = thread then prio else priority thread s)" |
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   125
  "priority thread (Set thread' prio#s) = 
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   126
     (if thread' = thread then prio else priority thread s)" |
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   127
  "priority thread (e#s) = priority thread s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
text {*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
  \noindent
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   131
  Observation @{text "last_set th s"} is the last time when the priority of thread @{text "th"} is set, 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
  observed from state @{text "s"}.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
  The time in the system is measured by the number of events happened so far since the very beginning.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
*}
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   135
fun last_set :: "thread \<Rightarrow> state \<Rightarrow> nat"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
  where
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   137
  "last_set thread [] = 0" |
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   138
  "last_set thread ((Create thread' prio)#s) = 
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   139
       (if (thread = thread') then length s else last_set thread s)" |
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   140
  "last_set thread ((Set thread' prio)#s) = 
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   141
       (if (thread = thread') then length s else last_set thread s)" |
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   142
  "last_set thread (_#s) = last_set thread s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
text {*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
  \noindent 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
  The {\em precedence} is a notion derived from {\em priority}, where the {\em precedence} of 
48
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
   147
  a thread is the combination of its {\em original priority} and {\em time} the priority is set. 
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
   148
  The intention is to discriminate threads with the same priority by giving threads whose priority
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
  is assigned earlier higher precedences, becasue such threads are more urgent to finish. 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
  This explains the following definition:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
definition preced :: "thread \<Rightarrow> state \<Rightarrow> precedence"
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   153
  where "preced thread s \<equiv> Prc (priority thread s) (last_set thread s)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
text {*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
  \noindent
49
8679d75b1d76 A little more change.
xingyuan zhang <xingyuanzhang@126.com>
parents: 48
diff changeset
   158
  A number of important notions in PIP are represented as the following functions, 
8679d75b1d76 A little more change.
xingyuan zhang <xingyuanzhang@126.com>
parents: 48
diff changeset
   159
  defined in terms of the waiting queues of the system, where the waiting queues 
48
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
   160
  , as a whole, is represented by the @{text "wq"} argument of every notion function.
49
8679d75b1d76 A little more change.
xingyuan zhang <xingyuanzhang@126.com>
parents: 48
diff changeset
   161
  The @{text "wq"} argument is itself a functions which maps every critical resource 
8679d75b1d76 A little more change.
xingyuan zhang <xingyuanzhang@126.com>
parents: 48
diff changeset
   162
  @{text "cs"} to the list of threads which are holding or waiting for it. 
48
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
   163
  The thread at the head of this list is designated as the thread which is current 
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
   164
  holding the resrouce, which is slightly different from tradition where
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
   165
  all threads in the waiting queue are considered as waiting for the resource.
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   168
(*
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
consts 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
  holding :: "'b \<Rightarrow> thread \<Rightarrow> cs \<Rightarrow> bool" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
  waiting :: "'b \<Rightarrow> thread \<Rightarrow> cs \<Rightarrow> bool"
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   172
  RAG :: "'b \<Rightarrow> (node \<times> node) set"
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   173
  dependants :: "'b \<Rightarrow> thread \<Rightarrow> thread set"
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   174
*)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   176
definition 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
  -- {* 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
  \begin{minipage}{0.9\textwidth}
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   179
  This meaning of @{text "wq"} is reflected in the following definition of
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   180
  @{text "holding wq th cs"}, where @{text "holding wq th cs"} means thread
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   181
  @{text "th"} is holding the critical resource @{text "cs"}. This decision
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   182
  is based on @{text "wq"}.
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   183
  \end{minipage}
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   184
  *}
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   185
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   186
  cs_holding_raw:   
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   187
  "holding_raw wq thread cs \<equiv> (thread \<in> set (wq cs) \<and> thread = hd (wq cs))"
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   188
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   189
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   190
definition
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   191
  -- {* 
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   192
  \begin{minipage}{0.9\textwidth}
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   193
  In accordance with the definition of @{text "holding wq th cs"}, a thread
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   194
  @{text "th"} is considered waiting for @{text "cs"} if it is in the {\em
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   195
  waiting queue} of critical resource @{text "cs"}, but not at the head.
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   196
  This is reflected in the definition of @{text "waiting wq th cs"} as
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   197
  follows:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
  \end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
  *}
48
c0f14399c12f Some changes in the PrioGDef.thy.
xingyuan zhang <xingyuanzhang@126.com>
parents: 35
diff changeset
   200
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   201
  cs_waiting_raw: 
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   202
  "waiting_raw wq thread cs \<equiv> (thread \<in> set (wq cs) \<and> thread \<noteq> hd (wq cs))"
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   203
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   204
definition
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
  -- {* 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
  \begin{minipage}{0.9\textwidth}
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   207
  @{text "RAG wq"} generates RAG (a binary relations on @{text "node"}) out
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   208
  of waiting queues of the system (represented by the @{text "wq"}
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   209
  argument): \end{minipage}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
  *}
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   211
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   212
  cs_RAG_raw: 
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   213
  "RAG_raw (wq::cs \<Rightarrow> thread list) \<equiv>
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   214
      {(Th th, Cs cs) | th cs. waiting_raw wq th cs} \<union> {(Cs cs, Th th) | cs th. holding_raw wq th cs}"
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   215
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   216
definition
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
  -- {* 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
  \begin{minipage}{0.9\textwidth}
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   219
  The following @{text "dependants wq th"} represents the set of threads
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   220
  which are RAGing on thread @{text "th"} in Resource Allocation Graph
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   221
  @{text "RAG wq"}. Here, "RAGing" means waiting directly or indirectly on
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   222
  the critical resource. 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
  \end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
  *}
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   225
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   226
  cs_dependants_def: 
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   227
  "dependants_raw (wq::cs \<Rightarrow> thread list) th \<equiv> {th' . (Th th', Th th) \<in> (RAG_raw wq)^+}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   229
text {* 
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   230
  \noindent The following @{text "cpreced s th"} gives the {\em current
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   231
  precedence} of thread @{text "th"} under state @{text "s"}. The definition
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   232
  of @{text "cpreced"} reflects the basic idea of Priority Inheritance that
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   233
  the {\em current precedence} of a thread is the precedence inherited from
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   234
  the maximum of all its dependants, i.e. the threads which are waiting
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   235
  directly or indirectly waiting for some resources from it. If no such
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   236
  thread exits, @{text "th"}'s {\em current precedence} equals its original
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   237
  precedence, i.e. @{text "preced th s"}. 
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   238
*}
33
9b9f2117561f simplified the cp_rec proof
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   239
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
definition cpreced :: "(cs \<Rightarrow> thread list) \<Rightarrow> state \<Rightarrow> thread \<Rightarrow> precedence"
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   241
  where "cpreced wq s = (\<lambda>th. Max ((\<lambda>th'. preced th' s) ` ({th} \<union> dependants_raw wq th)))"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   243
text {*
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   244
  Notice that the current precedence (@{text "cpreced"}) of one thread
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   245
  @{text "th"} can be boosted (becoming larger than its own precedence) by
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   246
  those threads in the @{text "dependants wq th"}-set. If one thread get
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   247
  boosted, we say it inherits the priority (or, more precisely, the
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   248
  precedence) of its dependants. This is how the word "Inheritance" in
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   249
  Priority Inheritance Protocol comes.
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   250
*}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   251
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
(*<*)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   253
lemma 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   254
  cpreced_def2:
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   255
  "cpreced wq s th \<equiv> Max ({preced th s} \<union> {preced th' s | th'. th' \<in> dependants_raw wq th})"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
  unfolding cpreced_def image_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
  apply(rule eq_reflection)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
  apply(rule_tac f="Max" in arg_cong)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
  by (auto)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
(*>*)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
49
8679d75b1d76 A little more change.
xingyuan zhang <xingyuanzhang@126.com>
parents: 48
diff changeset
   262
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   263
text {* 
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   264
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   265
  \noindent Assuming @{text "qs"} be the waiting queue of a critical
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   266
  resource, the following abbreviation "release qs" is the waiting queue
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   267
  after the thread holding the resource (which is thread at the head of
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   268
  @{text "qs"}) released the resource: 
49
8679d75b1d76 A little more change.
xingyuan zhang <xingyuanzhang@126.com>
parents: 48
diff changeset
   269
*}
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   270
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
abbreviation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
  "release qs \<equiv> case qs of
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
             [] => [] 
49
8679d75b1d76 A little more change.
xingyuan zhang <xingyuanzhang@126.com>
parents: 48
diff changeset
   274
          |  (_#qs') => (SOME q. distinct q \<and> set q = set qs')"
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   275
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   276
text {* 
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   277
  \noindent It can be seen from the definition that the thread at the head
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   278
  of @{text "qs"} is removed from the return value, and the value @{term
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   279
  "q"} is an reordering of @{text "qs'"}, the tail of @{text "qs"}. Through
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   280
  this reordering, one of the waiting threads (those in @{text "qs'"} } is
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   281
  chosen nondeterministically to be the head of the new queue @{text "q"}.
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   282
  Therefore, this thread is the one who takes over the resource. This is a
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   283
  little better different from common sense that the thread who comes the
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   284
  earliest should take over. The intention of this definition is to show
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   285
  that the choice of which thread to take over the release resource does not
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   286
  affect the correctness of the PIP protocol. 
49
8679d75b1d76 A little more change.
xingyuan zhang <xingyuanzhang@126.com>
parents: 48
diff changeset
   287
*}
8679d75b1d76 A little more change.
xingyuan zhang <xingyuanzhang@126.com>
parents: 48
diff changeset
   288
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   289
text {*
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   290
  The data structure used by the operating system for scheduling is referred
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   291
  to as {\em schedule state}. It is represented as a record consisting of a
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   292
  function assigning waiting queue to resources (to be used as the @{text
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   293
  "wq"} argument in @{text "holding"}, @{text "waiting"} and @{text "RAG"},
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   294
  etc) and a function assigning precedence to threads:
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   295
  *}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   296
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   297
record schedule_state = 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   298
    wq_fun :: "cs \<Rightarrow> thread list" -- {* The function assigning waiting queue. *}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   299
    cprec_fun :: "thread \<Rightarrow> precedence" -- {* The function assigning precedence. *}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   300
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   301
text {* 
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   302
  \noindent The following two abbreviations (@{text "all_unlocked"} and
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   303
  @{text "initial_cprec"}) are used to set the initial values of the @{text
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   304
  "wq_fun"} @{text "cprec_fun"} fields respectively of the @{text
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   305
  "schedule_state"} record by the following function @{text "sch"}, which is
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   306
  used to calculate the system's {\em schedule state}.
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   307
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   308
  Since there is no thread at the very beginning to make request, all
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   309
  critical resources are free (or unlocked). This status is represented by
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   310
  the abbreviation @{text "all_unlocked"}.
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   311
*}
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   312
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   313
abbreviation
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   314
  "all_unlocked \<equiv> \<lambda>_::cs. ([]::thread list)"
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   315
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   316
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   317
text {* \noindent
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   318
  The initial current precedence for a thread can be anything, because there is no thread then. 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   319
  We simply assume every thread has precedence @{text "Prc 0 0"}.
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   320
  *}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   321
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   322
abbreviation 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   323
  "initial_cprec \<equiv> \<lambda>_::thread. Prc 0 0"
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   324
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   325
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   326
text {* \noindent
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   327
  The following function @{text "schs"} is used to calculate the system's schedule state @{text "schs s"}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   328
  out of the current system state @{text "s"}. It is the central function to model Priority Inheritance:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   329
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
fun schs :: "state \<Rightarrow> schedule_state"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331
  where 
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   332
  -- {*
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   333
  \begin{minipage}{0.9\textwidth}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   334
    Setting the initial value of the @{text "schedule_state"} record (see the explanations above).
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   335
  \end{minipage}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   336
  *}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   337
  "schs [] = (| wq_fun = all_unlocked,  cprec_fun = initial_cprec |)" |
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   339
  -- {*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   340
  \begin{minipage}{0.9\textwidth}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   341
  \begin{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   342
  \item @{text "ps"} is the schedule state of last moment.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   343
  \item @{text "pwq"} is the waiting queue function of last moment.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   344
  \item @{text "pcp"} is the precedence function of last moment (NOT USED). 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   345
  \item @{text "nwq"} is the new waiting queue function. It is calculated using a @{text "case"} statement:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
  \begin{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   347
      \item If the happening event is @{text "P thread cs"}, @{text "thread"} is added to 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   348
            the end of @{text "cs"}'s waiting queue.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
      \item If the happening event is @{text "V thread cs"} and @{text "s"} is a legal state,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
            @{text "th'"} must equal to @{text "thread"}, 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
            because @{text "thread"} is the one currently holding @{text "cs"}. 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   352
            The case @{text "[] \<Longrightarrow> []"} may never be executed in a legal state.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   353
            the @{text "(SOME q. distinct q \<and> set q = set qs)"} is used to choose arbitrarily one 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
            thread in waiting to take over the released resource @{text "cs"}. In our representation,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
            this amounts to rearrange elements in waiting queue, so that one of them is put at the head.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   356
      \item For other happening event, the schedule state just does not change.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   357
  \end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   358
  \item @{text "ncp"} is new precedence function, it is calculated from the newly updated waiting queue 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   359
        function. The RAGency of precedence function on waiting queue function is the reason to 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   360
        put them in the same record so that they can evolve together.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   361
  \end{enumerate}
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   362
  
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   363
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   364
  The calculation of @{text "cprec_fun"} depends on the value of @{text "wq_fun"}. 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   365
  Therefore, in the following cases, @{text "wq_fun"} is always calculated first, in 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   366
  the name of @{text "wq"} (if  @{text "wq_fun"} is not changed
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   367
  by the happening event) or @{text "new_wq"} (if the value of @{text "wq_fun"} is changed).
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   368
  \end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   369
     *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   370
   "schs (Create th prio # s) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   371
       (let wq = wq_fun (schs s) in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   372
          (|wq_fun = wq, cprec_fun = cpreced wq (Create th prio # s)|))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   373
|  "schs (Exit th # s) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   374
       (let wq = wq_fun (schs s) in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   375
          (|wq_fun = wq, cprec_fun = cpreced wq (Exit th # s)|))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   376
|  "schs (Set th prio # s) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   377
       (let wq = wq_fun (schs s) in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   378
          (|wq_fun = wq, cprec_fun = cpreced wq (Set th prio # s)|))"
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   379
   -- {*
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   380
   \begin{minipage}{0.9\textwidth}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   381
      Different from the forth coming cases, the @{text "wq_fun"} field of the schedule state 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   382
      is changed. So, the new value is calculated first, in the name of @{text "new_wq"}.
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   383
   \end{minipage}   
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   384
   *}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   385
|  "schs (P th cs # s) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   386
       (let wq = wq_fun (schs s) in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
        let new_wq = wq(cs := (wq cs @ [th])) in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
          (|wq_fun = new_wq, cprec_fun = cpreced new_wq (P th cs # s)|))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
|  "schs (V th cs # s) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   390
       (let wq = wq_fun (schs s) in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   391
        let new_wq = wq(cs := release (wq cs)) in
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
          (|wq_fun = new_wq, cprec_fun = cpreced new_wq (V th cs # s)|))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   394
lemma cpreced_initial: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   395
  "cpreced (\<lambda> cs. []) [] = (\<lambda>_. (Prc 0 0))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   396
apply(simp add: cpreced_def)
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   397
apply(simp add: cs_dependants_def cs_RAG_raw cs_waiting_raw cs_holding_raw)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   398
apply(simp add: preced_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   399
done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   400
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   401
lemma sch_old_def:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   402
  "schs (e#s) = (let ps = schs s in 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
                  let pwq = wq_fun ps in 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   404
                  let nwq = case e of
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   405
                             P th cs \<Rightarrow>  pwq(cs:=(pwq cs @ [th])) |
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   406
                             V th cs \<Rightarrow> let nq = case (pwq cs) of
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   407
                                                      [] \<Rightarrow> [] | 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   408
                                                      (_#qs) \<Rightarrow> (SOME q. distinct q \<and> set q = set qs)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   409
                                            in pwq(cs:=nq)                 |
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   410
                              _ \<Rightarrow> pwq
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   411
                  in let ncp = cpreced nwq (e#s) in 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   412
                     \<lparr>wq_fun = nwq, cprec_fun = ncp\<rparr>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   413
                 )"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   414
apply(cases e)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   415
apply(simp_all)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   416
done
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   417
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   418
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   419
text {* 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   420
  \noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   421
  The following @{text "wq"} is a shorthand for @{text "wq_fun"}. 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   422
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   423
definition wq :: "state \<Rightarrow> cs \<Rightarrow> thread list" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   424
  where "wq s = wq_fun (schs s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   425
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   426
text {* \noindent 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   427
  The following @{text "cp"} is a shorthand for @{text "cprec_fun"}. 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   428
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   429
definition cp :: "state \<Rightarrow> thread \<Rightarrow> precedence"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   430
  where "cp s \<equiv> cprec_fun (schs s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   431
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   432
text {* \noindent
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   433
  Functions @{text "holding"}, @{text "waiting"}, @{text "RAG"} and 
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   434
  @{text "dependants"} still have the 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   435
  same meaning, but redefined so that they no longer RAG on the 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   436
  fictitious {\em waiting queue function}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   437
  @{text "wq"}, but on system state @{text "s"}.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   438
  *}
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   439
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   440
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   441
definition 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   442
  s_holding_abv: 
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   443
  "holding (s::state) \<equiv> holding_raw (wq_fun (schs s))"
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   444
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   445
definition
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   446
  s_waiting_abv: 
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   447
  "waiting (s::state) \<equiv> waiting_raw (wq_fun (schs s))"
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   448
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   449
definition
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   450
  s_RAG_abv: 
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   451
  "RAG (s::state) \<equiv> RAG_raw (wq_fun (schs s))"
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   452
  
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   453
definition
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   454
  s_dependants_abv: 
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   455
  "dependants (s::state) \<equiv> dependants_raw (wq_fun (schs s))"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   456
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   457
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   458
text {* 
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   459
  The following lemma can be proved easily, and the meaning is obvious.
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   460
  *}
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   461
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   462
lemma
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   463
  s_holding_def: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   464
  "holding (s::state) th cs \<equiv> (th \<in> set (wq_fun (schs s) cs) \<and> th = hd (wq_fun (schs s) cs))"
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   465
  by (auto simp:s_holding_abv wq_def cs_holding_raw)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   466
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   467
lemma s_waiting_def: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   468
  "waiting (s::state) th cs \<equiv> (th \<in> set (wq_fun (schs s) cs) \<and> th \<noteq> hd (wq_fun (schs s) cs))"
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   469
  by (auto simp:s_waiting_abv wq_def cs_waiting_raw)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   470
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   471
lemma s_RAG_def: 
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   472
  "RAG (s::state) =
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   473
    {(Th th, Cs cs) | th cs. waiting_raw (wq s) th cs} \<union> {(Cs cs, Th th) | cs th. holding_raw (wq s) th cs}"
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   474
  by (auto simp:s_RAG_abv wq_def cs_RAG_raw)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   475
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   476
lemma
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   477
  s_dependants_def: 
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   478
  "dependants (s::state) th \<equiv> {th' . (Th th', Th th) \<in> (RAG_raw (wq s))^+}"
32
e861aff29655 made some modifications.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   479
  by (auto simp:s_dependants_abv wq_def cs_dependants_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   480
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   481
text {*
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   482
  The following function @{text "readys"} calculates the set of ready
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   483
  threads. A thread is {\em ready} for running if it is a live thread and it
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   484
  is not waiting for any critical resource.
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   485
  *}
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   486
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   487
definition readys :: "state \<Rightarrow> thread set"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   488
  where "readys s \<equiv> {th . th \<in> threads s \<and> (\<forall> cs. \<not> waiting s th cs)}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   489
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   490
text {* 
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   491
  \noindent The following function @{text "runing"} calculates the set of
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   492
  running thread, which is the ready thread with the highest precedence.
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   493
  *}
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   494
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   495
definition runing :: "state \<Rightarrow> thread set"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   496
  where "runing s \<equiv> {th . th \<in> readys s \<and> cp s th = Max ((cp s) ` (readys s))}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   497
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   498
text {* 
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   499
  \noindent Notice that the definition of @{text "running"} reflects the
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   500
  preemptive scheduling strategy, because, if the @{text "running"}-thread
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   501
  (the one in @{text "runing"} set) lowered its precedence by resetting its
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   502
  own priority to a lower one, it will lose its status of being the max in
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   503
  @{text "ready"}-set and be superseded. 
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   504
*}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   505
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   506
text {* 
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   507
  \noindent The following function @{text "holdents s th"} returns the set
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   508
  of resources held by thread @{text "th"} in state @{text "s"}. *}
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   509
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   510
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   511
definition holdents :: "state \<Rightarrow> thread \<Rightarrow> cs set" 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   512
  where "holdents s th \<equiv> {cs . holding s th cs}"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   513
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   514
lemma holdents_test: 
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   515
  "holdents s th = {cs . (Cs cs, Th th) \<in> RAG s}"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   516
unfolding holdents_def
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   517
unfolding s_RAG_def
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   518
unfolding s_holding_abv
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   519
unfolding wq_def
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   520
by (simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   521
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   522
text {* \noindent
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   523
  According to the convention of Paulson's inductive method,
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   524
  the decision made by a protocol that event @{text "e"} is eligible to happen next under state @{text "s"} 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   525
  is expressed as @{text "step s e"}. The predicate @{text "step"} is inductively defined as 
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   526
  follows (notice how the decision is based on the {\em observation function}s 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   527
  defined above, and also notice how a complicated protocol is modeled by a few simple 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   528
  observations, and how such a kind of simplicity gives rise to improved trust on
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   529
  faithfulness):
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   530
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   531
inductive step :: "state \<Rightarrow> event \<Rightarrow> bool"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   532
  where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   533
  -- {* 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   534
  A thread can be created if it is not a live thread:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   535
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   536
  thread_create: "\<lbrakk>thread \<notin> threads s\<rbrakk> \<Longrightarrow> step s (Create thread prio)" |
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   537
  -- {*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   538
  A thread can exit if it no longer hold any resource:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   539
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   540
  thread_exit: "\<lbrakk>thread \<in> runing s; holdents s thread = {}\<rbrakk> \<Longrightarrow> step s (Exit thread)" |
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   541
  -- {*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   542
  \begin{minipage}{0.9\textwidth}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   543
  A thread can request for an critical resource @{text "cs"}, if it is running and 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   544
  the request does not form a loop in the current RAG. The latter condition 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   545
  is set up to avoid deadlock. The condition also reflects our assumption all threads are 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   546
  carefully programmed so that deadlock can not happen:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   547
  \end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   548
  *}
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   549
  thread_P: "\<lbrakk>thread \<in> runing s;  (Cs cs, Th thread)  \<notin> (RAG s)^+\<rbrakk> \<Longrightarrow> 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   550
                                                                step s (P thread cs)" |
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   551
  -- {*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   552
  \begin{minipage}{0.9\textwidth}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   553
  A thread can release a critical resource @{text "cs"} 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   554
  if it is running and holding that resource:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   555
  \end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   556
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   557
  thread_V: "\<lbrakk>thread \<in> runing s;  holding s thread cs\<rbrakk> \<Longrightarrow> step s (V thread cs)" |
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   558
  -- {*
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   559
  \begin{minipage}{0.9\textwidth}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   560
  A thread can adjust its own priority as long as it is current running. 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   561
  With the resetting of one thread's priority, its precedence may change. 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   562
  If this change lowered the precedence, according to the definition of @{text "running"}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   563
  function, 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   564
  \end{minipage}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   565
  *}  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   566
  thread_set: "\<lbrakk>thread \<in> runing s\<rbrakk> \<Longrightarrow> step s (Set thread prio)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   567
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   568
text {*
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   569
  In Paulson's inductive method, every protocol is defined by such a @{text "step"}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   570
  predicate. For instance, the predicate @{text "step"} given above 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   571
  defines the PIP protocol. So, it can also be called "PIP".
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   572
*}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   573
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   574
abbreviation
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   575
  "PIP \<equiv> step"
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   576
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   577
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   578
text {* \noindent
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   579
  For any protocol defined by a @{text "step"} predicate, 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   580
  the fact that @{text "s"} is a legal state in 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   581
  the protocol is expressed as: @{text "vt step s"}, where
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   582
  the predicate @{text "vt"} can be defined as the following:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   583
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   584
inductive vt :: "state \<Rightarrow> bool"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   585
  where
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   586
  -- {* Empty list @{text "[]"} is a legal state in any protocol:*}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   587
  vt_nil[intro]: "vt []" |
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   588
  -- {* 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   589
  \begin{minipage}{0.9\textwidth}
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   590
  If @{text "s"} a legal state of the protocol defined by predicate @{text "step"}, 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   591
  and event @{text "e"} is allowed to happen under state @{text "s"} by the protocol 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   592
  predicate @{text "step"}, then @{text "e#s"} is a new legal state rendered by the 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   593
  happening of @{text "e"}:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   594
  \end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   595
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   596
  vt_cons[intro]: "\<lbrakk>vt s; step s e\<rbrakk> \<Longrightarrow> vt (e#s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   597
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   598
text {*  \noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   599
  It is easy to see that the definition of @{text "vt"} is generic. It can be applied to 
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   600
  any specific protocol specified by a @{text "step"}-predicate to get the set of
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   601
  legal states of that particular protocol.
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   602
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   603
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   604
text {* 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   605
  The following are two very basic properties of @{text "vt"}.
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   606
*}
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   607
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   608
lemma step_back_vt: "vt (e#s) \<Longrightarrow> vt s"
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   609
  by(ind_cases "vt (e#s)", simp)
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   610
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   611
lemma step_back_step: "vt (e#s) \<Longrightarrow> step s e"
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   612
  by(ind_cases "vt (e#s)", simp)
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   613
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   614
text {* \noindent
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   615
  The following two auxiliary functions @{text "the_cs"} and @{text "the_th"} are used to extract
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   616
  critical resource and thread respectively out of RAG nodes.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   617
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   618
fun the_cs :: "node \<Rightarrow> cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   619
  where "the_cs (Cs cs) = cs"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   620
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   621
fun the_th :: "node \<Rightarrow> thread"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   622
  where "the_th (Th th) = th"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   623
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   624
text {* \noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   625
  The following predicate @{text "next_th"} describe the next thread to 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   626
  take over when a critical resource is released. In @{text "next_th s th cs t"}, 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   627
  @{text "th"} is the thread to release, @{text "t"} is the one to take over.
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   628
  Notice how this definition is backed up by the @{text "release"} function and its use 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   629
  in the @{text "V"}-branch of @{text "schs"} function. This @{text "next_th"} function
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   630
  is not needed for the execution of PIP. It is introduced as an auxiliary function 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   631
  to state lemmas. The correctness of this definition will be confirmed by 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   632
  lemmas @{text "step_v_hold_inv"}, @{text " step_v_wait_inv"}, 
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   633
  @{text "step_v_get_hold"} and @{text "step_v_not_wait"}.
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   634
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   635
definition next_th:: "state \<Rightarrow> thread \<Rightarrow> cs \<Rightarrow> thread \<Rightarrow> bool"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   636
  where "next_th s th cs t = (\<exists> rest. wq s cs = th#rest \<and> rest \<noteq> [] \<and> 
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   637
                                     t = hd (SOME q. distinct q \<and> set q = set rest))"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   638
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   639
text {* \noindent
53
8142e80f5d58 Finished comments on PrioGDef.thy
xingyuan zhang <xingyuanzhang@126.com>
parents: 49
diff changeset
   640
  The aux function @{text "count Q l"} is used to count the occurrence of situation @{text "Q"}
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   641
  in list @{text "l"}:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   642
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   643
definition count :: "('a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> nat"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   644
  where "count Q l = length (filter Q l)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   645
115
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   646
text {*
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   647
  The operation @{term P} is used by a thread to request for resources, while
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   648
  @{term V} is used to release. Therefore, the number of resources
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   649
  held by a thread roughly equals to the number of @{term P} it made minus 
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   650
  the number of @{term V}. The equality is rough because the @{term P}-operation
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   651
  might be blocked and fail to give back the holding of the requested resource.
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   652
  In the following, @{text "cntP"} and @{text "cntV"} are the number of @{term P}
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   653
  and @{term "V"} respectively, while @{term cntCS} is the number 
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   654
  resources held by a thread and @{text "pvD"} is introduced to account for 
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   655
  the above mentioned situation when @{term P} is blocked, so that 
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   656
  a equation between @{text cntP}, @{text "cntV"}, @{text "cntCS"} can be established
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   657
  (in the lemma named @{text "valid_trace.cnp_cnv_cncs"}).
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   658
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   659
  Such a equation, once established, is very handy, because the number of resources 
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   660
  held by a thread can be calculated by counting the number of @{term P} and @{text V},
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   661
  which is relatively easy.
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   662
*}
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   663
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   664
definition cntP :: "state \<Rightarrow> thread \<Rightarrow> nat"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   665
  where "cntP s th = count (\<lambda> e. \<exists> cs. e = P th cs) s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   666
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   667
definition cntV :: "state \<Rightarrow> thread \<Rightarrow> nat"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   668
  where "cntV s th = count (\<lambda> e. \<exists> cs. e = V th cs) s"
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   669
115
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   670
definition cntCS :: "state \<Rightarrow> thread \<Rightarrow> nat"
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   671
  where "cntCS s th = card (holdents s th)"
74fc1eae4605 Commenting of PIPBasics.thy almost completed. The last section needs to be distributed to Correctness.thy and Implementation.thy
zhangx
parents: 104
diff changeset
   672
80
17305a85493d CpsG.thy retrofiting almost completed. An important mile stone.
zhangx
parents: 67
diff changeset
   673
definition "pvD s th = (if (th \<in> readys s \<or> th \<notin> threads s) then 0 else (1::nat))"
17305a85493d CpsG.thy retrofiting almost completed. An important mile stone.
zhangx
parents: 67
diff changeset
   674
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   675
text {* @{text "the_preced"} is also the same as @{text "preced"}, the only
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   676
       difference is the order of arguemts. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   677
definition "the_preced s th = preced th s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   678
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   679
text {* @{term "the_thread"} extracts thread out of RAG node. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   680
fun the_thread :: "node \<Rightarrow> thread" where
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   681
   "the_thread (Th th) = th"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   682
80
17305a85493d CpsG.thy retrofiting almost completed. An important mile stone.
zhangx
parents: 67
diff changeset
   683
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   684
text {* The following @{text "wRAG"} is the waiting sub-graph of @{text "RAG"}. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   685
definition "wRAG (s::state) = {(Th th, Cs cs) | th cs. waiting s th cs}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   686
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   687
text {* The following @{text "hRAG"} is the holding sub-graph of @{text "RAG"}. *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   688
definition "hRAG (s::state) =  {(Cs cs, Th th) | th cs. holding s th cs}"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   689
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   690
text {* 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   691
  The following @{text "tRAG"} is the thread-graph derived from @{term "RAG"}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   692
  It characterizes the dependency between threads when calculating current
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   693
  precedences. It is defined as the composition of the above two sub-graphs, 
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   694
  names @{term "wRAG"} and @{term "hRAG"}.
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   695
 *}
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   696
definition "tRAG s = wRAG s O hRAG s"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   697
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   698
text {* The following lemma splits @{term "RAG"} graph into the above two sub-graphs. *}
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   699
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   700
lemma RAG_split: "RAG s = (wRAG s \<union> hRAG s)"
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   701
  by (unfold s_RAG_abv wRAG_def hRAG_def s_waiting_abv 
118
a4bb5525b7b6 updated to Isabelle 2016
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
   702
             s_holding_abv cs_RAG_raw, auto)
65
633b1fc8631b Reorganization completed, added "scripts_structure.pdf" and "scirpts_structure.pptx".
zhangx
parents: 64
diff changeset
   703
100
3d2b59f15f26 Reorganizing PIPBasics.thy
zhangx
parents: 80
diff changeset
   704
lemma tRAG_alt_def: 
3d2b59f15f26 Reorganizing PIPBasics.thy
zhangx
parents: 80
diff changeset
   705
  "tRAG s = {(Th th1, Th th2) | th1 th2. 
3d2b59f15f26 Reorganizing PIPBasics.thy
zhangx
parents: 80
diff changeset
   706
                  \<exists> cs. (Th th1, Cs cs) \<in> RAG s \<and> (Cs cs, Th th2) \<in> RAG s}"
3d2b59f15f26 Reorganizing PIPBasics.thy
zhangx
parents: 80
diff changeset
   707
 by (auto simp:tRAG_def RAG_split wRAG_def hRAG_def)
3d2b59f15f26 Reorganizing PIPBasics.thy
zhangx
parents: 80
diff changeset
   708
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   709
(*<*)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   710
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   711
end
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   712
(*>*)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   713