aboutsummaryrefslogtreecommitdiffstats
path: root/base/include/host/mars/workload_queue.h
blob: 87581c52aa5937c58e92873b1a7f430e87c6ce84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
 * Copyright 2008 Sony Corporation of America
 *
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this Library and associated documentation files (the
 * "Library"), to deal in the Library without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Library, and to
 * permit persons to whom the Library is furnished to do so, subject to
 * the following conditions:
 *
 *  The above copyright notice and this permission notice shall be
 *  included in all copies or substantial portions of the Library.
 *
 *  If you modify the Library, you may copy and distribute your modified
 *  version of the Library in object code or as an executable provided
 *  that you also do one of the following:
 *
 *   Accompany the modified version of the Library with the complete
 *   corresponding machine-readable source code for the modified version
 *   of the Library; or,
 *
 *   Accompany the modified version of the Library with a written offer
 *   for a complete machine-readable copy of the corresponding source
 *   code of the modified version of the Library.
 *
 *
 * THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
 */

#ifndef MARS_WORKLOAD_QUEUE_H
#define MARS_WORKLOAD_QUEUE_H

/**
 * \file
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> MARS Workload Queue API
 */

#include <mars/workload_types.h>

struct mars_context;

#if defined(__cplusplus)
extern "C" {
#endif

/**
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> Returns whether or not specified query is satisfied.
 *
 * \note Query type \ref MARS_WORKLOAD_QUERY_IS_MODULE_CACHED and
 * \ref MARS_WORKLOAD_QUERY_IS_CONTEXT_CACHED are only valid queries for the
 * MPU-side call to \ref mars_module_workload_query.
 * Calling \ref mars_workload_queue_query with these queries will always return
 * 0.
 *
 * \param[in] mars		- address of pointer to MARS context
 * \param[in] id		- id of workload
 * \param[in] query		- query type
 * \return
 *	int			- non-zero if query satisfied
 */
int mars_workload_queue_query(struct mars_context *mars,
			      uint16_t id,
			      int query);

/**
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> Begins adding workload to workload queue.
 *
 * This function will begin the process to add a workload to the workload queue.
 * This only initiates the add operation.
 * This function must be completed with a matching call to
 * \ref mars_workload_queue_add_end to guarantee the completion of the add
 * operation.
 *
 * If workload_ea is not NULL, the ea of the workload will be returned.
 *
 * The workload adding process is not completed until the matching call to
 * \ref mars_workload_queue_add_end is made.
 * The user should make any necessary updates to the returned workload context
 * in between this begin call and the end call.
 *
 * \param[in] mars		- address of pointer to MARS context
 * \param[out] id		- pointer to return workload id
 * \param[out] workload_ea	- address of pointer to workload context ea
 * \param[in] module_elf	- pointer to workload module elf image
 * \param[in] module_name	- name of module
 * \return
 *	MARS_SUCCESS		- workload adding started
 * \n	MARS_ERROR_NULL		- null pointer specified
 * \n	MARS_ERROR_PARAMS	- invalid mars context or module specified
 * \n	MARS_ERROR_LIMIT	- workload queue is full
 */
int mars_workload_queue_add_begin(struct mars_context *mars,
				  uint16_t *id,
				  uint64_t *workload_ea,
				  const void *module_elf,
				  const char *module_name);

/**
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> Ends adding of specified workload.
 *
 * This function will complete a add operation previously initiated with
 * \ref mars_workload_queue_add_begin.
 * This function must be called in pair for each call to
 * \ref mars_workload_queue_add_begin to guarantee the completion of the
 * initiated add operation.
 *
 * \param[in] mars		- address of pointer to MARS context
 * \param[in] id		- id of workload to end add
 * \param[in] cancel		- cancels the add operation
 * \return
 *	MARS_SUCCESS		- workload adding complete
 * \n	MARS_ERROR_NULL		- null pointer specified
 * \n	MARS_ERROR_PARAMS	- invalid mars context or workload id specified
 * \n	MARS_ERROR_STATE	- workload adding not started
 */
int mars_workload_queue_add_end(struct mars_context *mars,
				uint16_t id,
				int cancel);

/**
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> Begins removing workload from workload queue.
 *
 * This function will begin the process to remove a workload from the workload
 * queue.
 * This only initiates the remove operation.
 * This function must be completed with a matching call to
 * \ref mars_workload_queue_remove_end to guarantee the completion of the remove
 * operation.
 *
 * If workload_ea is not NULL, the ea of the workload will be returned.
 *
 * The workload removing process is not completed until the matching call to
 * \ref mars_workload_queue_remove_end is made.
 * The user should make any necessary updates to the returned workload context
 * in between this begin call and the end call.
 *
 * \param[in] mars		- address of pointer to MARS context
 * \param[in] id		- id of workload to begin remove
 * \param[out] workload_ea	- address of pointer to workload context ea
 * \return
 *	MARS_SUCCESS		- workload removing started
 * \n	MARS_ERROR_NULL		- null pointer specified
 * \n	MARS_ERROR_PARAMS	- invalid mars context specified
 * \n	MARS_ERROR_STATE	- specified workload not added or finished
 */
int mars_workload_queue_remove_begin(struct mars_context *mars,
				     uint16_t id,
				     uint64_t *workload_ea);

/**
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> Ends removing of specified workload.
 *
 * This function will complete a remove operation previously initiated with
 * \ref mars_workload_queue_remove_begin.
 * This function must be called in pair for each call to
 * \ref mars_workload_queue_remove_begin to guarantee the completion of the
 * initiated remove operation.
 *
 * \param[in] mars		- address of pointer to MARS context
 * \param[in] id		- id of workload
 * \param[in] cancel		- cancels the remove operation
 * \return
 *	MARS_SUCCESS		- workload removing complete
 * \n	MARS_ERROR_PARAMS	- invalid mars context or workload id specified
 * \n	MARS_ERROR_STATE	- workload removing not started
 */
int mars_workload_queue_remove_end(struct mars_context *mars,
				   uint16_t id,
				   int cancel);

/**
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> Begins scheduling of specified workload.
 *
 * This function will begin scheduling the workload specified.
 * This only initiates the scheduling of the workload.
 * This function must be completed with a matching call to
 * \ref mars_workload_queue_schedule_end to guarantee the completion of the
 * scheduling.
 *
 * If workload_ea is not NULL, the ea of the workload will be returned.
 *
 * The workload scheduling process is not completed until the matching call to
 * \ref mars_workload_queue_schedule_end is made.
 * The user should make any necessary updates to the returned workload context
 * in between this begin call and the end call.
 *
 * \param[in] mars		- address of pointer to MARS context
 * \param[in] id		- id of workload
 * \param[in] priority		- scheduling priority of workload
 * \param[out] workload_ea	- address of pointer to workload context ea
 * \return
 *	MARS_SUCCESS		- workload scheduling started
 * \n	MARS_ERROR_NULL		- null pointer specified
 * \n	MARS_ERROR_PARAMS	- invalid mars context or workload id specified
 * \n	MARS_ERROR_STATE	- specified workload not added or finished
 */
int mars_workload_queue_schedule_begin(struct mars_context *mars,
				       uint16_t id, uint8_t priority,
				       uint64_t *workload_ea);

/**
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> Ends scheduling of specified workload.
 *
 * This function will complete a schedule operation previously initiated with
 * \ref mars_workload_queue_schedule_begin.
 * This function must be called in pair for each call to
 * \ref mars_workload_queue_schedule_begin to guarantee the completion of the
 * initiated schedule operation.
 *
 * \param[in] mars		- address of pointer to MARS context
 * \param[in] id		- id of workload
 * \param[in] cancel		- cancels the schedule operation
 * \return
 *	MARS_SUCCESS		- workload scheduling complete
 * \n	MARS_ERROR_NULL		- null pointer specified
 * \n	MARS_ERROR_PARAMS	- invalid mars context or workload id specified
 * \n	MARS_ERROR_STATE	- workload scheduling not started
 */
int mars_workload_queue_schedule_end(struct mars_context *mars,
				     uint16_t id,
				     int cancel);

/**
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> Begins unscheduling of specified workload.
 *
 * This function will begin unscheduling the workload specified.
 * This only initiates the unscheduling of the workload.
 * This function must be completed with a matching call to
 * \ref mars_workload_queue_unschedule_end to guarantee the completion of the
 * unscheduling.
 *
 * If workload_ea is not NULL, the ea of the workload will be returned.
 *
 * The workload unscheduling process is not completed until the matching call to
 * \ref mars_workload_queue_unschedule_end is made.
 * The user should make any necessary updates to the returned workload context
 * in between this begin call and the end call.
 *
 * When a workload is unscheduled, it will be put into a finished state and any
 * entities waiting on the workload to finish will be resumed.
 *
 * If a scheduled workload is unscheduled before execution, the workload will
 * not be executed until a subsequent scheduling request is made.
 *
 * If the workload is currently in a waiting state, calling unschedule will
 * finish the workload and will not be resumed from the waiting state.
 *
 * If the workload is currently in a running state, calling unschedule will
 * immediately put the workload into a finished state. However, execution of the
 * workload will only be suspended when the workload yields, waits, or finishes.
 *
 * \note
 * Trying to unschedule a workload that has not yet been scheduled, or has
 * already finished a previously scheduled execution will return an error.
 *
 * \param[in] mars		- address of pointer to MARS context
 * \param[in] id		- id of workload
 * \param[out] workload_ea	- address of pointer to workload context ea
 * \return
 *	MARS_SUCCESS		- workload aborted
 * \n	MARS_ERROR_NULL		- null pointer specified
 * \n	MARS_ERROR_PARAMS	- invalid mars context or workload id specified
 * \n	MARS_ERROR_STATE	- workload is not scheduled or has finished
 */
int mars_workload_queue_unschedule_begin(struct mars_context *mars,
					 uint16_t id,
					 uint64_t *workload_ea);

/**
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> Ends unscheduling of specified workload.
 *
 * This function will complete an unschedule operation previously initiated with
 * \ref mars_workload_queue_unschedule_begin.
 * This function must be called in pair for each call to
 * \ref mars_workload_queue_unschedule_begin to guarantee the completion of the
 * initiated unschedule operation.
 *
 * \param[in] mars		- address of pointer to MARS context
 * \param[in] id		- id of workload
 * \return
 *	MARS_SUCCESS		- workload unscheduling complete
 * \n	MARS_ERROR_NULL		- null pointer specified
 * \n	MARS_ERROR_PARAMS	- invalid mars context or workload id specified
 * \n	MARS_ERROR_STATE	- workload unscheduling not started
 */
int mars_workload_queue_unschedule_end(struct mars_context *mars,
				       uint16_t id);

/**
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> Waits for specified workload to finish.
 *
 * This function will block and wait until the specified workload finishes.
 *
 * If workload_ea is not NULL, the ea of the workload will be returned.
 *
 * \param[in] mars		- address of pointer to MARS context
 * \param[in] id		- id of workload
 * \param[out] workload_ea	- address of pointer to workload context ea
 * \return
 *	MARS_SUCCESS		- workload is finished
 * \n	MARS_ERROR_NULL		- null pointer specified
 * \n	MARS_ERROR_PARAMS	- invalid mars context or workload id specified
 * \n	MARS_ERROR_STATE	- invalid workload specified
 */
int mars_workload_queue_wait(struct mars_context *mars,
			     uint16_t id,
			     uint64_t *workload_ea);

/**
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> Waits for specified workload to finish.
 *
 * This function will check whether the workload specified is finished or not
 * and return immediately without blocking.
 *
 * If workload_ea is not NULL, the ea of the workload will be returned.
 *
 * \param[in] mars		- address of pointer to MARS context
 * \param[in] id		- id of workload
 * \param[out] workload_ea	- address of pointer to workload context ea
 * \return
 *	MARS_SUCCESS		- workload is finished
 * \n	MARS_ERROR_NULL		- null pointer specified
 * \n	MARS_ERROR_PARAMS	- invalid mars context or workload id specified
 * \n	MARS_ERROR_STATE	- invalid workload specified
 * \n	MARS_ERROR_BUSY		- workload has not yet finished
 */
int mars_workload_queue_try_wait(struct mars_context *mars,
				 uint16_t id,
				 uint64_t *workload_ea);

/**
 * \ingroup group_mars_workload_queue
 * \brief <b>[host]</b> Sends signal to specified workload.
 *
 * This function will send a signal to the specified workload.
 *
 * \param[in] mars		- address of pointer to MARS context
 * \param[in] id		- id of workload
 * \return
 *	MARS_SUCCESS		- signalled workload
 * \n	MARS_ERROR_NULL		- null pointer specified
 * \n	MARS_ERROR_PARAMS	- invalid mars context or workload id specified
 * \n	MARS_ERROR_STATE	- invalid workload specified
 */
int mars_workload_queue_signal_send(struct mars_context *mars,
				    uint16_t id);

#if defined(__cplusplus)
}
#endif

#endif