Changeset 1344

Show
Ignore:
Timestamp:
09/24/08 07:26:29 (16 years ago)
Author:
ppalmers
Message:

switch back to a sleep based period signalling scheme to ensure proper wakeup timing

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/libffado-2.0/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.cpp

    r1136 r1344  
    3434#include "libutil/ByteSwap.h" 
    3535#include <assert.h> 
     36#include "libutil/SystemTimeSource.h" 
    3637 
    3738namespace Streaming { 
     
    6667} 
    6768 
     69unsigned int 
     70AmdtpReceiveStreamProcessor::getAveragePacketSize() 
     71{ 
     72    // in one second we have 8000 packets 
     73    // containing FRAMERATE frames of m_dimension quadlets 
     74    // so 8000 packet headers + FRAMERATE*m_dimension quadlets 
     75    unsigned int one_second = 8000 * 2 * sizeof(quadlet_t) + m_StreamProcessorManager.getNominalRate() * m_dimension * sizeof(quadlet_t); 
     76    return one_second / 8000; 
     77} 
     78 
    6879bool AmdtpReceiveStreamProcessor::prepareChild() { 
    6980    debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing (%p)...\n", this); 
     
    144155    // later than expected (the real receive time) 
    145156    #ifdef DEBUG 
     157    static int64_t last_t = Util::SystemTimeSource::getCurrentTime(); 
     158    int64_t now_t = Util::SystemTimeSource::getCurrentTime(); 
    146159    if(isRunning()) { 
    147160        debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, 
    148161                           "STMP: %lluticks | syt_interval=%d, tpf=%f\n", 
    149162                           m_last_timestamp, m_syt_interval, getTicksPerFrame()); 
    150     } 
     163/*        debugOutput(DEBUG_LEVEL_NORMAL, 
     164                           "STMP: %12llu ticks | delta_t: %5lld | bufferfill: %5d\n", 
     165                           m_last_timestamp, now_t-last_t, m_data_buffer->getBufferFill());*/ 
     166    } 
     167    last_t = now_t; 
    151168 
    152169    // check whether nevents is a multiple of 8. 
  • branches/libffado-2.0/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.h

    r1035 r1344  
    9090    virtual unsigned int getMaxPacketSize()  
    9191                    {return 4 * (2 + getSytInterval() * m_dimension);}; 
     92    virtual unsigned int getAveragePacketSize(); 
    9293    virtual unsigned int getEventsPerFrame()  
    9394                    { return m_dimension; }; 
  • branches/libffado-2.0/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp

    r1305 r1344  
    405405    } 
    406406} 
     407 
     408unsigned int 
     409AmdtpTransmitStreamProcessor::getAveragePacketSize() 
     410{ 
     411    // in one second we have 8000 packets 
     412    // containing FRAMERATE frames of m_dimension quadlets 
     413    // so 8000 packet headers + FRAMERATE*m_dimension quadlets 
     414    unsigned int one_second = 8000 * 2 * sizeof(quadlet_t) + m_StreamProcessorManager.getNominalRate() * m_dimension * sizeof(quadlet_t); 
     415    return one_second / 8000; 
     416} 
     417 
    407418unsigned int 
    408419AmdtpTransmitStreamProcessor::getFDF() { 
  • branches/libffado-2.0/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.h

    r1305 r1344  
    104104    virtual unsigned int getMaxPacketSize() 
    105105                    {return 4 * (2 + getSytInterval() * m_dimension);}; 
     106    virtual unsigned int getAveragePacketSize(); 
    106107    virtual unsigned int getEventsPerFrame() 
    107108                    { return m_dimension; }; 
  • branches/libffado-2.0/src/libstreaming/generic/StreamProcessor.cpp

    r1293 r1344  
    146146StreamProcessor::getNominalPacketsNeeded(unsigned int nframes) 
    147147{ 
    148     unsigned int nominal_frames_per_second  
     148    unsigned int nominal_frames_per_second 
    149149                    = m_StreamProcessorManager.getNominalRate(); 
    150150    uint64_t nominal_ticks_per_frame = TICKS_PER_SECOND / nominal_frames_per_second; 
    151151    uint64_t nominal_ticks = nominal_ticks_per_frame * nframes; 
    152     uint64_t nominal_packets = nominal_ticks / TICKS_PER_CYCLE; 
     152    // ensure proper ceiling 
     153    uint64_t nominal_packets = (nominal_ticks+TICKS_PER_CYCLE-1) / TICKS_PER_CYCLE; 
    153154    return nominal_packets; 
    154155} 
     
    508509            unsigned int bufferfill = m_data_buffer->getBufferFill(); 
    509510            if(bufferfill >= periodsize) { 
    510                 debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "signal activity, %d>%d\n", bufferfill, periodsize); 
    511                 SIGNAL_ACTIVITY_SPM; 
    512                 return RAW1394_ISO_DEFER; 
     511                debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "signal activity, %d>%d\n",  
     512                                                        bufferfill, periodsize); 
     513                //SIGNAL_ACTIVITY_SPM; 
     514                return RAW1394_ISO_DEFER; // FIXME: might not be needed 
    513515            } 
    514516            return RAW1394_ISO_OK; 
  • branches/libffado-2.0/src/libstreaming/generic/StreamProcessor.h

    r1292 r1344  
    289289    virtual unsigned int getPacketsPerPeriod(); 
    290290    virtual unsigned int getMaxPacketSize() = 0; 
     291    virtual unsigned int getAveragePacketSize() = 0; 
    291292private: 
    292293    int m_channel; 
     
    375376         * Returns the sync delay. This is the time a syncsource 
    376377         * delays a period signal, e.g. to cope with buffering. 
    377          * @return the sync delay 
     378         * @return the sync delay (in ticks) 
    378379         */ 
    379380        unsigned int getSyncDelay() {return m_sync_delay;}; 
  • branches/libffado-2.0/src/libstreaming/motu/MotuReceiveStreamProcessor.cpp

    r1235 r1344  
    9696 
    9797unsigned int 
     98MotuReceiveStreamProcessor::getAveragePacketSize() 
     99{ 
     100    // in one second we have 8000 packets 
     101    // containing FRAMERATE frames 
     102    // so on average bytes/packet: (8000 packet headers + FRAMERATE * frame_size) / 8000 
     103    #warning FIXME 
     104    int framerate = m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate(); 
     105    return framerate<=48000?616:(framerate<=96000?1032:1160); 
     106} 
     107 
     108unsigned int 
    98109MotuReceiveStreamProcessor::getNominalFramesPerPacket() { 
    99110    int framerate = m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate(); 
  • branches/libffado-2.0/src/libstreaming/motu/MotuReceiveStreamProcessor.h

    r1035 r1344  
    152152                {return m_event_size;}; 
    153153    virtual unsigned int getMaxPacketSize(); 
     154    virtual unsigned int getAveragePacketSize(); 
    154155    virtual unsigned int getEventsPerFrame()  
    155156                    { return 1; }; // FIXME: check 
  • branches/libffado-2.0/src/libstreaming/motu/MotuTransmitStreamProcessor.cpp

    r1235 r1344  
    8181 
    8282unsigned int 
     83MotuTransmitStreamProcessor::getAveragePacketSize() 
     84{ 
     85    // in one second we have 8000 packets 
     86    // containing FRAMERATE frames 
     87    // so on average bytes/packet: (8000 packet headers + FRAMERATE * frame_size) / 8000 
     88    #warning FIXME 
     89    int framerate = m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate(); 
     90    return framerate<=48000?616:(framerate<=96000?1032:1160); 
     91} 
     92 
     93unsigned int 
    8394MotuTransmitStreamProcessor::getNominalFramesPerPacket() { 
    8495    int framerate = m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate(); 
  • branches/libffado-2.0/src/libstreaming/motu/MotuTransmitStreamProcessor.h

    r1034 r1344  
    7676                {return m_event_size;}; 
    7777    virtual unsigned int getMaxPacketSize(); 
     78    virtual unsigned int getAveragePacketSize(); 
    7879    virtual unsigned int getEventsPerFrame()  
    7980                    { return 1; }; // FIXME: check 
  • branches/libffado-2.0/src/libstreaming/StreamProcessorManager.cpp

    r1292 r1344  
    476476    // DLL to have a decent sync (FIXME: does the DLL get updated when dry-running)? 
    477477    debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for sync...\n"); 
    478      
     478 
    479479    unsigned int nb_sync_runs = (STREAMPROCESSORMANAGER_SYNC_WAIT_TIME_MSEC * getNominalRate()); 
    480480    nb_sync_runs /= 1000; 
     
    929929    bool xrun_occurred = false; 
    930930    bool in_error = false; 
    931     bool period_not_ready = true; 
    932931 
    933932    // grab the wait lock 
    934933    // this ensures that bus reset handling doesn't interfere 
    935934    Util::MutexLockHelper lock(*m_WaitLock); 
    936  
     935    debugOutputExtreme(DEBUG_LEVEL_VERBOSE, 
     936                        "waiting for period (%d frames in buffer)...\n", 
     937                        m_SyncSource->getBufferFill()); 
     938    uint64_t ticks_at_period = m_SyncSource->getTimeAtPeriod(); 
     939    uint64_t ticks_at_period_margin = ticks_at_period + m_SyncSource->getSyncDelay(); 
     940    uint64_t pred_system_time_at_xfer = m_SyncSource->getParent().get1394Service().getSystemTimeForCycleTimerTicks(ticks_at_period_margin); 
     941 
     942    #ifdef DEBUG 
     943    int64_t now = Util::SystemTimeSource::getCurrentTime(); 
     944    debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "pred: %lld, now: %lld, wait: %lld\n", pred_system_time_at_xfer, now, pred_system_time_at_xfer-now ); 
     945    #endif 
     946 
     947    // wait until it's time to transfer 
     948    Util::SystemTimeSource::SleepUsecAbsolute(pred_system_time_at_xfer); 
     949 
     950    #ifdef DEBUG 
     951    now = Util::SystemTimeSource::getCurrentTime(); 
     952    debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "pred: %lld now: %lld, excess: %lld\n", pred_system_time_at_xfer, now, now-pred_system_time_at_xfer ); 
     953    #endif 
     954 
     955    // the period should be ready now 
     956 
     957    // HACK: we force wait until every SP is ready. this is needed 
     958    // since the raw1394 interface provides no control over interrupts 
     959    // resulting in very bad predictability on when the data is present. 
     960    bool period_not_ready = true; 
    937961    while(period_not_ready) { 
    938         debugOutputExtreme(DEBUG_LEVEL_VERBOSE,  
    939                            "waiting for period (%d frames in buffer)...\n", 
    940                            m_SyncSource->getBufferFill()); 
    941  
    942         // wait for something to happen 
    943         switch(waitForActivity()) { 
    944             case eAR_Error: 
    945                 debugError("Error while waiting for activity\n"); 
    946                 m_shutdown_needed = true; 
    947                 return false; 
    948             case eAR_Interrupted: 
    949                 // FIXME: what to do here? 
    950                 debugWarning("Interrupted while waiting for activity\n"); 
    951                 break; 
    952             case eAR_Timeout: 
    953                 debugWarning("Timeout while waiting for activity\n"); 
    954                 // ignore this since it can also be due to some other hardware 
    955                 // or high-prio software that preempts us. hence only an xrun should 
    956                 // be generated (if necessary) 
    957             case eAR_Activity: 
    958                 // do nothing 
    959                 break; 
    960         } 
    961         debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "got activity...\n"); 
    962  
    963         // HACK: this should be solved more elegantly 
    964962        period_not_ready = false; 
    965963        for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
     
    979977            } 
    980978        } 
    981         debugOutputExtreme(DEBUG_LEVEL_VERBOSE, " period not ready? %d...\n", period_not_ready); 
     979 
     980        if (period_not_ready) { 
     981            debugOutput(DEBUG_LEVEL_VERBOSE, " wait extended since period not ready...\n"); 
     982            Util::SystemTimeSource::SleepUsecRelative(125); // one cycle 
     983        } 
    982984 
    983985        // check for underruns/errors on the ISO side, 
     
    10311033    #endif 
    10321034 
    1033     debugOutputExtreme( DEBUG_LEVEL_VERBOSE, 
     1035    debugOutputExtreme(DEBUG_LEVEL_VERBOSE, 
    10341036                        "transfer period %d at %llu ticks...\n", 
    10351037                        m_nbperiods, m_time_of_transfer); 
     
    10371039    // this is to notify the client of the delay that we introduced by waiting 
    10381040    m_delayed_usecs = - m_SyncSource->getTimeUntilNextPeriodSignalUsecs(); 
    1039     debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, 
     1041    debugOutputExtreme(DEBUG_LEVEL_VERBOSE, 
    10401042                        "delayed for %d usecs...\n", 
    10411043                        m_delayed_usecs);