(trunk libT) #3662 "libtransmission cpu optimization: fewer calls to tr_time_msec()" -- fixed.
This commit is contained in:
parent
7b343c4ba0
commit
01ab067e9c
|
@ -343,8 +343,8 @@ tr_bandwidthGetPieceSpeed_Bps( const tr_bandwidth * b, const uint64_t now, const
|
|||
return getSpeed_Bps( &b->band[dir].piece, HISTORY_MSEC, now );
|
||||
}
|
||||
|
||||
static void
|
||||
bandwidthUsedImpl( tr_bandwidth * b,
|
||||
void
|
||||
tr_bandwidthUsed( tr_bandwidth * b,
|
||||
tr_direction dir,
|
||||
size_t byteCount,
|
||||
tr_bool isPieceData,
|
||||
|
@ -372,14 +372,5 @@ fprintf( stderr, "%p consumed %5zu bytes of %5s data... was %6zu, now %6zu left\
|
|||
bytesUsed( now, &band->piece, byteCount );
|
||||
|
||||
if( b->parent != NULL )
|
||||
bandwidthUsedImpl( b->parent, dir, byteCount, isPieceData, now );
|
||||
}
|
||||
|
||||
void
|
||||
tr_bandwidthUsed( tr_bandwidth * b,
|
||||
tr_direction dir,
|
||||
size_t byteCount,
|
||||
tr_bool isPieceData )
|
||||
{
|
||||
bandwidthUsedImpl( b, dir, byteCount, isPieceData, tr_time_msec( ) );
|
||||
tr_bandwidthUsed( b->parent, dir, byteCount, isPieceData, now );
|
||||
}
|
||||
|
|
|
@ -228,7 +228,8 @@ unsigned int tr_bandwidthGetPieceSpeed_Bps( const tr_bandwidth * bandwidth,
|
|||
void tr_bandwidthUsed ( tr_bandwidth * bandwidth,
|
||||
tr_direction direction,
|
||||
size_t byteCount,
|
||||
tr_bool isPieceData );
|
||||
tr_bool isPieceData,
|
||||
uint64_t now );
|
||||
|
||||
/******
|
||||
*******
|
||||
|
|
|
@ -74,7 +74,7 @@ struct tr_openfile
|
|||
tr_file_index_t fileNum;
|
||||
char filename[TR_PATH_MAX];
|
||||
int fd;
|
||||
uint64_t date;
|
||||
time_t date;
|
||||
};
|
||||
|
||||
struct tr_fdInfo
|
||||
|
@ -474,7 +474,7 @@ tr_fdFileGetCached( tr_session * session,
|
|||
|
||||
if( ( match != NULL ) && ( !doWrite || match->isWritable ) )
|
||||
{
|
||||
match->date = tr_time_msec( );
|
||||
match->date = tr_time( );
|
||||
return match->fd;
|
||||
}
|
||||
|
||||
|
@ -532,7 +532,7 @@ tr_fdFileCheckout( tr_session * session,
|
|||
dbgmsg( "it's not already open. looking for an open slot or an old file." );
|
||||
while( winner < 0 )
|
||||
{
|
||||
uint64_t date = tr_time_msec( ) + 1;
|
||||
time_t date = tr_time( ) + 1;
|
||||
|
||||
/* look for the file that's been open longest */
|
||||
for( i=0; i<gFd->openFileLimit; ++i )
|
||||
|
@ -582,7 +582,7 @@ tr_fdFileCheckout( tr_session * session,
|
|||
dbgmsg( "checking out '%s' in slot %d", filename, winner );
|
||||
o->torrentId = torrentId;
|
||||
o->fileNum = fileNum;
|
||||
o->date = tr_time_msec( );
|
||||
o->date = tr_time( );
|
||||
return o->fd;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,11 +98,12 @@ didWriteWrapper( tr_peerIo * io, unsigned int bytes_transferred )
|
|||
|
||||
const unsigned int payload = MIN( next->length, bytes_transferred );
|
||||
const unsigned int overhead = guessPacketOverhead( payload );
|
||||
const uint64_t now = tr_time_msec( );
|
||||
|
||||
tr_bandwidthUsed( &io->bandwidth, TR_UP, payload, next->isPieceData );
|
||||
tr_bandwidthUsed( &io->bandwidth, TR_UP, payload, next->isPieceData, now );
|
||||
|
||||
if( overhead > 0 )
|
||||
tr_bandwidthUsed( &io->bandwidth, TR_UP, overhead, FALSE );
|
||||
tr_bandwidthUsed( &io->bandwidth, TR_UP, overhead, FALSE, now );
|
||||
|
||||
if( io->didWrite )
|
||||
io->didWrite( io, payload, next->isPieceData, io->userData );
|
||||
|
@ -149,11 +150,16 @@ canReadWrapper( tr_peerIo * io )
|
|||
|
||||
assert( tr_isPeerIo( io ) );
|
||||
|
||||
if( piece || (piece!=used) )
|
||||
{
|
||||
const uint64_t now = tr_time_msec( );
|
||||
|
||||
if( piece )
|
||||
tr_bandwidthUsed( &io->bandwidth, TR_DOWN, piece, TRUE );
|
||||
tr_bandwidthUsed( &io->bandwidth, TR_DOWN, piece, TRUE, now );
|
||||
|
||||
if( used != piece )
|
||||
tr_bandwidthUsed( &io->bandwidth, TR_DOWN, used - piece, FALSE );
|
||||
tr_bandwidthUsed( &io->bandwidth, TR_DOWN, used - piece, FALSE, now );
|
||||
}
|
||||
|
||||
switch( ret )
|
||||
{
|
||||
|
|
|
@ -2918,7 +2918,9 @@ shouldPeerBeClosed( const Torrent * t,
|
|||
static void sortPeersByLivelinessReverse( tr_peer ** peers, void ** clientData, int n, uint64_t now );
|
||||
|
||||
static tr_peer **
|
||||
getPeersToClose( Torrent * t, tr_close_type_t closeType, const time_t now, int * setmeSize )
|
||||
getPeersToClose( Torrent * t, tr_close_type_t closeType,
|
||||
const uint64_t now_msec, const time_t now_sec,
|
||||
int * setmeSize )
|
||||
{
|
||||
int i, peerCount, outsize;
|
||||
tr_peer ** peers = (tr_peer**) tr_ptrArrayPeek( &t->peers, &peerCount );
|
||||
|
@ -2927,10 +2929,10 @@ getPeersToClose( Torrent * t, tr_close_type_t closeType, const time_t now, int *
|
|||
assert( torrentIsLocked( t ) );
|
||||
|
||||
for( i = outsize = 0; i < peerCount; ++i )
|
||||
if( shouldPeerBeClosed( t, peers[i], peerCount, now ) == closeType )
|
||||
if( shouldPeerBeClosed( t, peers[i], peerCount, now_sec ) == closeType )
|
||||
ret[outsize++] = peers[i];
|
||||
|
||||
sortPeersByLivelinessReverse ( ret, NULL, outsize, tr_time_msec( ) );
|
||||
sortPeersByLivelinessReverse ( ret, NULL, outsize, now_msec );
|
||||
|
||||
*setmeSize = outsize;
|
||||
return ret;
|
||||
|
@ -2997,10 +2999,8 @@ closePeer( Torrent * t, tr_peer * peer )
|
|||
}
|
||||
|
||||
static void
|
||||
closeBadPeers( Torrent * t )
|
||||
closeBadPeers( Torrent * t, const uint64_t now_msec, const time_t now_sec )
|
||||
{
|
||||
const time_t now = tr_time( );
|
||||
|
||||
if( !t->isRunning )
|
||||
{
|
||||
removeAllPeers( t );
|
||||
|
@ -3012,7 +3012,7 @@ closeBadPeers( Torrent * t )
|
|||
struct tr_peer ** mustClose;
|
||||
|
||||
/* disconnect the really bad peers */
|
||||
mustClose = getPeersToClose( t, TR_MUST_CLOSE, now, &mustCloseCount );
|
||||
mustClose = getPeersToClose( t, TR_MUST_CLOSE, now_msec, now_sec, &mustCloseCount );
|
||||
for( i=0; i<mustCloseCount; ++i )
|
||||
closePeer( t, mustClose[i] );
|
||||
tr_free( mustClose );
|
||||
|
@ -3178,7 +3178,8 @@ reconnectPulse( int foo UNUSED, short bar UNUSED, void * vmgr )
|
|||
{
|
||||
tr_torrent * tor;
|
||||
tr_peerMgr * mgr = vmgr;
|
||||
const uint64_t now = tr_time_msec( );
|
||||
const time_t now_sec = tr_time( );
|
||||
const uint64_t now_msec = tr_time_msec( );
|
||||
|
||||
/**
|
||||
*** enforce the per-session and per-torrent peer limits
|
||||
|
@ -3188,15 +3189,15 @@ reconnectPulse( int foo UNUSED, short bar UNUSED, void * vmgr )
|
|||
tor = NULL;
|
||||
while(( tor = tr_torrentNext( mgr->session, tor )))
|
||||
if( tor->isRunning )
|
||||
enforceTorrentPeerLimit( tor->torrentPeers, now );
|
||||
enforceTorrentPeerLimit( tor->torrentPeers, now_msec );
|
||||
|
||||
/* if we're over the per-session peer limits, cull some peers */
|
||||
enforceSessionPeerLimit( mgr->session, now );
|
||||
enforceSessionPeerLimit( mgr->session, now_msec );
|
||||
|
||||
/* remove crappy peers */
|
||||
tor = NULL;
|
||||
while(( tor = tr_torrentNext( mgr->session, tor )))
|
||||
closeBadPeers( tor->torrentPeers );
|
||||
closeBadPeers( tor->torrentPeers, now_msec, now_sec );
|
||||
|
||||
/* try to make new peer connections */
|
||||
makeNewPeerConnections( mgr, MAX_CONNECTIONS_PER_PULSE );
|
||||
|
|
|
@ -1359,7 +1359,7 @@ readBtPiece( tr_peermsgs * msgs,
|
|||
}
|
||||
}
|
||||
|
||||
static void updateDesiredRequestCount( tr_peermsgs * msgs, uint64_t now );
|
||||
static void updateDesiredRequestCount( tr_peermsgs * msgs );
|
||||
|
||||
static int
|
||||
readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen )
|
||||
|
@ -1398,7 +1398,7 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen )
|
|||
case BT_UNCHOKE:
|
||||
dbgmsg( msgs, "got Unchoke" );
|
||||
msgs->peer->clientIsChoked = 0;
|
||||
updateDesiredRequestCount( msgs, tr_time_msec( ) );
|
||||
updateDesiredRequestCount( msgs );
|
||||
break;
|
||||
|
||||
case BT_INTERESTED:
|
||||
|
@ -1685,7 +1685,7 @@ tr_peerMsgsIsReadingBlock( const tr_peermsgs * msgs, tr_block_index_t block )
|
|||
**/
|
||||
|
||||
static void
|
||||
updateDesiredRequestCount( tr_peermsgs * msgs, uint64_t now )
|
||||
updateDesiredRequestCount( tr_peermsgs * msgs )
|
||||
{
|
||||
const tr_torrent * const torrent = msgs->torrent;
|
||||
|
||||
|
@ -1708,6 +1708,7 @@ updateDesiredRequestCount( tr_peermsgs * msgs, uint64_t now )
|
|||
int irate_Bps;
|
||||
const int floor = 4;
|
||||
const int seconds = REQUEST_BUF_SECS;
|
||||
const uint64_t now = tr_time_msec( );
|
||||
|
||||
/* Get the rate limit we should use.
|
||||
* FIXME: this needs to consider all the other peers as well... */
|
||||
|
@ -1975,7 +1976,7 @@ peerPulse( void * vmsgs )
|
|||
const time_t now = tr_time( );
|
||||
|
||||
if ( tr_isPeerIo( msgs->peer->io ) ) {
|
||||
updateDesiredRequestCount( msgs, tr_time_msec( ) );
|
||||
updateDesiredRequestCount( msgs );
|
||||
updateBlockRequests( msgs );
|
||||
updateMetadataRequests( msgs, now );
|
||||
}
|
||||
|
@ -2363,7 +2364,7 @@ tr_peerMsgsNew( struct tr_torrent * torrent,
|
|||
}
|
||||
|
||||
tr_peerIoSetIOFuncs( m->peer->io, canRead, didWrite, gotError, m );
|
||||
updateDesiredRequestCount( m, tr_time_msec( ) );
|
||||
updateDesiredRequestCount( m );
|
||||
|
||||
return m;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue