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 D005F44687 for ; Tue, 20 Sep 2022 17:50:52 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7186768BB1A; Tue, 20 Sep 2022 20:50:44 +0300 (EEST) Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5FAE368B5F7 for ; Tue, 20 Sep 2022 20:50:36 +0300 (EEST) Received: by mail-qt1-f170.google.com with SMTP id g12so2300555qts.1 for ; Tue, 20 Sep 2022 10:50:36 -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=tTJVW/PTISN1fQYUZEQbfb6zYj39dW8NS5aUfQT0xww=; b=XYALwrgOXOE3Xe+MbDY0yd03EHm+dYJ+NDV/xhqyhBP9/WNbDBaSJ+LBqoFv62qDRn tt1NbH/IiwTqNV36tlv6xff8FP8hUeSIsDZi3nhE30DBexqfkKc/oecZI5CYBJEVCmNm fNLBmntvvyPUlEXNTQYQLhmRyrl2ZTQGk+TYxTwOWU7rxQDlHcO31+KPEGgL7cWGB+K0 SM24IP+55VX6WjrUF5Q9QGovuecLgMC3D3FY3P2LtufjTnUgsn51WlBcdin5JXn/XxsX A1hMqLD1sXPEyyYOkutJyzn1G7Vg+C0KaZRSzrJvbxoR4TcOX8yEd5zWokYdhMdRnPbi e9yg== 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=tTJVW/PTISN1fQYUZEQbfb6zYj39dW8NS5aUfQT0xww=; b=DMxOEXo/d7qY8/ywfVDTUhaa8fhA2HZmr86I2y0q6ti6vgVW8roRAOAM8PiWB/o1Rg mxO9yP58QkMid3BTSNrQuDoL9Bj8H53tksVaX2CbxfAy5lLGifKzbov+P7WMUV4b9Aqj CgTNQa+XPZx7A8f9p4uDg4xGQeCJyWcC63MpoxWMwOPwFTP4ZghQmjTUdomVNHqEwSYA XsODNK2VC+FYnTZY4Vt1Ygrtv6HmSYw6VgNi7yzWvC2DaZSl6b2pzhWnqnkfb/WL1xtG qe2/35NbRGtpd5wxDiXCNsQ1YIQsSfsu/od5tzcEN5MrN5YFV2hsSmokSrmxSBeVUF2b vRYA== X-Gm-Message-State: ACrzQf0LVXZV8KI3LWlF6EO8tZy3B7hQsyxVPdRSBphKy4+wl9rRcNXo 2GpkTK/wPRdzrUb4FAg0fGmJgefmOpbk X-Google-Smtp-Source: AMsMyM6HjohrISRxL4NjL+OkD1FtWhpMTwIqxzbF1Byu0/Ea5e08pcoTGFUdOLcIFQ7KkxMov617Sg== X-Received: by 2002:a05:622a:15ca:b0:35b:b99f:2e34 with SMTP id d10-20020a05622a15ca00b0035bb99f2e34mr20000463qty.506.1663696234417; Tue, 20 Sep 2022 10:50:34 -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.33 for (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 20 Sep 2022 10:50:33 -0700 (PDT) From: rcombs To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Sep 2022 12:50:15 -0500 Message-Id: <20220920175021.60790-2-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 1/7] lavu/cpu: add av_cpu_job_count() 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: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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".