fix messages, fix task thread priority (above main thread), reduced stack size, minor speed-ups to task runner

This commit is contained in:
niels
2014-12-28 22:26:50 +01:00
parent 68905f13bc
commit 09ec52b853
10 changed files with 51 additions and 63 deletions

View File

@@ -303,13 +303,14 @@ static void display_if_writeable( gpointer a, gpointer b )
if( gdk_pixbuf_format_is_writable( data ))
*list = g_slist_prepend( *list, data );
gchar *name = gdk_pixbuf_format_get_name( data );
veejay_msg( VEEJAY_MSG_DEBUG, "\t%s", name);
if( name ) g_free(name);
}
void vj_picture_display_formats()
{
GSList *f = gdk_pixbuf_get_formats();
GSList *res = NULL;
veejay_msg(VEEJAY_MSG_DEBUG, "List of supported image formats:");
g_slist_foreach( f, display_if_writeable, &res);
g_slist_free( f );
@@ -341,7 +342,6 @@ void vj_picture_init( void *templ )
// cool stuff
#ifdef USE_GDK_PIXBUF
g_type_init();
veejay_msg(VEEJAY_MSG_DEBUG, "Using gdk pixbuf %s", gdk_pixbuf_version );
#endif
__initialized = 1;
}

View File

@@ -515,8 +515,7 @@ vj_decoder *_el_new_decoder( int id , int width, int height, float fps, int pixe
d->img->width = width;
int tc = 2 * task_num_cpus();
tc = ( tc < 8 ? 8: tc );
veejay_msg(VEEJAY_MSG_DEBUG,"Allowing %d decoding threads. ",
tc );
veejay_msg(VEEJAY_MSG_DEBUG,"Using %d FFmpeg decoder threads", tc );
d->context->thread_type = FF_THREAD_FRAME;
d->context->thread_count = tc;
#if LIBAVCODEC_BUILD > 5400
@@ -999,30 +998,24 @@ int open_video_file(char *filename, editlist * el, int preserve_pathname, int de
void vj_el_show_formats(void)
{
#ifdef SUPPORT_READ_DV2
veejay_msg(VEEJAY_MSG_INFO,
veejay_msg(VEEJAY_MSG_DEBUG,
"Video containers: AVI (up to 32gb), RAW DV and Quicktime");
#else
veejay_msg(VEEJAY_MSG_INFO,
veejay_msg(VEEJAY_MSG_DEBUG,
"Video containers: AVI (up to 32gb) and Quicktime");
#endif
veejay_msg(VEEJAY_MSG_INFO,
veejay_msg(VEEJAY_MSG_DEBUG,
"Video fourcc (preferred): mjpg, mjpb, mjpa, dv, dvsd,sp5x,dmb1,dvcp,dvhd, yv16,i420");
veejay_msg(VEEJAY_MSG_INFO,
veejay_msg(VEEJAY_MSG_DEBUG,
"Video codecs (preferred): YV16, I420, Motion Jpeg or Digital Video");
veejay_msg(VEEJAY_MSG_INFO,
veejay_msg(VEEJAY_MSG_DEBUG,
"If the video file is made up out of only I-frames (whole images), you can also decode:");
veejay_msg(VEEJAY_MSG_INFO,
veejay_msg(VEEJAY_MSG_DEBUG,
" mpg4,mp4v,svq3,svq1,rpza,hfyu,mp42,mpg43,davc,div3,x264,h264,avc1,m4s2,divx,xvid");
veejay_msg(VEEJAY_MSG_INFO,
"Use veejay's internal format YV16 to reduce CPU usage");
#ifdef USE_GDK_PIXBUF
veejay_msg(VEEJAY_MSG_INFO,
"Image types supported:");
vj_picture_display_formats();
#endif
}

View File

@@ -1477,7 +1477,7 @@ void* deal_with_livido( void *handle, const char *name )
veejay_msg(0, "Loading LiVIDO-%d plugin '%s' , %d IP, %d OP" , compiled_as, plugin_name, n_params, n_oparams );
veejay_msg(VEEJAY_MSG_DEBUG, "Loading LiVIDO-%d plugin '%s' , %d IP, %d OP" , compiled_as, plugin_name, n_params, n_oparams );
#ifdef STRICT_CHECKING
assert( plugin_name != NULL );

View File

@@ -423,7 +423,6 @@ static int scan_plugins()
int fd = open( path, O_RDONLY );
if( fd < 0 ) {
veejay_msg(0, "unable to open veejay plugin configuration file : $HOME/.veejay/plugins.cfg");
return 0;
}
@@ -541,8 +540,8 @@ int plug_sys_detect_plugins(void)
if(!scan_plugins())
{
veejay_msg(VEEJAY_MSG_ERROR,
"Cannot locate plugins in $HOME/.veejay/plugins.cfg" );
veejay_msg(VEEJAY_MSG_WARNING,
"No plugins found in $HOME/.veejay/plugins.cfg" );
return 0;
}

View File

@@ -699,7 +699,7 @@ void vj_effect_initialize(int width, int height, int full_range)
for( p = MAX_EFFECTS; p < p_stop; p ++ )
vj_effects[p] = plug_get_plugin( (p-MAX_EFFECTS) );
veejay_msg(VEEJAY_MSG_INFO, "Found %d effects", p_stop );
}
void vj_effect_free(vj_effect *ve) {

View File

@@ -2499,7 +2499,7 @@ static void veejay_schedule_fifo(veejay_t *info, int pid )
{
struct sched_param schp;
veejay_memset( &schp, 0, sizeof(schp));
schp.sched_priority = sched_get_priority_max( SCHED_FIFO );
schp.sched_priority = (int)( sched_get_priority_max( SCHED_FIFO ) * 0.85f);
if( sched_setscheduler( pid, SCHED_FIFO, &schp ) != 0 )
{
@@ -2512,7 +2512,7 @@ static void veejay_schedule_fifo(veejay_t *info, int pid )
else
{
veejay_msg(VEEJAY_MSG_INFO, "Using First-In-First-Out II scheduling for process %d", pid);
veejay_msg(VEEJAY_MSG_INFO, "\tPriority is set to %d (RT)", schp.sched_priority );
veejay_msg(VEEJAY_MSG_DEBUG, "Priority is set to %d (RT)", schp.sched_priority );
}
}
#include <bio2jack/bio2jack.h>
@@ -3309,7 +3309,7 @@ int veejay_main(veejay_t * info)
if( task_num_cpus() > 1 ) {
CPU_ZERO( &cpuset );
CPU_SET ( 1, &cpuset ); /* run on cpu 1 */
CPU_SET ( 0, &cpuset ); /* run on the first cpu */
int err = pthread_attr_init( &attr );
if( err == ENOMEM ) {

View File

@@ -600,7 +600,7 @@ static int check_command_line_options(int argc, char *argv[])
switch_jpeg )<=0)
{
vj_el_show_formats();
veejay_msg(VEEJAY_MSG_ERROR, "Unable to open video file(s), codec/format not supported)");
veejay_msg(VEEJAY_MSG_ERROR, "Unable to open video file(s)");
nerr++;
}
}

View File

@@ -366,10 +366,7 @@ void vj_event_vevo_dump(void)
void vj_event_vevo_free(void)
{
int i;
veejay_msg(VEEJAY_MSG_DEBUG, "Closing VIMS event system");
unsigned int i;
if( !index_map_)
return;

View File

@@ -283,12 +283,14 @@ int vj_sdl_init(int ncpu, vj_sdl * vjsdl, int scaled_width, int scaled_height, c
veejay_msg(VEEJAY_MSG_DEBUG, "Video output driver: SDL");
veejay_msg( (info->hw_available ? VEEJAY_MSG_DEBUG : VEEJAY_MSG_WARNING), " hw_surface = %s",
(info->hw_available ? "Yes" : "No"));
if( info->hw_available == 0 ) {
veejay_msg(VEEJAY_MSG_WARNING, "(SDL) Hardware surface not available");
}
veejay_msg(VEEJAY_MSG_DEBUG, " window manager = %s",
(info->wm_available ? "Yes" : "No" ));
veejay_msg((info->blit_hw ? VEEJAY_MSG_DEBUG : VEEJAY_MSG_WARNING), " BLIT acceleration: %s ",
( info->blit_hw ? "Yes" : "No" ) );
(info->wm_available ? "Yes" : "No" ));
if( info->blit_hw == 0 ) {
veejay_msg(VEEJAY_MSG_WARNING, "(SDL) No BLIT acceleration");
}
veejay_msg(VEEJAY_MSG_DEBUG, " Software surface: %s",
( info->blit_sw ? "Yes" : "No" ) );
veejay_msg(VEEJAY_MSG_DEBUG, " Preferred depth: %d bits/pixel", info->vfmt->BitsPerPixel);

View File

@@ -60,8 +60,8 @@ static vj_task_arg_t *vj_task_args[MAX_WORKERS];
//@ task
struct task
{
int task_id;
void *data;
int8_t task_id;
void *data;
performer_job_routine handler;
struct task *next;
};
@@ -74,7 +74,7 @@ typedef struct {
//@ no dynamic, static allocation here.
static int total_tasks_ = 0;
static int tasks_done[MAX_WORKERS];
static uint8_t tasks_done[MAX_WORKERS];
static int tasks_todo = 0;
static int exitFlag = 0;
static pthread_mutex_t queue_mutex;
@@ -91,6 +91,8 @@ static int thr_id[MAX_WORKERS];
static pjob_t *job_list[MAX_WORKERS];
static int n_cpu = 1;
static struct task running_tasks[MAX_WORKERS];
#define __lock() pthread_mutex_lock(&queue_mutex)
#define __unlock() pthread_mutex_unlock(&queue_mutex)
@@ -99,37 +101,31 @@ int task_get_workers()
return numThreads;
}
static void task_add(int task_no, performer_job_routine fp , void *data)
static void task_add(uint8_t task_no, performer_job_routine fp , void *data)
{
struct task *enqueue_task = (struct task*) malloc( sizeof(struct task));
if(!enqueue_task) {
veejay_msg(0,"Failed to allocate memory for threaded task!");
return;
}
struct task *enqueue_task = &(running_tasks[task_no]);
enqueue_task->task_id = task_no;
enqueue_task->task_id = task_no;
enqueue_task->handler = fp;
enqueue_task->data = data;
enqueue_task->next = NULL;
enqueue_task->data = data;
enqueue_task->next = NULL;
if( total_tasks_ == 0 ) {
tasks_ = enqueue_task;
tail_task_ = tasks_;
tasks_ = enqueue_task;
tail_task_ = tasks_;
}
else {
tail_task_->next = enqueue_task;
tail_task_ = enqueue_task;
tail_task_->next= enqueue_task;
tail_task_ = enqueue_task;
}
total_tasks_ ++;
pthread_cond_signal( &current_task );
}
struct task *task_get()
{
// __lock();
struct task *t = NULL;
if( total_tasks_ > 0 ) {
t = tasks_;
@@ -141,7 +137,6 @@ struct task *task_get()
total_tasks_ --;
}
// __unlock();
return t;
}
@@ -177,14 +172,9 @@ void *task_thread(void *data)
t = task_get();
__unlock();
// __lock();
// t = task_get();
// __unlock();
if( t ) {
task_run( t, t->data, id );
free(t);
//free(t);
t = NULL;
}
}
@@ -215,6 +205,7 @@ void task_init()
memset( vj_task_args[i], 0, sizeof(vj_task_arg_t));
p_thread_args[i] = malloc( sizeof(int) );
memset( p_thread_args[i], 0, sizeof(int));
memset( &(running_tasks[i]), 0, sizeof(struct task));
}
n_cpu = sysconf( _SC_NPROCESSORS_ONLN );
@@ -263,16 +254,22 @@ int task_start(int max_workers)
for( i = 0 ; i < max_workers; i ++ ) {
thr_id[i] = i;
pthread_attr_init( &p_attr[i] );
pthread_attr_setstacksize( &p_attr[i], 256 * 1024 );
// pthread_attr_setstacksize( &p_attr[i], 256 * 1024 );
pthread_attr_setinheritsched( &p_attr[i], PTHREAD_EXPLICIT_SCHED );
pthread_attr_setschedpolicy( &p_attr[i], SCHED_FIFO );
pthread_attr_setschedparam( &p_attr[i], &param );
if( n_cpu > 1 ) {
int selected_cpu = ((i+1)%n_cpu);
CPU_ZERO(&cpuset);
CPU_SET( ((i+1) % n_cpu ), &cpuset );
CPU_SET( selected_cpu, &cpuset );
if(pthread_attr_setaffinity_np( &p_attr[i], sizeof(cpuset), &cpuset ) != 0 )
veejay_msg(0,"Unable to set CPU %d affinity to thread %d", ((i+1)%n_cpu),i);
else
veejay_msg(VEEJAY_MSG_DEBUG, "Task thread %d has CPU affinity %d",
i, selected_cpu );
}
*p_thread_args[i] = i;
@@ -322,7 +319,7 @@ void task_stop(int max_workers)
void performer_job( int n )
{
int i;
uint8_t i;
__lock();
tasks_todo = n;
veejay_memset( tasks_done, 0, sizeof(tasks_done));
@@ -338,7 +335,7 @@ void performer_job( int n )
while(!stop) {
__lock();
int done = 0;
uint8_t done = 0;
for( i = 0 ; i < tasks_todo; i ++ ) {
done += tasks_done[i];
}