[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [tor/master 2/2] Fold timestamp_created into highres_created
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Fri, 15 Oct 2010 12:35:55 -0400
Subject: Fold timestamp_created into highres_created
Commit: 36c5476e7081776fc33bcc3ce1f261666985f5da
There's no reason to keep a time_t and a struct timeval to represent
the same value: highres_created.tv_sec was the same as timestamp_created.
This should save a few bytes per circuit.
---
src/or/circuitbuild.c | 2 +-
src/or/circuitlist.c | 6 +++---
src/or/circuituse.c | 31 ++++++++++++++++---------------
src/or/or.h | 6 ++++--
src/or/rephist.c | 6 +++---
5 files changed, 27 insertions(+), 24 deletions(-)
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 9c7262a..f8a198b 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -1924,7 +1924,7 @@ circuit_send_next_onion_skin(origin_circuit_t *circ)
struct timeval end;
long timediff;
tor_gettimeofday(&end);
- timediff = tv_mdiff(&circ->_base.highres_created, &end);
+ timediff = tv_mdiff(&circ->_base.timestamp_created, &end);
/*
* If the circuit build time is much greater than we would have cut
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index da6d329..f654f6c 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -397,8 +397,7 @@ circuit_initial_package_window(void)
static void
init_circuit_base(circuit_t *circ)
{
- circ->timestamp_created = time(NULL);
- tor_gettimeofday(&circ->highres_created);
+ tor_gettimeofday(&circ->timestamp_created);
circ->package_window = circuit_initial_package_window();
circ->deliver_window = CIRCWINDOW_START;
@@ -610,7 +609,8 @@ circuit_dump_details(int severity, circuit_t *circ, int conn_array_index,
log(severity, LD_CIRC, "Conn %d has %s circuit: circID %d (other side %d), "
"state %d (%s), born %d:",
conn_array_index, type, this_circid, other_circid, circ->state,
- circuit_state_to_string(circ->state), (int)circ->timestamp_created);
+ circuit_state_to_string(circ->state),
+ (int)circ->timestamp_created.tv_sec);
if (CIRCUIT_IS_ORIGIN(circ)) { /* circ starts at this node */
circuit_log_path(severity, LD_CIRC, TO_ORIGIN_CIRCUIT(circ));
}
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 399fc28..5426563 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -163,7 +163,7 @@ circuit_is_better(circuit_t *a, circuit_t *b, uint8_t purpose)
return 1;
} else {
if (a->timestamp_dirty ||
- a->timestamp_created > b->timestamp_created)
+ tor_timercmp(&a->timestamp_created, &b->timestamp_created, >))
return 1;
if (CIRCUIT_IS_ORIGIN(b) &&
TO_ORIGIN_CIRCUIT(b)->build_state->is_internal)
@@ -223,8 +223,8 @@ circuit_get_best(edge_connection_t *conn, int must_be_open, uint8_t purpose,
* seen lately, a la Fallon Chen's GSoC work -RD */
#define REND_PARALLEL_INTRO_DELAY 15
if (purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT &&
- !must_be_open && circ->state != CIRCUIT_STATE_OPEN &&
- circ->timestamp_created + REND_PARALLEL_INTRO_DELAY < now) {
+ !must_be_open && circ->state != CIRCUIT_STATE_OPEN &&
+ circ->timestamp_created.tv_sec + REND_PARALLEL_INTRO_DELAY < now) {
intro_going_on_but_too_old = 1;
continue;
}
@@ -313,14 +313,14 @@ circuit_expire_building(time_t now)
else
cutoff = general_cutoff;
- if (victim->timestamp_created > cutoff)
+ if (victim->timestamp_created.tv_sec > cutoff)
continue; /* it's still young, leave it alone */
#if 0
/* some debug logs, to help track bugs */
if (victim->purpose == CIRCUIT_PURPOSE_C_INTRODUCING &&
- victim->timestamp_created <= introcirc_cutoff &&
- victim->timestamp_created > general_cutoff)
+ victim->timestamp_created.tv_sec <= introcirc_cutoff &&
+ victim->timestamp_created.tv_sec > general_cutoff)
log_info(LD_REND|LD_CIRC, "Timing out introduction circuit which we "
"would not have done if it had been a general circuit.");
@@ -408,15 +408,16 @@ circuit_expire_building(time_t now)
* it off at, we probably had a suspend event along this codepath,
* and we should discard the value.
*/
- if (now - victim->timestamp_created > 2*circ_times.close_ms/1000+1) {
+ if (now - victim->timestamp_created.tv_sec >
+ 2*circ_times.close_ms/1000+1) {
log_notice(LD_CIRC,
"Extremely large value for circuit build timeout: %lds. "
"Assuming clock jump. Purpose %d",
- (long)(now - victim->timestamp_created),
+ (long)(now - victim->timestamp_created.tv_sec),
victim->purpose);
} else if (circuit_build_times_count_close(&circ_times,
- first_hop_succeeded,
- victim->timestamp_created)) {
+ first_hop_succeeded,
+ victim->timestamp_created.tv_sec)) {
circuit_build_times_set_timeout(&circ_times);
}
}
@@ -643,7 +644,7 @@ circuit_build_needed_circs(time_t now)
circ = circuit_get_youngest_clean_open(CIRCUIT_PURPOSE_C_GENERAL);
if (get_options()->RunTesting &&
circ &&
- circ->timestamp_created + TESTING_CIRCUIT_INTERVAL < now) {
+ circ->timestamp_created.tv_sec + TESTING_CIRCUIT_INTERVAL < now) {
log_fn(LOG_INFO,"Creating a new testing circuit.");
circuit_launch(CIRCUIT_PURPOSE_C_GENERAL, 0);
}
@@ -754,7 +755,7 @@ circuit_expire_old_circuits_clientside(time_t now)
circ->purpose);
circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
} else if (!circ->timestamp_dirty && circ->state == CIRCUIT_STATE_OPEN) {
- if (circ->timestamp_created < cutoff) {
+ if (circ->timestamp_created.tv_sec < cutoff) {
if (circ->purpose == CIRCUIT_PURPOSE_C_GENERAL ||
circ->purpose == CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT ||
circ->purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO ||
@@ -764,7 +765,7 @@ circuit_expire_old_circuits_clientside(time_t now)
circ->purpose == CIRCUIT_PURPOSE_S_CONNECT_REND) {
log_debug(LD_CIRC,
"Closing circuit that has been unused for %ld seconds.",
- (long)(now - circ->timestamp_created));
+ (long)(now - circ->timestamp_created.tv_sec));
circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
} else if (!TO_ORIGIN_CIRCUIT(circ)->is_ancient) {
/* Server-side rend joined circuits can end up really old, because
@@ -778,7 +779,7 @@ circuit_expire_old_circuits_clientside(time_t now)
"Ancient non-dirty circuit %d is still around after "
"%ld seconds. Purpose: %d",
TO_ORIGIN_CIRCUIT(circ)->global_identifier,
- (long)(now - circ->timestamp_created),
+ (long)(now - circ->timestamp_created.tv_sec),
circ->purpose);
/* FFFF implement a new circuit_purpose_to_string() so we don't
* just print out a number for circ->purpose */
@@ -1116,7 +1117,7 @@ circuit_launch_by_extend_info(uint8_t purpose,
/* reset the birth date of this circ, else expire_building
* will see it and think it's been trying to build since it
* began. */
- circ->_base.timestamp_created = time(NULL);
+ tor_gettimeofday(&circ->_base.timestamp_created);
switch (purpose) {
case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
case CIRCUIT_PURPOSE_S_ESTABLISH_INTRO:
diff --git a/src/or/or.h b/src/or/or.h
index eadc3b1..36ed39d 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2260,10 +2260,12 @@ typedef struct circuit_t {
* length ONIONSKIN_CHALLENGE_LEN. */
char *n_conn_onionskin;
- time_t timestamp_created; /**< When was this circuit created? */
+ /** When was this circuit created? We keep this timestamp with a higher
+ * resolution tham most so that the circuit-build-time tracking code can
+ * get millisecond resolution. */
+ struct timeval timestamp_created;
time_t timestamp_dirty; /**< When the circuit was first used, or 0 if the
* circuit is clean. */
- struct timeval highres_created; /**< When exactly was the circuit created? */
uint16_t marked_for_close; /**< Should we close this circuit at the end of
* the main loop? (If true, holds the line number
diff --git a/src/or/rephist.c b/src/or/rephist.c
index 6ce4322..68bc616 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -2212,9 +2212,9 @@ rep_hist_buffer_stats_add_circ(circuit_t *circ, time_t end_of_interval)
return;
if (!circuits_for_buffer_stats)
circuits_for_buffer_stats = smartlist_create();
- start_of_interval = circ->timestamp_created >
- start_of_buffer_stats_interval ?
- circ->timestamp_created :
+ start_of_interval = (circ->timestamp_created.tv_sec >
+ start_of_buffer_stats_interval) ?
+ circ->timestamp_created.tv_sec :
start_of_buffer_stats_interval;
interval_length = (int) (end_of_interval - start_of_interval);
stat = tor_malloc_zero(sizeof(circ_buffer_stats_t));
--
1.7.1