History

plan 9: dirty multithreading (need to link with dav1d until this is moved somewhere else)

Sigrid Haflínudóttir committed 6 years agoplan9_0

Commit c097de81 parent ba694339 files · +152 −6Browse files

Unified · Split

9 files
  1. mkfile +1 −1
  2. plan9/pthread.h +75 −0
  3. plan9/sched.h +0 −0
  4. plan9/semaphore.h +50 −0
  5. plan9/vpx_config.h +13 −4
  6. vp8/common/generic/systemdependent.c +7 −1
  7. vp8/vp8_dx_iface.c +1 −0
  8. vpx_util/endian_inl.h +2 −0
  9. vpx_util/vpx_thread.h +3 −0
mkfile+1−1
@@ -60,7 +60,7 @@ OFILES=\ · 59 unmodified lines
60 detokenize.$O\60 detokenize.$O\
61# error_concealment.$O\61# error_concealment.$O\
62 onyxd_if.$O\62 onyxd_if.$O\
63# threading.$O\63 threading.$O\
64# vp8/encoder \64# vp8/encoder \
65 bitstream.$O\65 bitstream.$O\
66 boolhuff.$O\66 boolhuff.$O\
plan9/pthread.h+75−0
@@ -0,0 +1,75 @@
1#ifndef __pthread_h__
2#define __pthread_h__
3
4typedef struct pthread_t pthread_t;
5typedef struct pthread_cond_t pthread_cond_t;
6typedef struct pthread_once_t pthread_once_t;
7typedef struct pthread_mutex_t pthread_mutex_t;
8
9struct pthread_cond_t {
10 Rendez;
11 QLock lock;
12};
13
14struct pthread_once_t {
15 QLock;
16 int done;
17};
18
19struct pthread_mutex_t {
20 QLock;
21};
22
23#define PTHREAD_ONCE_INIT {0}
24
25struct pthread_t {
26 void *waitchan;
27 void *(*func)(void*);
28 void *arg;
29 int pid;
30};
31
32typedef struct {
33 unsigned stack_size;
34} pthread_attr_t;
35
36void dav1d_set_thread_name(const char *const name);
37int dav1d_pthread_join(pthread_t *thread, void **res);
38#define pthread_join(thread, res) dav1d_pthread_join(&(thread), res)
39
40static int pthread_attr_init(pthread_attr_t *const attr) {
41 attr->stack_size = 0;
42 return 0;
43}
44
45static int pthread_attr_destroy(pthread_attr_t *const attr) {
46 USED(attr);
47 return 0;
48}
49
50static int pthread_attr_setstacksize(pthread_attr_t *const attr,
51 const int stack_size)
52{
53 attr->stack_size = stack_size;
54 return 0;
55}
56
57static int
58pthread_mutex_trylock(pthread_mutex_t *const mutex)
59{
60 return canqlock(mutex) ? 0 : -1;
61}
62
63int pthread_mutex_init(pthread_mutex_t *const mutex, const void *const attr);
64int pthread_mutex_destroy(pthread_mutex_t *const mutex);
65int pthread_mutex_lock(pthread_mutex_t *const mutex);
66int pthread_mutex_unlock(pthread_mutex_t *const mutex);
67int pthread_cond_init(pthread_cond_t *const cond, const void *const attr);
68int pthread_cond_destroy(pthread_cond_t *const cond);
69int pthread_cond_wait(pthread_cond_t *const cond, pthread_mutex_t *const mutex);
70int pthread_cond_signal(pthread_cond_t *const cond);
71int pthread_cond_broadcast(pthread_cond_t *const cond);
72int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*func)(void*), void *arg);
73int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
74
75#endif
plan9/sched.h+0−0

Empty file added.

plan9/semaphore.h+50−0
@@ -0,0 +1,50 @@
1#ifndef __semaphore_h__
2#define __semaphore_h__
3
4typedef struct sem_t sem_t;
5
6struct sem_t {
7 Channel *c;
8};
9
10static int
11sem_post(sem_t *s)
12{
13 void *p;
14
15 if(s == nil || s->c == nil)
16 return -1;
17 nbrecv(s->c, &p);
18
19 return 0;
20}
21
22static int
23sem_wait(sem_t *s)
24{
25 void *p;
26
27 if(s == nil || s->c == nil)
28 return -1;
29 sendp(s->c, nil);
30
31 return 0;
32}
33
34static int
35sem_init(sem_t *s, int pshared, unsigned int value)
36{
37 s->c = chancreate(sizeof(void*), value);
38
39 return 0;
40}
41
42static int
43sem_destroy(sem_t *s)
44{
45 chanclose(s->c);
46
47 return 0;
48}
49
50#endif
plan9/vpx_config.h+13−4
@@ -11,6 +11,7 @@ · 10 unmodified lines
11 11
12#include <u.h>12#include <u.h>
13#include <libc.h>13#include <libc.h>
14#include <thread.h>
14#include </sys/include/stdio.h>15#include </sys/include/stdio.h>
15typedef u8int uint8_t;16typedef u8int uint8_t;
16typedef u16int uint16_t;17typedef u16int uint16_t;
@@ -59,6 +60,14 @@ int gettimeofday(struct timeval *, struct timezone *); · 42 unmodified lines
59double round(double);60double round(double);
60#define logf log61#define logf log
61 62
63#define sched_yield() yield()
64#define __atomic_load_n(p,o) *(p)
65#define __atomic_store_n(p,v,x) do { *(p) = (v); } while(0)
66#define __has_builtin(x) 1
67
68#define __ATOMIC_RELEASE 0
69#define __ATOMIC_ACQUIRE 1
70
62#define RESTRICT 71#define RESTRICT
63#define INLINE inline72#define INLINE inline
64#define VPX_ARCH_ARM 073#define VPX_ARCH_ARM 0
@@ -84,7 +93,7 @@ double round(double); · 19 unmodified lines
84#define HAVE_VSX 093#define HAVE_VSX 0
85#define HAVE_MMI 094#define HAVE_MMI 0
86#define HAVE_VPX_PORTS 095#define HAVE_VPX_PORTS 0
87#define HAVE_PTHREAD_H 096#define HAVE_PTHREAD_H 1
88#define HAVE_UNISTD_H 197#define HAVE_UNISTD_H 1
89#define CONFIG_DEPENDENCY_TRACKING 198#define CONFIG_DEPENDENCY_TRACKING 1
90#define CONFIG_EXTERNAL_BUILD 099#define CONFIG_EXTERNAL_BUILD 0
@@ -107,7 +116,7 @@ double round(double); · 16 unmodified lines
107#define CONFIG_RUNTIME_CPU_DETECT 1116#define CONFIG_RUNTIME_CPU_DETECT 1
108#define CONFIG_POSTPROC 0117#define CONFIG_POSTPROC 0
109#define CONFIG_VP9_POSTPROC 0118#define CONFIG_VP9_POSTPROC 0
110#define CONFIG_MULTITHREAD 0119#define CONFIG_MULTITHREAD 1
111#define CONFIG_INTERNAL_STATS 0120#define CONFIG_INTERNAL_STATS 0
112#define CONFIG_VP8_ENCODER 1121#define CONFIG_VP8_ENCODER 1
113#define CONFIG_VP8_DECODER 1122#define CONFIG_VP8_DECODER 1
@@ -122,12 +131,12 @@ double round(double); · 8 unmodified lines
122#define CONFIG_REALTIME_ONLY 0131#define CONFIG_REALTIME_ONLY 0
123#define CONFIG_ONTHEFLY_BITPACKING 0132#define CONFIG_ONTHEFLY_BITPACKING 0
124#define CONFIG_ERROR_CONCEALMENT 0133#define CONFIG_ERROR_CONCEALMENT 0
125#define CONFIG_SHARED 1134#define CONFIG_SHARED 0
126#define CONFIG_STATIC 1135#define CONFIG_STATIC 1
127#define CONFIG_SMALL 0136#define CONFIG_SMALL 0
128#define CONFIG_POSTPROC_VISUALIZER 0137#define CONFIG_POSTPROC_VISUALIZER 0
129#define CONFIG_OS_SUPPORT 1138#define CONFIG_OS_SUPPORT 1
130#define CONFIG_UNIT_TESTS 1139#define CONFIG_UNIT_TESTS 0
131#define CONFIG_WEBM_IO 0140#define CONFIG_WEBM_IO 0
132#define CONFIG_LIBYUV 0141#define CONFIG_LIBYUV 0
133#define CONFIG_DECODE_PERF_TESTS 0142#define CONFIG_DECODE_PERF_TESTS 0
vp8/common/generic/systemdependent.c+7−1
@@ -36,7 +36,7 @@ typedef void(WINAPI *PGNSI)(LPSYSTEM_INFO); · 35 unmodified lines
36#endif36#endif
37 37
38#if CONFIG_MULTITHREAD38#if CONFIG_MULTITHREAD
39static int get_cpu_count() {39static int get_cpu_count(void) {
40 int core_count = 16;40 int core_count = 16;
41 41
42#if HAVE_UNISTD_H && !defined(__OS2__)42#if HAVE_UNISTD_H && !defined(__OS2__)
@@ -79,6 +79,12 @@ static int get_cpu_count() { · 36 unmodified lines
79 if (status == PROC_ONLINE) core_count++;79 if (status == PROC_ONLINE) core_count++;
80 }80 }
81 }81 }
82#elif defined(__plan9__)
83 {
84 char *s = getenv("NPROC");
85 core_count = atoi(s ? s : "1");
86 fprint(2, "core count: %d\n", core_count);
87 }
82#else88#else
83/* other platforms */89/* other platforms */
84#endif90#endif
vp8/vp8_dx_iface.c+1−0
@@ -11,6 +11,7 @@ · 10 unmodified lines
11#include <assert.h>11#include <assert.h>
12#include <stdlib.h>12#include <stdlib.h>
13#include <string.h>13#include <string.h>
14#include "vpx_config.h"
14#include "./vp8_rtcd.h"15#include "./vp8_rtcd.h"
15#include "./vpx_dsp_rtcd.h"16#include "./vpx_dsp_rtcd.h"
16#include "./vpx_scale_rtcd.h"17#include "./vpx_scale_rtcd.h"
vpx_util/endian_inl.h+2−0
@@ -48,6 +48,7 @@ · 47 unmodified lines
48#define HToBE32(X) BSwap32(X)48#define HToBE32(X) BSwap32(X)
49#endif49#endif
50 50
51#ifndef __plan9__
51#if LOCAL_GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16)52#if LOCAL_GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16)
52#define HAVE_BUILTIN_BSWAP1653#define HAVE_BUILTIN_BSWAP16
53#endif54#endif
@@ -59,6 +60,7 @@ · 5 unmodified lines
59#if LOCAL_GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64)60#if LOCAL_GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64)
60#define HAVE_BUILTIN_BSWAP6461#define HAVE_BUILTIN_BSWAP64
61#endif62#endif
63#endif
62 64
63#if HAVE_MIPS32 && defined(__mips__) && !defined(__mips64) && \65#if HAVE_MIPS32 && defined(__mips__) && !defined(__mips64) && \
64 defined(__mips_isa_rev) && (__mips_isa_rev >= 2) && (__mips_isa_rev < 6)66 defined(__mips_isa_rev) && (__mips_isa_rev >= 2) && (__mips_isa_rev < 6)
vpx_util/vpx_thread.h+3−0
@@ -383,6 +383,7 @@ typedef int (*VPxWorkerHook)(void *, void *); · 382 unmodified lines
383 383
384// Platform-dependent implementation details for the worker.384// Platform-dependent implementation details for the worker.
385typedef struct VPxWorkerImpl VPxWorkerImpl;385typedef struct VPxWorkerImpl VPxWorkerImpl;
386#pragma incomplete VPxWorkerImpl
386 387
387// Synchronization object used to launch job in the worker thread388// Synchronization object used to launch job in the worker thread
388typedef struct {389typedef struct {
@@ -393,6 +394,7 @@ typedef struct { · 4 unmodified lines
393 void *data2; // second argument passed to 'hook'394 void *data2; // second argument passed to 'hook'
394 int had_error; // return value of the last call to 'hook'395 int had_error; // return value of the last call to 'hook'
395} VPxWorker;396} VPxWorker;
397#pragma incomplete VPxWorker
396 398
397// The interface for all thread-worker related functions. All these functions399// The interface for all thread-worker related functions. All these functions
398// must be implemented.400// must be implemented.
@@ -418,6 +420,7 @@ typedef struct { · 19 unmodified lines
418 // must call reset() again.420 // must call reset() again.
419 void (*end)(VPxWorker *const worker);421 void (*end)(VPxWorker *const worker);
420} VPxWorkerInterface;422} VPxWorkerInterface;
423#pragma incomplete VPxWorkerInterface
421 424
422// Install a new set of threading functions, overriding the defaults. This425// Install a new set of threading functions, overriding the defaults. This
423// should be done before any workers are started, i.e., before any encoding or426// should be done before any workers are started, i.e., before any encoding or

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