Subversion Repositories shark

Rev

Rev 1676 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1676 tullio 1
%----------------------------------------------------------------------------
2
\chapter{Resource Modules}
3
\label{CapModuliRisorsa}
4
%----------------------------------------------------------------------------
5
 
6
In this chapter the interface of a Resource Module is described. The semanthic
7
of the various functions, and the approach used to handle the Shared Resource
8
Access Protocols are described.
9
%
10
% Tool: such section does not exists.
11
%
12
% For architectural informations look at
13
% Sections\ref{ArchDetail_Moduli_GestioneRisorse} and
14
% \ref{ArchDetail_prot_ris_condiv}.
15
%----------------------------------------------------------------------------
16
\section{Resource Modules Interface}
17
%----------------------------------------------------------------------------
18
 
19
The approach used to define the interface of a Resource Module is
20
similar to that used for the Scheduling Modules (look at Section
21
\ref{CapSchedulingModules}, \ref{SchedModules_Interface} and
22
\ref{SchedModules_Convenzioni}).
23
 
24
The interface of a Scheduling Module is less complex than that of the Scheduling
25
Modules: only the \textit{create} and \textit{end} events are handled in the
26
task life. This choice is made because the Resource Modules usually does not
27
influence the scheduling of the system \footnote{Note that a Resource Handling
28
Algorithm that modifies the scheduling of the system is more like a Scheduling
29
Module than a Resource Module. Some hybrid approaches can be implemented
30
requiring that the implementation is made using two Modules that can modify the
31
private data of each other.}.
32
 
33
All the functions of a Resource Module are called with Interrupt
34
disabled.
35
 
36
%----------------------------------------------------------------------------
37
\subsubsection{\texttt{int (*res\_register)(RLEVEL l, PID p, RES\_MODEL *r);}}
38
%----------------------------------------------------------------------------
39
 
40
This function is called by the Generic Kernel by the
41
\texttt{task\_create} primitive to register a Resorce Model into a
42
Resource Module.
43
 
44
The function will accept as parameter the index p of the
45
descriptor allocated by the Generic Kernel for the task and one of
46
the Resource Models passed through the primitive.
47
 
48
The Generic Kernel guarantees that the Resource Model passed in
49
this function can be handled by the Module. The function returns 0
50
if the Module can handle the request, -1 if the task can not be
51
created because the Module can not guarantee the quality of
52
service required.
53
 
54
The function will set up the local Module data with the parameters
55
of Quality of Service passed with the Resource Model.
56
 
57
%----------------------------------------------------------------------------
58
\subsubsection{\texttt{void (*res\_detach)(RLEVEL l, PID p);}}
59
%----------------------------------------------------------------------------
60
 
61
The call of this function signals to the Module that the task p is
62
terminated, so all internal data structures must be updated.
63
 
64
This function is called independently from the fact that the task
65
has or not registered some Resource Model in the Module in two
66
cases:
67
 
68
\begin{itemize}
69
\item The primitive \texttt{task\_create} fails for some trouble
70
inependent from the Module; in this case the function is called
71
before the \texttt{public\_detach} function of the Scheduling
72
Module that owns the task;
73
 
74
\item The task terminates in the
75
correct way; in this case the function is called before the
76
function \texttt{public\_end} of the Scheduling Module that owns
77
the task.
78
\end{itemize}
79
 
80
In other words, this function implemets the behaviour of the
81
Scheduling Module's \texttt{public\_detach} and
82
\texttt{public\_end} functions. This is correct because the
83
Resource Module only react to the creation and termination events.
84
It doesn't matter if the task is terminated correctly or if it has
85
not been created\ldots{}
86
 
87
%----------------------------------------------------------------------------
88
\section{Implementation of the Shared Resource Access Protocols}
89
%----------------------------------------------------------------------------
90
 
91
The interface exported by the Resource Modules is used also by the
92
Modules that implements the Shared Resource access Protocols.
93
 
94
The problem solved developing these Modules is the project of some
95
OS primitives that can be independent from the used protocol, and,
96
moreover, independent from a specific Module registered at
97
run-time.
98
 
99
%----------------------------------------------------------------------------
100
\subsection{Used Approach}
101
%----------------------------------------------------------------------------
102
 
103
The approach used is to extend the Resource Module interface; in this way also
104
the protocols that requires some per-task parameters can be implemented
105
\footnote{For example, these parameters can be the ceiling of a task on a
106
Priority Ceiling or SRP protocol}.
107
 
108
Using an Object Oriented approach the hierarchy of the Modules can be described
109
(look at Figure\ref{ResMudules_Gerarchia}).
110
 
111
\begin{figure}
112
\begin{center}
113
\includegraphics[width=9cm]{images/resmodel_Gerarchia.eps}
114
\end{center}
115
\label{ResMudules_Gerarchia}
116
\caption{UML Diagram that shows the class hierarchy that implements the Shared
117
Resource AccesProtocols.}
118
\end{figure}
119
 
120
These Modules are viewed by the Generic Kernel as Resource Modules. When a mutex
121
is initialized some checks \footnote{Similar to those used in the primitive
122
\texttt{public\_create} for the Task Models.} are done to find the Module that
123
extends the interface in the correct way \footnote{To know that a Module has
124
extended the Resource Modules Interface the \texttt{rtype} field is provided
125
(look at Section \ref{KernSupport_Descrittore_GestioneRisorse}). }and therefore
126
implement the required protocol.
127
 
128
%----------------------------------------------------------------------------
129
\subsection{The mutexes}
130
%----------------------------------------------------------------------------
131
 
132
The mutexes are stored in the \texttt{mutex\_t} structure showed
133
in Figure \ref{ResModules_Fig_mutex_t}. That declaration is
134
contained in the file
135
\texttt{include/kernel/descr.h.}%
136
\begin{figure}
137
\begin{center} \fbox{\tt{ \begin{minipage}{6cm} \begin{tabbing}
138
123\=123\=123\=\kill
139
typedef struct \{ \\
140
\>RLEVEL mutexlevel; \\
141
\>int use;\\
142
\>void *opt;\\
143
\} mutex\_t;
144
\end{tabbing} \end{minipage} }} \end{center}
145
\label{ResModules_Fig_mutex_t}
146
\caption{The \texttt{mutex\_t} structure.}
147
\end{figure}
148
 
149
The structure contains the following fields:
150
 
151
\begin{description}
152
\item [mutexlevel]It is the level which the Module is registered
153
in.
154
 
155
\item [use]It tells if the mutex is currently used into a
156
synchronization done through condition variables.
157
 
158
\item [opt]This field is a pointer to a structure that the Module can
159
dinamically alloc to handle protocol-dependent parameters \footnote{These
160
parameters cannot be allocated internally to the Module because the mutexes are
161
not statically allocated as task or semaphore descriptors.}.
162
\end{description}
163
 
164
%----------------------------------------------------------------------------
165
\subsection{Interface extension}
166
%----------------------------------------------------------------------------
167
 
168
In this section the extension to the Resource Modules is
169
described. The proposed functions handles all the events that
170
belongs to amutex.
171
 
172
Only the function \texttt{init} is called with interrupts
173
disabled. The other functions have to disable the interrupts,
174
because there is not a generic behaviour for all these functions
175
(for example, the lock of a mutex may be non-blocking on some
176
protocols).
177
 
178
%----------------------------------------------------------------------------
179
\subsubsection{\texttt{int init(RLEVEL l, mutex\_t *m, mutexattr\_t *a);}}
180
%----------------------------------------------------------------------------
181
 
182
This function is called to init a mutex with a protocol. The
183
function accepts as parameters the mutex to be initialized and the
184
mutex attribute that store the parameters to be used in the
185
initialization.
186
 
187
The function returns a value of \texttt{0} if the mutex
188
initialization was successful, or an error code otherwise. The
189
error codes returned by the functions must be compatibles with the
190
functions \texttt{pthread\_mutex\_init} of the POSIX standard.
191
 
192
%----------------------------------------------------------------------------
193
\subsubsection{\texttt{int destroy(RLEVEL l, mutex\_t *m);}}
194
%----------------------------------------------------------------------------
195
 
196
%----------------------------------------------------------------------------
197
\subsubsection{\texttt{int lock(RLEVEL l, mutex\_t *m);}}
198
%----------------------------------------------------------------------------
199
 
200
%----------------------------------------------------------------------------
201
\subsubsection{\texttt{int trylock(RLEVEL l, mutex\_t *m);}}
202
%----------------------------------------------------------------------------
203
 
204
%----------------------------------------------------------------------------
205
\subsubsection{\texttt{int unlock(RLEVEL l, mutex\_t *m);}}
206
%----------------------------------------------------------------------------
207
 
208
These functions implements the core functionality of the mutexes
209
and they have a semantic similar to the corresponding POSIX
210
functions. In particular they receive as parameter a pointer to a
211
mutex, and they returns 0 if the operation was successful or an
212
error code if not.
213
 
214
These functions have to manage internally the context change in
215
the system, because it is not possible to give a fixed rule for
216
these functions (for example, the lock operation, that usually can
217
block the task, is never a blocking primitive under the SRP
218
assumptions).