From patchwork Tue Sep 20 17:50:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rcombs X-Patchwork-Id: 38110 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp2106178pzh; Tue, 20 Sep 2022 10:51:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5J65V0AegLxJRoQQSsq8VfxGL55pMjEB7t/IY9fDHY8bL7e+AbQGahj3BpSdqr1+DWYJ2p X-Received: by 2002:a05:6402:b6c:b0:44e:2faf:1ba4 with SMTP id cb12-20020a0564020b6c00b0044e2faf1ba4mr21319067edb.191.1663696271434; Tue, 20 Sep 2022 10:51:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663696271; cv=none; d=google.com; s=arc-20160816; b=OIJqrxLpvVx3j86RENLNKzKASuHzlnRtUOOFMconZbPk1Dnm86SVVLTm8CWRbjaESq b0QVC1rRTbl5tEaTRz+TPcyWPsJ54hfrnPp9lXlxULOmemKih2MFMDP4adkbSc7pZXDA TWRBRbd6B8lwQmZPYTVKesWyvEJ7IFMiWzvfkVeMHHQXp89c/TOnZozODqxC9peRtkO+ mxE+Kc0Wd3BwQOvpbGSN9URdLzJ5ExfIcTYs8f9PojRJKUO/u0hWiURf9Hz+2fY8fY3u XcyQg9BgNCBjBKyWHeAvyYqjE7EZ3yXmhQrr6tKSkNWY94VT+Xqz5ODggT1P4KHx+Su7 xKdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=Ooiiv/pOkYDuCWpKlCl4iR41HUicG7mmbpD6cgN74WM=; b=o1dLF1FSYsOM4YyNaB+miafMm96ywpwJknIQh6DDy+YPZO7AbIlrbmeIVDtXTj9bRg 041RY0lofjg3YCu+Mo/muBxJOaG3FTGG/DvmDCCmIyr6Csh73G7sx5oYIURq5DDnyHCL mLO2hTA0QXfwgekNLB7s6UzsP3J6zBcpJ8hjBHM0F48wmthlPt/JxxZ454N/z0qBDBkJ 2K6pnRL66xCYTJTXA96TqGmLyIzWbUYef/BPM3Ljj2fyKl0F0Mf+DLd1ddQ4P/Z5cbqr lfxU3pHOiyic0g0xXHQCgD45XrpWZGuzLQmSIceQi8kcNSFUlGKNFOWWEJnOlwQDbnbT hvng== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rcombs.me header.s=google header.b=PeTw9Mis; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=rcombs.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b10-20020a056402350a00b004513ce1a086si441580edd.56.2022.09.20.10.51.11; Tue, 20 Sep 2022 10:51:11 -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=@rcombs.me header.s=google header.b=PeTw9Mis; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=rcombs.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8A39768BA7C; Tue, 20 Sep 2022 20:50:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A0F5268BABD for ; Tue, 20 Sep 2022 20:50:38 +0300 (EEST) Received: by mail-qk1-f177.google.com with SMTP id d17so2153345qko.13 for ; Tue, 20 Sep 2022 10:50:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rcombs.me; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=tCHZ5zh2pPeCXefV9OI4IZxKh7RFdvEHBc9WplugToc=; b=PeTw9MisKbD1qYdGSJp5Y0nTrnvEuYuDBzjTkE3sxaWLiJh8/TDGvQDQlAgJijhzx4 hLWhv7rWdsio+fxCYcfXlny/MOs8LwQQ+j/hwYwXtKYRDBH4ir4TLT6LhzAiqrzO6lOP eo7yyxQaJ2T1K8VkglkUR+mwjmhpYueuNd7iZFKCnKiK9MlX84A1WVjDszwEQyzan1KJ RWt5qk7s6wkjQUubAcT24D80ow5eWWTW3x/lRxnIE4J2dr9rn/wcWbcEw28XBLTA4WkB /oK9Y6gX4xdKQ3PtFiEhSyX/MqwxQTQXr82Tx2eCQMCArk2vcB4ZeuuP9tW9Ce/CiBWb bWnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=tCHZ5zh2pPeCXefV9OI4IZxKh7RFdvEHBc9WplugToc=; b=sDkT419OZ1UvZc2UCMaiSQ8nllbiuDMbrn3m20PxulbF2X/vqDsm7fyAf3Cs41KusZ pFMymtxXZ270YLyJCiBvRSXWFrYbLCetjZt97w8hsvB95ophVDx11FZz0FhSjvn1X/ER rGCmD7+1ziXHm9Gh6DntOv+WSOVw27uLSAvaWtC/U9+bp2NeWylbli5IJyMoXvYrXt2z eQOhIVG3mYjb53/pCoE/97R2a77cd28vPKYdOEoJoEblfKeH6evTVea/Y1V6ghu/2G43 Es+IQ3fRjW8Zgjjf4i+uujPs2JjoJt4uQLJwwfyRWNwrndOe1BkQAsv9R2TzTbhwWg+m W5Gw== X-Gm-Message-State: ACrzQf2WRHzyqVsvG8tC9JOTOtjDAjNtD6W8g+VEzrtFyTi58qcGNcEI pAYQxHFNlz1XMJcSv4MCtO8gSfX08dgq X-Received: by 2002:a37:6409:0:b0:6cd:f0ff:31d with SMTP id y9-20020a376409000000b006cdf0ff031dmr17156307qkb.21.1663696236891; Tue, 20 Sep 2022 10:50:36 -0700 (PDT) Received: from rcombs-mbp.localdomain ([2601:243:2000:5ac:50a3:2f65:4798:4cad]) by smtp.gmail.com with ESMTPSA id o1-20020a05622a008100b003431446588fsm189017qtw.5.2022.09.20.10.50.35 for (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 20 Sep 2022 10:50:36 -0700 (PDT) From: rcombs To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Sep 2022 12:50:17 -0500 Message-Id: <20220920175021.60790-4-rcombs@rcombs.me> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220920175021.60790-1-rcombs@rcombs.me> References: <20220920175021.60790-1-rcombs@rcombs.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/7] lavfi: add jobs args 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: 5pIzcNG/TwOR 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 +#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