Changeset 907

Show
Ignore:
Timestamp:
03/06/08 11:18:43 (13 years ago)
Author:
ppalmers
Message:

fix concurrency issue

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/config.h.in

    r906 r907  
    3939#define DEBUG_EXTREME_ENABLE        0 
    4040 
    41 #define IEEE1394SERVICE_USE_CYCLETIMER_DLL  0 
     41#define IEEE1394SERVICE_USE_CYCLETIMER_DLL  1 
    4242#define IEEE1394SERVICE_CYCLETIMER_DLL_UPDATE_INTERVAL_USEC 200000 
    4343#define IEEE1394SERVICE_MAX_FIREWIRE_PORTS  16 
  • trunk/libffado/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.cpp

    r893 r907  
    174174                           m_last_timestamp, m_syt_interval, getTicksPerFrame()); 
    175175    } 
     176 
     177    // check whether nevents is a multiple of 8. 
     178    if (nevents & 0x7) { 
     179        debugError("Invalid nevents value for AMDTP (%u)\n", nevents); 
     180    } 
    176181    #endif 
    177182 
  • trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp

    r892 r907  
    350350    packet->syt = ntohs ( timestamp_SYT ); 
    351351 
     352    // FIXME: use a precomputed value here 
    352353    *length = m_syt_interval*sizeof ( quadlet_t ) *m_dimension + 8; 
    353354 
  • trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp

    r906 r907  
    199199{ 
    200200    if (getType() == ePT_Receive) { 
    201         ffado_timestamp_t next_period_boundary=m_data_buffer->getTimestampFromHead(m_StreamProcessorManager.getPeriodSize()); 
     201        ffado_timestamp_t next_period_boundary = m_data_buffer->getTimestampFromHead(m_StreamProcessorManager.getPeriodSize()); 
    202202     
    203203        #ifdef DEBUG 
     
    212212        return (uint64_t)next_period_boundary; 
    213213    } else { 
    214         ffado_timestamp_t next_period_boundary=m_data_buffer->getTimestampFromTail((m_StreamProcessorManager.getNbBuffers()-1) * m_StreamProcessorManager.getPeriodSize()); 
     214        ffado_timestamp_t next_period_boundary = m_data_buffer->getTimestampFromTail((m_StreamProcessorManager.getNbBuffers()-1) * m_StreamProcessorManager.getPeriodSize()); 
    215215     
    216216        #ifdef DEBUG 
     
    363363 
    364364    if (result == eCRV_OK) { 
     365        #ifdef DEBUG 
     366        int ticks_per_packet = getTicksPerFrame() * getNominalFramesPerPacket(); 
     367        int diff=diffTicks(m_last_timestamp, m_last_timestamp2); 
     368        // display message if the difference between two successive tick 
     369        // values is more than 50 ticks. 1 sample at 48k is 512 ticks 
     370        // so 50 ticks = 10%, which is a rather large jitter value. 
     371        if(diff-ticks_per_packet > 50 || diff-ticks_per_packet < -50) { 
     372            debugOutput(DEBUG_LEVEL_VERBOSE, "rather large TSP difference TS=%011llu => TS=%011llu (%d, nom %d)\n", 
     373                                             m_last_timestamp2, m_last_timestamp, diff, ticks_per_packet); 
     374        } 
     375        #endif 
     376 
    365377        debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, 
    366378                          "RECV: CY=%04u TS=%011llu\n", 
  • trunk/libffado/src/libstreaming/StreamProcessorManager.cpp

    r883 r907  
    772772    //       and the receive processors should have done their transfer. 
    773773    m_time_of_transfer = m_SyncSource->getTimeAtPeriod(); 
     774     
     775    #ifdef DEBUG 
     776    static uint64_t m_time_of_transfer2 = m_time_of_transfer; 
     777     
     778    int ticks_per_period = m_SyncSource->getTicksPerFrame() * m_period; 
     779    int diff=diffTicks(m_time_of_transfer, m_time_of_transfer2); 
     780    // display message if the difference between two successive tick 
     781    // values is more than 50 ticks. 1 sample at 48k is 512 ticks 
     782    // so 50 ticks = 10%, which is a rather large jitter value. 
     783    if(diff-ticks_per_period > 50 || diff-ticks_per_period < -50) { 
     784        debugOutput(DEBUG_LEVEL_VERBOSE, "rather large TSP difference TS=%011llu => TS=%011llu (%d, nom %d)\n", 
     785                                            m_time_of_transfer2, m_time_of_transfer, diff, ticks_per_period); 
     786    } 
     787    m_time_of_transfer2 = m_time_of_transfer; 
     788    #endif 
     789     
    774790    debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, 
    775791                        "transfer at %llu ticks...\n", 
  • trunk/libffado/src/libutil/TimestampedBuffer.cpp

    r866 r907  
    6666      m_wrap_at(0xFFFFFFFFFFFFFFFFLLU), 
    6767      m_Client(c), m_framecounter(0), 
    68       m_tick_offset(0.0), 
    6968      m_buffer_tail_timestamp(0.0), 
    7069      m_buffer_next_tail_timestamp(0.0), 
     
    224223    m_bytes_per_frame=m_event_size*m_events_per_frame; 
    225224    m_bytes_per_buffer=m_bytes_per_frame*m_buffer_size; 
    226  
    227     return true; 
    228 } 
    229  
    230 /** 
    231  * Sets the buffer offset in ticks. 
    232  * 
    233  * A positive value means that the buffer is 'delayed' for nticks ticks. 
    234  * 
    235  * @note These offsets are only used when reading timestamps. Any function 
    236  *       that returns a timestamp will incorporate this offset. 
    237  * @param nframes the number of ticks (positive = delay buffer) 
    238  * @return true if successful 
    239  */ 
    240 bool TimestampedBuffer::setTickOffset(ffado_timestamp_t nticks) { 
    241     debugOutput(DEBUG_LEVEL_VERBOSE,"Setting ticks offset to "TIMESTAMP_FORMAT_SPEC"\n",nticks); 
    242  
    243     // JMW: I think we need to update the internal DLL state to take account 
    244     // of the new offset.  Doing so certainly makes for a smoother MOTU 
    245     // startup. 
    246     ENTER_CRITICAL_SECTION; 
    247     m_buffer_tail_timestamp = m_buffer_tail_timestamp - m_tick_offset + nticks; 
    248     m_buffer_next_tail_timestamp = (ffado_timestamp_t)((double)m_buffer_tail_timestamp + m_dll_e2); 
    249     m_tick_offset=nticks; 
    250     EXIT_CRITICAL_SECTION; 
    251225 
    252226    return true; 
     
    427401            return false; 
    428402        } 
    429         incrementFrameCounter(nframes,ts); 
     403        incrementFrameCounter(nframes, ts); 
    430404    } 
    431405    return true; 
     
    752726    // add the offsets 
    753727    ffado_timestamp_t ts=new_timestamp; 
    754     ts += m_tick_offset; 
    755728 
    756729    if (ts >= m_wrap_at) { 
     
    842815 */ 
    843816void TimestampedBuffer::getBufferHeadTimestamp(ffado_timestamp_t *ts, signed int *fc) { 
    844     // NOTE: this is still ok with threads, because we use *fc to compute 
    845     //       the timestamp 
     817    ENTER_CRITICAL_SECTION; 
    846818    *fc = m_framecounter; 
    847819    *ts = getTimestampFromTail(*fc); 
     820    EXIT_CRITICAL_SECTION; 
    848821} 
    849822 
     
    859832 */ 
    860833void TimestampedBuffer::getBufferTailTimestamp(ffado_timestamp_t *ts, signed int *fc) { 
    861     // NOTE: this is still ok with threads, because we use *fc to compute 
    862     //       the timestamp 
     834    ENTER_CRITICAL_SECTION; 
    863835    *fc = m_framecounter; 
    864836    *ts = getTimestampFromTail(0); 
     837    EXIT_CRITICAL_SECTION; 
    865838} 
    866839 
     
    903876ffado_timestamp_t TimestampedBuffer::getTimestampFromHead(int nframes) 
    904877{ 
    905     return getTimestampFromTail(m_framecounter-nframes); 
     878    ffado_timestamp_t retval; 
     879    ENTER_CRITICAL_SECTION; 
     880    retval = getTimestampFromTail(m_framecounter-nframes); 
     881    EXIT_CRITICAL_SECTION; 
     882    return retval; 
    906883} 
    907884 
     
    939916void TimestampedBuffer::incrementFrameCounter(unsigned int nbframes, ffado_timestamp_t new_timestamp) { 
    940917 
    941     // add the offsets 
    942     ffado_timestamp_t diff; 
    943      
    944     ENTER_CRITICAL_SECTION; 
    945     diff = m_buffer_next_tail_timestamp - m_buffer_tail_timestamp; 
    946     EXIT_CRITICAL_SECTION; 
    947  
    948     if (diff < 0) diff += m_wrap_at; 
    949  
    950     ffado_timestamp_t ts = new_timestamp; 
    951     ts += m_tick_offset; 
    952  
    953     if (ts >= m_wrap_at) { 
    954         ts -= m_wrap_at; 
    955     } else if (ts < 0) { 
    956         ts += m_wrap_at; 
    957     } 
    958  
    959 #ifdef DEBUG 
    960     if (new_timestamp >= m_wrap_at) { 
    961         debugWarning("timestamp not wrapped: "TIMESTAMP_FORMAT_SPEC"\n", new_timestamp); 
    962     } 
    963     if ((ts >= m_wrap_at) || (ts < 0 )) { 
    964         debugWarning("ts not wrapped correctly: "TIMESTAMP_FORMAT_SPEC"\n",ts); 
    965     } 
    966 #endif 
    967 // FIXME: JMW: at some points during startup the timestamp doesn't change. 
    968 // This still needs to be verified in more detail.   
    969 // if (ts>m_buffer_tail_timestamp-1 && ts<m_buffer_tail_timestamp+1) { 
    970 //   ENTER_CRITICAL_SECTION; 
    971 //   m_framecounter += nbframes; 
    972 //   EXIT_CRITICAL_SECTION; 
    973 //   return; 
    974 // } 
    975     ffado_timestamp_t pred_buffer_next_tail_timestamp; 
    976     if(nbframes == m_update_period) { 
    977         pred_buffer_next_tail_timestamp = m_buffer_next_tail_timestamp; 
    978     } else { 
    979         debugOutput( DEBUG_LEVEL_VERBOSE, 
    980                      "Number of frames (%u) != update period (%u)\n", 
    981                      nbframes, m_update_period ); 
    982         // calculate the predicted timestamp for nframes (instead of m_update_period) 
    983         // after the previous update. 
    984         float rel_step = ((float)nbframes)/((float)m_update_period); 
    985         ENTER_CRITICAL_SECTION; // FIXME: do we need these? 
    986         ffado_timestamp_t corrected_step = (m_buffer_next_tail_timestamp - m_buffer_tail_timestamp) * rel_step; 
    987         pred_buffer_next_tail_timestamp = m_buffer_tail_timestamp + corrected_step; 
    988         EXIT_CRITICAL_SECTION; 
    989          
    990         debugOutput( DEBUG_LEVEL_VERBOSE, 
    991                      "Updated ("TIMESTAMP_FORMAT_SPEC","TIMESTAMP_FORMAT_SPEC") " 
    992                      "to ("TIMESTAMP_FORMAT_SPEC","TIMESTAMP_FORMAT_SPEC")\n", 
    993                      m_buffer_tail_timestamp, m_buffer_next_tail_timestamp, 
    994                      m_buffer_tail_timestamp, pred_buffer_next_tail_timestamp); 
    995     } 
    996      
     918    // require the timestamps to be in the correct range 
     919    assert(new_timestamp < m_wrap_at); 
     920    assert(new_timestamp >= 0); 
     921    // if this is not true the timestamps have to be corrected 
     922    // to account for the non-uniform update period 
     923    assert(nbframes == m_update_period); 
     924 
    997925    // the difference between the given TS and the one predicted for this time instant 
    998926    // this is the error for the DLL 
    999     diff = ts - pred_buffer_next_tail_timestamp; 
    1000  
     927    ffado_timestamp_t diff = new_timestamp - m_buffer_next_tail_timestamp; 
     928 
     929#ifdef DEBUG 
    1001930    // check whether the update is within the allowed bounds 
    1002     const float max_deviation = (50.0/100.0); // maximal relative difference considered normal 
     931/*    const float max_deviation = (50.0/100.0); // maximal relative difference considered normal 
    1003932    ffado_timestamp_t one_update_step = nbframes * getRate(); 
    1004     ffado_timestamp_t max_abs_diff = one_update_step * (1.0 + max_deviation); 
     933    ffado_timestamp_t max_abs_diff = one_update_step * (1.0 + max_deviation);*/ 
     934    ffado_timestamp_t max_abs_diff = 200; 
    1005935     
    1006936    debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, 
     
    1012942    debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, 
    1013943                       " new TS: "TIMESTAMP_FORMAT_SPEC", wrapped new TS: "TIMESTAMP_FORMAT_SPEC"\n",  
    1014                        new_timestamp, ts); 
     944                       new_timestamp, new_timestamp); 
    1015945 
    1016946    if (diff > max_abs_diff) { 
    1017 //         debugShowBackLogLines(100); 
     947        //debugShowBackLogLines(100); 
    1018948        debugWarning("(%p) difference rather large (+): diff="TIMESTAMP_FORMAT_SPEC", max="TIMESTAMP_FORMAT_SPEC", "TIMESTAMP_FORMAT_SPEC", "TIMESTAMP_FORMAT_SPEC"\n", 
    1019             this, diff, max_abs_diff, ts, pred_buffer_next_tail_timestamp); 
     949            this, diff, max_abs_diff, new_timestamp, m_buffer_next_tail_timestamp); 
    1020950    } else if (diff < -max_abs_diff) { 
    1021 //         debugShowBackLogLines(100); 
     951        //debugShowBackLogLines(100); 
    1022952        debugWarning("(%p) difference rather large (-): diff="TIMESTAMP_FORMAT_SPEC", max="TIMESTAMP_FORMAT_SPEC", "TIMESTAMP_FORMAT_SPEC", "TIMESTAMP_FORMAT_SPEC"\n", 
    1023             this, diff, -max_abs_diff, ts, pred_buffer_next_tail_timestamp); 
     953            this, diff, -max_abs_diff, new_timestamp, m_buffer_next_tail_timestamp); 
    1024954    } 
    1025955 
     
    1027957                       "(%p): diff="TIMESTAMP_FORMAT_SPEC" ", 
    1028958                       this, diff); 
     959#endif 
    1029960 
    1030961    double err = diff; 
     
    1038969    ENTER_CRITICAL_SECTION; 
    1039970    m_framecounter += nbframes; 
    1040     m_buffer_tail_timestamp = pred_buffer_next_tail_timestamp; 
    1041     m_buffer_next_tail_timestamp = pred_buffer_next_tail_timestamp + (ffado_timestamp_t)(m_dll_b * err + m_dll_e2); 
     971    m_buffer_tail_timestamp = m_buffer_next_tail_timestamp; 
     972    m_buffer_next_tail_timestamp = m_buffer_next_tail_timestamp + (ffado_timestamp_t)(m_dll_b * err + m_dll_e2); 
    1042973    m_dll_e2 += m_dll_c*err; 
    1043974 
     
    1065996        debugError("Wrapping failed for m_buffer_tail_timestamp! "TIMESTAMP_FORMAT_SPEC"\n",m_buffer_tail_timestamp); 
    1066997        debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " IN="TIMESTAMP_FORMAT_SPEC", TS="TIMESTAMP_FORMAT_SPEC", NTS="TIMESTAMP_FORMAT_SPEC"\n", 
    1067                     ts, m_buffer_tail_timestamp, m_buffer_next_tail_timestamp); 
     998                    new_timestamp, m_buffer_tail_timestamp, m_buffer_next_tail_timestamp); 
    1068999 
    10691000    } 
     
    10711002        debugError("Wrapping failed for m_buffer_next_tail_timestamp! "TIMESTAMP_FORMAT_SPEC"\n",m_buffer_next_tail_timestamp); 
    10721003        debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " IN="TIMESTAMP_FORMAT_SPEC", TS="TIMESTAMP_FORMAT_SPEC", NTS="TIMESTAMP_FORMAT_SPEC"\n", 
    1073                     ts, m_buffer_tail_timestamp, m_buffer_next_tail_timestamp); 
     1004                    new_timestamp, m_buffer_tail_timestamp, m_buffer_next_tail_timestamp); 
    10741005    } 
    10751006     
     
    10771008        debugError("Current and next timestamps are equal: "TIMESTAMP_FORMAT_SPEC" "TIMESTAMP_FORMAT_SPEC"\n", 
    10781009                   m_buffer_tail_timestamp,m_buffer_next_tail_timestamp); 
    1079      
    10801010    } 
    10811011 
  • trunk/libffado/src/libutil/TimestampedBuffer.h

    r866 r907  
    135135        ffado_timestamp_t getTimestampFromHead ( int nframes ); 
    136136 
    137         // buffer offset stuff 
    138         /// return the tick offset value 
    139         ffado_timestamp_t getTickOffset() {return m_tick_offset;}; 
    140  
    141         bool setFrameOffset ( int nframes ); 
    142         bool setTickOffset ( ffado_timestamp_t ); 
    143  
    144137        // dll stuff 
    145138        bool setNominalRate ( float r ); 
     
    183176        // the framecounter gives the number of frames in the buffer 
    184177        signed int m_framecounter; 
    185  
    186         // the offset that define the timing of the buffer 
    187         ffado_timestamp_t m_tick_offset; 
    188178 
    189179        // the buffer tail timestamp gives the timestamp of the last frame 
  • trunk/libffado/tests/SConscript

    r864 r907  
    5252        "test-streamdump" : "test-streamdump.cpp", 
    5353        "test-bufferops" : "test-bufferops.cpp", 
     54        "dumpiso_mod" : "dumpiso_mod.cpp" 
    5455} 
    5556 
  • trunk/libffado/tests/test-timestampedbuffer.cpp

    r864 r907  
    292292    t->setWrapValue(arguments.wrap_at); 
    293293 
    294     t->setTickOffset(10000); 
    295  
    296294    t->prepare(); 
    297295 
     
    314312        // and that setBufferHeadTimestamp doesn't take offset 
    315313        // into account 
    316         uint64_t timestamp2=timestamp+t->getTickOffset()
     314        uint64_t timestamp2=timestamp
    317315        if (timestamp2>=arguments.wrap_at) { 
    318316            timestamp2-=arguments.wrap_at;