update compat
[lttv.git] / doc / developer / lttv_requests_servicing_schedulers.txt
CommitLineData
ca566f70 1Linux Trace Toolkit
2
3Requests Servicing Schedulers
4
5
6Mathieu Desnoyers, 07/06/2004
7
8
9In the LTT graphical interface, two main types of events requests may occur :
10
11- events requests made by a viewer concerning a traceset for a ad hoc
12 computation.
13- events requests made by a viewer concerning a trace for a precomputation.
14
15
16Ad Hoc Computation
17
18The ad hoc computation must be serviced immediately : they are directly
19responding to events requests that must be serviced to complete the graphical
20widgets'data. This kind of computation may lead to incomplete result as long as
21precomputation are not finished. Once precomputation is over, the widgets will
22be redrawn if they needed such information. A ad hoc computation is done on a
23traceset : the workspace of a tab.
24
25Precomputation
26
27Traces are global objects. Only one instance of a trace is opened for all the
28program. Precomputation will append data to the traces attributes (states,
29statistics). It must inform the widgets which asked for such states or
30statistics of their availability. Only one precomputation must be launched for
31each trace and no duplication of precomputation must be done.
32
33
34Schedulers
35
36There is one tracesetcontext per traceset. Each reference to a trace by a
37traceset also has its own tracecontext. Each trace, by itself, has its own
38tracecontext.
39
40Let's define a scheduler as a g_idle events request servicing function.
41
42There is one scheduler per traceset context (registered when there are requests
43to answer). There is also one scheduler per autonomous trace context (not
44related to any traceset context).
45
46A scheduler processes requests for a specific traceset or trace by combining
47time intervals of the requests. It is interruptible by any GTK event. A
48precomputation scheduler has a lower priority than a ad hoc computation
49scheduler. That means that no precomputation will be performed until there is
50no more ad hoc compuation pending. When a scheduler is interrupted, it makes no
51assumption about the presence or absence of the current requests in its pool
52when it starts back.
53
54
55Foreground Scheduler
56
57There can be one foreground scheduler per traceset (one traceset per tab). It
58simply calls the hooks given by the events requests of the viewers for the
59specified time intervals.
60
61
62Background Scheduler
63
493c473c 64Right now, to simplify the problem of the background scheduler, we assume that
65the module that loads the extended statistics hooks has been loaded before the
66data is requested and that it is not unloaded until the program stops. We will
67eventually have to deal with the requests removal based on module load/unload,
68but it complicates the problem quite a bit.
69
70A background scheduler adds hooks located under a global attributes path
71(specified by the viewer who makes the request) to the trace's traceset
72context (the trace is specified by the viewer). Then, it processes the whole
73trace with this context (and hooks).
74
75Typically, a module that extends statistics will register hooks in the global
78d73d05 76attributes tree under /computation/modulename/hook_name . A viewer
493c473c 77that needs these statistics for a set of traces does a background computation
78request through a call to the main window API function. It must specify all
79types of hooks that must be called for the specified trace.
80
81The background computation requests for a trace are queued. When the idle
82function kicks in to answer these requests, it add the hooks of all the requests
83toghether in the context and starts the read. It also keeps a list of the
84background requests currently serviced.
85
86The read is done from start to end of the trace, calling all the hooks present
87in the context. Only when the read is over, the after_request hooks of the
88currently serviced requests are called and the requests are destroyed.
89
90If there are requests in the waiting queue, they are all added to the current
91pool and processed. It is important to understand that, while a processing is in
92being done, no requests are added to the pool : they wait for their turn in the
93queue.
94
95Every hook that are added to the context by the scheduler comes from global
96attributes, i.e.
78d73d05 97/traces/#
98 in LttvTrace attributes : modulename/hook_name
493c473c 99
100They come with a flag telling either in_progress or ready. If the flag
101ready is set, a viewer knows that the data it needs is already ready and he
102doesn't have to make a request.
103
104If the flag in_progress is set, that means that the data it needs is currently
105being serviced, and it must wait for the current servicing to be finished. It
106tells the lttvwindow API to call a hook when the actual servicing is over (there
107is a special function for this, as it requires to modify the pool of requests
108actually being serviced : we must make sure that no new reading hooks are
109added!).
110
111
112
113
114
115New Global Attributes
116
78d73d05 117/traces/#
118 in LttvTrace attributes :
493c473c 119
120When a processing is fired, a variable
78d73d05 121 computation/modulename/in_progress is set.
493c473c 122
123When a processing finished, a variable
78d73d05 124 computation/modulename/in_progress is unset
125 computation/modulename/ready is set
493c473c 126
127
128
129
130
131Typical Use For a Viewer
132
133When a viewer wants extended information, it must first check if it is ready.
134if not :
78d73d05 135Before a viewer makes a request, it must check the in_progress status of the
493c473c 136hooks.
137
138If the in_progress is unset, it makes the request.
139
140If the in_progress is set, it makes a special request for being informed of the
141end of request.
142
ca566f70 143
144
145
146Hooks Lists
147
148In order to answer the problems of background processing, we need to add a
149reference counter for each hook of a hook list. If the same hook is added twice,
150it will be called only once, but it will need two "remove" to be really removed
151from the list. Two hooks are identical if they have the same function pointer
152and hook_data.
153
154
63b8a718 155
493c473c 156
157
158
63b8a718 159Implementation
160
161Ad Hoc Computation
162
163see lttvwindow_events_delivery.txt
164
165
166Hooks Lists
167
168need new ref_count field with each hook
169lttv_hook_add and lttv_hook_add_list must compare addition with present and
170increment ref counter if already present.
171
172lttv_hook_remove and remove_with_data must decrement ref_count is >1, or remove
173the element otherwise (==1).
174
175
176
177Background Scheduler
178
179Global traces
180
181Two global attributes per trace :
78d73d05 182traces/#
63b8a718 183 It is a pointer to the LttvTrace structure.
78d73d05 184 In the LttvTrace attributes :
185 state/
186 saved_states/
187 statistics/
188 modes/
189 cpu/
190 processes/
191 modulename1/
192 modulename2/
193 ...
194 computation/ /* Trace specific background computation hooks status */
195 state/
196 in_progress
197 ready
e6f3a759 198 stats/
78d73d05 199 in_progress
200 ready
201 modulename1/
202 in_progress
203 ready
204 requests_queue/ /* Background computation requests */
205 requests_current/ /* Type : BackgroundRequest */
206 notify_queue/
207 notify_current/
e6f3a759 208 computation_traceset/
209 computation_traceset_context/
210
78d73d05 211
212computation/ /* Global background computation hooks */
213 state/
214 before_chunk_traceset
215 before_chunk_trace
216 before_chunk_tracefile
217 after_...
218 before_request
219 after_request
220 event_hook
221 event_hook_by_id
0c5dbe3b 222 hook_adder
223 hook_remover
e6f3a759 224 stats/
78d73d05 225 ...
226 modulename1/
227 ...
228
0c5dbe3b 229Hook Adder and Hook remover
230
231Hook functions that takes a trace context as call data. They simply
232add / remove the computation related hooks from the trace context.
233
234
63b8a718 235
63b8a718 236Modify Traceset
78d73d05 237Points to the global traces. Main window must open a new one only when no
238instance of the pathname exists.
63b8a718 239
240Modify trace opening / close to make them create and destroy
78d73d05 241LttvBackgroundComputation (and call end requests hooks for servicing requests)
242and global trace info when references to the trace is zero.
243
244
63b8a718 245
ca566f70 246EventsRequest Structure
247
78d73d05 248This structure is the element of the events requests pools. The owner field is
249used as an ownership identifier. The viewer field is a pointer to the data
250structure upon which the action applies. Typically, both will be pointers to
251the viewer's data structure.
252
253In a ad hoc events request, a pointer to the EventsRequest structure is used as
254hook_data in the hook lists : it must have been added by the viewers.
255
256
257Modify module load/unload
ca566f70 258
78d73d05 259A module that registers global computation hooks in the global attributes upon
260load should unregister them when unloaded. Also, it must remove every background
e6f3a759 261computation request for each trace that has its own module_name as GQuark.
ca566f70 262
ca566f70 263
e6f3a759 264Give an API for calculation modules
265
266Must have an API for module which register calculation hooks. Unregistration
267must also remove all requests made for these hooks.
268
4f70505a 269
270Background Requests Servicing Algorithm (v1)
271
272
273list_in : currently serviced requests
274list_out : queue of requests waiting for processing
275
2d262115 276notification lists :
277notify_in : currently checked notifications
278notify_out : queue of notifications that comes along with next processing.
279
4f70505a 280
0c5dbe3b 2810.1 Lock traces
2820.2 Sync tracefiles
283
4f70505a 2841. Before processing
e6f3a759 285 - if list_in is empty
4f70505a 286 - Add all requests in list_out to list_in, empty list_out
287 - for each request in list_in
4f70505a 288 - set hooks'in_progress flag to TRUE
0c5dbe3b 289 - call before request hook
4f70505a 290 - seek trace to start
2d262115 291 - Move all notifications from notify_out to notify_in.
e6f3a759 292 - for each request in list_in
293 - Call before chunk hooks for list_in
0c5dbe3b 294 - add hooks to context *note only one hook of each type added.
4f70505a 295
2962. call process traceset middle for a chunk
297 (assert list_in is not empty! : should not even be called in that case)
298
2993. After the chunk
e6f3a759 300 3.1 call after_chunk hooks for list_in
301 - for each request in list_in
302 - Call after chunk hooks for list_in
0c5dbe3b 303 - remove hooks from context *note : only one hook of each type
2d262115 304 3.2 for each notify_in
305 - if current time >= notify time, call notify and remove from notify_in
306 - if current position >= notify position, call notify and remove from
307 notify_in
e6f3a759 308 3.3 if end of trace reached
4f70505a 309 - for each request in list_in
310 - set hooks'in_progress flag to FALSE
311 - set hooks'ready flag to TRUE
0c5dbe3b 312 - call after request hook
4f70505a 313 - remove request
2d262115 314 - for each notifications in notify_in
315 - call notify and remove from notify_in
0c5dbe3b 316 - reset the context
317 - if list_out is empty
318 return FALSE (scheduler stopped)
319 - else
320 return TRUE (scheduler still registered)
e6f3a759 321 3.4 else
4f70505a 322 - return TRUE (scheduler still registered)
323
0c5dbe3b 3244. Unlock traces
This page took 0.100104 seconds and 4 git commands to generate.