Changeset 7160
- Timestamp:
- Nov 26, 2008, 6:00:37 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/bandwidth.c
r7159 r7160 30 30 HISTORY_MSEC = 2000, 31 31 INTERVAL_MSEC = HISTORY_MSEC, 32 GRANULARITY_MSEC = 250,32 GRANULARITY_MSEC = 40, 33 33 HISTORY_SIZE = ( INTERVAL_MSEC / GRANULARITY_MSEC ), 34 34 MAGIC_NUMBER = 43143 … … 42 42 43 43 static float 44 getSpeed( const struct bratecontrol * r ) 45 { 46 const uint64_t interval_msec = HISTORY_MSEC; 44 getSpeed( const struct bratecontrol * r, int interval_msec ) 45 { 47 46 uint64_t bytes = 0; 48 47 const uint64_t cutoff = tr_date ( ) - interval_msec; … … 241 240 } 242 241 243 #if 0242 #if 1 244 243 #define DEBUG_DIRECTION TR_UP 245 244 #endif … … 259 258 const double currentSpeed = tr_bandwidthGetPieceSpeed( b, dir ); /* KiB/s */ 260 259 const double desiredSpeed = b->band[dir].desiredSpeed; /* KiB/s */ 261 const double seconds_per_pulse = period_msec / 1000.0; 262 const double current_bytes_per_pulse = currentSpeed * 1024.0 * seconds_per_pulse; 263 const double desired_bytes_per_pulse = desiredSpeed * 1024.0 * seconds_per_pulse; 264 const double pulses_per_history = (double)HISTORY_MSEC / period_msec; 265 const double min = desired_bytes_per_pulse * 0.85; 266 const double max = desired_bytes_per_pulse * 1.15; 267 const double next_pulse_bytes = desired_bytes_per_pulse * ( pulses_per_history + 1 ) 268 - ( current_bytes_per_pulse * pulses_per_history ); 269 270 /* clamp the return value to lessen oscillation */ 271 clamped = next_pulse_bytes; 272 clamped = MAX( clamped, min ); 273 clamped = MIN( clamped, max ); 274 275 b->band[dir].bytesLeft = clamped; 260 const double pulseCount = HISTORY_MSEC / (double)period_msec; 261 const double nextPulseSpeed = desiredSpeed * ( pulseCount + 1 ) - ( currentSpeed * pulseCount ); 262 b->band[dir].bytesLeft = nextPulseSpeed * 1024.0 * period_msec / 1000.0; 276 263 277 264 #ifdef DEBUG_DIRECTION 278 265 if( dir == DEBUG_DIRECTION ) 279 fprintf( stderr, "bandwidth %p currentPieceSpeed(%5.2f of %5.2f) desiredSpeed(%5.2f), allocating %5.2f (unclamped: %5.2f)\n",266 fprintf( stderr, "bandwidth %p currentPieceSpeed(%5.2f of %5.2f) desiredSpeed(%5.2f), allocating %5.2f\n", 280 267 b, currentSpeed, tr_bandwidthGetRawSpeed( b, dir ), desiredSpeed, 281 clamped/1024.0, next_pulse_bytes/1024.0 );268 b->band[dir].bytesLeft/1024.0 ); 282 269 #endif 283 270 } 284 271 285 272 /* notify the io buffers that there's more bandwidth available */ 286 if( !b->band[dir].isLimited || ( clamped > 0.001) )273 if( !b->band[dir].isLimited || ( b->band[dir].bytesLeft > 0 ) ) 287 274 { 288 275 int i, n=0; … … 360 347 assert( isDirection( dir ) ); 361 348 362 return getSpeed( &b->band[dir].raw );349 return getSpeed( &b->band[dir].raw, HISTORY_MSEC ); 363 350 } 364 351 … … 369 356 assert( isDirection( dir ) ); 370 357 371 return getSpeed( &b->band[dir].piece );358 return getSpeed( &b->band[dir].piece, HISTORY_MSEC ); 372 359 } 373 360
Note: See TracChangeset
for help on using the changeset viewer.