From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 86CA143539 for ; Thu, 16 Jun 2022 18:28:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B017D68B7D2; Thu, 16 Jun 2022 21:27:59 +0300 (EEST) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9701A68B5B7 for ; Thu, 16 Jun 2022 21:27:52 +0300 (EEST) Received: from localhost (213-47-68-29.cable.dynamic.surfer.at [213.47.68.29]) (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id DB3D2E0005 for ; Thu, 16 Jun 2022 18:27:50 +0000 (UTC) Date: Thu, 16 Jun 2022 20:27:49 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20220616182749.GP396728@pb2> References: <07b64fb90f72d9bc4b5aa154b715ae121f849c71.camel@acc.umu.se> MIME-Version: 1.0 In-Reply-To: <07b64fb90f72d9bc4b5aa154b715ae121f849c71.camel@acc.umu.se> Subject: Re: [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 Content-Type: multipart/mixed; boundary="===============6323975354141873525==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============6323975354141873525== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="90fWGTmSS3PqCuVl" Content-Disposition: inline --90fWGTmSS3PqCuVl Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 16, 2022 at 02:04:47PM +0200, Tomas H=E4rdin wrote: >=20 > 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(-) > be6eb9df96feec948b97acb76d2a9f7abc0cec52 0001-Make-execute-and-execute2-= return-FFMIN-of-thread-ret.patch > From 2895c86dd908f6ddf3562d81050c50ea697a0bad Mon Sep 17 00:00:00 2001 > From: =3D?UTF-8?q?Tomas=3D20H=3DC3=3DA4rdin?=3D > Date: Thu, 16 Jun 2022 12:16:44 +0200 > Subject: [PATCH] Make execute() and execute2() return FFMIN() of thread r= eturn > codes >=20 > At the moment only fic.c actually checks return code of execute() hence t= he change to its FATE reference [...] > 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; > =20 > struct AVSliceThread { > @@ -48,11 +49,11 @@ struct AVSliceThread { > int finished; > =20 > 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); > }; > =20 > -static int run_jobs(AVSliceThread *ctx) > +static int run_jobs(AVSliceThread *ctx, int *ret_out) > { > unsigned nb_jobs =3D ctx->nb_jobs; > unsigned nb_active_threads =3D ctx->nb_active_threads; > @@ -60,7 +61,8 @@ static int run_jobs(AVSliceThread *ctx) > unsigned current_job =3D first_job; > =20 > do { > - ctx->worker_func(ctx->priv, current_job, first_job, nb_jobs, nb_= active_threads); > + int ret =3D ctx->worker_func(ctx->priv, current_job, first_job, = nb_jobs, nb_active_threads); > + *ret_out =3D FFMIN(*ret_out, ret); > } while ((current_job =3D atomic_fetch_add_explicit(&ctx->current_jo= b, 1, memory_order_acq_rel)) < nb_jobs); > =20 > return current_job =3D=3D nb_jobs + nb_active_threads - 1; > @@ -84,7 +86,7 @@ static void *attribute_align_arg thread_worker(void *v) > return NULL; > } > =20 > - if (run_jobs(ctx)) { > + if (run_jobs(ctx, &w->ret)) { > pthread_mutex_lock(&ctx->done_mutex); > ctx->done =3D 1; > pthread_cond_signal(&ctx->done_cond); > @@ -94,8 +96,8 @@ static void *attribute_align_arg thread_worker(void *v) > } > =20 > 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, v= oid *priv, > return nb_threads; > } > =20 > -void avpriv_slicethread_execute(AVSliceThread *ctx, int nb_jobs, int exe= cute_main) > +int avpriv_slicethread_execute(AVSliceThread *ctx, int nb_jobs, int exec= ute_main) > { > - int nb_workers, i, is_last =3D 0; > + int nb_workers, i, is_last =3D 0, ret =3D 0; > =20 > av_assert0(nb_jobs > 0); > ctx->nb_jobs =3D nb_jobs; > @@ -180,14 +182,15 @@ void avpriv_slicethread_execute(AVSliceThread *ctx,= int nb_jobs, int execute_mai > WorkerContext *w =3D &ctx->workers[i]; > pthread_mutex_lock(&w->mutex); > w->done =3D 0; > + w->ret =3D 0; > pthread_cond_signal(&w->cond); > pthread_mutex_unlock(&w->mutex); > } > =20 > if (ctx->main_func && execute_main) > - ctx->main_func(ctx->priv); > + ret =3D ctx->main_func(ctx->priv); > else > - is_last =3D run_jobs(ctx); > + is_last =3D run_jobs(ctx, &ret); > =20 > 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 =3D 0; > pthread_mutex_unlock(&ctx->done_mutex); > } > + > + for (i =3D 0; i < nb_workers; i++) > + ret =3D FFMIN(ret, ctx->workers[i].ret); > + > + return ret; > } > =20 > void avpriv_slicethread_free(AVSliceThread **pctx) > @@ -236,8 +244,8 @@ void avpriv_slicethread_free(AVSliceThread **pctx) > #else /* HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS32THREADS */ > =20 > 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 =3D NULL; You forgot to update the fallback code when threads are disabled [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I know you won't believe me, but the highest form of Human Excellence is to question oneself and others. -- Socrates --90fWGTmSS3PqCuVl Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCYqt2IgAKCRBhHseHBAsP q9C2AJ0T8qJV2x//OOmSlPwfY4vI5UWWzQCfQt+LO3ImtWitXIRIUkLibIGkOpU= =/zf/ -----END PGP SIGNATURE----- --90fWGTmSS3PqCuVl-- --===============6323975354141873525== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". --===============6323975354141873525==--