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
1616 API changes, most recent first:
1717
1818
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
2023 Add picture_structure to AVCodecParserContext.
2124
2225 2013-05-17 - xxxxxxx - lavu 52.33.100 - opt.h
libavcodec/pthread.c+4−52
@@ -31,32 +31,12 @@ · 30 unmodified lines
3131
3232 #include "config.h"
3333
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−
5534 #include "avcodec.h"
5635 #include "internal.h"
5736 #include "thread.h"
5837 #include "libavutil/avassert.h"
5938 #include "libavutil/common.h"
39+#include "libavutil/cpu.h"
6040
6141 #if HAVE_PTHREADS
6242 #include <pthread.h>
@@ -168,42 +148,13 @@ typedef struct FrameThreadContext { · 105 unmodified lines
168148
169149 int ff_get_logical_cpus(AVCodecContext *avctx)
170150 {
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();
200152 if (avctx->height)
201153 nb_cpus = FFMIN(nb_cpus, (avctx->height+15)/16);
202154
203155 return nb_cpus;
204156 }
205157
206−
207158 static void* attribute_align_arg worker(void *v)
208159 {
209160 AVCodecContext *avctx = v;
@@ -843,9 +794,10 @@ static int frame_thread_init(AVCodecContext *avctx) · 633 unmodified lines
843794 int i, err = 0;
844795
845796 if (!thread_count) {
846− int nb_cpus = ff_get_logical_cpus(avctx);
797+ int nb_cpus = av_cpu_count();
847798 if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) || avctx->debug_mv)
848799 nb_cpus = 1;
800+ av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus);
849801 // use number of cores + 1 as thread count if there is more than one
850802 if (nb_cpus > 1)
851803 thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
libavutil/cpu.c+55−0
@@ -20,6 +20,27 @@ · 19 unmodified lines
2020 #include "config.h"
2121 #include "opt.h"
2222
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+
2344 static int flags, checked;
2445
2546 void av_force_cpu_flags(int arg){
@@ -173,6 +194,40 @@ int av_parse_cpu_caps(unsigned *flags, const char *s) · 147 unmodified lines
173194
174195 return av_opt_eval_flags(&pclass, &cpuflags_opts[0], s, flags);
175196 }
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+
176231 #ifdef TEST
177232
178233 #include <stdio.h>
libavutil/cpu.h+5−0
@@ -100,6 +100,11 @@ int av_parse_cpu_flags(const char *s); · 99 unmodified lines
100100 */
101101 int av_parse_cpu_caps(unsigned *flags, const char *s);
102102
103+/**
104+ * @return the number of logical CPU cores present.
105+ */
106+int av_cpu_count(void);
107+
103108 /* The following CPU-specific functions shall not be called directly. */
104109 int ff_get_cpu_flags_arm(void);
105110 int ff_get_cpu_flags_ppc(void);
libavutil/version.h+1−1
@@ -75,7 +75,7 @@ · 74 unmodified lines
7575 */
7676
7777 #define LIBAVUTIL_VERSION_MAJOR 52
78−#define LIBAVUTIL_VERSION_MINOR 33
78+#define LIBAVUTIL_VERSION_MINOR 34
7979 #define LIBAVUTIL_VERSION_MICRO 100
8080
8181 #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