Changeset 397
- Timestamp:
- 02/16/07 14:40:14 (16 years ago)
- Files:
-
- branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp (modified) (1 diff)
- branches/streaming-rework/src/libstreaming/cycletimer.h (modified) (5 diffs)
- branches/streaming-rework/src/libstreaming/IsoHandler.cpp (modified) (1 diff)
- branches/streaming-rework/src/libstreaming/IsoHandlerManager.cpp (modified) (2 diffs)
- branches/streaming-rework/src/libstreaming/StreamProcessor.cpp (modified) (2 diffs)
- branches/streaming-rework/src/libutil/TimestampedBuffer.cpp (modified) (6 diffs)
- branches/streaming-rework/src/libutil/TimestampedBuffer.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp
r396 r397 36 36 #include <assert.h> 37 37 38 #define RECEIVE_PROCESSING_DELAY ( 0U)38 #define RECEIVE_PROCESSING_DELAY (TICKS_PER_CYCLE * 2) 39 39 40 40 // in ticks branches/streaming-rework/src/libstreaming/cycletimer.h
r394 r397 46 46 #define USECS_PER_CYCLE (125U) 47 47 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))) 51 51 #define CYCLE_TIMER_TO_TICKS(x) ((CYCLE_TIMER_GET_SECS(x) * TICKS_PER_SECOND) +\ 52 52 (CYCLE_TIMER_GET_CYCLES(x) * TICKS_PER_CYCLE ) +\ … … 73 73 74 74 DECLARE_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 */ 85 static 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 */ 104 static 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 */ 139 static 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 */ 173 static inline uint32_t addTicks(uint32_t x, uint32_t y) { 174 uint64_t sum=x+y; 175 176 return wrapAtMaxTicks(sum); 177 } 75 178 76 179 /** … … 143 246 timestamp += CYCLE_TIMER_GET_OFFSET(syt_timestamp); 144 247 145 timestamp += cc_seconds * TICKS_PER_SECOND;248 timestamp = addTicks(timestamp, cc_seconds * TICKS_PER_SECOND); 146 249 147 250 #ifdef DEBUG … … 229 332 timestamp += CYCLE_TIMER_GET_OFFSET(syt_timestamp); 230 333 231 timestamp += cc_seconds * TICKS_PER_SECOND;334 timestamp = addTicks(timestamp, cc_seconds * TICKS_PER_SECOND); 232 335 233 336 #ifdef DEBUG … … 243 346 244 347 /** 245 * @brief Wraps x to the maximum number of ticks246 *247 * The input value is wrapped to the maximum value of the cycle248 * timer, in ticks (128sec * 24576000 ticks/sec).249 *250 * @param x time to wrap251 * @return wrapped time252 */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 DEBUG259 if (x >= TICKS_PER_SECOND * 128L) {260 debugWarning("insufficient wrapping: %llu\n",x);261 }262 #endif263 264 return x;265 }266 267 /**268 * @brief Wraps both at minimum and maximum value for ticks269 * @param x value to wrap270 * @return wrapped value271 */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 DEBUG281 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 #endif288 return x;289 290 }291 292 /**293 * @brief Computes a difference between timestamps294 *295 * This function computes a difference between timestamps296 * such that it respects wrapping.297 *298 * If x wraps around, but y doesn't, the result of x-y is299 * negative and very large. However the real difference is300 * not large. It can be calculated by unwrapping x and then301 * calculating x-y.302 *303 * @param x First timestamp304 * @param y Second timestamp305 * @return the difference x-y, unwrapped306 */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, but315 // x has not. we should unwrap y316 // by adding TICKS_PER_SECOND*128L, meaning that we should substract317 // this value from diff318 diff -= TICKS_PER_SECOND*128L;319 } else if (diff < -max) {320 // this means that x has wrapped, but321 // y has not. we should unwrap x322 // by adding TICKS_PER_SECOND*128L, meaning that we should add323 // this value to diff324 diff += TICKS_PER_SECOND*128L;325 }326 327 return (int32_t)diff;328 329 }330 331 /**332 * @brief Computes a sum of timestamps333 *334 * This function computes a sum of timestamps in ticks,335 * wrapping the result if nescessary.336 *337 * @param x First timestamp338 * @param y Second timestamp339 * @return the sum x+y, wrapped340 */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 /**348 348 * @brief Computes a difference between cycles 349 349 * branches/streaming-rework/src/libstreaming/IsoHandler.cpp
r394 r397 342 342 debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); 343 343 } 344 return CYCLE_TIMER_TO_TICKS( ctr.cycle_timer);344 return CYCLE_TIMER_TO_TICKS((uint32_t)ctr.cycle_timer); 345 345 346 346 #else branches/streaming-rework/src/libstreaming/IsoHandlerManager.cpp
r391 r397 35 35 36 36 37 #define MINIMUM_INTERRUPTS_PER_PERIOD 4U37 #define MINIMUM_INTERRUPTS_PER_PERIOD 2U 38 38 #define PACKETS_PER_INTERRUPT 4U 39 39 … … 323 323 unsigned int packets_per_period=stream->getPacketsPerPeriod(); 324 324 325 #if 0325 #if 1 326 326 // 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 is327 // block = PAGE_SIZE. Setting the max_packet_size makes sure that the HW irq 328 328 // occurs at a period boundary (optimal CPU use) 329 329 330 330 // NOTE: try and use MINIMUM_INTERRUPTS_PER_PERIOD hardware interrupts 331 331 // 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; 333 333 if (max_packet_size < stream->getMaxPacketSize()) { 334 334 max_packet_size=stream->getMaxPacketSize(); branches/streaming-rework/src/libstreaming/StreamProcessor.cpp
r396 r397 227 227 const int64_t max=(int64_t)(TICKS_PER_SECOND/2); 228 228 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; 230 230 231 231 if (diff > max) { … … 236 236 237 237 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", 239 239 diff,now_cycles,time_to_enable_at); 240 240 } branches/streaming-rework/src/libutil/TimestampedBuffer.cpp
r395 r397 259 259 260 260 // 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)); 265 265 266 266 return true; … … 548 548 if (diff < 0) diff += m_wrap_at; 549 549 550 doublerate;550 float rate; 551 551 552 552 if (diff) { 553 rate=( double)diff / (double)m_update_period;553 rate=(float)diff / (float)m_update_period; 554 554 } else { 555 555 rate=m_nominal_rate; … … 579 579 580 580 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); 582 582 583 583 pthread_mutex_unlock(&m_framecounter_lock); … … 639 639 if (diff < 0) diff += m_wrap_at; 640 640 641 double rate=(double)diff / (double)m_update_period;641 float rate=(float)diff / (float)m_update_period; 642 642 643 643 int64_t timestamp; … … 709 709 if (diff < 0) diff += m_wrap_at; 710 710 711 double rate=(double)diff / (double)m_update_period;711 float rate=(float)diff / (float)m_update_period; 712 712 713 713 int64_t ts=new_timestamp; … … 758 758 } 759 759 760 doubleerr=diff;760 float err=diff; 761 761 762 762 debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "diff2=%lld err=%f\n", branches/streaming-rework/src/libutil/TimestampedBuffer.h
r395 r397 172 172 173 173 // tracking DLL variables 174 doublem_dll_e2;175 doublem_dll_b;176 doublem_dll_c;174 float m_dll_e2; 175 float m_dll_b; 176 float m_dll_c; 177 177 178 178 float m_nominal_rate;