|
@@ -14,7 +14,10 @@ const char tor_git_revision[] = "";
|
|
|
|
|
|
#include "orconfig.h"
|
|
|
|
|
|
+#define RELAY_PRIVATE
|
|
|
+
|
|
|
#include "or.h"
|
|
|
+#include "relay.h"
|
|
|
|
|
|
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID)
|
|
|
static uint64_t nanostart;
|
|
@@ -199,6 +202,59 @@ bench_dmap(void)
|
|
|
smartlist_free(sl2);
|
|
|
}
|
|
|
|
|
|
+static void
|
|
|
+bench_cell_ops(void)
|
|
|
+{
|
|
|
+ const int iters = 1<<16;
|
|
|
+ int i;
|
|
|
+
|
|
|
+ /* benchmarks for cell ops at relay. */
|
|
|
+ or_circuit_t *or_circ = tor_malloc_zero(sizeof(or_circuit_t));
|
|
|
+ cell_t *cell = tor_malloc(sizeof(cell_t));
|
|
|
+ int outbound;
|
|
|
+ uint64_t start, end;
|
|
|
+
|
|
|
+ crypto_rand((char*)cell->payload, sizeof(cell->payload));
|
|
|
+
|
|
|
+ /* Mock-up or_circuit_t */
|
|
|
+ or_circ->_base.magic = OR_CIRCUIT_MAGIC;
|
|
|
+ or_circ->_base.purpose = CIRCUIT_PURPOSE_OR;
|
|
|
+
|
|
|
+ /* Initialize crypto */
|
|
|
+ or_circ->p_crypto = crypto_new_cipher_env();
|
|
|
+ crypto_cipher_generate_key(or_circ->p_crypto);
|
|
|
+ crypto_cipher_encrypt_init_cipher(or_circ->p_crypto);
|
|
|
+ or_circ->n_crypto = crypto_new_cipher_env();
|
|
|
+ crypto_cipher_generate_key(or_circ->n_crypto);
|
|
|
+ crypto_cipher_encrypt_init_cipher(or_circ->n_crypto);
|
|
|
+ or_circ->p_digest = crypto_new_digest_env();
|
|
|
+ or_circ->n_digest = crypto_new_digest_env();
|
|
|
+
|
|
|
+ reset_perftime();
|
|
|
+
|
|
|
+ for (outbound = 0; outbound <= 1; ++outbound) {
|
|
|
+ cell_direction_t d = outbound ? CELL_DIRECTION_OUT : CELL_DIRECTION_IN;
|
|
|
+ start = perftime();
|
|
|
+ for (i = 0; i < iters; ++i) {
|
|
|
+ char recognized = 0;
|
|
|
+ crypt_path_t *layer_hint = NULL;
|
|
|
+ relay_crypt(TO_CIRCUIT(or_circ), cell, d, &layer_hint, &recognized);
|
|
|
+ }
|
|
|
+ end = perftime();
|
|
|
+ printf("%sbound cells: %.2f ns per cell. (%.2f ns per byte of payload)\n",
|
|
|
+ outbound?"Out":" In",
|
|
|
+ NANOCOUNT(start,end,iters),
|
|
|
+ NANOCOUNT(start,end,iters*CELL_PAYLOAD_SIZE));
|
|
|
+ }
|
|
|
+
|
|
|
+ crypto_free_digest_env(or_circ->p_digest);
|
|
|
+ crypto_free_digest_env(or_circ->n_digest);
|
|
|
+ crypto_free_cipher_env(or_circ->p_crypto);
|
|
|
+ crypto_free_cipher_env(or_circ->n_crypto);
|
|
|
+ tor_free(or_circ);
|
|
|
+ tor_free(cell);
|
|
|
+}
|
|
|
+
|
|
|
typedef void (*bench_fn)(void);
|
|
|
|
|
|
typedef struct benchmark_t {
|
|
@@ -213,6 +269,7 @@ static struct benchmark_t benchmarks[] = {
|
|
|
ENT(dmap),
|
|
|
ENT(aes),
|
|
|
ENT(cell_aes),
|
|
|
+ ENT(cell_ops),
|
|
|
{NULL,NULL,0}
|
|
|
};
|
|
|
|
|
@@ -255,6 +312,8 @@ main(int argc, const char **argv)
|
|
|
|
|
|
reset_perftime();
|
|
|
|
|
|
+ crypto_seed_rng(1);
|
|
|
+
|
|
|
for (b = benchmarks; b->name; ++b) {
|
|
|
if (b->enabled || n_enabled == 0) {
|
|
|
printf("===== %s =====\n", b->name);
|