]> granicus.if.org Git - libx264/commitdiff
Remove thread priority tweaking
authorHenrik Gramner <henrik@gramner.com>
Sun, 12 Dec 2021 22:15:51 +0000 (23:15 +0100)
committerHenrik Gramner <henrik@gramner.com>
Sun, 12 Dec 2021 22:24:11 +0000 (23:24 +0100)
Back in 2009 when this was added it improved scheduling of lookahead
threads on prevalent operating systems at the time.

According to more recent testing by Intel however, lowering thread
priorities does not improve performance on modern operating systems.
And more importantly, doing so on systems with heterogeneous CPU
topologies may actually result in a severe performance reduction.

Removing this code altogether eliminates the issue with performance
degradation on such systems, while having no noticeable impact on
regular systems with homogeneous CPU topologies.

common/osdep.h
common/threadpool.c
common/threadpool.h
encoder/encoder.c
input/thread.c

index 556bf5840acad4378605727ffb5f9e6912432e42..0f36545d359f6744f1a966776f47f89f77cb2746 100644 (file)
@@ -552,29 +552,4 @@ static ALWAYS_INLINE void x264_prefetch( void *p )
 #define x264_prefetch(x)
 #endif
 
-#if HAVE_POSIXTHREAD
-#if SYS_WINDOWS
-#define x264_lower_thread_priority(p)\
-{\
-    x264_pthread_t handle = pthread_self();\
-    struct sched_param sp;\
-    int policy = SCHED_OTHER;\
-    pthread_getschedparam( handle, &policy, &sp );\
-    sp.sched_priority -= p;\
-    pthread_setschedparam( handle, policy, &sp );\
-}
-#elif SYS_HAIKU
-#include <OS.h>
-#define x264_lower_thread_priority(p)\
-    { UNUSED status_t nice_ret = set_thread_priority( find_thread( NULL ), B_LOW_PRIORITY ); }
-#else
-#include <unistd.h>
-#define x264_lower_thread_priority(p) { UNUSED int nice_ret = nice(p); }
-#endif /* SYS_WINDOWS */
-#elif HAVE_WIN32THREAD
-#define x264_lower_thread_priority(p) SetThreadPriority( GetCurrentThread(), X264_MAX( -2, -p ) )
-#else
-#define x264_lower_thread_priority(p)
-#endif
-
 #endif /* X264_OSDEP_H */
index 599b03d40e50d2061100c5041e6d9fd4bbc974d3..6d4c182914c63ae2c6428fc5d937aaacfd8ef8e1 100644 (file)
@@ -37,8 +37,6 @@ struct x264_threadpool_t
     volatile int   exit;
     int            threads;
     x264_pthread_t *thread_handle;
-    void           (*init_func)(void *);
-    void           *init_arg;
 
     /* requires a synchronized list structure and associated methods,
        so use what is already implemented for frames */
@@ -49,9 +47,6 @@ struct x264_threadpool_t
 
 REALIGN_STACK static void *threadpool_thread( x264_threadpool_t *pool )
 {
-    if( pool->init_func )
-        pool->init_func( pool->init_arg );
-
     while( !pool->exit )
     {
         x264_threadpool_job_t *job = NULL;
@@ -72,8 +67,7 @@ REALIGN_STACK static void *threadpool_thread( x264_threadpool_t *pool )
     return NULL;
 }
 
-int x264_threadpool_init( x264_threadpool_t **p_pool, int threads,
-                          void (*init_func)(void *), void *init_arg )
+int x264_threadpool_init( x264_threadpool_t **p_pool, int threads )
 {
     if( threads <= 0 )
         return -1;
@@ -85,8 +79,6 @@ int x264_threadpool_init( x264_threadpool_t **p_pool, int threads,
     CHECKED_MALLOCZERO( pool, sizeof(x264_threadpool_t) );
     *p_pool = pool;
 
-    pool->init_func = init_func;
-    pool->init_arg  = init_arg;
     pool->threads   = threads;
 
     CHECKED_MALLOC( pool->thread_handle, pool->threads * sizeof(x264_pthread_t) );
index cbc4ef7835d40f500f9fb7c30254af5bf4efdf19..f7120e42d63f6c34cde077c1dc0e6f999e0f77d9 100644 (file)
@@ -30,8 +30,7 @@ typedef struct x264_threadpool_t x264_threadpool_t;
 
 #if HAVE_THREAD
 #define x264_threadpool_init x264_template(threadpool_init)
-X264_API int   x264_threadpool_init( x264_threadpool_t **p_pool, int threads,
-                                     void (*init_func)(void *), void *init_arg );
+X264_API int   x264_threadpool_init( x264_threadpool_t **p_pool, int threads );
 #define x264_threadpool_run x264_template(threadpool_run)
 X264_API void  x264_threadpool_run( x264_threadpool_t *pool, void *(*func)(void *), void *arg );
 #define x264_threadpool_wait x264_template(threadpool_wait)
@@ -39,7 +38,7 @@ X264_API void *x264_threadpool_wait( x264_threadpool_t *pool, void *arg );
 #define x264_threadpool_delete x264_template(threadpool_delete)
 X264_API void  x264_threadpool_delete( x264_threadpool_t *pool );
 #else
-#define x264_threadpool_init(p,t,f,a) -1
+#define x264_threadpool_init(p,t) -1
 #define x264_threadpool_run(p,f,a)
 #define x264_threadpool_wait(p,a)     NULL
 #define x264_threadpool_delete(p)
index d4ddfa0cd2bc1251d41a48197e1da84aadfe41a9..378bbc99be498568cf230a0691fdcc38e7ace0d4 100644 (file)
@@ -412,14 +412,6 @@ static int bitstream_check_buffer_filler( x264_t *h, int filler )
     return bitstream_check_buffer_internal( h, filler, 0, -1 );
 }
 
-#if HAVE_THREAD
-static void encoder_thread_init( x264_t *h )
-{
-    if( h->param.i_sync_lookahead )
-        x264_lower_thread_priority( 10 );
-}
-#endif
-
 /****************************************************************************
  *
  ****************************************************************************
@@ -1743,10 +1735,10 @@ x264_t *x264_encoder_open( x264_param_t *param, void *api )
     CHECKED_MALLOC( h->reconfig_h, sizeof(x264_t) );
 
     if( h->param.i_threads > 1 &&
-        x264_threadpool_init( &h->threadpool, h->param.i_threads, (void*)encoder_thread_init, h ) )
+        x264_threadpool_init( &h->threadpool, h->param.i_threads ) )
         goto fail;
     if( h->param.i_lookahead_threads > 1 &&
-        x264_threadpool_init( &h->lookaheadpool, h->param.i_lookahead_threads, NULL, NULL ) )
+        x264_threadpool_init( &h->lookaheadpool, h->param.i_lookahead_threads ) )
         goto fail;
 
 #if HAVE_OPENCL
index 0633d841ef846a39da6b66275d953bebc13089f0..0dda9702343764c5b226c63ea2c7408357ecaeb1 100644 (file)
@@ -63,7 +63,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
     h->next_args->status = 0;
     h->frame_total = info->num_frames;
 
-    if( x264_threadpool_init( &h->pool, 1, NULL, NULL ) )
+    if( x264_threadpool_init( &h->pool, 1 ) )
         return -1;
 
     *p_handle = h;