From patchwork Thu Jun 16 12:04:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Tomas_H=C3=A4rdin?= X-Patchwork-Id: 36255 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp899235pzb; Thu, 16 Jun 2022 05:05:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1venPvU73djE55LqtqAXyxb2030+qufnpnhIILsPsdR9Pi3bi1Jj5bUkezwN0/0awxEkGgC X-Received: by 2002:a17:906:58cb:b0:70a:751c:91fc with SMTP id e11-20020a17090658cb00b0070a751c91fcmr4140142ejs.258.1655381100425; Thu, 16 Jun 2022 05:05:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655381100; cv=none; d=google.com; s=arc-20160816; b=LMGLFVk7EQyidmItD38n12np6sGWWUEXiy7VWBZh1rkTAy2Bn5mWQwOhEUYUatliBl N7yW6KhmRB4oi3N1ZRSaYQE/EVjhQKAPqlOBcYaqUEx1W79gvZ2J3V2N0b9V8du1aW2p 1eqtbRSfGYYTfXbfSNLDUihXpeb5QqHGPYhuJCQ68t/VmxLLfNJKTH3HTHC+E0SO/x4R QmXv4n2RnSfQ/tRviVFBFmm6Kc5Y34erlsCTlfZcAkDydFA3GnMZbhg9Nf7BbwWb3J7e 89ZwRESXkJefqD/s9CGDGWDMpqGuawfW+BCtxEh3BibokbVNqSgiqR+BSSQGgxDupjuU q4yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:user-agent:date:to:from:message-id:dkim-signature :dkim-signature:delivered-to; bh=Oz0QvCy2bTFsipaFixb0XN3gU1qoFVjww1/5uHabMns=; b=X8sHAKa/d+J6THwBkwLPMW2owKjuWfsF+tEQtPuOebH2IZLoom7pn6Svw+tA11IkWw vTHVORzgWuGdzuVMgX6lARnPSpPH4BoJtQWFwOsIXE556p200earDa/UKpmu3Pgh6i06 f090F/ka1QVWhJ1/dyCWweXIkf+eNhuD0ySRksgb57ezRUBEKTIpu1ioJVifRGxo88fG y0fA3NZ6MUVu8HaEGonInYRJ34cDSzQ1i1d6xTlNfuWcFERGxBSo0UiyHBweyybTpCGE LKAduGx5PswOXswoxh6z7yQ3dGl2I2xsRn4+OksJKCrE3wG3CO8l5UyqWa5Wprodk/Pi /NLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@acc.umu.se header.s=mail1 header.b=DQD5slIv; dkim=neutral (body hash did not verify) header.i=@acc.umu.se header.s=mail1 header.b=nF8OaREK; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=acc.umu.se Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ss28-20020a170907c01c00b006fec3d39909si1223720ejc.572.2022.06.16.05.04.58; Thu, 16 Jun 2022 05:05:00 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@acc.umu.se header.s=mail1 header.b=DQD5slIv; dkim=neutral (body hash did not verify) header.i=@acc.umu.se header.s=mail1 header.b=nF8OaREK; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=acc.umu.se Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6023F68B80F; Thu, 16 Jun 2022 15:04:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.acc.umu.se (mail.acc.umu.se [130.239.18.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9655468B5B5 for ; Thu, 16 Jun 2022 15:04:49 +0300 (EEST) Received: from localhost (localhost.localdomain [127.0.0.1]) by amavisd-new (Postfix) with ESMTP id 1FA7F44DE6 for ; Thu, 16 Jun 2022 14:04:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=acc.umu.se; s=mail1; t=1655381089; bh=FVzzk4j4yJ7/K8HzkW53h0dhE2ia/CV0U4h1h4zJiJs=; h=Subject:From:To:Date:From; b=DQD5slIvl4DAnExtIdWHBEaR5a9EdPG3U35PB33go/S+c+LalixGi4FgrpoZFyfhN 0gU4R1lAkgF1IhKiUAR8y0s4NJPxIHPCFgqhH9sRoVgw2VMVqk2Tk4c5zJqpl0XdlP BGGHuhuJ26agYY6OprjYaDtxNxKOo97wXEVeVg92JFjphsN42HP3qzcyd+CFBoOLwd qfydk6jIbKkZ7/+F1wdUB6qNbR2nkx6tr5qI3lZQkDjS95SIgF6E/bk81Tpnb+JIAr KaCNCsuuqLcnEc0abhACwi/S7GFDejePmm2zrxaAePIBhSk1i0X86G8kJKbwYPiXIP bJCk6SG65qthQ== Received: from debian.lan (unknown [IPv6:2a00:66c0:a::72c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: tjoppen) by mail.acc.umu.se (Postfix) with ESMTPSA id 3317344DE0 for ; Thu, 16 Jun 2022 14:04:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=acc.umu.se; s=mail1; t=1655381088; bh=FVzzk4j4yJ7/K8HzkW53h0dhE2ia/CV0U4h1h4zJiJs=; h=Subject:From:To:Date:From; b=nF8OaREK3uEAhdJWeJWu7+/P1a5W4SYO767cqICwTzjyGwo/ulMtwp8qfoLLsMkID bFUdq8fiE0NYqzK9l7+W349NfGE7CzdHLV03FgdpWUsFI89f88Ft/ABZ8HnkSMR0zB Jti0aUjgW9syrzmsFfiT1QdbrNexErq+T/e0MB78cdpBRAf5jqaRi/YeO6iQlzDfng jG1ddd8TWBNAMaMnvzmETREKI0Trq+Ga9XF7mjTnbh5YEopREqN6qt9QovbCtXb3mO M2EajU3Ag5xK0R0/TVo1SRECspGR1zpXj9m7TQ0dUUQk1rD76Cs1QjX3RvhK46vZPo uCQyM1pGHj5Ww== Message-ID: <07b64fb90f72d9bc4b5aa154b715ae121f849c71.camel@acc.umu.se> From: Tomas =?iso-8859-1?q?H=E4rdin?= To: FFmpeg development discussions and patches Date: Thu, 16 Jun 2022 14:04:47 +0200 User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] Make execute() and execute2() return FFMIN() of thread return codes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Xx/6lja6kIan From 2895c86dd908f6ddf3562d81050c50ea697a0bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= Date: Thu, 16 Jun 2022 12:16:44 +0200 Subject: [PATCH] Make execute() and execute2() return FFMIN() of thread return codes At the moment only fic.c actually checks return code of execute() hence the change to its FATE reference --- libavcodec/avcodec.c | 10 ++++++---- libavcodec/pthread_slice.c | 9 +++++---- libavfilter/pthread.c | 3 ++- libavutil/slicethread.c | 34 +++++++++++++++++++++------------- libavutil/slicethread.h | 6 +++--- libswscale/swscale.c | 5 +++-- libswscale/swscale_internal.h | 4 ++-- tests/ref/fate/fic-avi | 30 +++++++++++++----------------- 8 files changed, 55 insertions(+), 46 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 5f6e71a39e..49f0fd06fb 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -44,28 +44,30 @@ int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size) { - int i; + int i, rr = 0; for (i = 0; i < count; i++) { int r = func(c, (char *)arg + i * size); + rr = FFMIN(rr, r); if (ret) ret[i] = r; } emms_c(); - return 0; + return rr; } int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count) { - int i; + int i, rr = 0; for (i = 0; i < count; i++) { int r = func(c, arg, i, 0); + rr = FFMIN(rr, r); if (ret) ret[i] = r; } emms_c(); - return 0; + return rr; } static AVMutex codec_mutex = AV_MUTEX_INITIALIZER; diff --git a/libavcodec/pthread_slice.c b/libavcodec/pthread_slice.c index 0ad1965a22..5f02b9b6a1 100644 --- a/libavcodec/pthread_slice.c +++ b/libavcodec/pthread_slice.c @@ -57,13 +57,13 @@ typedef struct SliceThreadContext { pthread_mutex_t *progress_mutex; } SliceThreadContext; -static void main_function(void *priv) { +static int main_function(void *priv) { AVCodecContext *avctx = priv; SliceThreadContext *c = avctx->internal->thread_ctx; - c->mainfunc(avctx); + return c->mainfunc(avctx); } -static void worker_func(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads) +static int worker_func(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads) { AVCodecContext *avctx = priv; SliceThreadContext *c = avctx->internal->thread_ctx; @@ -73,6 +73,7 @@ static void worker_func(void *priv, int jobnr, int threadnr, int nb_jobs, int nb : c->func2(avctx, c->args, jobnr, threadnr); if (c->rets) c->rets[jobnr] = ret; + return ret; } void ff_slice_thread_free(AVCodecContext *avctx) @@ -131,7 +132,7 @@ int ff_slice_thread_init(AVCodecContext *avctx) { SliceThreadContext *c; int thread_count = avctx->thread_count; - void (*mainfunc)(void *); + int (*mainfunc)(void *); // We cannot do this in the encoder init as the threads are created before if (av_codec_is_encoder(avctx->codec) && diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c index 1a063d3cc0..8cec278be0 100644 --- a/libavfilter/pthread.c +++ b/libavfilter/pthread.c @@ -43,12 +43,13 @@ typedef struct ThreadContext { int *rets; } ThreadContext; -static void worker_func(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads) +static int worker_func(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads) { ThreadContext *c = priv; int ret = c->func(c->ctx, c->arg, jobnr, nb_jobs); if (c->rets) c->rets[jobnr] = ret; + return ret; } static void slice_thread_uninit(ThreadContext *c) diff --git a/libavutil/slicethread.c b/libavutil/slicethread.c index ea1c9c8311..83a98a7ae7 100644 --- a/libavutil/slicethread.c +++ b/libavutil/slicethread.c @@ -32,6 +32,7 @@ typedef struct WorkerContext { pthread_cond_t cond; pthread_t thread; int done; + int ret; } WorkerContext; struct AVSliceThread { @@ -48,11 +49,11 @@ struct AVSliceThread { int finished; void *priv; - void (*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads); - void (*main_func)(void *priv); + int (*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads); + int (*main_func)(void *priv); }; -static int run_jobs(AVSliceThread *ctx) +static int run_jobs(AVSliceThread *ctx, int *ret_out) { unsigned nb_jobs = ctx->nb_jobs; unsigned nb_active_threads = ctx->nb_active_threads; @@ -60,7 +61,8 @@ static int run_jobs(AVSliceThread *ctx) unsigned current_job = first_job; do { - ctx->worker_func(ctx->priv, current_job, first_job, nb_jobs, nb_active_threads); + int ret = ctx->worker_func(ctx->priv, current_job, first_job, nb_jobs, nb_active_threads); + *ret_out = FFMIN(*ret_out, ret); } while ((current_job = atomic_fetch_add_explicit(&ctx->current_job, 1, memory_order_acq_rel)) < nb_jobs); return current_job == nb_jobs + nb_active_threads - 1; @@ -84,7 +86,7 @@ static void *attribute_align_arg thread_worker(void *v) return NULL; } - if (run_jobs(ctx)) { + if (run_jobs(ctx, &w->ret)) { pthread_mutex_lock(&ctx->done_mutex); ctx->done = 1; pthread_cond_signal(&ctx->done_cond); @@ -94,8 +96,8 @@ static void *attribute_align_arg thread_worker(void *v) } int avpriv_slicethread_create(AVSliceThread **pctx, void *priv, - void (*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), - void (*main_func)(void *priv), + int (*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), + int (*main_func)(void *priv), int nb_threads) { AVSliceThread *ctx; @@ -163,9 +165,9 @@ int avpriv_slicethread_create(AVSliceThread **pctx, void *priv, return nb_threads; } -void avpriv_slicethread_execute(AVSliceThread *ctx, int nb_jobs, int execute_main) +int avpriv_slicethread_execute(AVSliceThread *ctx, int nb_jobs, int execute_main) { - int nb_workers, i, is_last = 0; + int nb_workers, i, is_last = 0, ret = 0; av_assert0(nb_jobs > 0); ctx->nb_jobs = nb_jobs; @@ -180,14 +182,15 @@ void avpriv_slicethread_execute(AVSliceThread *ctx, int nb_jobs, int execute_mai WorkerContext *w = &ctx->workers[i]; pthread_mutex_lock(&w->mutex); w->done = 0; + w->ret = 0; pthread_cond_signal(&w->cond); pthread_mutex_unlock(&w->mutex); } if (ctx->main_func && execute_main) - ctx->main_func(ctx->priv); + ret = ctx->main_func(ctx->priv); else - is_last = run_jobs(ctx); + is_last = run_jobs(ctx, &ret); if (!is_last) { pthread_mutex_lock(&ctx->done_mutex); @@ -196,6 +199,11 @@ void avpriv_slicethread_execute(AVSliceThread *ctx, int nb_jobs, int execute_mai ctx->done = 0; pthread_mutex_unlock(&ctx->done_mutex); } + + for (i = 0; i < nb_workers; i++) + ret = FFMIN(ret, ctx->workers[i].ret); + + return ret; } void avpriv_slicethread_free(AVSliceThread **pctx) @@ -236,8 +244,8 @@ void avpriv_slicethread_free(AVSliceThread **pctx) #else /* HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS32THREADS */ int avpriv_slicethread_create(AVSliceThread **pctx, void *priv, - void (*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), - void (*main_func)(void *priv), + int (*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), + int (*main_func)(void *priv), int nb_threads) { *pctx = NULL; diff --git a/libavutil/slicethread.h b/libavutil/slicethread.h index f6f6f302c4..5c8f197932 100644 --- a/libavutil/slicethread.h +++ b/libavutil/slicethread.h @@ -31,8 +31,8 @@ typedef struct AVSliceThread AVSliceThread; * @return return number of threads or negative AVERROR on failure */ int avpriv_slicethread_create(AVSliceThread **pctx, void *priv, - void (*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), - void (*main_func)(void *priv), + int (*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), + int (*main_func)(void *priv), int nb_threads); /** @@ -41,7 +41,7 @@ int avpriv_slicethread_create(AVSliceThread **pctx, void *priv, * @param nb_jobs number of jobs, must be > 0 * @param execute_main also execute main_func */ -void avpriv_slicethread_execute(AVSliceThread *ctx, int nb_jobs, int execute_main); +int avpriv_slicethread_execute(AVSliceThread *ctx, int nb_jobs, int execute_main); /** * Destroy slice threading context. diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 7b40f49da4..2f9a0b5a7c 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -1211,8 +1211,8 @@ int attribute_align_arg sws_scale(struct SwsContext *c, dst, dstStride, 0, c->dstH); } -void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, - int nb_jobs, int nb_threads) +int ff_sws_slice_worker(void *priv, int jobnr, int threadnr, + int nb_jobs, int nb_threads) { SwsContext *parent = priv; SwsContext *c = parent->slice_ctx[threadnr]; @@ -1241,4 +1241,5 @@ void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, } parent->slice_err[threadnr] = err; + return err; } diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index e118b54457..eab3e26331 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -1135,8 +1135,8 @@ void ff_init_vscale_pfn(SwsContext *c, yuv2planar1_fn yuv2plane1, yuv2planarX_fn yuv2interleavedX_fn yuv2nv12cX, yuv2packed1_fn yuv2packed1, yuv2packed2_fn yuv2packed2, yuv2packedX_fn yuv2packedX, yuv2anyX_fn yuv2anyX, int use_mmx); -void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, - int nb_jobs, int nb_threads); +int ff_sws_slice_worker(void *priv, int jobnr, int threadnr, + int nb_jobs, int nb_threads); //number of extra lines to process #define MAX_LINES_AHEAD 4 diff --git a/tests/ref/fate/fic-avi b/tests/ref/fate/fic-avi index df55789d54..4546f230b1 100644 --- a/tests/ref/fate/fic-avi +++ b/tests/ref/fate/fic-avi @@ -76,19 +76,18 @@ 0, 70, 70, 1, 1566720, 0x40f7d39a 0, 71, 71, 1, 1566720, 0x40f7d39a 0, 72, 72, 1, 1566720, 0x40f7d39a -0, 73, 73, 1, 1566720, 0xa7d6e25f -0, 74, 74, 1, 1566720, 0xa7d6e25f -0, 75, 75, 1, 1566720, 0xa7d6e25f -0, 76, 76, 1, 1566720, 0xa7d6e25f -0, 77, 77, 1, 1566720, 0xa7d6e25f -0, 78, 78, 1, 1566720, 0xa7d6e25f -0, 79, 79, 1, 1566720, 0xa7d6e25f -0, 80, 80, 1, 1566720, 0xa7d6e25f -0, 81, 81, 1, 1566720, 0xa7d6e25f -0, 82, 82, 1, 1566720, 0xa7d6e25f -0, 83, 83, 1, 1566720, 0xa7d6e25f -0, 84, 84, 1, 1566720, 0xa7d6e25f -0, 85, 85, 1, 1566720, 0xa7d6e25f +0, 74, 74, 1, 1566720, 0x40f7d39a +0, 75, 75, 1, 1566720, 0x40f7d39a +0, 76, 76, 1, 1566720, 0x40f7d39a +0, 77, 77, 1, 1566720, 0x40f7d39a +0, 78, 78, 1, 1566720, 0x40f7d39a +0, 79, 79, 1, 1566720, 0x40f7d39a +0, 80, 80, 1, 1566720, 0x40f7d39a +0, 81, 81, 1, 1566720, 0x40f7d39a +0, 82, 82, 1, 1566720, 0x40f7d39a +0, 83, 83, 1, 1566720, 0x40f7d39a +0, 84, 84, 1, 1566720, 0x40f7d39a +0, 85, 85, 1, 1566720, 0x40f7d39a 0, 86, 86, 1, 1566720, 0xa7d6e25f 0, 87, 87, 1, 1566720, 0xa7d6e25f 0, 88, 88, 1, 1566720, 0xa7d6e25f @@ -104,7 +103,6 @@ 0, 98, 98, 1, 1566720, 0xa7d6e25f 0, 99, 99, 1, 1566720, 0xa7d6e25f 0, 100, 100, 1, 1566720, 0xeaf8d207 -0, 101, 101, 1, 1566720, 0x6724983e 0, 102, 102, 1, 1566720, 0x0e95d209 0, 103, 103, 1, 1566720, 0x0e95d209 0, 104, 104, 1, 1566720, 0x0e95d209 @@ -121,6 +119,4 @@ 0, 115, 115, 1, 1566720, 0xfe83b964 0, 116, 116, 1, 1566720, 0xfe83b964 0, 117, 117, 1, 1566720, 0xfe83b964 -0, 118, 118, 1, 1566720, 0x25dc30a6 -0, 119, 119, 1, 1566720, 0x25dc30a6 -0, 120, 120, 1, 1566720, 0x25dc30a6 +0, 119, 119, 1, 1566720, 0xfe83b964 -- 2.30.2