History

Merge commit '2a6eaeaa85d17b27ee0dd449183ec197c35c9675'

* 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

Michael Niedermayer committed 13 years ago

Commit fe40a9f2 parents a4d3757 2a6eaea5 files · +69 −54Browse files

Unified · Split

5 files
  1. doc/APIchanges +4 −1
  2. libavcodec/pthread.c +4 −52
  3. libavutil/cpu.c +55 −0
  4. libavutil/cpu.h +5 −0
  5. libavutil/version.h +1 −1
doc/APIchanges+4−1
@@ -16,7 +16,10 @@ libavutil: 2012-10-22 · 15 unmodified lines
16API changes, most recent first:16API changes, most recent first:
17 17
18 18
192013-05-24 - xxxxxxx - lavc 55.7.0 - avcodec.h192013-05-24 - xxxxxxx - lavu 52.34.100 - cpu.h
20 Add av_cpu_count() function for getting the number of logical CPUs.
21
222013-05-24 - xxxxxxx - lavc 55.12.100 - avcodec.h
20 Add picture_structure to AVCodecParserContext.23 Add picture_structure to AVCodecParserContext.
21 24
222013-05-17 - xxxxxxx - lavu 52.33.100 - opt.h252013-05-17 - xxxxxxx - lavu 52.33.100 - opt.h
libavcodec/pthread.c+4−52
@@ -31,32 +31,12 @@ · 30 unmodified lines
31 31
32#include "config.h"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#include "avcodec.h"34#include "avcodec.h"
56#include "internal.h"35#include "internal.h"
57#include "thread.h"36#include "thread.h"
58#include "libavutil/avassert.h"37#include "libavutil/avassert.h"
59#include "libavutil/common.h"38#include "libavutil/common.h"
39#include "libavutil/cpu.h"
60 40
61#if HAVE_PTHREADS41#if HAVE_PTHREADS
62#include <pthread.h>42#include <pthread.h>
@@ -168,42 +148,13 @@ typedef struct FrameThreadContext { · 105 unmodified lines
168 148
169int ff_get_logical_cpus(AVCodecContext *avctx)149int ff_get_logical_cpus(AVCodecContext *avctx)
170{150{
171 int ret, nb_cpus = 1;151 int nb_cpus = av_cpu_count();
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
200 if (avctx->height)152 if (avctx->height)
201 nb_cpus = FFMIN(nb_cpus, (avctx->height+15)/16);153 nb_cpus = FFMIN(nb_cpus, (avctx->height+15)/16);
202 154
203 return nb_cpus;155 return nb_cpus;
204}156}
205 157
206
207static void* attribute_align_arg worker(void *v)158static void* attribute_align_arg worker(void *v)
208{159{
209 AVCodecContext *avctx = v;160 AVCodecContext *avctx = v;
@@ -843,9 +794,10 @@ static int frame_thread_init(AVCodecContext *avctx) · 633 unmodified lines
843 int i, err = 0;794 int i, err = 0;
844 795
845 if (!thread_count) {796 if (!thread_count) {
846 int nb_cpus = ff_get_logical_cpus(avctx);797 int nb_cpus = av_cpu_count();
847 if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) || avctx->debug_mv)798 if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) || avctx->debug_mv)
848 nb_cpus = 1;799 nb_cpus = 1;
800 av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus);
849 // use number of cores + 1 as thread count if there is more than one801 // use number of cores + 1 as thread count if there is more than one
850 if (nb_cpus > 1)802 if (nb_cpus > 1)
851 thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);803 thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
libavutil/cpu.c+55−0
@@ -20,6 +20,27 @@ · 19 unmodified lines
20#include "config.h"20#include "config.h"
21#include "opt.h"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
23static int flags, checked;44static int flags, checked;
24 45
25void av_force_cpu_flags(int arg){46void 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 return av_opt_eval_flags(&pclass, &cpuflags_opts[0], s, flags);195 return av_opt_eval_flags(&pclass, &cpuflags_opts[0], s, flags);
175}196}
197
198int 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#ifdef TEST231#ifdef TEST
177 232
178#include <stdio.h>233#include <stdio.h>
libavutil/cpu.h+5−0
@@ -100,6 +100,11 @@ int av_parse_cpu_flags(const char *s); · 99 unmodified lines
100 */100 */
101int av_parse_cpu_caps(unsigned *flags, const char *s);101int av_parse_cpu_caps(unsigned *flags, const char *s);
102 102
103/**
104 * @return the number of logical CPU cores present.
105 */
106int av_cpu_count(void);
107
103/* The following CPU-specific functions shall not be called directly. */108/* The following CPU-specific functions shall not be called directly. */
104int ff_get_cpu_flags_arm(void);109int ff_get_cpu_flags_arm(void);
105int ff_get_cpu_flags_ppc(void);110int ff_get_cpu_flags_ppc(void);
libavutil/version.h+1−1
@@ -75,7 +75,7 @@ · 74 unmodified lines
75 */75 */
76 76
77#define LIBAVUTIL_VERSION_MAJOR 5277#define LIBAVUTIL_VERSION_MAJOR 52
78#define LIBAVUTIL_VERSION_MINOR 3378#define LIBAVUTIL_VERSION_MINOR 34
79#define LIBAVUTIL_VERSION_MICRO 10079#define LIBAVUTIL_VERSION_MICRO 100
80 80
81#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \81#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t