diff options
author | johnallen <[email protected]> | 2007-01-08 03:18:40 +0000 |
---|---|---|
committer | johnallen <[email protected]> | 2007-01-08 03:18:40 +0000 |
commit | 18189c197f5d5e04e8e8cd37de0caedb1a469a38 (patch) | |
tree | b0fbfe562fd5d8c371033d316fe455eb89c3eb45 /libhb | |
parent | dc22ce2c46ee62a46963d92ccb4a7fc26bd21d26 (diff) |
added worker thread sleep throttling.
each of the work object threads now self adjust their sleep interval based on the "fullness" of their fifo.
80% is the choose threshold.
Work objects with a fifo fullness of greater than 80% increase their sleep interval.
This allows other work object with less than 80% fullness more CPU usage.
Also adjusted thread_func, reader, and muxer sleep intervals to more reasonable values.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@98 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/common.h | 1 | ||||
-rw-r--r-- | libhb/fifo.c | 11 | ||||
-rw-r--r-- | libhb/hb.c | 4 | ||||
-rw-r--r-- | libhb/internal.h | 1 | ||||
-rw-r--r-- | libhb/muxcommon.c | 14 | ||||
-rw-r--r-- | libhb/reader.c | 3 | ||||
-rw-r--r-- | libhb/work.c | 19 |
7 files changed, 41 insertions, 12 deletions
diff --git a/libhb/common.h b/libhb/common.h index 0e53dde24..859711f81 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -352,6 +352,7 @@ struct hb_work_object_s volatile int * done; hb_work_object_t * next; + int thread_sleep_interval; #endif }; diff --git a/libhb/fifo.c b/libhb/fifo.c index acdb21188..93e3e162e 100644 --- a/libhb/fifo.c +++ b/libhb/fifo.c @@ -101,6 +101,17 @@ int hb_fifo_is_full( hb_fifo_t * f ) return ret; } +float hb_fifo_percent_full( hb_fifo_t * f ) +{ + float ret; + + hb_lock( f->lock ); + ret = f->size / f->capacity; + hb_unlock( f->lock ); + + return ret; +} + hb_buffer_t * hb_fifo_get( hb_fifo_t * f ) { hb_buffer_t * b; diff --git a/libhb/hb.c b/libhb/hb.c index 28f3245cb..977e3dc71 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -98,7 +98,7 @@ hb_handle_t * hb_init_real( int verbose, int update_check ) "update_thread" ); break; } - hb_snooze( 50 ); + hb_snooze( 500 ); } } @@ -664,7 +664,7 @@ static void thread_func( void * _h ) hb_unlock( h->state_lock ); } - hb_snooze( 50 ); + hb_snooze( 1000 ); } if( h->work_thread ) diff --git a/libhb/internal.h b/libhb/internal.h index e13008f9b..36ead1bf0 100644 --- a/libhb/internal.h +++ b/libhb/internal.h @@ -57,6 +57,7 @@ void hb_buffer_close( hb_buffer_t ** ); hb_fifo_t * hb_fifo_init(); int hb_fifo_size( hb_fifo_t * ); int hb_fifo_is_full( hb_fifo_t * ); +float hb_fifo_percent_full( hb_fifo_t * f ); hb_buffer_t * hb_fifo_get( hb_fifo_t * ); hb_buffer_t * hb_fifo_see( hb_fifo_t * ); hb_buffer_t * hb_fifo_see2( hb_fifo_t * ); diff --git a/libhb/muxcommon.c b/libhb/muxcommon.c index f1723ccf8..99fe6fc91 100644 --- a/libhb/muxcommon.c +++ b/libhb/muxcommon.c @@ -108,7 +108,7 @@ static void MuxerFunc( void * _mux ) break; } - hb_snooze( 50 ); + hb_snooze( 200 ); } /* Create file, write headers */ @@ -134,13 +134,21 @@ static void MuxerFunc( void * _mux ) hb_list_add( list, track ); } - while( !*job->die && !job->done ) + int thread_sleep_interval = 50; + while( !*job->die && !job->done ) { if( !( track = GetTrack( list ) ) ) { - hb_snooze( 50 ); + hb_snooze( thread_sleep_interval ); + thread_sleep_interval += 1; continue; } + thread_sleep_interval = MAX(1, (thread_sleep_interval - 1)); +#if 0 + if ((thread_sleep_interval <= 1) || (thread_sleep_interval > 100)) { + hb_log("%s: %d", "Muxer", thread_sleep_interval); + } +#endif buf = hb_fifo_get( track->fifo ); if( job->pass != 1 ) diff --git a/libhb/reader.c b/libhb/reader.c index ed4a675ff..47ec9d546 100644 --- a/libhb/reader.c +++ b/libhb/reader.c @@ -100,8 +100,7 @@ static void ReaderFunc( void * _r ) while( !*r->die && !r->job->done && hb_fifo_is_full( fifo ) ) { - hb_snooze( 1 ); - //hb_log("sleep: ReaderFunc"); + hb_snooze( 50 ); } hb_fifo_push( fifo, buf ); } diff --git a/libhb/work.c b/libhb/work.c index 38346f80a..d1f2aaf5c 100644 --- a/libhb/work.c +++ b/libhb/work.c @@ -40,7 +40,7 @@ hb_thread_t * hb_work_init( hb_list_t * jobs, int cpu_count, } /** - * Interates through job list and calls do_job for each job. + * Iterates through job list and calls do_job for each job. * @param _work Handle work object. */ static void work_func( void * _work ) @@ -247,6 +247,7 @@ static void do_job( hb_job_t * job, int cpu_count ) { w = hb_list_item( job->list_work, i ); w->done = &job->done; + w->thread_sleep_interval = 10; w->init( w, job ); w->thread = hb_thread_init( w->name, work_loop, w, HB_LOW_PRIORITY ); @@ -254,6 +255,7 @@ static void do_job( hb_job_t * job, int cpu_count ) done = 0; w = hb_list_item( job->list_work, 0 ); + w->thread_sleep_interval = 50; w->init( w, job ); while( !*job->die ) { @@ -268,7 +270,7 @@ static void do_job( hb_job_t * job, int cpu_count ) { break; } - hb_snooze( 50 ); + hb_snooze( w->thread_sleep_interval ); } hb_list_rem( job->list_work, w ); w->close( w ); @@ -325,13 +327,20 @@ static void work_loop( void * _w ) hb_lock( job->pause ); hb_unlock( job->pause ); #endif - if( hb_fifo_is_full( w->fifo_out ) || + //if( hb_fifo_is_full( w->fifo_out ) || + if( (hb_fifo_percent_full( w->fifo_out ) > 0.8) || !( buf_in = hb_fifo_get( w->fifo_in ) ) ) { - hb_snooze( 50 ); + hb_snooze( w->thread_sleep_interval ); + w->thread_sleep_interval += 1; continue; } - + w->thread_sleep_interval = MAX(1, (w->thread_sleep_interval - 1)); +#if 0 + if ((w->thread_sleep_interval <= 1) || (w->thread_sleep_interval > 100)) { + hb_log("%s: %d", w->name, w->thread_sleep_interval); + } +#endif w->work( w, &buf_in, &buf_out ); if( buf_in ) { |