diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-03-04 10:54:54 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-03-04 10:54:54 -0500 |
commit | 46118d7d7542aa960a26a08d9d5fbac33698765c (patch) | |
tree | 12b52cfd6bbec9ab8b29d97ec585c2a6c162f61b /src | |
parent | 05d8111eedee9e11e4bb1c42e93ae2fc168d52ec (diff) | |
parent | 833d027778ba97020fb5ded1d94e4b21fbcab766 (diff) | |
download | tor-46118d7d7542aa960a26a08d9d5fbac33698765c.tar tor-46118d7d7542aa960a26a08d9d5fbac33698765c.tar.gz |
Merge remote-tracking branch 'public/bug10169_023' into bug10169_024
Conflicts:
src/or/relay.c
Diffstat (limited to 'src')
-rw-r--r-- | src/common/compat_libevent.c | 30 | ||||
-rw-r--r-- | src/common/compat_libevent.h | 1 | ||||
-rw-r--r-- | src/or/buffers.c | 2 | ||||
-rw-r--r-- | src/or/circuitlist.c | 8 | ||||
-rw-r--r-- | src/or/relay.c | 3 |
5 files changed, 39 insertions, 5 deletions
diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c index 200a7c65f..835d3b83d 100644 --- a/src/common/compat_libevent.c +++ b/src/common/compat_libevent.c @@ -653,3 +653,33 @@ tor_gettimeofday_cache_clear(void) } #endif +/** + * As tor_gettimeofday_cached, but can never move backwards in time. + * + * The returned value may diverge from wall-clock time, since wall-clock time + * can trivially be adjusted backwards, and this can't. Don't mix wall-clock + * time with these values in the same calculation. + * + * Depending on implementation, this function may or may not "smooth out" huge + * jumps forward in wall-clock time. It may or may not keep its results + * advancing forward (as opposed to stalling) if the wall-clock time goes + * backwards. The current implementation does neither of of these. + * + * This function is not thread-safe; do not call it outside the main thread. + * + * In future versions of Tor, this may return a time does not have its + * origin at the Unix epoch. + */ +void +tor_gettimeofday_cached_monotonic(struct timeval *tv) +{ + struct timeval last_tv = { 0, 0 }; + + tor_gettimeofday_cached(tv); + if (timercmp(tv, &last_tv, <)) { + memcpy(tv, &last_tv, sizeof(struct timeval)); + } else { + memcpy(&last_tv, tv, sizeof(struct timeval)); + } +} + diff --git a/src/common/compat_libevent.h b/src/common/compat_libevent.h index 2472e2c49..b5f644547 100644 --- a/src/common/compat_libevent.h +++ b/src/common/compat_libevent.h @@ -90,6 +90,7 @@ int tor_add_bufferevent_to_rate_limit_group(struct bufferevent *bev, void tor_gettimeofday_cached(struct timeval *tv); void tor_gettimeofday_cache_clear(void); +void tor_gettimeofday_cached_monotonic(struct timeval *tv); #endif diff --git a/src/or/buffers.c b/src/or/buffers.c index c0a3534d8..c2eb228d2 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -631,7 +631,7 @@ buf_add_chunk_with_capacity(buf_t *buf, size_t capacity, int capped) chunk = chunk_new_with_alloc_size(preferred_chunk_size(capacity)); } - tor_gettimeofday_cached(&now); + tor_gettimeofday_cached_monotonic(&now); chunk->inserted_time = (uint32_t)tv_to_msec(&now); if (buf->tail) { diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c index 3081035ab..959334e76 100644 --- a/src/or/circuitlist.c +++ b/src/or/circuitlist.c @@ -1693,7 +1693,7 @@ circuits_handle_oom(size_t current_allocation) mem_to_recover = current_allocation - mem_target; } - tor_gettimeofday_cached(&now); + tor_gettimeofday_cached_monotonic(&now); now_ms = (uint32_t)tv_to_msec(&now); /* This algorithm itself assumes that you've got enough memory slack @@ -1731,9 +1731,11 @@ circuits_handle_oom(size_t current_allocation) buf_shrink_freelists(1); /* This is necessary to actually release buffer chunks. */ - log_notice(LD_GENERAL, "Removed "U64_FORMAT" bytes by killing %d circuits.", + log_notice(LD_GENERAL, "Removed "U64_FORMAT" bytes by killing %d circuits; " + "%d circuits remain alive.", U64_PRINTF_ARG(mem_recovered), - n_circuits_killed); + n_circuits_killed, + smartlist_len(circlist) - n_circuits_killed); smartlist_free(circlist); } diff --git a/src/or/relay.c b/src/or/relay.c index 01143f418..857b7e9d3 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -2151,7 +2151,8 @@ cell_queue_append_packed_copy(cell_queue_t *queue, const cell_t *cell, { struct timeval now; packed_cell_t *copy = packed_cell_copy(cell, wide_circ_ids); - tor_gettimeofday_cached(&now); + tor_gettimeofday_cached_monotonic(&now); + copy->inserted_time = (uint32_t)tv_to_msec(&now); /* Remember the time when this cell was put in the queue. */ |