static void test_benchmark(struct ovs_cmdl_context *ctx) { struct thread_aux *threads; long long start; unsigned i; fatal_signal_init(); /* Parse arguments */ n_threads = strtoul(ctx->argv[1], NULL, 0); if (!n_threads) { ovs_fatal(0, "n_threads must be at least one"); } n_pkts = strtoul(ctx->argv[2], NULL, 0); batch_size = strtoul(ctx->argv[3], NULL, 0); if (batch_size == 0 || batch_size > NETDEV_MAX_BURST) { ovs_fatal(0, "batch_size must be between 1 and NETDEV_MAX_BURST(%u)", NETDEV_MAX_BURST); } if (ctx->argc > 4) { change_conn = strtoul(ctx->argv[4], NULL, 0); } threads = xcalloc(n_threads, sizeof *threads); ovs_barrier_init(&barrier, n_threads + 1); ct = conntrack_init(); /* Create threads */ for (i = 0; i < n_threads; i++) { threads[i].tid = i; threads[i].thread = ovs_thread_create("ct_thread", ct_thread_main, &threads[i]); } /* Starts the work inside the threads */ ovs_barrier_block(&barrier); start = time_msec(); /* Wait for the threads to finish the work */ ovs_barrier_block(&barrier); printf("conntrack: %5lld ms\n", time_msec() - start); for (i = 0; i < n_threads; i++) { xpthread_join(threads[i].thread, NULL); } conntrack_destroy(ct); ovs_barrier_destroy(&barrier); free(threads); }
static void benchmark_ccmap(void) { struct ccmap ccmap; struct timeval start; pthread_t *threads; struct ccmap_aux aux; size_t i; /* Insertions. */ xgettimeofday(&start); ccmap_init(&ccmap); for (i = 0; i < n_elems; i++) { ccmap_inc(&ccmap, hash_int(i, 0)); } printf("ccmap insert: %5d ms\n", elapsed(&start)); /* Search and mutation. */ xgettimeofday(&start); aux.ccmap = &ccmap; ovs_mutex_init(&aux.mutex); threads = xmalloc(n_threads * sizeof *threads); for (i = 0; i < n_threads; i++) { threads[i] = ovs_thread_create("search", search_ccmap, &aux); } for (i = 0; i < n_threads; i++) { xpthread_join(threads[i], NULL); } free(threads); printf("ccmap search: %5d ms\n", elapsed(&start)); /* Destruction. */ xgettimeofday(&start); for (i = 0; i < n_elems; i++) { uint32_t hash = hash_int(i, 0); if (ccmap_find(&ccmap, hash)) { /* Also remove any colliding hashes. */ while (ccmap_dec(&ccmap, hash)) { ; } } } ccmap_destroy(&ccmap); printf("ccmap destroy: %5d ms\n", elapsed(&start)); }