Index: /trunk/libffado/src/libieee1394/CycleTimerHelper.cpp =================================================================== --- /trunk/libffado/src/libieee1394/CycleTimerHelper.cpp (revision 764) +++ /trunk/libffado/src/libieee1394/CycleTimerHelper.cpp (revision 767) @@ -32,4 +32,20 @@ #define DLL_COEFF_B (DLL_SQRT2 * DLL_OMEGA) #define DLL_COEFF_C (DLL_OMEGA * DLL_OMEGA) + +/* +#define ENTER_CRITICAL_SECTION { \ + if (pthread_mutex_trylock(&m_compute_vars_lock) == EBUSY) { \ + debugWarning(" (%p) lock clash\n", this); \ + ENTER_CRITICAL_SECTION; \ + } \ + } +*/ +#define ENTER_CRITICAL_SECTION { \ + ENTER_CRITICAL_SECTION; \ + } +#define EXIT_CRITICAL_SECTION { \ + EXIT_CRITICAL_SECTION; \ + } + IMPL_DEBUG_MODULE( CycleTimerHelper, CycleTimerHelper, DEBUG_LEVEL_NORMAL ); @@ -168,5 +184,5 @@ CycleTimerHelper::Execute() { - debugOutput( DEBUG_LEVEL_ULTRA_VERBOSE, "Execute %p...\n", this); + debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Execute %p...\n", this); uint32_t cycle_timer; uint64_t local_time; @@ -175,5 +191,5 @@ return false; } - debugOutput( DEBUG_LEVEL_ULTRA_VERBOSE, " read : CTR: %11lu, local: %17llu\n", + debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " read : CTR: %11lu, local: %17llu\n", cycle_timer, local_time); @@ -195,5 +211,5 @@ double diff = m_next_time_usecs - m_current_time_usecs; - debugOutput( DEBUG_LEVEL_ULTRA_VERBOSE, " usecs: local: %11llu current: %f next: %f, diff: %f\n", + debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " usecs: local: %11llu current: %f next: %f, diff: %f\n", local_time, m_current_time_usecs, m_next_time_usecs, diff); @@ -204,5 +220,5 @@ m_current_time_usecs = m_next_time_usecs; m_next_time_usecs = (local_time - usecs_late) + m_usecs_per_update; - debugOutput( DEBUG_LEVEL_ULTRA_VERBOSE, " usecs: current: %f next: %f usecs_late=%f\n", + debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " usecs: current: %f next: %f usecs_late=%f\n", m_current_time_usecs, m_next_time_usecs, usecs_late); @@ -213,8 +229,8 @@ (uint64_t)((DLL_COEFF_B * diff_ticks) + m_dll_e2)); m_dll_e2 += DLL_COEFF_C * diff_ticks; - debugOutput( DEBUG_LEVEL_ULTRA_VERBOSE, " ticks: current: %f next: %f diff=%f\n", + debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " ticks: current: %f next: %f diff=%f\n", m_current_time_ticks, m_next_time_ticks, diff_ticks); - debugOutput( DEBUG_LEVEL_ULTRA_VERBOSE, " state: local: %11llu, dll_e2: %f, rate: %f\n", + debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " state: local: %11llu, dll_e2: %f, rate: %f\n", local_time, m_dll_e2, getRate()); } @@ -224,9 +240,9 @@ // FIXME: priority inversion! - pthread_mutex_lock(&m_compute_vars_lock); + ENTER_CRITICAL_SECTION; m_current_vars.ticks = m_current_time_ticks; m_current_vars.usecs = m_current_time_usecs; m_current_vars.rate = getRate(); - pthread_mutex_unlock(&m_compute_vars_lock); + EXIT_CRITICAL_SECTION; // wait for the next update period @@ -235,5 +251,5 @@ //int64_t time_to_sleep = m_usecs_per_update; if (time_to_sleep > 0) { - debugOutput( DEBUG_LEVEL_ULTRA_VERBOSE, " sleeping %lld usecs (avg delay: %f)\n", time_to_sleep, m_avg_wakeup_delay); + debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " sleeping %lld usecs (avg delay: %f)\n", time_to_sleep, m_avg_wakeup_delay); usleep(time_to_sleep); } @@ -255,7 +271,7 @@ // reduce lock contention - pthread_mutex_lock(&m_compute_vars_lock); + ENTER_CRITICAL_SECTION; my_vars = m_current_vars; - pthread_mutex_unlock(&m_compute_vars_lock); + EXIT_CRITICAL_SECTION; double time_diff = now - my_vars.usecs; @@ -266,9 +282,12 @@ if (y_step_in_ticks_int > 0) { retval = addTicks(offset_in_ticks_int, y_step_in_ticks_int); + debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "y_step_in_ticks_int > 0: %lld, time_diff: %f, rate: %f, retval: %lu\n", + y_step_in_ticks_int, time_diff, my_vars.rate, retval); } else { + retval = substractTicks(offset_in_ticks_int, -y_step_in_ticks_int); + // this can happen if the update thread was woken up earlier than it should have been - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "y_step_in_ticks_int <= 0: %lld, time_diff: %f, rate: %f\n", - y_step_in_ticks_int, time_diff, my_vars.rate); - retval = substractTicks(offset_in_ticks_int, -y_step_in_ticks_int); + debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "y_step_in_ticks_int <= 0: %lld, time_diff: %f, rate: %f, retval: %lu\n", + y_step_in_ticks_int, time_diff, my_vars.rate, retval); } Index: /trunk/libffado/src/libieee1394/IsoHandlerManager.cpp =================================================================== --- /trunk/libffado/src/libieee1394/IsoHandlerManager.cpp (revision 759) +++ /trunk/libffado/src/libieee1394/IsoHandlerManager.cpp (revision 767) @@ -356,5 +356,5 @@ if(irq_interval <= 0) irq_interval=1; // FIXME: test - //irq_interval=1; + irq_interval=1; #else @@ -440,5 +440,5 @@ debugError("Max packet size too large! (%d)\n", stream->getMaxPacketSize()); } - + irq_interval=2; #endif // the SP specifies how many packets to buffer Index: /trunk/libffado/src/libieee1394/IsoHandlerManager.h =================================================================== --- /trunk/libffado/src/libieee1394/IsoHandlerManager.h (revision 760) +++ /trunk/libffado/src/libieee1394/IsoHandlerManager.h (revision 767) @@ -34,5 +34,5 @@ #include -//#define THREAD_PER_ISOHANDLER +// #define THREAD_PER_ISOHANDLER #define FFADO_MAX_ISO_HANDLERS_PER_PORT 16