diff --git a/changes/bug10870 b/changes/bug10870 new file mode 100644 index 0000000000..d8a00f4029 --- /dev/null +++ b/changes/bug10870 @@ -0,0 +1,6 @@ + o Code simplification and refactoring: + - Remove data structures which were introduced to implement the + CellStatistics option: they are now redundant with the addition + of timestamp to the regular packed_cell_t data structure, which + we did in 0.2.4.18-rc in order to resolve #9093. Fixes bug + 10870. \ No newline at end of file diff --git a/src/or/or.h b/src/or/or.h index 5318b0fe5d..3eaf3447dc 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1081,31 +1081,12 @@ typedef struct packed_cell_t { * bits truncated) when this cell was inserted. */ } packed_cell_t; -/* XXXX This next structure may be obsoleted by inserted_time in - * packed_cell_t */ - -/** Number of cells added to a circuit queue including their insertion - * time on 10 millisecond detail; used for buffer statistics. */ -typedef struct insertion_time_elem_t { - struct insertion_time_elem_t *next; /**< Next element in queue. */ - uint32_t insertion_time; /**< When were cells inserted (in 10 ms steps - * starting at 0:00 of the current day)? */ - unsigned counter; /**< How many cells were inserted? */ -} insertion_time_elem_t; - -/** Queue of insertion times. */ -typedef struct insertion_time_queue_t { - struct insertion_time_elem_t *first; /**< First element in queue. */ - struct insertion_time_elem_t *last; /**< Last element in queue. */ -} insertion_time_queue_t; - /** A queue of cells on a circuit, waiting to be added to the * or_connection_t's outbuf. */ typedef struct cell_queue_t { packed_cell_t *head; /**< The first cell, or NULL if the queue is empty. */ packed_cell_t *tail; /**< The last cell, or NULL if the queue is empty. */ int n; /**< The number of cells in the queue. */ - insertion_time_queue_t *insertion_times; /**< Insertion times of cells. */ } cell_queue_t; /** Beginning of a RELAY cell payload. */ diff --git a/src/or/relay.c b/src/or/relay.c index 57633f86ab..7f06c6e145 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -2042,10 +2042,6 @@ static size_t total_cells_allocated = 0; /** A memory pool to allocate packed_cell_t objects. */ static mp_pool_t *cell_pool = NULL; -/** Memory pool to allocate insertion_time_elem_t objects used for cell - * statistics. */ -static mp_pool_t *it_pool = NULL; - /** Allocate structures to hold cells. */ void init_cell_pool(void) @@ -2064,10 +2060,6 @@ free_cell_pool(void) mp_pool_destroy(cell_pool); cell_pool = NULL; } - if (it_pool) { - mp_pool_destroy(it_pool); - it_pool = NULL; - } } /** Free excess storage in cell pool. */ @@ -2156,36 +2148,6 @@ cell_queue_append_packed_copy(cell_queue_t *queue, const cell_t *cell, tor_gettimeofday_cached(&now); copy->inserted_time = (uint32_t)tv_to_msec(&now); - /* Remember the time when this cell was put in the queue. */ - /*XXXX This may be obsoleted by inserted_time */ - if (get_options()->CellStatistics) { - uint32_t added; - insertion_time_queue_t *it_queue = queue->insertion_times; - if (!it_pool) - it_pool = mp_pool_new(sizeof(insertion_time_elem_t), 1024); - -#define SECONDS_IN_A_DAY 86400L - added = (uint32_t)(((now.tv_sec % SECONDS_IN_A_DAY) * 100L) - + ((uint32_t)now.tv_usec / (uint32_t)10000L)); - if (!it_queue) { - it_queue = tor_malloc_zero(sizeof(insertion_time_queue_t)); - queue->insertion_times = it_queue; - } - if (it_queue->last && it_queue->last->insertion_time == added) { - it_queue->last->counter++; - } else { - insertion_time_elem_t *elem = mp_pool_get(it_pool); - elem->next = NULL; - elem->insertion_time = added; - elem->counter = 1; - if (it_queue->last) { - it_queue->last->next = elem; - it_queue->last = elem; - } else { - it_queue->first = it_queue->last = elem; - } - } - } cell_queue_append(queue, copy); } @@ -2202,14 +2164,6 @@ cell_queue_clear(cell_queue_t *queue) } queue->head = queue->tail = NULL; queue->n = 0; - if (queue->insertion_times) { - while (queue->insertion_times->first) { - insertion_time_elem_t *elem = queue->insertion_times->first; - queue->insertion_times->first = elem->next; - mp_pool_release(elem); - } - tor_free(queue->insertion_times); - } } /** Extract and return the cell at the head of queue; return NULL if @@ -2234,9 +2188,7 @@ cell_queue_pop(cell_queue_t *queue) size_t packed_cell_mem_cost(void) { - return sizeof(packed_cell_t) + MP_POOL_ITEM_OVERHEAD + - get_options()->CellStatistics ? - (sizeof(insertion_time_elem_t)+MP_POOL_ITEM_OVERHEAD) : 0; + return sizeof(packed_cell_t) + MP_POOL_ITEM_OVERHEAD; } /** Check whether we've got too much space used for cells. If so, @@ -2415,35 +2367,14 @@ channel_flush_from_first_active_circuit(channel_t *chan, int max) /* Calculate the exact time that this cell has spent in the queue. */ if (get_options()->CellStatistics && !CIRCUIT_IS_ORIGIN(circ)) { + uint32_t msec_waiting; struct timeval tvnow; - uint32_t flushed; - uint32_t cell_waiting_time; - insertion_time_queue_t *it_queue = queue->insertion_times; + or_circ = TO_OR_CIRCUIT(circ); tor_gettimeofday_cached(&tvnow); - flushed = (uint32_t)((tvnow.tv_sec % SECONDS_IN_A_DAY) * 100L + - (uint32_t)tvnow.tv_usec / (uint32_t)10000L); - if (!it_queue || !it_queue->first) { - log_info(LD_GENERAL, "Cannot determine insertion time of cell. " - "Looks like the CellStatistics option was " - "recently enabled."); - } else { - insertion_time_elem_t *elem = it_queue->first; - or_circ = TO_OR_CIRCUIT(circ); - cell_waiting_time = - (uint32_t)((flushed * 10L + SECONDS_IN_A_DAY * 1000L - - elem->insertion_time * 10L) % - (SECONDS_IN_A_DAY * 1000L)); -#undef SECONDS_IN_A_DAY - elem->counter--; - if (elem->counter < 1) { - it_queue->first = elem->next; - if (elem == it_queue->last) - it_queue->last = NULL; - mp_pool_release(elem); - } - or_circ->total_cell_waiting_time += cell_waiting_time; - or_circ->processed_cells++; - } + msec_waiting = ((uint32_t)tv_to_msec(&tvnow)) - cell->inserted_time; + + or_circ->total_cell_waiting_time += msec_waiting; + or_circ->processed_cells++; } /* If we just flushed our queue and this circuit is used for a