* commit '2a6eaeaa85d17b27ee0dd449183ec197c35c9675': Move get_logical_cpus() from lavc/pthread to lavu/cpu. Conflicts: doc/APIchanges libavcodec/pthread.c libavutil/cpu.c libavutil/cpu.h libavutil/version.h
Unified · Split
| @@ -16,7 +16,10 @@ libavutil: 2012-10-22 · 15 unmodified lines | ||
| 16 | 16 | API changes, most recent first: |
| 17 | 17 | |
| 18 | 18 | |
| 19 | −2013-05-24 - xxxxxxx - lavc 55.7.0 - avcodec.h | |
| 19 | +2013-05-24 - xxxxxxx - lavu 52.34.100 - cpu.h | |
| 20 | + Add av_cpu_count() function for getting the number of logical CPUs. | |
| 21 | + | |
| 22 | +2013-05-24 - xxxxxxx - lavc 55.12.100 - avcodec.h | |
| 20 | 23 | Add picture_structure to AVCodecParserContext. |
| 21 | 24 | |
| 22 | 25 | 2013-05-17 - xxxxxxx - lavu 52.33.100 - opt.h |
| @@ -31,32 +31,12 @@ · 30 unmodified lines | ||
| 31 | 31 | |
| 32 | 32 | #include "config.h" |
| 33 | 33 | |
| 34 | −#if HAVE_SCHED_GETAFFINITY | |
| 35 | −#ifndef _GNU_SOURCE | |
| 36 | −# define _GNU_SOURCE | |
| 37 | −#endif | |
| 38 | −#include <sched.h> | |
| 39 | −#endif | |
| 40 | −#if HAVE_GETPROCESSAFFINITYMASK | |
| 41 | −#include <windows.h> | |
| 42 | −#endif | |
| 43 | −#if HAVE_SYSCTL | |
| 44 | −#if HAVE_SYS_PARAM_H | |
| 45 | −#include <sys/param.h> | |
| 46 | −#endif | |
| 47 | −#include <sys/types.h> | |
| 48 | −#include <sys/param.h> | |
| 49 | −#include <sys/sysctl.h> | |
| 50 | −#endif | |
| 51 | −#if HAVE_SYSCONF | |
| 52 | −#include <unistd.h> | |
| 53 | −#endif | |
| 54 | − | |
| 55 | 34 | #include "avcodec.h" |
| 56 | 35 | #include "internal.h" |
| 57 | 36 | #include "thread.h" |
| 58 | 37 | #include "libavutil/avassert.h" |
| 59 | 38 | #include "libavutil/common.h" |
| 39 | +#include "libavutil/cpu.h" | |
| 60 | 40 | |
| 61 | 41 | #if HAVE_PTHREADS |
| 62 | 42 | #include <pthread.h> |
| @@ -168,42 +148,13 @@ typedef struct FrameThreadContext { · 105 unmodified lines | ||
| 168 | 148 | |
| 169 | 149 | int ff_get_logical_cpus(AVCodecContext *avctx) |
| 170 | 150 | { |
| 171 | − int ret, nb_cpus = 1; | |
| 172 | −#if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT) | |
| 173 | − cpu_set_t cpuset; | |
| 174 | − | |
| 175 | − CPU_ZERO(&cpuset); | |
| 176 | − | |
| 177 | − ret = sched_getaffinity(0, sizeof(cpuset), &cpuset); | |
| 178 | − if (!ret) { | |
| 179 | − nb_cpus = CPU_COUNT(&cpuset); | |
| 180 | − } | |
| 181 | −#elif HAVE_GETPROCESSAFFINITYMASK | |
| 182 | − DWORD_PTR proc_aff, sys_aff; | |
| 183 | − ret = GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff); | |
| 184 | − if (ret) | |
| 185 | − nb_cpus = av_popcount64(proc_aff); | |
| 186 | −#elif HAVE_SYSCTL && defined(HW_NCPU) | |
| 187 | − int mib[2] = { CTL_HW, HW_NCPU }; | |
| 188 | − size_t len = sizeof(nb_cpus); | |
| 189 | − | |
| 190 | − ret = sysctl(mib, 2, &nb_cpus, &len, NULL, 0); | |
| 191 | − if (ret == -1) | |
| 192 | − nb_cpus = 0; | |
| 193 | −#elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN) | |
| 194 | − nb_cpus = sysconf(_SC_NPROC_ONLN); | |
| 195 | −#elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN) | |
| 196 | − nb_cpus = sysconf(_SC_NPROCESSORS_ONLN); | |
| 197 | −#endif | |
| 198 | − av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus); | |
| 199 | − | |
| 151 | + int nb_cpus = av_cpu_count(); | |
| 200 | 152 | if (avctx->height) |
| 201 | 153 | nb_cpus = FFMIN(nb_cpus, (avctx->height+15)/16); |
| 202 | 154 | |
| 203 | 155 | return nb_cpus; |
| 204 | 156 | } |
| 205 | 157 | |
| 206 | − | |
| 207 | 158 | static void* attribute_align_arg worker(void *v) |
| 208 | 159 | { |
| 209 | 160 | AVCodecContext *avctx = v; |
| @@ -843,9 +794,10 @@ static int frame_thread_init(AVCodecContext *avctx) · 633 unmodified lines | ||
| 843 | 794 | int i, err = 0; |
| 844 | 795 | |
| 845 | 796 | if (!thread_count) { |
| 846 | − int nb_cpus = ff_get_logical_cpus(avctx); | |
| 797 | + int nb_cpus = av_cpu_count(); | |
| 847 | 798 | if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) || avctx->debug_mv) |
| 848 | 799 | nb_cpus = 1; |
| 800 | + av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus); | |
| 849 | 801 | // use number of cores + 1 as thread count if there is more than one |
| 850 | 802 | if (nb_cpus > 1) |
| 851 | 803 | thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS); |
| @@ -20,6 +20,27 @@ · 19 unmodified lines | ||
| 20 | 20 | #include "config.h" |
| 21 | 21 | #include "opt.h" |
| 22 | 22 | |
| 23 | +#if HAVE_SCHED_GETAFFINITY | |
| 24 | +#ifndef _GNU_SOURCE | |
| 25 | +# define _GNU_SOURCE | |
| 26 | +#endif | |
| 27 | +#include <sched.h> | |
| 28 | +#endif | |
| 29 | +#if HAVE_GETPROCESSAFFINITYMASK | |
| 30 | +#include <windows.h> | |
| 31 | +#endif | |
| 32 | +#if HAVE_SYSCTL | |
| 33 | +#if HAVE_SYS_PARAM_H | |
| 34 | +#include <sys/param.h> | |
| 35 | +#endif | |
| 36 | +#include <sys/types.h> | |
| 37 | +#include <sys/param.h> | |
| 38 | +#include <sys/sysctl.h> | |
| 39 | +#endif | |
| 40 | +#if HAVE_SYSCONF | |
| 41 | +#include <unistd.h> | |
| 42 | +#endif | |
| 43 | + | |
| 23 | 44 | static int flags, checked; |
| 24 | 45 | |
| 25 | 46 | void av_force_cpu_flags(int arg){ |
| @@ -173,6 +194,40 @@ int av_parse_cpu_caps(unsigned *flags, const char *s) · 147 unmodified lines | ||
| 173 | 194 | |
| 174 | 195 | return av_opt_eval_flags(&pclass, &cpuflags_opts[0], s, flags); |
| 175 | 196 | } |
| 197 | + | |
| 198 | +int av_cpu_count(void) | |
| 199 | +{ | |
| 200 | + int ret, nb_cpus = 1; | |
| 201 | +#if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT) | |
| 202 | + cpu_set_t cpuset; | |
| 203 | + | |
| 204 | + CPU_ZERO(&cpuset); | |
| 205 | + | |
| 206 | + ret = sched_getaffinity(0, sizeof(cpuset), &cpuset); | |
| 207 | + if (!ret) { | |
| 208 | + nb_cpus = CPU_COUNT(&cpuset); | |
| 209 | + } | |
| 210 | +#elif HAVE_GETPROCESSAFFINITYMASK | |
| 211 | + DWORD_PTR proc_aff, sys_aff; | |
| 212 | + ret = GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff); | |
| 213 | + if (ret) | |
| 214 | + nb_cpus = av_popcount64(proc_aff); | |
| 215 | +#elif HAVE_SYSCTL && defined(HW_NCPU) | |
| 216 | + int mib[2] = { CTL_HW, HW_NCPU }; | |
| 217 | + size_t len = sizeof(nb_cpus); | |
| 218 | + | |
| 219 | + ret = sysctl(mib, 2, &nb_cpus, &len, NULL, 0); | |
| 220 | + if (ret == -1) | |
| 221 | + nb_cpus = 0; | |
| 222 | +#elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN) | |
| 223 | + nb_cpus = sysconf(_SC_NPROC_ONLN); | |
| 224 | +#elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN) | |
| 225 | + nb_cpus = sysconf(_SC_NPROCESSORS_ONLN); | |
| 226 | +#endif | |
| 227 | + | |
| 228 | + return nb_cpus; | |
| 229 | +} | |
| 230 | + | |
| 176 | 231 | #ifdef TEST |
| 177 | 232 | |
| 178 | 233 | #include <stdio.h> |
| @@ -100,6 +100,11 @@ int av_parse_cpu_flags(const char *s); · 99 unmodified lines | ||
| 100 | 100 | */ |
| 101 | 101 | int av_parse_cpu_caps(unsigned *flags, const char *s); |
| 102 | 102 | |
| 103 | +/** | |
| 104 | + * @return the number of logical CPU cores present. | |
| 105 | + */ | |
| 106 | +int av_cpu_count(void); | |
| 107 | + | |
| 103 | 108 | /* The following CPU-specific functions shall not be called directly. */ |
| 104 | 109 | int ff_get_cpu_flags_arm(void); |
| 105 | 110 | int ff_get_cpu_flags_ppc(void); |
| @@ -75,7 +75,7 @@ · 74 unmodified lines | ||
| 75 | 75 | */ |
| 76 | 76 | |
| 77 | 77 | #define LIBAVUTIL_VERSION_MAJOR 52 |
| 78 | −#define LIBAVUTIL_VERSION_MINOR 33 | |
| 78 | +#define LIBAVUTIL_VERSION_MINOR 34 | |
| 79 | 79 | #define LIBAVUTIL_VERSION_MICRO 100 |
| 80 | 80 | |
| 81 | 81 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |