From: rcombs <rcombs@rcombs.me> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 1/7] lavu/cpu: add av_cpu_job_count() Date: Tue, 20 Sep 2022 12:50:15 -0500 Message-ID: <20220920175021.60790-2-rcombs@rcombs.me> (raw) In-Reply-To: <20220920175021.60790-1-rcombs@rcombs.me> This estimates an appropriate number of jobs for a task to be broken up into. This may be higher than the core count in a heterogeneous system. Currently implemented only on Apple platforms; otherwise, we assume homogeneity. --- doc/APIchanges | 3 +++ libavutil/cpu.c | 37 +++++++++++++++++++++++++++++++++++++ libavutil/cpu.h | 11 +++++++++++ libavutil/version.h | 4 ++-- 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 729f56be7b..6059b495dd 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,9 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-09-20 - xxxxxxxxxx - lavu 57.37.100 - cpu.h + Add av_cpu_job_count() and av_cpu_force_job_count(). + 2022-09-03 - xxxxxxxxxx - lavu 57.36.100 - pixfmt.h Add AV_PIX_FMT_P012, AV_PIX_FMT_Y212, AV_PIX_FMT_XV30, AV_PIX_FMT_XV36 diff --git a/libavutil/cpu.c b/libavutil/cpu.c index 0035e927a5..b846a4a2d5 100644 --- a/libavutil/cpu.c +++ b/libavutil/cpu.c @@ -51,6 +51,7 @@ static atomic_int cpu_flags = ATOMIC_VAR_INIT(-1); static atomic_int cpu_count = ATOMIC_VAR_INIT(-1); +static atomic_int job_count = ATOMIC_VAR_INIT(-1); static int get_cpu_flags(void) { @@ -251,6 +252,42 @@ void av_cpu_force_count(int count) atomic_store_explicit(&cpu_count, count, memory_order_relaxed); } +int av_cpu_job_count(void) +{ + static atomic_int printed = ATOMIC_VAR_INIT(0); + int loaded = 0; + + int jobs = av_cpu_count(); + +#if __APPLE__ + int nperflevels = 1; + size_t len = sizeof(nperflevels); + + if (sysctlbyname("hw.nperflevels", &nperflevels, &len, NULL, 0) == -1) + nperflevels = 1; + + if (nperflevels > 1) + jobs *= 3; +#endif + + if (!atomic_exchange_explicit(&printed, 1, memory_order_relaxed)) + av_log(NULL, AV_LOG_DEBUG, "computed default job factor of %d\n", jobs); + + loaded = atomic_load_explicit(&job_count, memory_order_relaxed); + + if (loaded > 0) { + jobs = loaded; + av_log(NULL, AV_LOG_DEBUG, "overriding to job factor of %d\n", jobs); + } + + return jobs; +} + +void av_cpu_force_job_count(int factor) +{ + atomic_store_explicit(&job_count, factor, memory_order_relaxed); +} + size_t av_cpu_max_align(void) { #if ARCH_MIPS diff --git a/libavutil/cpu.h b/libavutil/cpu.h index 9711e574c5..20f037afe1 100644 --- a/libavutil/cpu.h +++ b/libavutil/cpu.h @@ -110,6 +110,17 @@ int av_cpu_count(void); */ void av_cpu_force_count(int count); +/** + * @return an estimated optimal maximum number of jobs for tasks to be sliced into. + */ +int av_cpu_job_count(void); + +/** + * Overrides job count computation and forces the specified count. + * Count < 1 disables forcing of specific count. + */ +void av_cpu_force_job_count(int count); + /** * Get the maximum data alignment that may be required by FFmpeg. * diff --git a/libavutil/version.h b/libavutil/version.h index 0585fa7b80..9c44cef6aa 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,8 +79,8 @@ */ #define LIBAVUTIL_VERSION_MAJOR 57 -#define LIBAVUTIL_VERSION_MINOR 36 -#define LIBAVUTIL_VERSION_MICRO 102 +#define LIBAVUTIL_VERSION_MINOR 37 +#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \ -- 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:50 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 ` rcombs [this message] 2022-09-22 13:49 ` [FFmpeg-devel] [PATCH 1/7] lavu/cpu: add av_cpu_job_count() 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 ` [FFmpeg-devel] [PATCH 3/7] lavfi: add jobs args rcombs 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-2-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