[x264-devel] [Git][videolan/x264][master] Remove thread priority tweaking

Anton Mitrofanov (@BugMaster) gitlab at videolan.org
Thu Dec 30 19:52:07 UTC 2021



Anton Mitrofanov pushed to branch master at VideoLAN / x264


Commits:
8a43cc14 by Henrik Gramner at 2021-12-12T23:24:11+01:00
Remove thread priority tweaking

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.

- - - - -


5 changed files:

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


Changes:

=====================================
common/osdep.h
=====================================
@@ -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 */


=====================================
common/threadpool.c
=====================================
@@ -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) );


=====================================
common/threadpool.h
=====================================
@@ -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)


=====================================
encoder/encoder.c
=====================================
@@ -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


=====================================
input/thread.c
=====================================
@@ -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;



View it on GitLab: https://code.videolan.org/videolan/x264/-/commit/8a43cc145aa1b97705b18b2e8bc2260071eb3656

-- 
View it on GitLab: https://code.videolan.org/videolan/x264/-/commit/8a43cc145aa1b97705b18b2e8bc2260071eb3656
You're receiving this email because of your account on code.videolan.org.




More information about the x264-devel mailing list