Changeset 1038

Show
Ignore:
Timestamp:
04/25/08 13:39:03 (13 years ago)
Author:
ppalmers
Message:

reduce the amount of system time read kernel calls

Files:

Legend:

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

    r1028 r1038  
    8181 
    8282#define ISOHANDLER_DEATH_DETECT_TIMEOUT_USECS    1000000LL 
     83 
     84#define ISOHANDLER_CHECK_CTR_RECONSTRUCTION 0 
    8385 
    8486#define ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT         16 
  • trunk/libffado/src/libieee1394/cycletimer.h

    r1020 r1038  
    385385 
    386386/** 
     387 * @brief Converts a received SYT timestamp to a full timestamp in ticks. 
     388 * 
     389 * 
     390 * @param syt_timestamp The SYT timestamp as present in the packet 
     391 * @param rcv_ctr The CTR value this timestamp was received on (offset can be 0) 
     392 * @return 
     393 */ 
     394static inline uint64_t sytRecvToFullTicks2(uint64_t syt_timestamp, uint32_t rcv_ctr) { 
     395    uint64_t timestamp; 
     396 
     397    debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, "SYT=%04llX RCV_CTR=%08X\n", 
     398                       syt_timestamp, rcv_ctr); 
     399 
     400    // reconstruct the top part of the timestamp using the current cycle number 
     401    unsigned int rcv_cycle = CYCLE_TIMER_GET_CYCLES(rcv_ctr); 
     402    unsigned int rcv_cycle_masked = rcv_cycle & 0xF; 
     403    unsigned int syt_cycle = CYCLE_TIMER_GET_CYCLES(syt_timestamp); 
     404 
     405    // if this is true, wraparound has occurred, undo this wraparound 
     406    if(syt_cycle<rcv_cycle_masked) syt_cycle += 0x10; 
     407 
     408    // this is the difference in cycles wrt the cycle the 
     409    // timestamp was received 
     410    unsigned int delta_cycles = syt_cycle - rcv_cycle_masked; 
     411 
     412    // reconstruct the cycle part of the timestamp 
     413    rcv_cycle += delta_cycles; 
     414 
     415    // if the cycles cause a wraparound of the cycle timer, 
     416    // perform this wraparound 
     417    // and convert the timestamp into ticks 
     418    if(rcv_cycle<8000) { 
     419        timestamp = rcv_cycle * TICKS_PER_CYCLE; 
     420    } else { 
     421        rcv_cycle -= 8000; // wrap around 
     422#ifdef DEBUG 
     423        if (rcv_cycle >= 8000) { 
     424            debugWarning("insufficient unwrapping\n"); 
     425        } 
     426#endif 
     427        timestamp  = rcv_cycle * TICKS_PER_CYCLE; 
     428        // add one second due to wraparound 
     429        timestamp += TICKS_PER_SECOND; 
     430    } 
     431 
     432    timestamp += CYCLE_TIMER_GET_OFFSET(syt_timestamp); 
     433 
     434    timestamp = addTicks(timestamp, CYCLE_TIMER_GET_SECS(rcv_ctr) * TICKS_PER_SECOND); 
     435 
     436    #ifdef DEBUG 
     437        if(( TICKS_TO_CYCLE_TIMER(timestamp) & 0xFFFF) != syt_timestamp) { 
     438            debugWarning("back-converted timestamp not equal to SYT\n"); 
     439            debugWarning("TS=%011llu TSC=%08lX SYT=%04X\n", 
     440                  timestamp, TICKS_TO_CYCLE_TIMER(timestamp), syt_timestamp); 
     441        } 
     442    #endif 
     443 
     444    return timestamp; 
     445} 
     446 
     447/** 
    387448 * @brief Converts a transmit SYT timestamp to a full timestamp in ticks. 
    388449 * 
  • trunk/libffado/src/libieee1394/IsoHandler.cpp

    r1032 r1038  
    9191   , m_irq_interval( -1 ) 
    9292   , m_last_cycle( -1 ) 
     93   , m_last_now( 0xFFFFFFFF ) 
    9394   , m_Client( 0 ) 
    9495   , m_speed( RAW1394_ISO_SPEED_400 ) 
     
    113114   , m_irq_interval( irq ) 
    114115   , m_last_cycle( -1 ) 
     116   , m_last_now( 0xFFFFFFFF ) 
    115117   , m_Client( 0 ) 
    116118   , m_speed( RAW1394_ISO_SPEED_400 ) 
     
    134136   , m_max_packet_size( max_packet_size ) 
    135137   , m_irq_interval( irq ) 
     138   , m_last_cycle( -1 ) 
     139   , m_last_now( 0xFFFFFFFF ) 
    136140   , m_Client( 0 ) 
    137141   , m_speed( speed ) 
     
    186190        flush(); 
    187191#endif 
     192        m_last_now = m_manager.get1394Service().getCycleTimer(); 
    188193        if(raw1394_loop_iterate(m_handle)) { 
    189194            debugError( "IsoHandler (%p): Failed to iterate handler: %s\n", 
     
    363368                    unsigned int cycle, unsigned int dropped, unsigned int skipped) { 
    364369 
    365     unsigned int pkt_ctr = cycle << 12; 
     370    uint32_t pkt_ctr = cycle << 12; 
     371 
     372    // if we assume that one iterate() loop doesn't take longer than 0.5 seconds, 
     373    // the seconds field won't change while the iterate loop runs 
     374    // this means that we can preset 'now' before running iterate() 
     375    uint32_t now_secs = CYCLE_TIMER_GET_SECS(m_last_now); 
     376    // causality results in the fact that 'now' is always after 'cycle' 
     377    if(CYCLE_TIMER_GET_CYCLES(m_last_now) < cycle) { 
     378        // the cycle field has wrapped, substract one second 
     379        if(now_secs == 0) { 
     380            now_secs = 127; 
     381        } else  { 
     382            now_secs -= 1; 
     383        } 
     384    } 
     385    pkt_ctr |= (now_secs & 0x7F) << 25; 
     386 
     387    #if ISOHANDLER_CHECK_CTR_RECONSTRUCTION 
     388    // add a seconds field 
     389    uint32_t now = m_manager.get1394Service().getCycleTimer(); 
     390    uint32_t now_secs_ref = CYCLE_TIMER_GET_SECS(now); 
     391    // causality results in the fact that 'now' is always after 'cycle' 
     392    if(CYCLE_TIMER_GET_CYCLES(now) < cycle) { 
     393        // the cycle field has wrapped, substract one second 
     394        if(now_secs_ref == 0) { 
     395            now_secs_ref = 127; 
     396        } else  { 
     397            now_secs_ref -= 1; 
     398        } 
     399    } 
     400    uint32_t pkt_ctr_ref = cycle << 12; 
     401    pkt_ctr_ref |= (now_secs_ref & 0x7F) << 25; 
     402 
     403    if(pkt_ctr != pkt_ctr_ref) { 
     404        debugWarning("reconstructed CTR counter discrepancy\n"); 
     405        pkt_ctr=pkt_ctr_ref; 
     406    } 
     407    #endif 
     408 
     409    // leave the offset field (for now?) 
    366410 
    367411    debugOutputExtreme(DEBUG_LEVEL_ULTRA_VERBOSE, 
     
    422466                      int cycle, unsigned int dropped, unsigned int skipped) { 
    423467 
    424     unsigned int pkt_ctr; 
     468    uint32_t pkt_ctr; 
    425469    if (cycle < 0) { 
     470        // mark invalid 
    426471        pkt_ctr = 0xFFFFFFFF; 
    427472    } else { 
    428473        pkt_ctr = cycle << 12; 
     474 
     475#if 0 // we don't need this for xmit 
     476        // if we assume that one iterate() loop doesn't take longer than 0.5 seconds, 
     477        // the seconds field won't change while the iterate loop runs 
     478        // this means that we can preset 'now' before running iterate() 
     479        uint32_t now_secs = CYCLE_TIMER_GET_SECS(m_last_now); 
     480        // causality results in the fact that 'now' is always after 'cycle' 
     481        if(CYCLE_TIMER_GET_CYCLES(m_last_now) > (unsigned int)cycle) { 
     482            // the cycle field has wrapped, add one second 
     483            now_secs += 1; 
     484            // no need for this: 
     485            //if(now_secs == 128) { 
     486            //    now_secs = 0; 
     487            //} 
     488            // since we mask later on 
     489        } 
     490        pkt_ctr |= (now_secs & 0x7F) << 25; 
     491 
     492        #if ISOHANDLER_CHECK_CTR_RECONSTRUCTION 
     493        // add a seconds field 
     494        uint32_t now = m_manager.get1394Service().getCycleTimer(); 
     495        uint32_t now_secs_ref = CYCLE_TIMER_GET_SECS(now); 
     496        // causality results in the fact that 'now' is always after 'cycle' 
     497        if(CYCLE_TIMER_GET_CYCLES(now) > (unsigned int)cycle) { 
     498            // the cycle field has wrapped, add one second 
     499            now_secs_ref += 1; 
     500            // no need for this: 
     501            //if(now_secs == 128) { 
     502            //    now_secs = 0; 
     503            //} 
     504            // since we mask later on 
     505        } 
     506        uint32_t pkt_ctr_ref = cycle << 12; 
     507        pkt_ctr_ref |= (now_secs_ref & 0x7F) << 25; 
     508     
     509        if(pkt_ctr != pkt_ctr_ref) { 
     510            debugWarning("reconstructed CTR counter discrepancy\n"); 
     511            pkt_ctr=pkt_ctr_ref; 
     512        } 
     513        #endif 
     514#endif 
    429515    } 
    430516 
  • trunk/libffado/src/libieee1394/IsoHandler.h

    r1032 r1038  
    153153    int             m_irq_interval; 
    154154    int             m_last_cycle; 
     155    uint32_t        m_last_now; 
    155156 
    156157    Streaming::StreamProcessor *m_Client; // FIXME: implement with functors