Commit 236f10dfb3 for aom
commit 236f10dfb318791ed35d0ea8f46bbfe537dd9971
Author: Frank Galligan <fgalligan@google.com>
Date: Thu Dec 3 12:48:04 2026 -0800
Revert "av1: add atomic waiter-gated row/lpf/mt sync"
This reverts commit 27f59a40579554f65b82edd08880ed6f7d8790bc
(CL 221281).
Reason for revert: Guarding AV1LfSyncData::waiters and
AV1EncRowMultiThreadSync::waiters with #if AOM_HAVE_ATOMIC_SYNC caused
a 16-byte C-vs-C++ ABI struct layout mismatch on Jenkins
libaom__unit_tests-multi-target arch=arm (#3196/#3197), where
-DCMAKE_C_FLAGS overrides -march=armv7-a for C files only while C++
tests retain it. Reverting while we redesign a simpler, header-macro-
free implementation.
TAG=agy
CONV=f57e68e5-f406-4d82-a08f-9a737c3ba2b5
Change-Id: I11d556007c088002c45b50313ffa9191edf2e779
Change-Id: Ifacc6c3373212679f7e001d1ccfcec0a46966a55
diff --git a/av1/common/thread_common.c b/av1/common/thread_common.c
index c04bfe3e41..975c0902f8 100644
--- a/av1/common/thread_common.c
+++ b/av1/common/thread_common.c
@@ -11,7 +11,6 @@
#include <assert.h>
#include <limits.h>
-#include <stddef.h>
#include "aom/aom_image.h"
#include "config/aom_config.h"
@@ -103,19 +102,9 @@ void av1_loop_filter_alloc(AV1LfSync *lf_sync, AV1_COMMON *cm, int rows,
aom_malloc(num_workers * sizeof(*(lf_sync->lfdata))));
lf_sync->num_workers = num_workers;
-#if AOM_HAVE_ATOMIC_SYNC
- const size_t sb_col_count = (size_t)rows * 2;
-#else
- const size_t sb_col_count = (size_t)rows;
-#endif
for (int j = 0; j < MAX_MB_PLANE; j++) {
- CHECK_MEM_ERROR(
- cm, lf_sync->cur_sb_col[j],
- aom_malloc(sizeof(*(lf_sync->cur_sb_col[j])) * sb_col_count));
-#if AOM_HAVE_ATOMIC_SYNC
- lf_sync->waiters[j] = lf_sync->cur_sb_col[j] + rows;
- memset(lf_sync->waiters[j], 0, sizeof(*(lf_sync->waiters[j])) * rows);
-#endif
+ CHECK_MEM_ERROR(cm, lf_sync->cur_sb_col[j],
+ aom_malloc(sizeof(*(lf_sync->cur_sb_col[j])) * rows));
}
CHECK_MEM_ERROR(
cm, lf_sync->job_queue,
@@ -223,34 +212,6 @@ static inline void cdef_row_mt_sync_write(AV1CdefSync *const cdef_sync,
// Returns true if the sync read is successful and the caller can continue.
// Returns false if the caller should exit because a worker has encountered an
// error.
-#if AOM_HAVE_ATOMIC_SYNC
-// Keep cold mutex/condvar wait path out of sync_read() fast path.
-AOM_NOINLINE static bool sync_read_slow(AV1LfSync *const lf_sync, int r, int c,
- int plane, int nsync) {
- int *const sb_col = &lf_sync->cur_sb_col[plane][r - 1];
- pthread_mutex_t *const mutex = &lf_sync->mutex_[plane][r - 1];
- int *const waiters = &lf_sync->waiters[plane][r - 1];
- int cur;
- pthread_mutex_lock(mutex);
- __atomic_add_fetch(waiters, 1, __ATOMIC_SEQ_CST);
- while (c > (cur = __atomic_load_n(sb_col, __ATOMIC_SEQ_CST)) - nsync) {
- pthread_cond_wait(&lf_sync->cond_[plane][r - 1], mutex);
- }
- __atomic_sub_fetch(waiters, 1, __ATOMIC_RELEASE);
- const bool lf_mt_continue = cur != LF_SYNC_EXIT;
- pthread_mutex_unlock(mutex);
- return lf_mt_continue;
-}
-
-// Keep cold condvar broadcast out of sync_write() fast path.
-AOM_NOINLINE static void sync_write_wake_slow(AV1LfSync *const lf_sync, int r,
- int plane) {
- pthread_mutex_lock(&lf_sync->mutex_[plane][r]);
- pthread_cond_broadcast(&lf_sync->cond_[plane][r]);
- pthread_mutex_unlock(&lf_sync->mutex_[plane][r]);
-}
-#endif // AOM_HAVE_ATOMIC_SYNC
-
static inline bool sync_read(AV1LfSync *const lf_sync, int r, int c,
int plane) {
bool lf_mt_continue = true;
@@ -258,15 +219,6 @@ static inline bool sync_read(AV1LfSync *const lf_sync, int r, int c,
const int nsync = lf_sync->sync_range;
if (r && !(c & (nsync - 1))) {
-#if AOM_HAVE_ATOMIC_SYNC
- const int cur =
- __atomic_load_n(&lf_sync->cur_sb_col[plane][r - 1], __ATOMIC_ACQUIRE);
- if (LIKELY(c <= cur - nsync)) {
- lf_mt_continue = cur != LF_SYNC_EXIT;
- } else {
- lf_mt_continue = sync_read_slow(lf_sync, r, c, plane, nsync);
- }
-#else
pthread_mutex_t *const mutex = &lf_sync->mutex_[plane][r - 1];
pthread_mutex_lock(mutex);
@@ -275,7 +227,6 @@ static inline bool sync_read(AV1LfSync *const lf_sync, int r, int c,
}
lf_mt_continue = lf_sync->cur_sb_col[plane][r - 1] != LF_SYNC_EXIT;
pthread_mutex_unlock(mutex);
-#endif
}
#else
(void)lf_sync;
@@ -302,23 +253,6 @@ static inline void sync_write(AV1LfSync *const lf_sync, int r, int c,
}
if (sig) {
-#if AOM_HAVE_ATOMIC_SYNC
- int *const sb_col = &lf_sync->cur_sb_col[plane][r];
- int prev = __atomic_load_n(sb_col, __ATOMIC_RELAXED);
- // After an error cur_sb_col[plane][r] holds LF_SYNC_EXIT. CAS keeps it
- // from being lowered, so workers waiting in sync_read() still see it and
- // exit.
- while (prev < cur) {
- if (__atomic_compare_exchange_n(sb_col, &prev, cur, true,
- __ATOMIC_SEQ_CST, __ATOMIC_RELAXED)) {
- break;
- }
- }
- if (UNLIKELY(__atomic_load_n(&lf_sync->waiters[plane][r],
- __ATOMIC_SEQ_CST) > 0)) {
- sync_write_wake_slow(lf_sync, r, plane);
- }
-#else
pthread_mutex_lock(&lf_sync->mutex_[plane][r]);
// After an error cur_sb_col[plane][r] holds LF_SYNC_EXIT. AOMMAX keeps it
@@ -328,7 +262,6 @@ static inline void sync_write(AV1LfSync *const lf_sync, int r, int c,
pthread_cond_broadcast(&lf_sync->cond_[plane][r]);
pthread_mutex_unlock(&lf_sync->mutex_[plane][r]);
-#endif
}
#else
(void)lf_sync;
@@ -430,12 +363,7 @@ void av1_set_vert_loop_filter_done(AV1_COMMON *cm, AV1LfSync *lf_sync,
for (int sb_row = 0; sb_row < sb_rows; ++sb_row) {
for (int plane = 0; plane < MAX_MB_PLANE; ++plane) {
pthread_mutex_lock(&lf_sync->mutex_[plane][sb_row]);
-#if AOM_HAVE_ATOMIC_SYNC
- __atomic_store_n(&lf_sync->cur_sb_col[plane][sb_row], LF_SYNC_EXIT,
- __ATOMIC_SEQ_CST);
-#else
lf_sync->cur_sb_col[plane][sb_row] = LF_SYNC_EXIT;
-#endif
pthread_cond_broadcast(&lf_sync->cond_[plane][sb_row]);
pthread_mutex_unlock(&lf_sync->mutex_[plane][sb_row]);
}
diff --git a/av1/common/thread_common.h b/av1/common/thread_common.h
index 1736f54afc..5d467c5d00 100644
--- a/av1/common/thread_common.h
+++ b/av1/common/thread_common.h
@@ -23,14 +23,6 @@
extern "C" {
#endif
-#if CONFIG_MULTITHREAD && defined(__GCC_ATOMIC_BOOL_LOCK_FREE) && \
- __GCC_ATOMIC_BOOL_LOCK_FREE == 2 && defined(__GCC_ATOMIC_INT_LOCK_FREE) && \
- __GCC_ATOMIC_INT_LOCK_FREE == 2
-#define AOM_HAVE_ATOMIC_SYNC 1
-#else
-#define AOM_HAVE_ATOMIC_SYNC 0
-#endif
-
struct AV1Common;
typedef struct AV1LfMTInfo {
@@ -48,11 +40,6 @@ typedef struct AV1LfSyncData {
#endif
// Allocate memory to store the loop-filtered superblock index in each row.
int *cur_sb_col[MAX_MB_PLANE];
-#if AOM_HAVE_ATOMIC_SYNC
- // Active waiter count per (plane, row) for waiter-gated wakeup. Points into
- // the tail of cur_sb_col[plane]; do not free separately.
- int *waiters[MAX_MB_PLANE];
-#endif
// The optimal sync_range for different resolution and platform should be
// determined by testing. Currently, it is chosen to be a power-of-2 number.
int sync_range;
@@ -290,13 +277,10 @@ static inline void loop_filter_frame_mt_init(
}
lf_sync->lf_mt_exit = false;
- // Initialize cur_sb_col to -1 and waiters to 0 for all SB rows.
+ // Initialize cur_sb_col to -1 for all SB rows.
for (int i = 0; i < MAX_MB_PLANE; i++) {
memset(lf_sync->cur_sb_col[i], -1,
sizeof(*(lf_sync->cur_sb_col[i])) * sb_rows);
-#if AOM_HAVE_ATOMIC_SYNC
- memset(lf_sync->waiters[i], 0, sizeof(*(lf_sync->waiters[i])) * sb_rows);
-#endif
}
enqueue_lf_jobs(lf_sync, start_mi_row, end_mi_row, planes_to_lf,
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 652b91a0f8..646114b7fa 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -1390,16 +1390,11 @@ static inline void encode_sb_row(AV1_COMP *cpi, ThreadData *td,
#if CONFIG_MULTITHREAD
if (row_mt_enabled) {
-#if AOM_HAVE_ATOMIC_SYNC
- const bool row_mt_exit =
- __atomic_load_n(&enc_row_mt->row_mt_exit, __ATOMIC_ACQUIRE);
-#else
pthread_mutex_lock(enc_row_mt->mutex_);
const bool row_mt_exit = enc_row_mt->row_mt_exit;
pthread_mutex_unlock(enc_row_mt->mutex_);
-#endif
// Exit in case any worker has encountered an error.
- if (UNLIKELY(row_mt_exit)) return;
+ if (row_mt_exit) return;
}
#endif
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 9d4f7c0572..00d3368317 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -1423,14 +1423,6 @@ typedef struct {
* encoding in the ith superblock row.
*/
int *num_finished_cols;
-#if AOM_HAVE_ATOMIC_SYNC
- /*!
- * Number of worker threads currently waiting on each superblock row's
- * condvar. Points into the tail of num_finished_cols; do not free
- * separately.
- */
- int *waiters;
-#endif
/*!
* Denotes the superblock interval at which conditional signalling should
* happen. Also denotes the minimum number of extra superblocks of the top row
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index 978f927791..0e6c08bd09 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -11,7 +11,6 @@
#include <assert.h>
#include <stdbool.h>
-#include <stddef.h>
#include "aom_util/aom_pthread.h"
@@ -118,47 +117,11 @@ void av1_row_mt_sync_write_dummy(AV1EncRowMultiThreadSync *row_mt_sync, int r,
(void)cols;
}
-#if AOM_HAVE_ATOMIC_SYNC
-// Keep cold mutex/condvar wait path out of av1_row_mt_sync_read() fast path.
-AOM_NOINLINE static void row_mt_sync_read_slow(
- AV1EncRowMultiThreadSync *row_mt_sync, int r, int min_finished) {
- int *const finished_col = &row_mt_sync->num_finished_cols[r - 1];
- pthread_mutex_t *const mutex = &row_mt_sync->mutex_[r - 1];
- pthread_cond_t *const cond = &row_mt_sync->cond_[r - 1];
- int *const waiters = &row_mt_sync->waiters[r - 1];
- pthread_mutex_lock(mutex);
- __atomic_add_fetch(waiters, 1, __ATOMIC_SEQ_CST);
- while (__atomic_load_n(finished_col, __ATOMIC_SEQ_CST) < min_finished) {
- pthread_cond_wait(cond, mutex);
- }
- __atomic_sub_fetch(waiters, 1, __ATOMIC_RELEASE);
- pthread_mutex_unlock(mutex);
-}
-
-// Keep cold condvar signal out of av1_row_mt_sync_write() fast path.
-AOM_NOINLINE static void row_mt_sync_write_wake_slow(
- AV1EncRowMultiThreadSync *row_mt_sync, int r) {
- pthread_mutex_t *const mutex = &row_mt_sync->mutex_[r];
- pthread_mutex_lock(mutex);
- pthread_cond_signal(&row_mt_sync->cond_[r]);
- pthread_mutex_unlock(mutex);
-}
-#endif // AOM_HAVE_ATOMIC_SYNC
-
void av1_row_mt_sync_read(AV1EncRowMultiThreadSync *row_mt_sync, int r, int c) {
#if CONFIG_MULTITHREAD
const int nsync = row_mt_sync->sync_range;
if (r) {
-#if AOM_HAVE_ATOMIC_SYNC
- const int min_finished =
- c + nsync + row_mt_sync->intrabc_extra_top_right_sb_delay;
- if (LIKELY(__atomic_load_n(&row_mt_sync->num_finished_cols[r - 1],
- __ATOMIC_ACQUIRE) >= min_finished)) {
- return;
- }
- row_mt_sync_read_slow(row_mt_sync, r, min_finished);
-#else
pthread_mutex_t *const mutex = &row_mt_sync->mutex_[r - 1];
pthread_mutex_lock(mutex);
@@ -167,7 +130,6 @@ void av1_row_mt_sync_read(AV1EncRowMultiThreadSync *row_mt_sync, int r, int c) {
pthread_cond_wait(&row_mt_sync->cond_[r - 1], mutex);
}
pthread_mutex_unlock(mutex);
-#endif
}
#else
(void)row_mt_sync;
@@ -192,24 +154,6 @@ void av1_row_mt_sync_write(AV1EncRowMultiThreadSync *row_mt_sync, int r, int c,
}
if (sig) {
-#if AOM_HAVE_ATOMIC_SYNC
- int *const finished_col = &row_mt_sync->num_finished_cols[r];
- int prev = __atomic_load_n(finished_col, __ATOMIC_RELAXED);
- // When a thread encounters an error, num_finished_cols[r] is set to maximum
- // column number. In this case, the CAS keeps num_finished_cols[r] from
- // being lowered, preventing workers in av1_row_mt_sync_read() from waiting
- // indefinitely.
- while (prev < cur) {
- if (__atomic_compare_exchange_n(finished_col, &prev, cur, true,
- __ATOMIC_SEQ_CST, __ATOMIC_RELAXED)) {
- break;
- }
- }
- if (UNLIKELY(__atomic_load_n(&row_mt_sync->waiters[r], __ATOMIC_SEQ_CST) >
- 0)) {
- row_mt_sync_write_wake_slow(row_mt_sync, r);
- }
-#else
pthread_mutex_lock(&row_mt_sync->mutex_[r]);
// When a thread encounters an error, num_finished_cols[r] is set to maximum
@@ -222,7 +166,6 @@ void av1_row_mt_sync_write(AV1EncRowMultiThreadSync *row_mt_sync, int r, int c,
pthread_cond_signal(&row_mt_sync->cond_[r]);
pthread_mutex_unlock(&row_mt_sync->mutex_[r]);
-#endif
}
#else
(void)row_mt_sync;
@@ -255,18 +198,8 @@ static void row_mt_sync_mem_alloc(AV1EncRowMultiThreadSync *row_mt_sync,
}
#endif // CONFIG_MULTITHREAD
-#if AOM_HAVE_ATOMIC_SYNC
- const size_t cols_count = (size_t)rows * 2;
-#else
- const size_t cols_count = (size_t)rows;
-#endif
- CHECK_MEM_ERROR(
- cm, row_mt_sync->num_finished_cols,
- aom_malloc(sizeof(*row_mt_sync->num_finished_cols) * cols_count));
-#if AOM_HAVE_ATOMIC_SYNC
- row_mt_sync->waiters = row_mt_sync->num_finished_cols + rows;
- memset(row_mt_sync->waiters, 0, sizeof(*row_mt_sync->waiters) * rows);
-#endif
+ CHECK_MEM_ERROR(cm, row_mt_sync->num_finished_cols,
+ aom_malloc(sizeof(*row_mt_sync->num_finished_cols) * rows));
row_mt_sync->rows = rows;
// Set up nsync.
@@ -683,11 +616,7 @@ static int enc_row_mt_worker_hook(void *arg1, void *unused) {
error_info->setjmp = 0;
#if CONFIG_MULTITHREAD
pthread_mutex_lock(enc_row_mt_mutex_);
-#if AOM_HAVE_ATOMIC_SYNC
- __atomic_store_n(&enc_row_mt->row_mt_exit, true, __ATOMIC_RELEASE);
-#else
enc_row_mt->row_mt_exit = true;
-#endif
// Wake up all the workers waiting in launch_loop_filter_rows() to exit in
// case of an error.
pthread_cond_broadcast(enc_row_mt->cond_);
@@ -804,13 +733,9 @@ static int enc_row_mt_worker_hook(void *arg1, void *unused) {
#endif
this_tile->abs_sum_level += td->abs_sum_level;
row_mt_sync->num_threads_working--;
- if (do_pipelined_lpf_mt_with_enc) {
- enc_row_mt->num_tile_cols_done[sb_row]++;
-#if CONFIG_MULTITHREAD
- pthread_cond_broadcast(enc_row_mt->cond_);
-#endif
- }
+ enc_row_mt->num_tile_cols_done[sb_row]++;
#if CONFIG_MULTITHREAD
+ pthread_cond_broadcast(enc_row_mt->cond_);
pthread_mutex_unlock(enc_row_mt_mutex_);
#endif
}
@@ -2069,10 +1994,6 @@ void av1_encode_tiles_row_mt(AV1_COMP *cpi) {
// Initialize num_finished_cols to -1 for all rows.
memset(row_mt_sync->num_finished_cols, -1,
sizeof(*row_mt_sync->num_finished_cols) * max_sb_rows_in_tile);
-#if AOM_HAVE_ATOMIC_SYNC
- memset(row_mt_sync->waiters, 0,
- sizeof(*row_mt_sync->waiters) * max_sb_rows_in_tile);
-#endif
row_mt_sync->next_mi_row = this_tile->tile_info.mi_row_start;
row_mt_sync->num_threads_working = 0;
row_mt_sync->intrabc_extra_top_right_sb_delay =
@@ -2200,10 +2121,6 @@ void av1_fp_encode_tiles_row_mt(AV1_COMP *cpi) {
// Initialize num_finished_cols to -1 for all rows.
memset(row_mt_sync->num_finished_cols, -1,
sizeof(*row_mt_sync->num_finished_cols) * max_mb_rows);
-#if AOM_HAVE_ATOMIC_SYNC
- memset(row_mt_sync->waiters, 0,
- sizeof(*row_mt_sync->waiters) * max_mb_rows);
-#endif
row_mt_sync->next_mi_row = this_tile->tile_info.mi_row_start;
row_mt_sync->num_threads_working = 0;