From e8b2750904fd78cf168fa196b38d35594b060e8a Mon Sep 17 00:00:00 2001 From: James Zern Date: Sat, 6 Apr 2019 17:07:13 -0700 Subject: loop_filter_rows_mt: unify worker count calculation fixes a deadlock with an odd number of threads that go from < number of tiles to >. the previous calculations were out of sync so going from e.g., 8 tiles to 2 with 3 threads would result in scheduling only 2 workers, but thread_loop_filter_rows() would expect 3. BUG=webm:1618 Change-Id: I78c967a8c3c927d929e13c949808a5ef443ebacb --- vp9/common/vp9_thread_common.c | 7 ++++++- vp9/common/vp9_thread_common.h | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'vp9') diff --git a/vp9/common/vp9_thread_common.c b/vp9/common/vp9_thread_common.c index 00882a5f9..c79d9b7f0 100644 --- a/vp9/common/vp9_thread_common.c +++ b/vp9/common/vp9_thread_common.c @@ -8,6 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include #include #include "./vpx_config.h" #include "vpx_dsp/vpx_dsp_common.h" @@ -92,7 +93,7 @@ static INLINE void thread_loop_filter_rows( int y_only, VP9LfSync *const lf_sync) { const int num_planes = y_only ? 1 : MAX_MB_PLANE; const int sb_cols = mi_cols_aligned_to_sb(cm->mi_cols) >> MI_BLOCK_SIZE_LOG2; - const int num_active_workers = VPXMIN(lf_sync->num_workers, lf_sync->rows); + const int num_active_workers = lf_sync->num_active_workers; int mi_row, mi_col; enum lf_path path; if (y_only) @@ -104,6 +105,8 @@ static INLINE void thread_loop_filter_rows( else path = LF_PATH_SLOW; + assert(num_active_workers > 0); + for (mi_row = start; mi_row < stop; mi_row += num_active_workers * MI_BLOCK_SIZE) { MODE_INFO **const mi = cm->mi_grid_visible + mi_row * cm->mi_stride; @@ -172,6 +175,7 @@ static void loop_filter_rows_mt(YV12_BUFFER_CONFIG *frame, VP9_COMMON *cm, vp9_loop_filter_dealloc(lf_sync); vp9_loop_filter_alloc(lf_sync, cm, sb_rows, cm->width, num_workers); } + lf_sync->num_active_workers = num_workers; // Initialize cur_sb_col to -1 for all SB rows. memset(lf_sync->cur_sb_col, -1, sizeof(*lf_sync->cur_sb_col) * sb_rows); @@ -319,6 +323,7 @@ void vp9_loop_filter_alloc(VP9LfSync *lf_sync, VP9_COMMON *cm, int rows, CHECK_MEM_ERROR(cm, lf_sync->lfdata, vpx_malloc(num_workers * sizeof(*lf_sync->lfdata))); lf_sync->num_workers = num_workers; + lf_sync->num_active_workers = lf_sync->num_workers; CHECK_MEM_ERROR(cm, lf_sync->cur_sb_col, vpx_malloc(sizeof(*lf_sync->cur_sb_col) * rows)); diff --git a/vp9/common/vp9_thread_common.h b/vp9/common/vp9_thread_common.h index 1a2d79abd..94c9de659 100644 --- a/vp9/common/vp9_thread_common.h +++ b/vp9/common/vp9_thread_common.h @@ -36,7 +36,8 @@ typedef struct VP9LfSyncData { // Row-based parallel loopfilter data LFWorkerData *lfdata; - int num_workers; + int num_workers; // number of allocated workers. + int num_active_workers; // number of scheduled workers. #if CONFIG_MULTITHREAD pthread_mutex_t lf_mutex; -- cgit v1.2.3