Changeset 11349


Ignore:
Timestamp:
Oct 24, 2010, 1:08:08 AM (11 years ago)
Author:
charles
Message:

(trunk libT) #3662 "libtransmission cpu optimization: fewer calls to tr_time_msec()" -- fixed.

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.c

    r10998 r11349  
    344344}
    345345
    346 static void
    347 bandwidthUsedImpl( tr_bandwidth  * b,
    348                    tr_direction    dir,
    349                    size_t          byteCount,
    350                    tr_bool         isPieceData,
    351                    uint64_t        now )
     346void
     347tr_bandwidthUsed( tr_bandwidth  * b,
     348                  tr_direction    dir,
     349                  size_t          byteCount,
     350                  tr_bool         isPieceData,
     351                  uint64_t        now )
    352352{
    353353    struct tr_band * band;
     
    373373
    374374    if( b->parent != NULL )
    375         bandwidthUsedImpl( b->parent, dir, byteCount, isPieceData, now );
    376 }
    377 
    378 void
    379 tr_bandwidthUsed( tr_bandwidth  * b,
    380                   tr_direction    dir,
    381                   size_t          byteCount,
    382                   tr_bool         isPieceData )
    383 {
    384     bandwidthUsedImpl( b, dir, byteCount, isPieceData, tr_time_msec( ) );
    385 }
     375        tr_bandwidthUsed( b->parent, dir, byteCount, isPieceData, now );
     376}
  • trunk/libtransmission/bandwidth.h

    r10931 r11349  
    229229                                        tr_direction          direction,
    230230                                        size_t                byteCount,
    231                                         tr_bool               isPieceData );
     231                                        tr_bool               isPieceData,
     232                                        uint64_t              now );
    232233
    233234/******
  • trunk/libtransmission/fdlimit.c

    r11301 r11349  
    7575    char             filename[TR_PATH_MAX];
    7676    int              fd;
    77     uint64_t         date;
     77    time_t           date;
    7878};
    7979
     
    475475    if( ( match != NULL ) && ( !doWrite || match->isWritable ) )
    476476    {
    477         match->date = tr_time_msec( );
     477        match->date = tr_time( );
    478478        return match->fd;
    479479    }
     
    533533    while( winner < 0 )
    534534    {
    535         uint64_t date = tr_time_msec( ) + 1;
     535        time_t date = tr_time( ) + 1;
    536536
    537537        /* look for the file that's been open longest */
     
    583583    o->torrentId = torrentId;
    584584    o->fileNum = fileNum;
    585     o->date = tr_time_msec( );
     585    o->date = tr_time( );
    586586    return o->fd;
    587587}
  • trunk/libtransmission/peer-io.c

    r11299 r11349  
    9999        const unsigned int payload = MIN( next->length, bytes_transferred );
    100100        const unsigned int overhead = guessPacketOverhead( payload );
    101 
    102         tr_bandwidthUsed( &io->bandwidth, TR_UP, payload, next->isPieceData );
     101        const uint64_t now = tr_time_msec( );
     102
     103        tr_bandwidthUsed( &io->bandwidth, TR_UP, payload, next->isPieceData, now );
    103104
    104105        if( overhead > 0 )
    105             tr_bandwidthUsed( &io->bandwidth, TR_UP, overhead, FALSE );
     106            tr_bandwidthUsed( &io->bandwidth, TR_UP, overhead, FALSE, now );
    106107
    107108        if( io->didWrite )
     
    150151            assert( tr_isPeerIo( io ) );
    151152
    152             if( piece )
    153                 tr_bandwidthUsed( &io->bandwidth, TR_DOWN, piece, TRUE );
    154 
    155             if( used != piece )
    156                 tr_bandwidthUsed( &io->bandwidth, TR_DOWN, used - piece, FALSE );
     153            if( piece || (piece!=used) )
     154            {
     155                const uint64_t now = tr_time_msec( );
     156
     157                if( piece )
     158                    tr_bandwidthUsed( &io->bandwidth, TR_DOWN, piece, TRUE, now );
     159
     160                if( used != piece )
     161                    tr_bandwidthUsed( &io->bandwidth, TR_DOWN, used - piece, FALSE, now );
     162            }
    157163
    158164            switch( ret )
  • trunk/libtransmission/peer-mgr.c

    r11307 r11349  
    29192919
    29202920static tr_peer **
    2921 getPeersToClose( Torrent * t, tr_close_type_t closeType, const time_t now, int * setmeSize )
     2921getPeersToClose( Torrent * t, tr_close_type_t closeType,
     2922                 const uint64_t now_msec, const time_t now_sec,
     2923                 int * setmeSize )
    29222924{
    29232925    int i, peerCount, outsize;
     
    29282930
    29292931    for( i = outsize = 0; i < peerCount; ++i )
    2930         if( shouldPeerBeClosed( t, peers[i], peerCount, now ) == closeType )
     2932        if( shouldPeerBeClosed( t, peers[i], peerCount, now_sec ) == closeType )
    29312933            ret[outsize++] = peers[i];
    29322934
    2933     sortPeersByLivelinessReverse ( ret, NULL, outsize, tr_time_msec( ) );
     2935    sortPeersByLivelinessReverse ( ret, NULL, outsize, now_msec );
    29342936
    29352937    *setmeSize = outsize;
     
    29983000
    29993001static void
    3000 closeBadPeers( Torrent * t )
    3001 {
    3002     const time_t  now = tr_time( );
    3003 
     3002closeBadPeers( Torrent * t, const uint64_t now_msec, const time_t now_sec )
     3003{
    30043004    if( !t->isRunning )
    30053005    {
     
    30133013
    30143014        /* disconnect the really bad peers */
    3015         mustClose = getPeersToClose( t, TR_MUST_CLOSE, now, &mustCloseCount );
     3015        mustClose = getPeersToClose( t, TR_MUST_CLOSE, now_msec, now_sec, &mustCloseCount );
    30163016        for( i=0; i<mustCloseCount; ++i )
    30173017            closePeer( t, mustClose[i] );
     
    31793179    tr_torrent * tor;
    31803180    tr_peerMgr * mgr = vmgr;
    3181     const uint64_t now = tr_time_msec( );
     3181    const time_t now_sec = tr_time( );
     3182    const uint64_t now_msec = tr_time_msec( );
    31823183
    31833184    /**
     
    31893190    while(( tor = tr_torrentNext( mgr->session, tor )))
    31903191        if( tor->isRunning )
    3191             enforceTorrentPeerLimit( tor->torrentPeers, now );
     3192            enforceTorrentPeerLimit( tor->torrentPeers, now_msec );
    31923193
    31933194    /* if we're over the per-session peer limits, cull some peers */
    3194     enforceSessionPeerLimit( mgr->session, now );
     3195    enforceSessionPeerLimit( mgr->session, now_msec );
    31953196
    31963197    /* remove crappy peers */
    31973198    tor = NULL;
    31983199    while(( tor = tr_torrentNext( mgr->session, tor )))
    3199         closeBadPeers( tor->torrentPeers );
     3200        closeBadPeers( tor->torrentPeers, now_msec, now_sec );
    32003201
    32013202    /* try to make new peer connections */
  • trunk/libtransmission/peer-msgs.c

    r11313 r11349  
    13601360}
    13611361
    1362 static void updateDesiredRequestCount( tr_peermsgs * msgs, uint64_t now );
     1362static void updateDesiredRequestCount( tr_peermsgs * msgs );
    13631363
    13641364static int
     
    13991399            dbgmsg( msgs, "got Unchoke" );
    14001400            msgs->peer->clientIsChoked = 0;
    1401             updateDesiredRequestCount( msgs, tr_time_msec( ) );
     1401            updateDesiredRequestCount( msgs );
    14021402            break;
    14031403
     
    16861686
    16871687static void
    1688 updateDesiredRequestCount( tr_peermsgs * msgs, uint64_t now )
     1688updateDesiredRequestCount( tr_peermsgs * msgs )
    16891689{
    16901690    const tr_torrent * const torrent = msgs->torrent;
     
    17091709        const int floor = 4;
    17101710        const int seconds = REQUEST_BUF_SECS;
     1711        const uint64_t now = tr_time_msec( );
    17111712
    17121713        /* Get the rate limit we should use.
     
    19761977
    19771978    if ( tr_isPeerIo( msgs->peer->io ) ) {
    1978         updateDesiredRequestCount( msgs, tr_time_msec( ) );
     1979        updateDesiredRequestCount( msgs );
    19791980        updateBlockRequests( msgs );
    19801981        updateMetadataRequests( msgs, now );
     
    23642365
    23652366    tr_peerIoSetIOFuncs( m->peer->io, canRead, didWrite, gotError, m );
    2366     updateDesiredRequestCount( m, tr_time_msec( ) );
     2367    updateDesiredRequestCount( m );
    23672368
    23682369    return m;
Note: See TracChangeset for help on using the changeset viewer.