Changeset 397

Show
Ignore:
Timestamp:
02/16/07 14:40:14 (14 years ago)
Author:
pieterpalmers
Message:

- make timestampedbuffer use floats instead of doubles
- change iso receive back to the efficient case

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp

    r396 r397  
    3636#include <assert.h> 
    3737 
    38 #define RECEIVE_PROCESSING_DELAY (0U
     38#define RECEIVE_PROCESSING_DELAY (TICKS_PER_CYCLE * 2
    3939 
    4040// in ticks 
  • branches/streaming-rework/src/libstreaming/cycletimer.h

    r394 r397  
    4646#define USECS_PER_CYCLE    (125U) 
    4747 
    48 #define CYCLE_TIMER_GET_SECS(x)   ((((x) & 0xFE000000U) >> 25)) 
    49 #define CYCLE_TIMER_GET_CYCLES(x) ((((x) & 0x01FFF000U) >> 12)) 
    50 #define CYCLE_TIMER_GET_OFFSET(x)  ((((x) & 0x00000FFFU))) 
     48#define CYCLE_TIMER_GET_SECS(x)   ((((x) & 0xFE000000UL) >> 25)) 
     49#define CYCLE_TIMER_GET_CYCLES(x) ((((x) & 0x01FFF000UL) >> 12)) 
     50#define CYCLE_TIMER_GET_OFFSET(x)  ((((x) & 0x00000FFFUL))) 
    5151#define CYCLE_TIMER_TO_TICKS(x) ((CYCLE_TIMER_GET_SECS(x)   * TICKS_PER_SECOND) +\ 
    5252                                   (CYCLE_TIMER_GET_CYCLES(x) * TICKS_PER_CYCLE ) +\ 
     
    7373 
    7474DECLARE_GLOBAL_DEBUG_MODULE; 
     75 
     76/** 
     77 * @brief Wraps x to the maximum number of ticks 
     78 * 
     79 * The input value is wrapped to the maximum value of the cycle 
     80 * timer, in ticks (128sec * 24576000 ticks/sec). 
     81 * 
     82 * @param x time to wrap 
     83 * @return wrapped time 
     84 */ 
     85static inline uint32_t wrapAtMaxTicks(uint64_t x) { 
     86    if (x >= TICKS_PER_SECOND * 128L) { 
     87        x -= TICKS_PER_SECOND * 128L; 
     88    } 
     89 
     90#ifdef DEBUG 
     91        if (x >= TICKS_PER_SECOND * 128L) { 
     92            debugWarning("insufficient wrapping: %llu\n",x); 
     93        } 
     94#endif 
     95 
     96    return x; 
     97} 
     98 
     99/** 
     100 * @brief Wraps both at minimum and maximum value for ticks 
     101 * @param x value to wrap 
     102 * @return wrapped value 
     103 */ 
     104static inline uint32_t wrapAtMinMaxTicks(int64_t x) { 
     105     
     106    if (x < 0) { 
     107        x += TICKS_PER_SECOND * 128L; 
     108    } else if (x >= TICKS_PER_SECOND * 128L) { 
     109        x -= TICKS_PER_SECOND * 128L; 
     110    } 
     111 
     112#ifdef DEBUG 
     113        if (x >= TICKS_PER_SECOND * 128L) { 
     114            debugWarning("insufficient wrapping (max): %llu\n",x); 
     115        } 
     116        if (x < 0) { 
     117            debugWarning("insufficient wrapping (min): %lld\n",x); 
     118        } 
     119#endif 
     120    return x; 
     121 
     122} 
     123 
     124/** 
     125 * @brief Computes a difference between timestamps 
     126 * 
     127 * This function computes a difference between timestamps 
     128 * such that it respects wrapping. 
     129 * 
     130 * If x wraps around, but y doesn't, the result of x-y is  
     131 * negative and very large. However the real difference is 
     132 * not large. It can be calculated by unwrapping x and then 
     133 * calculating x-y. 
     134 * 
     135 * @param x First timestamp  
     136 * @param y Second timestamp 
     137 * @return the difference x-y, unwrapped 
     138 */ 
     139static inline int32_t substractTicks(uint32_t x, uint32_t y) { 
     140    int64_t diff=(int64_t)x - (int64_t)y; 
     141     
     142    // the maximal difference we allow (64secs) 
     143    const int64_t max=TICKS_PER_SECOND*64L; 
     144     
     145    if(diff > max) { 
     146        // this means that y has wrapped, but 
     147        // x has not. we should unwrap y 
     148        // by adding TICKS_PER_SECOND*128L, meaning that we should substract 
     149        // this value from diff 
     150        diff -= TICKS_PER_SECOND*128L; 
     151    } else if (diff < -max) { 
     152        // this means that x has wrapped, but 
     153        // y has not. we should unwrap x 
     154        // by adding TICKS_PER_SECOND*128L, meaning that we should add 
     155        // this value to diff 
     156        diff += TICKS_PER_SECOND*128L; 
     157    } 
     158     
     159    return (int32_t)diff; 
     160     
     161} 
     162 
     163/** 
     164 * @brief Computes a sum of timestamps 
     165 * 
     166 * This function computes a sum of timestamps in ticks, 
     167 * wrapping the result if nescessary. 
     168 * 
     169 * @param x First timestamp  
     170 * @param y Second timestamp 
     171 * @return the sum x+y, wrapped 
     172 */ 
     173static inline uint32_t addTicks(uint32_t x, uint32_t y) { 
     174    uint64_t sum=x+y; 
     175 
     176    return wrapAtMaxTicks(sum); 
     177} 
    75178 
    76179/** 
     
    143246    timestamp += CYCLE_TIMER_GET_OFFSET(syt_timestamp); 
    144247     
    145     timestamp += cc_seconds * TICKS_PER_SECOND
     248    timestamp = addTicks(timestamp, cc_seconds * TICKS_PER_SECOND)
    146249     
    147250    #ifdef DEBUG 
     
    229332    timestamp += CYCLE_TIMER_GET_OFFSET(syt_timestamp); 
    230333     
    231     timestamp += cc_seconds * TICKS_PER_SECOND
     334    timestamp = addTicks(timestamp, cc_seconds * TICKS_PER_SECOND)
    232335     
    233336    #ifdef DEBUG 
     
    243346 
    244347/** 
    245  * @brief Wraps x to the maximum number of ticks 
    246  * 
    247  * The input value is wrapped to the maximum value of the cycle 
    248  * timer, in ticks (128sec * 24576000 ticks/sec). 
    249  * 
    250  * @param x time to wrap 
    251  * @return wrapped time 
    252  */ 
    253 static inline uint32_t wrapAtMaxTicks(uint64_t x) { 
    254     if (x >= TICKS_PER_SECOND * 128L) { 
    255         x -= TICKS_PER_SECOND * 128L; 
    256     } 
    257  
    258 #ifdef DEBUG 
    259         if (x >= TICKS_PER_SECOND * 128L) { 
    260             debugWarning("insufficient wrapping: %llu\n",x); 
    261         } 
    262 #endif 
    263  
    264     return x; 
    265 } 
    266  
    267 /** 
    268  * @brief Wraps both at minimum and maximum value for ticks 
    269  * @param x value to wrap 
    270  * @return wrapped value 
    271  */ 
    272 static inline uint32_t wrapAtMinMaxTicks(int64_t x) { 
    273      
    274     if (x < 0) { 
    275         x += TICKS_PER_SECOND * 128L; 
    276     } else if (x >= TICKS_PER_SECOND * 128L) { 
    277         x -= TICKS_PER_SECOND * 128L; 
    278     } 
    279  
    280 #ifdef DEBUG 
    281         if (x >= TICKS_PER_SECOND * 128L) { 
    282             debugWarning("insufficient wrapping (max): %llu\n",x); 
    283         } 
    284         if (x < 0) { 
    285             debugWarning("insufficient wrapping (min): %lld\n",x); 
    286         } 
    287 #endif 
    288     return x; 
    289  
    290 } 
    291  
    292 /** 
    293  * @brief Computes a difference between timestamps 
    294  * 
    295  * This function computes a difference between timestamps 
    296  * such that it respects wrapping. 
    297  * 
    298  * If x wraps around, but y doesn't, the result of x-y is  
    299  * negative and very large. However the real difference is 
    300  * not large. It can be calculated by unwrapping x and then 
    301  * calculating x-y. 
    302  * 
    303  * @param x First timestamp  
    304  * @param y Second timestamp 
    305  * @return the difference x-y, unwrapped 
    306  */ 
    307 static inline int32_t substractTicks(uint32_t x, uint32_t y) { 
    308     int64_t diff=(int64_t)x - (int64_t)y; 
    309      
    310     // the maximal difference we allow (64secs) 
    311     const int64_t max=TICKS_PER_SECOND*64L; 
    312      
    313     if(diff > max) { 
    314         // this means that y has wrapped, but 
    315         // x has not. we should unwrap y 
    316         // by adding TICKS_PER_SECOND*128L, meaning that we should substract 
    317         // this value from diff 
    318         diff -= TICKS_PER_SECOND*128L; 
    319     } else if (diff < -max) { 
    320         // this means that x has wrapped, but 
    321         // y has not. we should unwrap x 
    322         // by adding TICKS_PER_SECOND*128L, meaning that we should add 
    323         // this value to diff 
    324         diff += TICKS_PER_SECOND*128L; 
    325     } 
    326      
    327     return (int32_t)diff; 
    328      
    329 } 
    330  
    331 /** 
    332  * @brief Computes a sum of timestamps 
    333  * 
    334  * This function computes a sum of timestamps in ticks, 
    335  * wrapping the result if nescessary. 
    336  * 
    337  * @param x First timestamp  
    338  * @param y Second timestamp 
    339  * @return the sum x+y, wrapped 
    340  */ 
    341 static inline uint32_t addTicks(uint32_t x, uint32_t y) { 
    342     uint64_t sum=x+y; 
    343  
    344     return wrapAtMaxTicks(sum); 
    345 } 
    346  
    347 /** 
    348348 * @brief Computes a difference between cycles 
    349349 * 
  • branches/streaming-rework/src/libstreaming/IsoHandler.cpp

    r394 r397  
    342342        debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); 
    343343    } 
    344     return CYCLE_TIMER_TO_TICKS(ctr.cycle_timer); 
     344    return CYCLE_TIMER_TO_TICKS((uint32_t)ctr.cycle_timer); 
    345345 
    346346#else 
  • branches/streaming-rework/src/libstreaming/IsoHandlerManager.cpp

    r391 r397  
    3535 
    3636 
    37 #define MINIMUM_INTERRUPTS_PER_PERIOD  4
     37#define MINIMUM_INTERRUPTS_PER_PERIOD  2
    3838#define PACKETS_PER_INTERRUPT          4U 
    3939 
     
    323323                unsigned int packets_per_period=stream->getPacketsPerPeriod(); 
    324324                 
    325 #if 0 
     325#if 1 
    326326                // hardware interrupts occur when one DMA block is full, and the size of one DMA 
    327                 // block = PAGE_SIZE. Setting the max_packet_size makes sure that the HW irq is  
     327                // block = PAGE_SIZE. Setting the max_packet_size makes sure that the HW irq  
    328328                // occurs at a period boundary (optimal CPU use) 
    329329                 
    330330                // NOTE: try and use MINIMUM_INTERRUPTS_PER_PERIOD hardware interrupts 
    331331                //       per period for better latency. 
    332                 unsigned int max_packet_size=MINIMUM_INTERRUPTS_PER_PERIOD * getpagesize() / packets_per_period; 
     332                unsigned int max_packet_size=(MINIMUM_INTERRUPTS_PER_PERIOD * getpagesize()) / packets_per_period; 
    333333                if (max_packet_size < stream->getMaxPacketSize()) { 
    334334                        max_packet_size=stream->getMaxPacketSize(); 
  • branches/streaming-rework/src/libstreaming/StreamProcessor.cpp

    r396 r397  
    227227    const int64_t max=(int64_t)(TICKS_PER_SECOND/2); 
    228228     
    229     int64_t diff=m_cycle_to_enable_at-now_cycles; 
     229    int64_t diff=(int64_t)m_cycle_to_enable_at-(int64_t)now_cycles; 
    230230     
    231231    if (diff > max) { 
     
    236236     
    237237    if (diff<0) { 
    238         debugWarning("Request to enable streamprocessor %d cycles ago (now=%llu, cy=%llu).\n", 
     238        debugWarning("Request to enable streamprocessor %lld cycles ago (now=%llu, cy=%llu).\n", 
    239239            diff,now_cycles,time_to_enable_at); 
    240240    } 
  • branches/streaming-rework/src/libutil/TimestampedBuffer.cpp

    r395 r397  
    259259     
    260260    // init the DLL 
    261     m_dll_e2=m_nominal_rate * (double)m_update_period; 
    262      
    263     m_dll_b=((double)(0.877)); 
    264     m_dll_c=((double)(0.384)); 
     261    m_dll_e2=m_nominal_rate * (float)m_update_period; 
     262     
     263    m_dll_b=((float)(0.877)); 
     264    m_dll_c=((float)(0.384)); 
    265265 
    266266    return true; 
     
    548548    if (diff < 0) diff += m_wrap_at; 
    549549     
    550     double rate; 
     550    float rate; 
    551551     
    552552    if (diff) { 
    553         rate=(double)diff / (double)m_update_period; 
     553        rate=(float)diff / (float)m_update_period; 
    554554    } else { 
    555555        rate=m_nominal_rate; 
     
    579579     
    580580    m_dll_e2=m_update_period * m_nominal_rate; 
    581     m_buffer_next_tail_timestamp = (uint64_t)((double)m_buffer_tail_timestamp + m_dll_e2); 
     581    m_buffer_next_tail_timestamp = (uint64_t)((float)m_buffer_tail_timestamp + m_dll_e2); 
    582582     
    583583    pthread_mutex_unlock(&m_framecounter_lock);     
     
    639639    if (diff < 0) diff += m_wrap_at; 
    640640     
    641     double rate=(double)diff / (double)m_update_period; 
     641    float rate=(float)diff / (float)m_update_period; 
    642642     
    643643    int64_t timestamp; 
     
    709709    if (diff < 0) diff += m_wrap_at; 
    710710     
    711     double rate=(double)diff / (double)m_update_period; 
     711    float rate=(float)diff / (float)m_update_period; 
    712712         
    713713    int64_t ts=new_timestamp; 
     
    758758    } 
    759759     
    760     double err=diff; 
     760    float err=diff; 
    761761     
    762762    debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "diff2=%lld err=%f\n", 
  • branches/streaming-rework/src/libutil/TimestampedBuffer.h

    r395 r397  
    172172 
    173173    // tracking DLL variables 
    174     double m_dll_e2; 
    175     double m_dll_b; 
    176     double m_dll_c; 
     174    float m_dll_e2; 
     175    float m_dll_b; 
     176    float m_dll_c; 
    177177     
    178178    float m_nominal_rate;