/src/libhevc/encoder/ihevce_dep_mngr.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2018 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | /*! |
21 | | ****************************************************************************** |
22 | | * \file ihevce_dep_mngr.c |
23 | | * |
24 | | * \brief |
25 | | * This file contains all the functions related to Sync manager |
26 | | * |
27 | | * \date |
28 | | * 12/12/2013 |
29 | | * |
30 | | * \author |
31 | | * Ittiam |
32 | | * |
33 | | * List of Functions |
34 | | * <TODO: TO BE ADDED> |
35 | | * |
36 | | ****************************************************************************** |
37 | | */ |
38 | | |
39 | | /*****************************************************************************/ |
40 | | /* File Includes */ |
41 | | /*****************************************************************************/ |
42 | | /* System include files */ |
43 | | #include <stdio.h> |
44 | | #include <string.h> |
45 | | #include <stdlib.h> |
46 | | #include <assert.h> |
47 | | #include <stdarg.h> |
48 | | #include <math.h> |
49 | | |
50 | | /* User include files */ |
51 | | #include "ihevc_typedefs.h" |
52 | | #include "itt_video_api.h" |
53 | | #include "ihevc_debug.h" |
54 | | #include "ihevc_macros.h" |
55 | | #include "ihevc_platform_macros.h" |
56 | | |
57 | | #include "ihevce_api.h" |
58 | | #include "ihevce_dep_mngr_interface.h" |
59 | | #include "ihevce_dep_mngr_private.h" |
60 | | |
61 | | #include "cast_types.h" |
62 | | #include "osal.h" |
63 | | #include "osal_defaults.h" |
64 | | |
65 | | /*****************************************************************************/ |
66 | | /* Function Definitions */ |
67 | | /*****************************************************************************/ |
68 | | |
69 | | /*! |
70 | | ****************************************************************************** |
71 | | * \if Function name : ihevce_dmgr_get_num_mem_recs \endif |
72 | | * |
73 | | * \brief |
74 | | * Number of memory records are returned for Dependency manager. |
75 | | * |
76 | | * \return |
77 | | * None |
78 | | * |
79 | | * \author |
80 | | * Ittiam |
81 | | * |
82 | | ***************************************************************************** |
83 | | */ |
84 | | WORD32 ihevce_dmgr_get_num_mem_recs() |
85 | 321k | { |
86 | 321k | return (NUM_DEP_MNGR_MEM_RECS); |
87 | 321k | } |
88 | | |
89 | | /*! |
90 | | ****************************************************************************** |
91 | | * \if Function name : ihevce_dmgr_get_mem_recs \endif |
92 | | * |
93 | | * \brief |
94 | | * Memory requirements are returned for Dependency manager. |
95 | | * |
96 | | * \param[in,out] ps_mem_tab : pointer to memory descriptors table |
97 | | * \param[in] dep_mngr_mode : Mode of operation of dependency manager |
98 | | * \param[in] max_num_vert_units : Maximum nunber of units to be processed |
99 | | * \param[in] num_tile_cols : Number of column tiles for which encoder is working |
100 | | * \param[in] num_threads : Number of threads among which sync will be established |
101 | | * \param[in] i4_mem_space : memspace in which memory request should be done |
102 | | * |
103 | | * \return |
104 | | * None |
105 | | * |
106 | | * \author |
107 | | * Ittiam |
108 | | * |
109 | | ***************************************************************************** |
110 | | */ |
111 | | WORD32 ihevce_dmgr_get_mem_recs( |
112 | | iv_mem_rec_t *ps_mem_tab, |
113 | | WORD32 dep_mngr_mode, |
114 | | WORD32 max_num_vert_units, |
115 | | WORD32 num_tile_cols, |
116 | | WORD32 num_threads, |
117 | | WORD32 i4_mem_space) |
118 | 99.5k | { |
119 | 99.5k | WORD32 num_vert_units; |
120 | 99.5k | WORD32 num_wait_thrd_ids; |
121 | | |
122 | | /* Dependency manager state structure */ |
123 | 99.5k | ps_mem_tab[DEP_MNGR_CTXT].i4_mem_size = sizeof(dep_mngr_state_t); |
124 | 99.5k | ps_mem_tab[DEP_MNGR_CTXT].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space; |
125 | 99.5k | ps_mem_tab[DEP_MNGR_CTXT].i4_mem_alignment = 8; |
126 | | |
127 | | /* SANITY CHECK */ |
128 | 99.5k | ASSERT( |
129 | 99.5k | (DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode) || (DEP_MNGR_ROW_FRM_SYNC == dep_mngr_mode) || |
130 | 99.5k | (DEP_MNGR_ROW_ROW_SYNC == dep_mngr_mode)); |
131 | | |
132 | | /* Default value */ |
133 | 99.5k | if(num_tile_cols < 1) |
134 | 0 | { |
135 | 0 | num_tile_cols = 1; |
136 | 0 | } |
137 | | |
138 | | /**************** Get Processed status Memory Requirements *********************/ |
139 | 99.5k | if(DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode) |
140 | 49.3k | { |
141 | | /* for frame to frame sync |
142 | | 2 words are used for holding num units processed prev |
143 | | 2 words are used for holding num units processed curr |
144 | | */ |
145 | 49.3k | num_vert_units = (2 + 2) * num_threads; |
146 | 49.3k | } |
147 | 50.2k | else |
148 | 50.2k | { |
149 | | /* for both frm-row and row-row num vertical units in frame is allocated */ |
150 | | /* (* num_tile_cols) as each column tile can separately update and check */ |
151 | 50.2k | num_vert_units = max_num_vert_units * num_tile_cols; |
152 | 50.2k | } |
153 | | |
154 | 99.5k | ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].i4_mem_size = (sizeof(WORD32) * num_vert_units); |
155 | 99.5k | ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space; |
156 | 99.5k | ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].i4_mem_alignment = 8; |
157 | | |
158 | | /**************** Get Wait thread ids Memory Requirements *********************/ |
159 | 99.5k | if(DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode) |
160 | 49.3k | { |
161 | | /* for frame to frame sync number of threads worth memory is allocated */ |
162 | 49.3k | num_wait_thrd_ids = num_threads; |
163 | 49.3k | } |
164 | 50.2k | else if(DEP_MNGR_ROW_ROW_SYNC == dep_mngr_mode) |
165 | 50.2k | { |
166 | | /* for row to row sync number of vertical rows worth memory is allocated */ |
167 | 50.2k | num_wait_thrd_ids = max_num_vert_units; |
168 | 50.2k | } |
169 | 0 | else |
170 | 0 | { |
171 | | /* for row to frame sync number of threads * number of vertical rows worth memory is allocated */ |
172 | 0 | num_wait_thrd_ids = max_num_vert_units * num_threads; |
173 | 0 | } |
174 | | |
175 | 99.5k | ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].i4_mem_size = (sizeof(WORD32) * num_wait_thrd_ids); |
176 | 99.5k | ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space; |
177 | 99.5k | ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].i4_mem_alignment = 8; |
178 | | |
179 | | /**************** Get Semaphore Requirements *********************/ |
180 | 99.5k | ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].i4_mem_size = (sizeof(void *) * num_threads); |
181 | 99.5k | ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space; |
182 | 99.5k | ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].i4_mem_alignment = 8; |
183 | | |
184 | 99.5k | return (NUM_DEP_MNGR_MEM_RECS); |
185 | 99.5k | } |
186 | | |
187 | | /*! |
188 | | ****************************************************************************** |
189 | | * \if Function name : ihevce_dmgr_map_get_mem_recs \endif |
190 | | * |
191 | | * \brief |
192 | | * Memory requirements are returned for Dependency manager. |
193 | | * |
194 | | * \param[in,out] ps_mem_tab : pointer to memory descriptors table |
195 | | * \param[in] num_units : Number of units in the map |
196 | | * \param[in] num_threads : Number of threads among which sync will be established |
197 | | * \param[in] i4_mem_space : memspace in which memory request should be done |
198 | | * |
199 | | * \return |
200 | | * None |
201 | | * |
202 | | * \author |
203 | | * Ittiam |
204 | | * |
205 | | ***************************************************************************** |
206 | | */ |
207 | | WORD32 ihevce_dmgr_map_get_mem_recs( |
208 | | iv_mem_rec_t *ps_mem_tab, WORD32 num_units, WORD32 num_threads, WORD32 i4_mem_space) |
209 | 41.1k | { |
210 | | /* Dependency manager state structure */ |
211 | 41.1k | ps_mem_tab[DEP_MNGR_CTXT].i4_mem_size = sizeof(dep_mngr_state_t); |
212 | 41.1k | ps_mem_tab[DEP_MNGR_CTXT].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space; |
213 | 41.1k | ps_mem_tab[DEP_MNGR_CTXT].i4_mem_alignment = 8; |
214 | | |
215 | | /**************** Get Processed status Memory Requirements *********************/ |
216 | 41.1k | ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].i4_mem_size = (sizeof(WORD8) * num_units); |
217 | 41.1k | ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space; |
218 | 41.1k | ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].i4_mem_alignment = 8; |
219 | | |
220 | | /**************** Get Wait thread ids Memory Requirements *********************/ |
221 | | /* Map-mode: semaphore post is unconditionally done on all threads */ |
222 | 41.1k | ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].i4_mem_size = (sizeof(WORD32) * num_threads); |
223 | 41.1k | ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space; |
224 | 41.1k | ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].i4_mem_alignment = 8; |
225 | | |
226 | | /**************** Get Semaphore Requirements *********************/ |
227 | 41.1k | ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].i4_mem_size = (sizeof(void *) * num_threads); |
228 | 41.1k | ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space; |
229 | 41.1k | ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].i4_mem_alignment = 8; |
230 | | |
231 | 41.1k | return (NUM_DEP_MNGR_MEM_RECS); |
232 | 41.1k | } |
233 | | |
234 | | /*! |
235 | | ****************************************************************************** |
236 | | * \if Function name : ihevce_dmgr_rst_frm_frm_sync \endif |
237 | | * |
238 | | * \brief |
239 | | * Resets the values stored to init value |
240 | | * |
241 | | * \param[in,out] pv_dep_mngr_state : Pointer to Sync Manager handle. |
242 | | * |
243 | | * \return |
244 | | * None |
245 | | * |
246 | | * \author |
247 | | * Ittiam |
248 | | * |
249 | | ***************************************************************************** |
250 | | */ |
251 | | void ihevce_dmgr_rst_frm_frm_sync(void *pv_dep_mngr_state) |
252 | 49.3k | { |
253 | 49.3k | dep_mngr_state_t *ps_dep_mngr_state; |
254 | 49.3k | WORD32 thrds; |
255 | 49.3k | ULWORD64 *pu8_num_units_proc_prev; |
256 | 49.3k | ULWORD64 *pu8_num_units_proc_curr; |
257 | | |
258 | | /* dep manager state structure */ |
259 | 49.3k | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
260 | | |
261 | | /* Reset the num units processed by each thread */ |
262 | 49.3k | pu8_num_units_proc_curr = (ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row; |
263 | 49.3k | pu8_num_units_proc_prev = pu8_num_units_proc_curr + ps_dep_mngr_state->i4_num_thrds; |
264 | | |
265 | | /* Reset the values thread ids waiting */ |
266 | 98.7k | for(thrds = 0; thrds < ps_dep_mngr_state->i4_num_thrds; thrds++) |
267 | 49.3k | { |
268 | 49.3k | pu8_num_units_proc_prev[thrds] = 0; |
269 | 49.3k | pu8_num_units_proc_curr[thrds] = 0; |
270 | 49.3k | ps_dep_mngr_state->pi4_wait_thrd_id[thrds] = -1; |
271 | 49.3k | } |
272 | | |
273 | 49.3k | return; |
274 | 49.3k | } |
275 | | |
276 | | /*! |
277 | | ****************************************************************************** |
278 | | * \if Function name : ihevce_dmgr_rst_row_frm_sync \endif |
279 | | * |
280 | | * \brief |
281 | | * Resets the values stored to init value |
282 | | * |
283 | | * \param[in,out] pv_dep_mngr_state : Pointer to Sync Manager handle. |
284 | | * |
285 | | * \return |
286 | | * None |
287 | | * |
288 | | * \author |
289 | | * Ittiam |
290 | | * |
291 | | ***************************************************************************** |
292 | | */ |
293 | | void ihevce_dmgr_rst_row_frm_sync(void *pv_dep_mngr_state) |
294 | 0 | { |
295 | 0 | dep_mngr_state_t *ps_dep_mngr_state; |
296 | 0 | WORD32 ctr, thrds; |
297 | | |
298 | | /* dep manager state structure */ |
299 | 0 | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
300 | | |
301 | | /* Reset the values of number of units processed in a row */ |
302 | 0 | for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_vert_units; ctr++) |
303 | 0 | { |
304 | 0 | ((WORD32 *)ps_dep_mngr_state->pv_units_prcsd_in_row)[ctr] = 0; |
305 | 0 | } |
306 | | |
307 | | /* Reset the values thread ids waiting on each row */ |
308 | 0 | for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_vert_units; ctr++) |
309 | 0 | { |
310 | 0 | for(thrds = 0; thrds < ps_dep_mngr_state->i4_num_thrds; thrds++) |
311 | 0 | { |
312 | 0 | ps_dep_mngr_state->pi4_wait_thrd_id[thrds + (ps_dep_mngr_state->i4_num_thrds * ctr)] = |
313 | 0 | -1; |
314 | 0 | } |
315 | 0 | } |
316 | |
|
317 | 0 | return; |
318 | 0 | } |
319 | | |
320 | | /*! |
321 | | ****************************************************************************** |
322 | | * \if Function name : ihevce_dmgr_map_rst_sync \endif |
323 | | * |
324 | | * \brief |
325 | | * Resets the values stored to init value |
326 | | * |
327 | | * \param[in,out] pv_dep_mngr_state : Pointer to Sync Manager handle. |
328 | | * |
329 | | * \return |
330 | | * None |
331 | | * |
332 | | * \author |
333 | | * Ittiam |
334 | | * |
335 | | ***************************************************************************** |
336 | | */ |
337 | | void ihevce_dmgr_map_rst_sync(void *pv_dep_mngr_state) |
338 | 190k | { |
339 | 190k | dep_mngr_state_t *ps_dep_mngr_state; |
340 | 190k | WORD8 *pi1_ptr; |
341 | | |
342 | | /* dep manager state structure */ |
343 | 190k | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
344 | | |
345 | 190k | pi1_ptr = (WORD8 *)ps_dep_mngr_state->pv_units_prcsd_in_row - |
346 | 190k | ps_dep_mngr_state->ai4_tile_xtra_ctb[0] * ps_dep_mngr_state->i4_num_horz_units - |
347 | 190k | ps_dep_mngr_state->ai4_tile_xtra_ctb[1]; |
348 | | |
349 | 190k | memset( |
350 | 190k | pi1_ptr, |
351 | 190k | MAP_CTB_INIT, |
352 | 190k | ps_dep_mngr_state->i4_num_vert_units * ps_dep_mngr_state->i4_num_horz_units * |
353 | 190k | sizeof(WORD8)); |
354 | | |
355 | | //ps_dep_mngr_state->i4_frame_map_complete = 0; |
356 | | |
357 | 190k | return; |
358 | 190k | } |
359 | | |
360 | | /*! |
361 | | ****************************************************************************** |
362 | | * \if Function name : ihevce_dmgr_rst_row_row_sync \endif |
363 | | * |
364 | | * \brief |
365 | | * Resets the values stored to init value |
366 | | * |
367 | | * \param[in,out] pv_dep_mngr_state : Pointer to Sync Manager handle. |
368 | | * |
369 | | * \return |
370 | | * None |
371 | | * |
372 | | * \author |
373 | | * Ittiam |
374 | | * |
375 | | ***************************************************************************** |
376 | | */ |
377 | | void ihevce_dmgr_rst_row_row_sync(void *pv_dep_mngr_state) |
378 | 950k | { |
379 | 950k | dep_mngr_state_t *ps_dep_mngr_state; |
380 | 950k | WORD32 ctr; |
381 | | |
382 | | /* dep manager state structure */ |
383 | 950k | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
384 | | |
385 | | /* Reset the values of number of units processed in a row */ |
386 | 3.34M | for(ctr = 0; ctr < (ps_dep_mngr_state->i4_num_vert_units * ps_dep_mngr_state->i4_num_tile_cols); |
387 | 2.39M | ctr++) |
388 | 2.39M | { |
389 | 2.39M | ((WORD32 *)ps_dep_mngr_state->pv_units_prcsd_in_row)[ctr] = 0; |
390 | 2.39M | } |
391 | | |
392 | | /* Reset the values thread ids waiting on each row */ |
393 | 3.34M | for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_vert_units; ctr++) |
394 | 2.39M | { |
395 | 2.39M | ps_dep_mngr_state->pi4_wait_thrd_id[ctr] = -1; |
396 | 2.39M | } |
397 | | |
398 | 950k | return; |
399 | 950k | } |
400 | | |
401 | | /*! |
402 | | ****************************************************************************** |
403 | | * \if Function name : ihevce_dmgr_init \endif |
404 | | * |
405 | | * \brief |
406 | | * Intialization for Dependency manager state structure . |
407 | | * |
408 | | * \param[in] ps_mem_tab : pointer to memory descriptors table |
409 | | * \param[in] pv_osal_handle : osal handle |
410 | | * \param[in] dep_mngr_mode : Mode of operation of dependency manager |
411 | | * \param[in] max_num_vert_units : Maximum nunber of units to be processed (Frame Data) |
412 | | * \param[in] max_num_horz_units : Maximun Number of Horizontal units to be processed (Frame Data) |
413 | | * \param[in] num_tile_cols : Number of column tiles for which encoder is working |
414 | | * \param[in] sem_enable : Whether you want to enable semaphore or not |
415 | | 1 : Sem. Enabled, 0 : Spin lock enabled (do-while) |
416 | | * \param[in] num_threads : Number of threads among which sync will be established |
417 | | * \param[in] i4_mem_space : memspace in which memory request should be do |
418 | | * |
419 | | * \return |
420 | | * Handle to context |
421 | | * |
422 | | * \author |
423 | | * Ittiam |
424 | | * |
425 | | ***************************************************************************** |
426 | | */ |
427 | | void *ihevce_dmgr_init( |
428 | | iv_mem_rec_t *ps_mem_tab, |
429 | | void *pv_osal_handle, |
430 | | WORD32 dep_mngr_mode, |
431 | | WORD32 max_num_vert_units, |
432 | | WORD32 max_num_horz_units, |
433 | | WORD32 num_tile_cols, |
434 | | WORD32 num_threads, |
435 | | WORD32 sem_enable) |
436 | 99.5k | { |
437 | 99.5k | dep_mngr_state_t *ps_dep_mngr_state; |
438 | | |
439 | 99.5k | (void)pv_osal_handle; |
440 | | /* dep manager state structure */ |
441 | 99.5k | ps_dep_mngr_state = (dep_mngr_state_t *)ps_mem_tab[DEP_MNGR_CTXT].pv_base; |
442 | | |
443 | | /* dep manager memory init */ |
444 | 99.5k | ps_dep_mngr_state->ppv_thrd_sem_handles = (void **)ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].pv_base; |
445 | 99.5k | ps_dep_mngr_state->pi4_wait_thrd_id = (WORD32 *)ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].pv_base; |
446 | 99.5k | ps_dep_mngr_state->pv_units_prcsd_in_row = ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].pv_base; |
447 | | |
448 | | /* SANITY CHECK */ |
449 | 99.5k | ASSERT(NULL != pv_osal_handle); |
450 | 99.5k | ASSERT( |
451 | 99.5k | (DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode) || (DEP_MNGR_ROW_FRM_SYNC == dep_mngr_mode) || |
452 | 99.5k | (DEP_MNGR_ROW_ROW_SYNC == dep_mngr_mode)); |
453 | | |
454 | | /* Default value */ |
455 | 99.5k | if(num_tile_cols < 1) |
456 | 0 | { |
457 | 0 | num_tile_cols = 1; |
458 | 0 | } |
459 | | |
460 | | /* reset the state structure variables */ |
461 | 99.5k | ps_dep_mngr_state->i4_num_horz_units = max_num_horz_units; |
462 | 99.5k | ps_dep_mngr_state->i4_num_vert_units = max_num_vert_units; |
463 | 99.5k | ps_dep_mngr_state->i1_sem_enable = sem_enable; |
464 | 99.5k | ps_dep_mngr_state->i4_dep_mngr_mode = dep_mngr_mode; |
465 | 99.5k | ps_dep_mngr_state->i4_num_thrds = num_threads; |
466 | 99.5k | ps_dep_mngr_state->i4_num_tile_cols = num_tile_cols; |
467 | | |
468 | | /* call the reset function baed on mode */ |
469 | 99.5k | if(DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode) |
470 | 49.3k | { |
471 | 49.3k | ihevce_dmgr_rst_frm_frm_sync((void *)ps_dep_mngr_state); |
472 | 49.3k | } |
473 | 50.2k | else if(DEP_MNGR_ROW_ROW_SYNC == dep_mngr_mode) |
474 | 50.2k | { |
475 | 50.2k | ihevce_dmgr_rst_row_row_sync((void *)ps_dep_mngr_state); |
476 | 50.2k | } |
477 | 0 | else |
478 | 0 | { |
479 | 0 | ihevce_dmgr_rst_row_frm_sync((void *)ps_dep_mngr_state); |
480 | 0 | } |
481 | | |
482 | 99.5k | return ((void *)ps_dep_mngr_state); |
483 | 99.5k | } |
484 | | |
485 | | /*! |
486 | | ****************************************************************************** |
487 | | * \if Function name : ihevce_dmgr_map_init \endif |
488 | | * |
489 | | * \brief |
490 | | * Intialization for Dependency manager state structure . |
491 | | * |
492 | | * \param[in] ps_mem_tab : pointer to memory descriptors table |
493 | | * \param[in] max_num_vert_units : Maximum nunber of units to be processed |
494 | | * \param[in] max_num_horz_units : Maximun Number of Horizontal units to be processed |
495 | | * \param[in] sem_enable : Whether you want to enable semaphore or not |
496 | | 1 : Sem. Enabled, 0 : Spin lock enabled (do-while) |
497 | | * \param[in] num_threads : Number of threads among which sync will be established |
498 | | * \param[in] ai4_tile_xtra_ctb : Array containing the number of CTBs which are |
499 | | * are present in the Search Range outside the tile in dist-client mode. |
500 | | * In standalone mode this array should be zero. |
501 | | * |
502 | | * \return |
503 | | * Handle to context |
504 | | * |
505 | | * \author |
506 | | * Ittiam |
507 | | * |
508 | | ***************************************************************************** |
509 | | */ |
510 | | void *ihevce_dmgr_map_init( |
511 | | iv_mem_rec_t *ps_mem_tab, |
512 | | WORD32 max_num_vert_units, |
513 | | WORD32 max_num_horz_units, |
514 | | WORD32 sem_enable, |
515 | | WORD32 num_threads, |
516 | | WORD32 ai4_tile_xtra_ctb[4]) |
517 | 41.1k | { |
518 | 41.1k | WORD32 ctr; |
519 | 41.1k | dep_mngr_state_t *ps_dep_mngr_state; |
520 | | |
521 | | /* dep manager state structure */ |
522 | 41.1k | ps_dep_mngr_state = (dep_mngr_state_t *)ps_mem_tab[DEP_MNGR_CTXT].pv_base; |
523 | | |
524 | 41.1k | ps_dep_mngr_state->ai4_tile_xtra_ctb[0] = ai4_tile_xtra_ctb[0]; |
525 | 41.1k | ps_dep_mngr_state->ai4_tile_xtra_ctb[1] = ai4_tile_xtra_ctb[1]; |
526 | 41.1k | ps_dep_mngr_state->ai4_tile_xtra_ctb[2] = ai4_tile_xtra_ctb[2]; |
527 | 41.1k | ps_dep_mngr_state->ai4_tile_xtra_ctb[3] = ai4_tile_xtra_ctb[3]; |
528 | | |
529 | | /* dep manager memory init */ |
530 | 41.1k | ps_dep_mngr_state->pv_units_prcsd_in_row = ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].pv_base; |
531 | 41.1k | ps_dep_mngr_state->pi4_wait_thrd_id = (WORD32 *)ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].pv_base; |
532 | 41.1k | ps_dep_mngr_state->ppv_thrd_sem_handles = (void **)ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].pv_base; |
533 | | |
534 | | /* Pointing to first CTB of tile */ |
535 | 41.1k | ps_dep_mngr_state->pv_units_prcsd_in_row = |
536 | 41.1k | (void*)((WORD8*)ps_dep_mngr_state->pv_units_prcsd_in_row + |
537 | 41.1k | ps_dep_mngr_state->ai4_tile_xtra_ctb[1] + |
538 | 41.1k | max_num_horz_units * ps_dep_mngr_state->ai4_tile_xtra_ctb[0]); |
539 | | |
540 | | /* Map-mode: semaphore post is unconditionally done on all threads. Hence |
541 | | store these one time IDs. The use of pi4_wait_thrd_id itself can be removed |
542 | | altogether for map-mode, but keeping it for the sake of laziness */ |
543 | 82.2k | for(ctr = 0; ctr < num_threads; ctr++) |
544 | 41.1k | { |
545 | 41.1k | ps_dep_mngr_state->pi4_wait_thrd_id[ctr] = ctr; |
546 | 41.1k | } |
547 | | |
548 | | /* reset the state structure variables */ |
549 | 41.1k | ps_dep_mngr_state->i4_num_horz_units = max_num_horz_units; |
550 | 41.1k | ps_dep_mngr_state->i4_num_vert_units = max_num_vert_units; |
551 | 41.1k | ps_dep_mngr_state->i1_sem_enable = sem_enable; |
552 | 41.1k | ps_dep_mngr_state->i4_dep_mngr_mode = DEP_MNGR_MAP_SYNC; |
553 | 41.1k | ps_dep_mngr_state->i4_num_thrds = num_threads; |
554 | | |
555 | | /* call the reset function baed on mode */ |
556 | 41.1k | ihevce_dmgr_map_rst_sync((void *)ps_dep_mngr_state); |
557 | | |
558 | 41.1k | return ((void *)ps_dep_mngr_state); |
559 | 41.1k | } |
560 | | |
561 | | /*! |
562 | | ****************************************************************************** |
563 | | * \if Function name : ihevce_dmgr_del \endif |
564 | | * |
565 | | * \brief |
566 | | * Delete the Dependency manager state structure. |
567 | | * Note : Destroys the mutex only. System has to free the allocated memory |
568 | | * |
569 | | * \param[in,out] pv_dep_mngr_state : Pointer to Sync Manager handle. |
570 | | * |
571 | | * \return |
572 | | * None |
573 | | * |
574 | | * \author |
575 | | * Ittiam |
576 | | * |
577 | | ***************************************************************************** |
578 | | */ |
579 | | void ihevce_dmgr_del(void *pv_dep_mngr_state) |
580 | 140k | { |
581 | 140k | dep_mngr_state_t *ps_dep_mngr_state; |
582 | | |
583 | | /* dep manager state structure */ |
584 | 140k | (void)ps_dep_mngr_state; |
585 | 140k | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
586 | 140k | } |
587 | | |
588 | | /*! |
589 | | ****************************************************************************** |
590 | | * \if Function name : ihevce_dmgr_register_sem_hdls \endif |
591 | | * |
592 | | * \brief |
593 | | * Register sem handles of threads wihci are part of dependency group |
594 | | * |
595 | | * \param[in,out] pv_dep_mngr_state : Pointer to Sync Manager handle. |
596 | | * \param[in] ppv_thread_sem_hdl : arry of pointer to all the sem handles |
597 | | * \param[in] num_threads : Number of threads part of this dependency group |
598 | | * |
599 | | * \return |
600 | | * None |
601 | | * |
602 | | * \author |
603 | | * Ittiam |
604 | | * |
605 | | ***************************************************************************** |
606 | | */ |
607 | | void ihevce_dmgr_reg_sem_hdls(void *pv_dep_mngr_state, void **ppv_thread_sem_hdl, WORD32 num_threads) |
608 | 140k | { |
609 | 140k | dep_mngr_state_t *ps_dep_mngr_state; |
610 | 140k | WORD32 ctr; |
611 | | |
612 | | /* dep manager state structure */ |
613 | 140k | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
614 | | |
615 | 140k | ASSERT(num_threads <= ps_dep_mngr_state->i4_num_thrds); |
616 | | |
617 | 281k | for(ctr = 0; ctr < num_threads; ctr++) |
618 | 140k | { |
619 | 140k | ps_dep_mngr_state->ppv_thrd_sem_handles[ctr] = ppv_thread_sem_hdl[ctr]; |
620 | 140k | } |
621 | | |
622 | 140k | return; |
623 | 140k | } |
624 | | |
625 | | /*! |
626 | | ****************************************************************************** |
627 | | * \if Function name : ihevce_dmgr_set_prev_done_frm_frm_sync \endif |
628 | | * |
629 | | * \brief |
630 | | * Set the values to dependency not resolved state |
631 | | * |
632 | | * \param[in,out] pv_dep_mngr_state : Pointer to Sync Manager handle. |
633 | | * |
634 | | * \return |
635 | | * None |
636 | | * |
637 | | * \author |
638 | | * Ittiam |
639 | | * |
640 | | ***************************************************************************** |
641 | | */ |
642 | | void ihevce_dmgr_set_prev_done_frm_frm_sync(void *pv_dep_mngr_state) |
643 | 8.22k | { |
644 | 8.22k | dep_mngr_state_t *ps_dep_mngr_state; |
645 | 8.22k | WORD32 thrds; |
646 | 8.22k | ULWORD64 *pu8_num_units_proc_curr; |
647 | 8.22k | ULWORD64 *pu8_num_units_proc_prev; |
648 | | |
649 | | /* dep manager state structure */ |
650 | 8.22k | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
651 | | |
652 | | /* Reset the values num threads entering processing state */ |
653 | 8.22k | pu8_num_units_proc_curr = (ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row; |
654 | 8.22k | pu8_num_units_proc_prev = |
655 | 8.22k | (ULWORD64 *)(pu8_num_units_proc_curr + ps_dep_mngr_state->i4_num_thrds); |
656 | | |
657 | | /* Reset the values thread ids waiting */ |
658 | 16.4k | for(thrds = 0; thrds < ps_dep_mngr_state->i4_num_thrds; thrds++) |
659 | 8.22k | { |
660 | 8.22k | pu8_num_units_proc_prev[thrds] = 1; |
661 | 8.22k | ps_dep_mngr_state->pi4_wait_thrd_id[thrds] = -1; |
662 | 8.22k | } |
663 | | |
664 | 8.22k | return; |
665 | 8.22k | } |
666 | | |
667 | | /*! |
668 | | ****************************************************************************** |
669 | | * \if Function name : ihevce_dmgr_set_done_frm_frm_sync \endif |
670 | | * |
671 | | * \brief |
672 | | * Set the values to dependency met state |
673 | | * |
674 | | * \param[in,out] pv_dep_mngr_state : Pointer to Sync Manager handle. |
675 | | * |
676 | | * \return |
677 | | * None |
678 | | * |
679 | | * \author |
680 | | * Ittiam |
681 | | * |
682 | | ***************************************************************************** |
683 | | */ |
684 | | void ihevce_dmgr_set_done_frm_frm_sync(void *pv_dep_mngr_state) |
685 | 49.3k | { |
686 | 49.3k | dep_mngr_state_t *ps_dep_mngr_state; |
687 | 49.3k | WORD32 thrds; |
688 | 49.3k | ULWORD64 *pu8_num_units_proc_curr; |
689 | | |
690 | | /* dep manager state structure */ |
691 | 49.3k | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
692 | | |
693 | | /* Reset the values num threads entering processing state */ |
694 | 49.3k | pu8_num_units_proc_curr = (ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row; |
695 | | |
696 | | /* Reset the values thread ids waiting */ |
697 | 98.7k | for(thrds = 0; thrds < ps_dep_mngr_state->i4_num_thrds; thrds++) |
698 | 49.3k | { |
699 | 49.3k | pu8_num_units_proc_curr[thrds] = 1; |
700 | 49.3k | ps_dep_mngr_state->pi4_wait_thrd_id[thrds] = -1; |
701 | 49.3k | } |
702 | | |
703 | 49.3k | return; |
704 | 49.3k | } |
705 | | |
706 | | /*! |
707 | | ************************************************************************** |
708 | | * \if Function name : ihevce_dmgr_chk_row_row_sync \endif |
709 | | * |
710 | | * \brief |
711 | | * This function checks whether the dependency is met to proceed with |
712 | | * processing. If condition is not met, it should go to a sem_wait state, |
713 | | * else start processing. |
714 | | * |
715 | | * \param[in] pv_dep_mngr_state : Pointer to Sync Manager handle. |
716 | | * \param[in] cur_offset : Current offset of the dep. variable |
717 | | * \param[in] dep_offset : Offset from the current value to meet the dep. |
718 | | * \param[in] dep_row : The position of the Ref. |
719 | | * \param[in] cur_tile_col : The current column tile number (not tile id) |
720 | | * Assuming the dependency is within the tile only (Acroos tiles won't work now) |
721 | | * \param[in] thrd_id : Thread id of the current thread checking for dependency |
722 | | * |
723 | | * \return |
724 | | * 0 on Success and -1 on error |
725 | | * |
726 | | * \author |
727 | | * Ittiam |
728 | | * |
729 | | ************************************************************************** |
730 | | */ |
731 | | WORD32 ihevce_dmgr_chk_row_row_sync( |
732 | | void *pv_dep_mngr_state, |
733 | | WORD32 cur_offset, |
734 | | WORD32 dep_offset, |
735 | | WORD32 dep_row, |
736 | | WORD32 cur_tile_col, |
737 | | WORD32 thrd_id) |
738 | 4.42M | { |
739 | 4.42M | dep_mngr_state_t *ps_dep_mngr_state; |
740 | 4.42M | volatile WORD32 *pi4_ref_value; |
741 | 4.42M | WORD32 ref_value; |
742 | | |
743 | 4.42M | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
744 | | |
745 | | /* Sanity Check */ |
746 | 4.42M | ASSERT(dep_row >= 0); |
747 | 4.42M | ASSERT(dep_row < ps_dep_mngr_state->i4_num_vert_units); |
748 | 4.42M | ASSERT(cur_tile_col >= 0); |
749 | 4.42M | ASSERT(cur_tile_col < ps_dep_mngr_state->i4_num_tile_cols); |
750 | | |
751 | 4.42M | pi4_ref_value = ((volatile WORD32 *)(ps_dep_mngr_state->pv_units_prcsd_in_row)) + |
752 | 4.42M | (cur_tile_col * ps_dep_mngr_state->i4_num_vert_units) + dep_row; |
753 | | |
754 | | /* Sanity Check */ |
755 | 4.42M | ASSERT((cur_offset + dep_offset) <= ps_dep_mngr_state->i4_num_horz_units); |
756 | | |
757 | | /* Check whether Dep. is met */ |
758 | 4.42M | while(1) |
759 | 4.42M | { |
760 | 4.42M | ref_value = *pi4_ref_value; |
761 | | |
762 | 4.42M | if(ref_value >= (cur_offset + dep_offset)) |
763 | 4.42M | break; |
764 | | |
765 | 0 | if(1 == ps_dep_mngr_state->i1_sem_enable) |
766 | 0 | { |
767 | 0 | void *pv_sem_handle; |
768 | 0 | WORD32 ret_val; |
769 | |
|
770 | 0 | (void)ret_val; |
771 | 0 | pv_sem_handle = ps_dep_mngr_state->ppv_thrd_sem_handles[thrd_id]; |
772 | | |
773 | | /* register the thread id before going to pend state */ |
774 | 0 | ps_dep_mngr_state->pi4_wait_thrd_id[dep_row] = thrd_id; |
775 | | |
776 | | /* go to the pend state */ |
777 | 0 | ret_val = osal_sem_wait(pv_sem_handle); |
778 | | //ASSERT(0 == ret_val); |
779 | 0 | } |
780 | 0 | } |
781 | | |
782 | 4.42M | return 0; |
783 | 4.42M | } |
784 | | |
785 | | /*! |
786 | | ************************************************************************** |
787 | | * \if Function name : ihevce_dmgr_set_row_row_sync \endif |
788 | | * |
789 | | * \brief |
790 | | * This function sets the dependency and wakes up the proper semaphores |
791 | | * to start processing. |
792 | | * |
793 | | * \param[in] pv_dep_mngr_state : Pointer to Sync Manager handle. |
794 | | * \param[in] cur_offset : Current offset processed |
795 | | * \param[in] cur_row : The cur. vertical position |
796 | | * \param[in] cur_tile_col : The current column tile number (not tile id) |
797 | | * Assuming the dependency is within the tile only (Acroos tiles won't work now) |
798 | | * |
799 | | * \return |
800 | | * 0 on Success and -1 on error |
801 | | * |
802 | | * \author |
803 | | * Ittiam |
804 | | * |
805 | | ************************************************************************** |
806 | | */ |
807 | | WORD32 ihevce_dmgr_set_row_row_sync( |
808 | | void *pv_dep_mngr_state, WORD32 cur_offset, WORD32 cur_row, WORD32 cur_tile_col) |
809 | 4.75M | { |
810 | 4.75M | dep_mngr_state_t *ps_dep_mngr_state; |
811 | 4.75M | WORD32 *pi4_units_prcsd; |
812 | 4.75M | void *pv_sem_handle; |
813 | 4.75M | WORD32 ret_val; |
814 | | |
815 | 4.75M | (void)ret_val; |
816 | 4.75M | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
817 | | |
818 | | /* Sanity Check */ |
819 | 4.75M | ASSERT(cur_offset >= 0); |
820 | 4.75M | ASSERT(cur_offset <= ps_dep_mngr_state->i4_num_horz_units); |
821 | 4.75M | ASSERT(cur_row <= ps_dep_mngr_state->i4_num_vert_units); |
822 | 4.75M | ASSERT(cur_tile_col >= 0); |
823 | 4.75M | ASSERT(cur_tile_col < ps_dep_mngr_state->i4_num_tile_cols); |
824 | | |
825 | 4.75M | DATA_SYNC(); |
826 | | |
827 | 4.75M | pi4_units_prcsd = ((WORD32 *)(ps_dep_mngr_state->pv_units_prcsd_in_row)) + |
828 | 4.75M | (cur_tile_col * ps_dep_mngr_state->i4_num_vert_units) + cur_row; |
829 | | |
830 | | /* Update the number of units processed */ |
831 | 4.75M | *pi4_units_prcsd = cur_offset; |
832 | | |
833 | 4.75M | if(1 == ps_dep_mngr_state->i1_sem_enable) |
834 | 4.02M | { |
835 | 4.02M | WORD32 wait_thrd_id; |
836 | | |
837 | 4.02M | wait_thrd_id = ps_dep_mngr_state->pi4_wait_thrd_id[cur_row]; |
838 | | |
839 | | /* Post on threads waiting on the current row */ |
840 | 4.02M | if(-1 != wait_thrd_id) |
841 | 0 | { |
842 | 0 | pv_sem_handle = ps_dep_mngr_state->ppv_thrd_sem_handles[wait_thrd_id]; |
843 | | /* Post on the semaphore */ |
844 | 0 | ret_val = osal_sem_post(pv_sem_handle); |
845 | | //ASSERT(0 == ret_val); |
846 | |
|
847 | 0 | ps_dep_mngr_state->pi4_wait_thrd_id[cur_row] = -1; |
848 | 0 | } |
849 | | |
850 | | /* towards end of row all threads are posted (to avoid any corner cases) */ |
851 | 4.02M | if(cur_offset == ps_dep_mngr_state->i4_num_horz_units) |
852 | 843k | { |
853 | 843k | WORD32 ctr; |
854 | | |
855 | 1.68M | for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_thrds; ctr++) |
856 | 843k | { |
857 | 843k | ret_val = osal_sem_post(ps_dep_mngr_state->ppv_thrd_sem_handles[ctr]); |
858 | | //ASSERT(0 == ret_val); |
859 | 843k | } |
860 | 843k | } |
861 | 4.02M | } |
862 | | |
863 | 4.75M | return 0; |
864 | 4.75M | } |
865 | | |
866 | | /*! |
867 | | ************************************************************************** |
868 | | * \if Function name : ihevce_dmgr_chk_frm_frm_sync \endif |
869 | | * |
870 | | * \brief |
871 | | * This function checks whether the dependency is met to proceed with |
872 | | * processing. If condition is not met, it should go to a sem_wait state, |
873 | | * else start processing. |
874 | | * For Barrier case, the thread will wait till all threads have completed |
875 | | * the processing on the previosu instance of same stage |
876 | | * \param[in] pv_dep_mngr_state : Pointer to Sync Manager handle. |
877 | | * \param[in] thrd_id : Thread id checking for dependency |
878 | | * |
879 | | * \return |
880 | | * 0 on Success and -1 on error |
881 | | * |
882 | | * \author |
883 | | * Ittiam |
884 | | * |
885 | | ************************************************************************** |
886 | | */ |
887 | | WORD32 ihevce_dmgr_chk_frm_frm_sync(void *pv_dep_mngr_state, WORD32 thrd_id) |
888 | 790k | { |
889 | 790k | dep_mngr_state_t *ps_dep_mngr_state; |
890 | 790k | void *pv_sem_handle; |
891 | 790k | volatile ULWORD64 *pu8_num_units_proc_prev; |
892 | 790k | volatile ULWORD64 *pu8_num_units_proc_curr; |
893 | 790k | ULWORD64 prev_value; |
894 | 790k | ULWORD64 curr_value; |
895 | | |
896 | 790k | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
897 | 790k | pv_sem_handle = ps_dep_mngr_state->ppv_thrd_sem_handles[thrd_id]; |
898 | | |
899 | 790k | pu8_num_units_proc_curr = (volatile ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row; |
900 | 790k | pu8_num_units_proc_prev = |
901 | 790k | (volatile ULWORD64 *)(pu8_num_units_proc_curr + ps_dep_mngr_state->i4_num_thrds); |
902 | | |
903 | | /* Check whether Dep. is met */ |
904 | 790k | while(1) |
905 | 790k | { |
906 | 790k | WORD32 ret_val; |
907 | | |
908 | 790k | (void)ret_val; |
909 | 790k | curr_value = pu8_num_units_proc_curr[thrd_id]; |
910 | 790k | prev_value = pu8_num_units_proc_prev[thrd_id]; |
911 | | |
912 | 790k | if(curr_value == (prev_value + 1)) |
913 | 790k | { |
914 | 790k | break; |
915 | 790k | } |
916 | 0 | else |
917 | 0 | { |
918 | | /* register the thread id before going to pend state */ |
919 | 0 | ps_dep_mngr_state->pi4_wait_thrd_id[thrd_id] = thrd_id; |
920 | | |
921 | | /* go to the pend state */ |
922 | 0 | ret_val = osal_sem_wait(pv_sem_handle); |
923 | | //ASSERT(0 == ret_val); |
924 | 0 | } |
925 | 790k | } |
926 | | |
927 | | /* store curr value to prev for next iteration */ |
928 | 790k | pu8_num_units_proc_prev[thrd_id] = pu8_num_units_proc_curr[thrd_id]; |
929 | | |
930 | 790k | return 0; |
931 | 790k | } |
932 | | |
933 | | /*! |
934 | | ************************************************************************** |
935 | | * \if Function name : ihevce_dmgr_update_frm_frm_sync \endif |
936 | | * |
937 | | * \brief |
938 | | * This function sets the dependency and wakes up the proper semaphores |
939 | | * to start processing. |
940 | | * For barrier case, if the dep. is met, all waiting threads should be waked up |
941 | | * |
942 | | * \param[in] pv_dep_mngr_state : Pointer to Sync Manager handle. |
943 | | * |
944 | | * \return |
945 | | * 0 on Success and -1 on error |
946 | | * |
947 | | * \author |
948 | | * Ittiam |
949 | | * |
950 | | ************************************************************************** |
951 | | */ |
952 | | WORD32 ihevce_dmgr_update_frm_frm_sync(void *pv_dep_mngr_state) |
953 | 782k | { |
954 | 782k | dep_mngr_state_t *ps_dep_mngr_state; |
955 | 782k | void *pv_sem_handle; |
956 | 782k | volatile ULWORD64 *pu8_num_units_proc_curr; |
957 | 782k | WORD32 ctr; |
958 | | |
959 | 782k | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
960 | | |
961 | 782k | pu8_num_units_proc_curr = (volatile ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row; |
962 | | |
963 | | /* Post on All vertical waiting threads semaphores & update the cur unit proc */ |
964 | 1.56M | for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_thrds; ctr++) |
965 | 782k | { |
966 | 782k | WORD32 ret_val; |
967 | 782k | WORD32 wait_thrd_id; |
968 | | |
969 | 782k | (void)ret_val; |
970 | | /* increment the curr unit counter for all threads */ |
971 | 782k | pu8_num_units_proc_curr[ctr] = pu8_num_units_proc_curr[ctr] + 1; |
972 | | |
973 | 782k | wait_thrd_id = ctr; |
974 | | //wait_thrd_id = ps_dep_mngr_state->pi4_wait_thrd_id[ctr]; |
975 | | |
976 | 782k | if(-1 != wait_thrd_id) |
977 | 782k | { |
978 | 782k | pv_sem_handle = ps_dep_mngr_state->ppv_thrd_sem_handles[wait_thrd_id]; |
979 | | /* Post on the semaphore */ |
980 | 782k | ret_val = osal_sem_post(pv_sem_handle); |
981 | | //ASSERT(0 == ret_val); |
982 | | |
983 | 782k | ps_dep_mngr_state->pi4_wait_thrd_id[ctr] = -1; |
984 | 782k | } |
985 | 782k | } |
986 | | |
987 | 782k | return 0; |
988 | 782k | } |
989 | | |
990 | | /*! |
991 | | ************************************************************************** |
992 | | * \if Function name : ihevce_dmgr_map_chk \endif |
993 | | * |
994 | | * \brief |
995 | | * This function checks whether all entries in the dependency map are set |
996 | | * |
997 | | * \param[in] pu1_start : Pointer to the start of the search area |
998 | | * \param[in] i4_num_ctb_x : Size of search area |
999 | | * \param[in] i4_num_ctb_y : Size of search area |
1000 | | * \param[in] i4_stride : Stride of search area |
1001 | | * |
1002 | | * \return |
1003 | | * 1 on Success otherwise 0 |
1004 | | * |
1005 | | * \author |
1006 | | * Ittiam |
1007 | | * |
1008 | | ************************************************************************** |
1009 | | */ |
1010 | | WORD32 |
1011 | | ihevce_dmgr_map_chk(WORD8 *pu1_start, WORD32 i4_num_ctb_x, WORD32 i4_num_ctb_y, WORD32 i4_stride) |
1012 | 250k | { |
1013 | 250k | WORD8 *pi1_ctb = pu1_start; |
1014 | 250k | WORD32 row, col; |
1015 | 250k | WORD32 map_ready_flag = MAP_CTB_COMPLETE; |
1016 | | |
1017 | 570k | for(row = 0; row < i4_num_ctb_y; row++) |
1018 | 320k | { |
1019 | 850k | for(col = 0; col < i4_num_ctb_x; col++) |
1020 | 529k | { |
1021 | 529k | map_ready_flag &= pi1_ctb[col]; |
1022 | 529k | } |
1023 | 320k | pi1_ctb += i4_stride; |
1024 | 320k | } |
1025 | | |
1026 | | /* NOTE: early exit in the above loop can taken if map_ready_flag |
1027 | | is found to be zero somewhere at the start itself */ |
1028 | 250k | return (map_ready_flag == MAP_CTB_COMPLETE); |
1029 | 250k | } |
1030 | | |
1031 | | /*! |
1032 | | ************************************************************************** |
1033 | | * \if Function name : ihevce_dmgr_map_chk_sync \endif |
1034 | | * |
1035 | | * \brief |
1036 | | * This function checks whether the dependency is met by searching in a |
1037 | | * rectangular area. If condition is not met, it should go to a sem_wait state, |
1038 | | * else start processing. |
1039 | | * |
1040 | | * \param[in] pv_dep_mngr_state : Pointer to Sync Manager handle. |
1041 | | * \param[in] thrd_id : Thread id of the current thread checking for dependency |
1042 | | * \param[in] offset_x : Offset of current CTB in Tile in ctb-unit |
1043 | | * \param[in] offset_y : Offset of current CTB in Tile in ctb-unit |
1044 | | * \param[in] i4_sr_ctb_x : Search Range in ctb-unit |
1045 | | * \param[in] i4_sr_ctb_y : Search Range in ctb-unit |
1046 | | * |
1047 | | * \return |
1048 | | * 0 on Success and -1 on error |
1049 | | * |
1050 | | * \author |
1051 | | * Ittiam |
1052 | | * |
1053 | | ************************************************************************** |
1054 | | */ |
1055 | | WORD32 ihevce_dmgr_map_chk_sync( |
1056 | | void *pv_dep_mngr_state, |
1057 | | WORD32 thrd_id, |
1058 | | WORD32 offset_x, |
1059 | | WORD32 offset_y, |
1060 | | WORD32 i4_sr_ctb_x, |
1061 | | WORD32 i4_sr_ctb_y) |
1062 | 250k | { |
1063 | 250k | dep_mngr_state_t *ps_dep_mngr_state; |
1064 | 250k | volatile WORD8 *pi1_ctb; |
1065 | 250k | WORD8 *pi1_tile_start; |
1066 | 250k | WORD32 i4_avail_left, i4_avail_right, i4_avail_top, i4_avail_bot; |
1067 | 250k | WORD32 i4_num_ctb_x, i4_num_ctb_y; |
1068 | 250k | WORD32 i4_stride; |
1069 | 250k | WORD32 i4_tile_wd, i4_tile_ht; //in ctb units |
1070 | | |
1071 | 250k | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
1072 | | |
1073 | 250k | i4_tile_wd = ps_dep_mngr_state->i4_num_horz_units - ps_dep_mngr_state->ai4_tile_xtra_ctb[1] - |
1074 | 250k | ps_dep_mngr_state->ai4_tile_xtra_ctb[2]; |
1075 | | |
1076 | 250k | i4_tile_ht = ps_dep_mngr_state->i4_num_vert_units - ps_dep_mngr_state->ai4_tile_xtra_ctb[0] - |
1077 | 250k | ps_dep_mngr_state->ai4_tile_xtra_ctb[3]; |
1078 | | |
1079 | 250k | i4_stride = ps_dep_mngr_state->i4_num_horz_units; |
1080 | | |
1081 | | /* Sanity Checks, confirm if ctb offsets are within tiles */ |
1082 | 250k | ASSERT(offset_x >= 0); |
1083 | 250k | ASSERT(offset_y >= 0); |
1084 | 250k | ASSERT(offset_x < i4_tile_wd); |
1085 | 250k | ASSERT(offset_y < i4_tile_ht); |
1086 | | |
1087 | 250k | pi1_tile_start = (WORD8 *)ps_dep_mngr_state->pv_units_prcsd_in_row; |
1088 | 250k | pi1_ctb = (volatile WORD8 *)pi1_tile_start; |
1089 | | |
1090 | 250k | if(ps_dep_mngr_state->ai4_tile_xtra_ctb[0]) |
1091 | 0 | { |
1092 | 0 | i4_avail_top = i4_sr_ctb_y; |
1093 | 0 | } |
1094 | 250k | else |
1095 | 250k | { |
1096 | 250k | i4_avail_top = MIN(i4_sr_ctb_y, offset_y); |
1097 | 250k | } |
1098 | | |
1099 | 250k | if(ps_dep_mngr_state->ai4_tile_xtra_ctb[1]) |
1100 | 0 | { |
1101 | 0 | i4_avail_left = i4_sr_ctb_x; |
1102 | 0 | } |
1103 | 250k | else |
1104 | 250k | { |
1105 | 250k | i4_avail_left = MIN(i4_sr_ctb_x, offset_x); |
1106 | 250k | } |
1107 | | |
1108 | 250k | if(ps_dep_mngr_state->ai4_tile_xtra_ctb[2]) |
1109 | 0 | { |
1110 | 0 | i4_avail_right = i4_sr_ctb_x; |
1111 | 0 | } |
1112 | 250k | else |
1113 | 250k | { |
1114 | 250k | i4_avail_right = MIN(i4_sr_ctb_x, (i4_tile_wd - offset_x - 1)); |
1115 | 250k | } |
1116 | | |
1117 | 250k | if(ps_dep_mngr_state->ai4_tile_xtra_ctb[3]) |
1118 | 0 | { |
1119 | 0 | i4_avail_bot = i4_sr_ctb_y; |
1120 | 0 | } |
1121 | 250k | else |
1122 | 250k | { |
1123 | 250k | i4_avail_bot = MIN(i4_sr_ctb_y, (i4_tile_ht - offset_y - 1)); |
1124 | 250k | } |
1125 | | |
1126 | 250k | i4_num_ctb_x = (i4_avail_left + 1 + i4_avail_right); |
1127 | 250k | i4_num_ctb_y = (i4_avail_top + 1 + i4_avail_bot); |
1128 | | |
1129 | | /* Point to the start of the search-area */ |
1130 | 250k | pi1_ctb += ((offset_y - i4_avail_top) * i4_stride + (offset_x - i4_avail_left)); |
1131 | | |
1132 | | /* Check whether Dep. is met */ |
1133 | 250k | while(1) |
1134 | 250k | { |
1135 | 250k | if(1 == ihevce_dmgr_map_chk((WORD8 *)pi1_ctb, i4_num_ctb_x, i4_num_ctb_y, i4_stride)) |
1136 | 250k | { |
1137 | 250k | break; |
1138 | 250k | } |
1139 | 0 | else |
1140 | 0 | { |
1141 | 0 | if(1 == ps_dep_mngr_state->i1_sem_enable) |
1142 | 0 | { |
1143 | 0 | osal_sem_wait(ps_dep_mngr_state->ppv_thrd_sem_handles[thrd_id]); |
1144 | 0 | } |
1145 | 0 | } |
1146 | 250k | } |
1147 | | |
1148 | 250k | return 0; |
1149 | 250k | } |
1150 | | |
1151 | | /*! |
1152 | | ************************************************************************** |
1153 | | * \if Function name : ihevce_dmgr_map_set_sync \endif |
1154 | | * |
1155 | | * \brief |
1156 | | * This function sets the dependency and wakes up the proper semaphores |
1157 | | * to start processing. |
1158 | | * |
1159 | | * \param[in] pv_dep_mngr_state : Pointer to Sync Manager handle. |
1160 | | * \param[in] offset_x : Offset of current CTB in Tile(ctb unit) |
1161 | | * \param[in] offset_y : Offset of current CTB in Tile(ctb unit) |
1162 | | * |
1163 | | * \return |
1164 | | * 0 on Success and -1 on error |
1165 | | * |
1166 | | * \author |
1167 | | * Ittiam |
1168 | | * |
1169 | | ************************************************************************** |
1170 | | */ |
1171 | | WORD32 ihevce_dmgr_map_set_sync( |
1172 | | void *pv_dep_mngr_state, WORD32 offset_x, WORD32 offset_y, WORD32 i4_map_value) |
1173 | 262k | { |
1174 | 262k | dep_mngr_state_t *ps_dep_mngr_state; |
1175 | 262k | WORD8 *pi1_tile_start; |
1176 | 262k | WORD32 map_stride; |
1177 | | |
1178 | 262k | ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state; |
1179 | | |
1180 | | /* Sanity Checks */ |
1181 | 262k | ASSERT(offset_x >= (-ps_dep_mngr_state->ai4_tile_xtra_ctb[1])); |
1182 | 262k | ASSERT(offset_y >= (-ps_dep_mngr_state->ai4_tile_xtra_ctb[0])); |
1183 | | |
1184 | 262k | ASSERT( |
1185 | 262k | offset_x < |
1186 | 262k | (ps_dep_mngr_state->i4_num_horz_units - ps_dep_mngr_state->ai4_tile_xtra_ctb[1])); |
1187 | | |
1188 | 262k | ASSERT( |
1189 | 262k | offset_y < |
1190 | 262k | (ps_dep_mngr_state->i4_num_vert_units - ps_dep_mngr_state->ai4_tile_xtra_ctb[0])); |
1191 | | |
1192 | 262k | DATA_SYNC(); |
1193 | | |
1194 | 262k | map_stride = ps_dep_mngr_state->i4_num_horz_units; |
1195 | | |
1196 | 262k | pi1_tile_start = (WORD8 *)ps_dep_mngr_state->pv_units_prcsd_in_row; |
1197 | | |
1198 | | /* Set the flag to indicate that this CTB has been processed */ |
1199 | 262k | *(pi1_tile_start + offset_y * map_stride + offset_x) = (WORD8)i4_map_value; |
1200 | | |
1201 | 262k | if(1 == ps_dep_mngr_state->i1_sem_enable) |
1202 | 143k | { |
1203 | 143k | WORD32 wait_thrd_id; |
1204 | | |
1205 | | /* Post on threads waiting on the current row */ |
1206 | 287k | for(wait_thrd_id = 0; wait_thrd_id < ps_dep_mngr_state->i4_num_thrds; wait_thrd_id++) |
1207 | 143k | { |
1208 | | /* Post on the semaphore */ |
1209 | | /* Map-mode: semaphore post is unconditionally done on all threads */ |
1210 | 143k | osal_sem_post(ps_dep_mngr_state->ppv_thrd_sem_handles[wait_thrd_id]); |
1211 | 143k | } |
1212 | 143k | } |
1213 | | |
1214 | 262k | return 0; |
1215 | 262k | } |