From: rcombs <rcombs@rcombs.me> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 3/7] lavfi: add jobs args Date: Tue, 20 Sep 2022 12:50:17 -0500 Message-ID: <20220920175021.60790-4-rcombs@rcombs.me> (raw) In-Reply-To: <20220920175021.60790-1-rcombs@rcombs.me> This allows tuning the number of tasks that frames are sliced into independently from the number of execution pool threads, which can improve performance significantly on asymmetric-multiprocessing systems. --- doc/APIchanges | 3 +++ libavfilter/avfilter.c | 9 +++++++++ libavfilter/avfilter.h | 14 ++++++++++++++ libavfilter/avfiltergraph.c | 4 ++++ libavfilter/internal.h | 6 ++++++ libavfilter/pthread.c | 5 +++++ libavfilter/version.h | 2 +- 7 files changed, 42 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 6059b495dd..ae8b0bf0b4 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,9 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-09-20 - xxxxxxxxxx - lavfi 8.50.100 - avfilter.h + Add AVFilterContext.nb_jobs and AVFilterGraph.nb_jobs. + 2022-09-20 - xxxxxxxxxx - lavu 57.37.100 - cpu.h Add av_cpu_job_count() and av_cpu_force_job_count(). diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index f34204e650..4e16e312c6 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -621,6 +621,8 @@ static const AVOption avfilter_options[] = { { "enable", "set enable expression", OFFSET(enable_str), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = TFLAGS }, { "threads", "Allowed number of threads", OFFSET(nb_threads), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, + { "jobs", "Allowed number of jobs", OFFSET(nb_jobs), AV_OPT_TYPE_INT, + { .i64 = 0 }, 0, INT_MAX, FLAGS }, { "extra_hw_frames", "Number of extra hardware frames to allocate for the user", OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS }, { NULL }, @@ -797,6 +799,13 @@ int ff_filter_get_nb_threads(AVFilterContext *ctx) return ctx->graph->nb_threads; } +int ff_filter_get_nb_jobs(AVFilterContext *ctx) +{ + if (ctx->nb_jobs > 0) + return FFMIN(ctx->nb_jobs, ctx->graph->nb_jobs); + return ctx->graph->nb_jobs; +} + static int process_options(AVFilterContext *ctx, AVDictionary **options, const char *args) { diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 2e8197c9a6..aadeadd41c 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -492,6 +492,13 @@ struct AVFilterContext { * configured. */ int extra_hw_frames; + + /** + * Max number of jobs allowed in this filter instance. + * If <= 0, its value is ignored. + * Overrides global number of jobs set per filter graph. + */ + int nb_jobs; }; /** @@ -935,6 +942,13 @@ typedef struct AVFilterGraph { int sink_links_count; unsigned disable_auto_convert; + + /** + * Maximum number of jobs used by filters in this graph. May be set by + * the caller before adding any filters to the filtergraph. Zero (the + * default) means that the number of jobs is determined automatically. + */ + int nb_jobs; } AVFilterGraph; /** diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 53f468494d..4aac62c6c3 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -51,6 +51,9 @@ static const AVOption filtergraph_options[] = { { "threads", "Maximum number of threads", OFFSET(nb_threads), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, F|V|A, "threads"}, {"auto", "autodetect a suitable number of threads to use", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, .flags = F|V|A, .unit = "threads"}, + { "jobs", "Maximum number of jobs", OFFSET(nb_jobs), AV_OPT_TYPE_INT, + { .i64 = 0 }, 0, INT_MAX, F|V|A, "jobs"}, + {"auto", "autodetect a suitable number of jobs to use", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, .flags = F|V|A, .unit = "jobs"}, {"scale_sws_opts" , "default scale filter options" , OFFSET(scale_sws_opts) , AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, F|V }, {"aresample_swr_opts" , "default aresample filter options" , OFFSET(aresample_swr_opts) , @@ -75,6 +78,7 @@ int ff_graph_thread_init(AVFilterGraph *graph) { graph->thread_type = 0; graph->nb_threads = 1; + graph->nb_jobs = 1; return 0; } #endif diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 0128820be0..be05e8550b 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -384,6 +384,12 @@ int ff_filter_graph_run_once(AVFilterGraph *graph); */ int ff_filter_get_nb_threads(AVFilterContext *ctx) av_pure; +/** + * Get number of jobs for current filter instance. + * This number is always same or less than graph->nb_jobs. + */ +int ff_filter_get_nb_jobs(AVFilterContext *ctx) av_pure; + /** * Generic processing of user supplied commands that are set * in the same way as the filter options. diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c index 1a063d3cc0..589e32e263 100644 --- a/libavfilter/pthread.c +++ b/libavfilter/pthread.c @@ -23,6 +23,7 @@ #include <stddef.h> +#include "libavutil/cpu.h" #include "libavutil/error.h" #include "libavutil/macros.h" #include "libavutil/mem.h" @@ -98,10 +99,14 @@ int ff_graph_thread_init(AVFilterGraph *graph) av_freep(&graph->internal->thread); graph->thread_type = 0; graph->nb_threads = 1; + graph->nb_jobs = 1; return (ret < 0) ? ret : 0; } graph->nb_threads = ret; + if (graph->nb_jobs < 1) + graph->nb_jobs = av_cpu_job_count(); + graph->internal->thread_execute = thread_execute; return 0; diff --git a/libavfilter/version.h b/libavfilter/version.h index 5aac9c513a..436c2b8b17 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -31,7 +31,7 @@ #include "version_major.h" -#define LIBAVFILTER_VERSION_MINOR 49 +#define LIBAVFILTER_VERSION_MINOR 50 #define LIBAVFILTER_VERSION_MICRO 100 -- 2.37.2 _______________________________________________ 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".
next prev parent reply other threads:[~2022-09-20 17:51 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-20 17:50 [FFmpeg-devel] [PATCH] lavfi: make job count configurable separately from thread count rcombs 2022-09-20 17:50 ` [FFmpeg-devel] [PATCH 1/7] lavu/cpu: add av_cpu_job_count() rcombs 2022-09-22 13:49 ` Anton Khirnov 2022-09-22 14:56 ` Ronald S. Bultje 2022-09-20 17:50 ` [FFmpeg-devel] [PATCH 2/7] sws: add jobs option, distinct from threads rcombs 2022-09-21 8:37 ` Michael Niedermayer 2022-09-21 9:04 ` Michael Niedermayer 2022-09-21 18:25 ` James Almer 2022-09-20 17:50 ` rcombs [this message] 2022-09-20 17:50 ` [FFmpeg-devel] [PATCH 4/7] ffmpeg: add filter_jobs and filter_complex_jobs args rcombs 2022-09-20 17:50 ` [FFmpeg-devel] [PATCH 5/7] ffplay: add filter_jobs arg rcombs 2022-09-20 17:50 ` [FFmpeg-devel] [PATCH 6/7] lavfi/vf_unsharp: use ff_filter_get_nb_jobs rcombs 2022-09-20 17:50 ` [FFmpeg-devel] [PATCH 7/7] lavfi/vf_scale: set sws job count using ff_filter_get_nb_jobs rcombs
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220920175021.60790-4-rcombs@rcombs.me \ --to=rcombs@rcombs.me \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git