Excise the insertion_time_elem_t logic

It's now redundant with the inserted_time field in packed_cell_t

Fixes bug 10870.
This commit is contained in:
Nick Mathewson 2014-02-10 13:55:27 -05:00
parent 7f6aa780e3
commit 3133cde3c1
3 changed files with 13 additions and 95 deletions

6
changes/bug10870 Normal file
View File

@ -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.

View File

@ -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. */

View File

@ -2040,10 +2040,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)
@ -2062,10 +2058,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. */
@ -2154,36 +2146,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);
}
@ -2200,14 +2162,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 <b>queue</b>; return NULL if
@ -2232,9 +2186,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,
@ -2413,35 +2365,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