Index: /branches/libfreebob-2.0/AUTHORS =================================================================== --- /branches/libfreebob-2.0/AUTHORS (revision 336) +++ /branches/libfreebob-2.0/AUTHORS (revision 341) @@ -1,3 +1,2 @@ -Pieter Palmers Daniel Wagner Pieter Palmers Index: /branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.cpp =================================================================== --- /branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.cpp (revision 309) +++ /branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.cpp (revision 341) @@ -57,26 +57,13 @@ } -// Intel recommends that a serializing instruction -// should be called before and after rdtsc. -// CPUID is a serializing instruction. -#define read_rdtsc(time) \ - __asm__ __volatile__( \ - "pushl %%ebx\n\t" \ - "cpuid\n\t" \ - "rdtsc\n\t" \ - "mov %%eax,(%0)\n\t" \ - "cpuid\n\t" \ - "popl %%ebx\n\t" \ - : /* no output */ \ - : "S"(&time) \ - : "eax", "ecx", "edx", "memory") - -static inline unsigned long debugGetCurrentUTime() { - unsigned retval; - read_rdtsc(retval); - return retval; -} - +// the IsoHandlerManager thread updates the handler caches +// it doesn't iterate them !!! bool IsoHandlerManager::Execute() +{ + updateCycleCounters(); + return true; +} + +bool IsoHandlerManager::iterate() { int err; @@ -84,9 +71,5 @@ debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "enter...\n"); - unsigned long tstamp=debugGetCurrentUTime(); - err = poll (m_poll_fds, m_poll_nfds, m_poll_timeout); - -// debugOutput(DEBUG_LEVEL_VERBOSE, "Poll took: %6d\n", debugGetCurrentUTime()-tstamp); if (err == -1) { @@ -111,16 +94,22 @@ assert(s); - unsigned int packetcount_prev=s->getPacketCount(); - - tstamp=debugGetCurrentUTime(); - s->iterate(); -/* debugOutput(DEBUG_LEVEL_VERBOSE, "Iterate %p: time: %6d | packets: %3d\n", - s, debugGetCurrentUTime()-tstamp, s->getPacketCount()-packetcount_prev - );*/ - } - } - return true; - + } + } + + return true; + +} + +// updates the internal cycle counter caches of the handlers +void IsoHandlerManager::updateCycleCounters() { + debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "enter...\n"); + + for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); + it != m_IsoHandlers.end(); + ++it ) + { + (*it)->updateCycleCounter(); + } } Index: /branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.cpp =================================================================== --- /branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.cpp (revision 312) +++ /branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.cpp (revision 341) @@ -150,6 +150,6 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); - // and the tread that runs the runner - m_streamingThread=new FreebobUtil::PosixThread(this, m_thread_realtime, m_thread_priority, PTHREAD_CANCEL_DEFERRED); + // the tread that runs the packet iterators + m_streamingThread=new FreebobUtil::PosixThread(this, m_thread_realtime, m_thread_priority+5, PTHREAD_CANCEL_DEFERRED); if(!m_streamingThread) { debugFatal("Could not create streaming thread\n"); @@ -166,6 +166,9 @@ m_isoManager->setVerboseLevel(getDebugLevel()); - if(!m_isoManager->Init()) { - debugFatal("Could not init IsoHandlerManager\n"); + // the tread that keeps the handler's cycle counters up to date + // NOTE: is lower priority nescessary? it can block + m_isoManagerThread=new FreebobUtil::PosixThread(m_isoManager, m_thread_realtime, m_thread_priority+6, PTHREAD_CANCEL_DEFERRED); + if(!m_isoManagerThread) { + debugFatal("Could not create iso manager thread\n"); return false; } @@ -225,16 +228,12 @@ bool xrun_has_occured=false; bool this_period_ready; - - unsigned long tstamp_enter=debugGetCurrentTSC(); - + // debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "------------- EXECUTE -----------\n"); - - if(!m_isoManager->Execute()) { - debugFatal("Could not execute isoManager\n"); + + if(!m_isoManager->iterate()) { + debugFatal("Could not iterate the isoManager\n"); return false; } - unsigned long tstamp_iso=debugGetCurrentTSC(); - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " RCV PROC: "); for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); @@ -266,6 +265,4 @@ } debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "\n"); - - unsigned long tstamp_periodcheck=debugGetCurrentTSC(); if(xrun_has_occured) { @@ -275,4 +272,5 @@ m_xrun_happened=true; sem_post(&m_period_semaphore); + return false; // stop thread } @@ -300,10 +298,4 @@ m_nbperiods++; } - - unsigned long tstamp_exit=debugGetCurrentTSC(); - -// debugOutput( DEBUG_LEVEL_VERBOSE, "EXECUTE TIME: ISO: %6d | PeriodCheck: %6d | FrameCounter: %6d \n", -// tstamp_iso-tstamp_enter, tstamp_periodcheck-tstamp_iso, tstamp_exit-tstamp_periodcheck -// ); return true; @@ -364,4 +356,7 @@ m_streamingThread->Start(); + // start the runner thread + m_isoManagerThread->Start(); + debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for all StreamProcessors to start running...\n"); // we have to wait until all streamprocessors indicate that they are running @@ -425,5 +420,5 @@ } - (*it)->reset(); + (*it)->reset(); if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) { @@ -441,5 +436,5 @@ } - (*it)->reset(); + (*it)->reset(); if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) { @@ -503,7 +498,8 @@ - debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping thread...\n"); + debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping threads...\n"); m_streamingThread->Stop(); + m_isoManagerThread->Stop(); debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping handlers...\n"); Index: /branches/libfreebob-2.0/src/libstreaming/IsoHandler.cpp =================================================================== --- /branches/libfreebob-2.0/src/libstreaming/IsoHandler.cpp (revision 309) +++ /branches/libfreebob-2.0/src/libstreaming/IsoHandler.cpp (revision 341) @@ -32,5 +32,5 @@ #include #include - +#include #include @@ -127,4 +127,7 @@ raw1394_set_bus_reset_handler(m_handle, busreset_handler); + // update the cycle counter value for initial value + updateCycleCounter(); + return true; } @@ -145,5 +148,16 @@ #define CSR_REGISTER_BASE 0xfffff0000000ULL +#define CYCLE_COUNTER_GET_SECS(x) (((x & 0xFE000000) >> 25)) +#define CYCLE_COUNTER_GET_CYCLES(x) (((x & 0x01FFF000) >> 12)) +#define CYCLE_COUNTER_GET_TICKS(x) (((x & 0x00000FFF))) +#define CYCLE_COUNTER_TO_TICKS(x) ((CYCLE_COUNTER_GET_SECS(x) * 24576000) +\ + (CYCLE_COUNTER_GET_CYCLES(x) * 3072) +\ + (CYCLE_COUNTER_GET_TICKS(x) )) + unsigned int IsoHandler::getCycleCounter() { + return m_cyclecounter; +} + +void IsoHandler::updateCycleCounter() { quadlet_t buf=0; @@ -153,8 +167,16 @@ raw1394_read(m_handle_util, raw1394_get_local_id(m_handle_util), CSR_REGISTER_BASE | CSR_CYCLE_TIME, 4, &buf); - - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Current timestamp: %08X = %u\n",buf, ntohl(buf)); - return ntohl(buf) & 0xFFFFFFFF; + m_cyclecounter= ntohl(buf) & 0xFFFFFFFF; + +// debugOutput(DEBUG_LEVEL_VERBOSE,"Updating timestamp: %08X (%2u sec + %2u cycles + %04u ticks)\n", +// m_cyclecounter, +// CYCLE_COUNTER_GET_SECS(m_cyclecounter), +// CYCLE_COUNTER_GET_CYCLES(m_cyclecounter), +// CYCLE_COUNTER_GET_TICKS(m_cyclecounter) +// ); + + + usleep(100); } Index: /branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.h =================================================================== --- /branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.h (revision 250) +++ /branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.h (revision 341) @@ -93,9 +93,16 @@ protected: + + // RunnableInterface interface bool Execute(); // note that this is called in we while(running) loop bool Init(); - + // iterate all handlers + bool iterate(); + + // updates the cycle counter caches of all handlers + void updateCycleCounters(); + // note: there is a disctinction between streams and handlers // because one handler can serve multiple streams (in case of Index: /branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.h =================================================================== --- /branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.h (revision 250) +++ /branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.h (revision 341) @@ -124,4 +124,5 @@ FreebobUtil::PosixThread *m_streamingThread; + FreebobUtil::PosixThread *m_isoManagerThread; unsigned int m_nbperiods; Index: /branches/libfreebob-2.0/src/libstreaming/IsoHandler.h =================================================================== --- /branches/libfreebob-2.0/src/libstreaming/IsoHandler.h (revision 309) +++ /branches/libfreebob-2.0/src/libstreaming/IsoHandler.h (revision 341) @@ -111,5 +111,12 @@ virtual bool prepare() = 0; + // get the most recent cycle counter value + // RT safe unsigned int getCycleCounter(); + + // update the cycle counter cache + // not RT safe + // the isohandlermanager is responsible for calling this! + void updateCycleCounter(); protected: @@ -120,4 +127,5 @@ unsigned int m_max_packet_size; int m_irq_interval; + unsigned int m_cyclecounter; int m_packetcount; Index: /branches/libfreebob-2.0/src/debugmodule/debugmodule.h =================================================================== --- /branches/libfreebob-2.0/src/debugmodule/debugmodule.h (revision 336) +++ /branches/libfreebob-2.0/src/debugmodule/debugmodule.h (revision 341) @@ -126,5 +126,5 @@ */ -#define DO_PREEMPTION_CHECKING +// #define DO_PREEMPTION_CHECKING #include @@ -132,7 +132,7 @@ #ifdef DO_PREEMPTION_CHECKING #define CHECK_PREEMPTION(onoff) \ - gettimeofday (1, (onoff)) + gettimeofday((struct timeval *)1, (struct timezone *)onoff) #else -#define CHECK_PREEMPTION(engine, onoff) +#define CHECK_PREEMPTION(onoff) #endif Index: /branches/libfreebob-2.0/src/bebob/bebob_functionblock.h =================================================================== --- /branches/libfreebob-2.0/src/bebob/bebob_functionblock.h (revision 336) +++ /branches/libfreebob-2.0/src/bebob/bebob_functionblock.h (revision 341) @@ -53,5 +53,5 @@ no_of_input_plugs_t nrOfInputPlugs, no_of_output_plugs_t nrOfOutputPlugs, - bool verbose ); + int verbose ); FunctionBlock( const FunctionBlock& rhs ); virtual ~FunctionBlock(); @@ -73,5 +73,5 @@ no_of_input_plugs_t m_nrOfInputPlugs; no_of_output_plugs_t m_nrOfOutputPlugs; - bool m_verbose; + int m_verbose; AvPlugVector m_plugs; @@ -93,5 +93,5 @@ no_of_input_plugs_t nrOfInputPlugs, no_of_output_plugs_t nrOfOutputPlugs, - bool verbose); + int verbose); FunctionBlockSelector( const FunctionBlockSelector& rhs ); virtual ~FunctionBlockSelector(); @@ -110,5 +110,5 @@ no_of_input_plugs_t nrOfInputPlugs, no_of_output_plugs_t nrOfOutputPlugs, - bool verbose); + int verbose); FunctionBlockFeature( const FunctionBlockFeature& rhs ); virtual ~FunctionBlockFeature(); @@ -127,5 +127,5 @@ no_of_input_plugs_t nrOfInputPlugs, no_of_output_plugs_t nrOfOutputPlugs, - bool verbose ); + int verbose ); FunctionBlockEnhancedMixer( const FunctionBlockEnhancedMixer& rhs ); virtual ~FunctionBlockEnhancedMixer(); @@ -144,5 +144,5 @@ no_of_input_plugs_t nrOfInputPlugs, no_of_output_plugs_t nrOfOutputPlugs, - bool verbose ); + int verbose ); FunctionBlockProcessing( const FunctionBlockProcessing& rhs ); virtual ~FunctionBlockProcessing(); @@ -161,5 +161,5 @@ no_of_input_plugs_t nrOfInputPlugs, no_of_output_plugs_t nrOfOutputPlugs, - bool verbose); + int verbose); FunctionBlockCodec( const FunctionBlockCodec& rhs ); virtual ~FunctionBlockCodec(); Index: /branches/libfreebob-2.0/src/bebob/bebob_avplug.cpp =================================================================== --- /branches/libfreebob-2.0/src/bebob/bebob_avplug.cpp (revision 336) +++ /branches/libfreebob-2.0/src/bebob/bebob_avplug.cpp (revision 341) @@ -57,7 +57,5 @@ , m_globalId( m_globalIdCounter++ ) { - if ( m_verboseLevel ) { - setDebugLevel( DEBUG_LEVEL_VERBOSE ); - } + setDebugLevel( m_verboseLevel ); debugOutput( DEBUG_LEVEL_VERBOSE, "nodeId = %d, subunitType = %d, " @@ -883,5 +881,5 @@ if ( plug ) { - debugOutput( DEBUG_LEVEL_NORMAL, + debugOutput( DEBUG_LEVEL_VERBOSE, "'(%d) %s' has a connection to '(%d) %s'\n", getGlobalId(), @@ -1315,5 +1313,5 @@ plugId = pUnitPlugAddress->m_plugId; - debugOutput( DEBUG_LEVEL_NORMAL, + debugOutput( DEBUG_LEVEL_VERBOSE, "'(%d) %s': Remote plug is a unit plug " "(%s, %s, %d)\n", @@ -1481,7 +1479,5 @@ : m_verboseLevel( verboseLevel ) { - if ( m_verboseLevel ) { - setDebugLevel( DEBUG_LEVEL_VERBOSE ); - } + setDebugLevel( m_verboseLevel ); } @@ -1489,7 +1485,5 @@ : m_verboseLevel( rhs.m_verboseLevel ) { - if ( m_verboseLevel ) { - setDebugLevel( DEBUG_LEVEL_VERBOSE ); - } + setDebugLevel( m_verboseLevel ); } Index: /branches/libfreebob-2.0/src/bebob/bebob_avdevice_subunit.cpp =================================================================== --- /branches/libfreebob-2.0/src/bebob/bebob_avdevice_subunit.cpp (revision 336) +++ /branches/libfreebob-2.0/src/bebob/bebob_avdevice_subunit.cpp (revision 341) @@ -44,7 +44,5 @@ , m_verboseLevel( verboseLevel ) { - if ( m_verboseLevel ) { - setDebugLevel( DEBUG_LEVEL_VERBOSE ); - } + setDebugLevel( m_verboseLevel ); } Index: /branches/libfreebob-2.0/src/bebob/bebob_functionblock.cpp =================================================================== --- /branches/libfreebob-2.0/src/bebob/bebob_functionblock.cpp (revision 336) +++ /branches/libfreebob-2.0/src/bebob/bebob_functionblock.cpp (revision 341) @@ -35,5 +35,5 @@ no_of_input_plugs_t nrOfInputPlugs, no_of_output_plugs_t nrOfOutputPlugs, - bool verbose ) + int verbose ) : m_subunit( &subunit ) , m_type( type ) @@ -44,7 +44,5 @@ , m_verbose( verbose ) { - if ( m_verbose ) { - setDebugLevel( DEBUG_LEVEL_VERBOSE ); - } + setDebugLevel( verbose ); } @@ -157,5 +155,5 @@ no_of_input_plugs_t nrOfInputPlugs, no_of_output_plugs_t nrOfOutputPlugs, - bool verbose ) + int verbose ) : FunctionBlock( subunit, eFBT_AudioSubunitSelector, @@ -192,5 +190,5 @@ no_of_input_plugs_t nrOfInputPlugs, no_of_output_plugs_t nrOfOutputPlugs, - bool verbose ) + int verbose ) : FunctionBlock( subunit, eFBT_AudioSubunitFeature, @@ -227,5 +225,5 @@ no_of_input_plugs_t nrOfInputPlugs, no_of_output_plugs_t nrOfOutputPlugs, - bool verbose ) + int verbose ) : FunctionBlock( subunit, eFBT_AudioSubunitProcessing, @@ -262,5 +260,5 @@ no_of_input_plugs_t nrOfInputPlugs, no_of_output_plugs_t nrOfOutputPlugs, - bool verbose ) + int verbose ) : FunctionBlock( subunit, eFBT_AudioSubunitProcessing, @@ -297,5 +295,5 @@ no_of_input_plugs_t nrOfInputPlugs, no_of_output_plugs_t nrOfOutputPlugs, - bool verbose ) + int verbose ) : FunctionBlock( subunit, eFBT_AudioSubunitCodec, Index: /branches/libfreebob-2.0/src/devicemanager.cpp =================================================================== --- /branches/libfreebob-2.0/src/devicemanager.cpp (revision 336) +++ /branches/libfreebob-2.0/src/devicemanager.cpp (revision 341) @@ -90,10 +90,7 @@ DeviceManager::discover( int verboseLevel ) { - switch ( verboseLevel ) { - case 3: - m_1394Service->setVerbose( true ); - case 1: - setDebugLevel( DEBUG_LEVEL_VERBOSE ); - } + + setDebugLevel( verboseLevel ); + m_1394Service->setVerbose( verboseLevel ); for ( IAvDeviceVectorIterator it = m_avDevices.begin(); Index: /branches/libfreebob-2.0/README =================================================================== --- /branches/libfreebob-2.0/README (revision 336) +++ /branches/libfreebob-2.0/README (revision 341) @@ -1,4 +1,4 @@ -FreeBoB version 1.0.0 -===================== +FreeBoB version 1.999.0 +======================= This project aims to provide a free driver implemenation for the BeBoB