Beispiel #1
0
void benchmark(struct benchmark_config *config)
{
	int i;
	struct worker_info *producers;
	struct worker_info *consumers;
	struct work_queue queue_to_producer;
	struct work_queue queue_to_consumer;
	struct work_queue trash_queue;
	unsigned long long start, elapsed;

	work_queue_init(&queue_to_producer);
	work_queue_init(&queue_to_consumer);
	work_queue_init(&trash_queue);

	producers = create_workers(config, config->producer_thnum,
				config->producer, &queue_to_producer,
				&queue_to_consumer);
	consumers = create_workers(config, config->consumer_thnum,
				config->consumer, &queue_to_consumer,
				&trash_queue);
	start = stopwatch_start();

	for (i = 0; i < config->num_works; i++) {
		struct work *work = xmalloc(sizeof(*work));

		memset(work, 0, sizeof(*work));
		work->seed = config->seed_offset + i;
		work_queue_push(&queue_to_producer, work);
	}
	work_queue_close(&queue_to_producer);

	join_workers(producers, config->producer_thnum);
	work_queue_close(&queue_to_consumer);

	join_workers(consumers, config->consumer_thnum);
	work_queue_close(&trash_queue);

	elapsed = stopwatch_stop(start);

	collect_results(config, &trash_queue, start, elapsed);

	destroy_workers(consumers, config->consumer_thnum);
	destroy_workers(producers, config->producer_thnum);

	work_queue_destroy(&queue_to_producer);
	work_queue_destroy(&queue_to_consumer);
	work_queue_destroy(&trash_queue);
}
Beispiel #2
0
int image_cache(char *local_cache_path, unsigned short cache_write_port)
{
	pthread_t local_req_thr, remote_req_thr;
	int local_req_fd, remote_req_fd;

	pr_info("Proxy to Cache Port %d, CRIU to Cache Path %s\n", cache_write_port, local_cache_path);


	if (opts.ps_socket != -1) {
		remote_req_fd = opts.ps_socket;
		pr_info("Re-using ps socket %d\n", remote_req_fd);
	} else {
		remote_req_fd = setup_TCP_server_socket(cache_write_port);
		if (remote_req_fd < 0) {
			pr_perror("Unable to open proxy to cache TCP socket");
			return -1;
		}
	}

	local_req_fd = setup_UNIX_server_socket(local_cache_path);
	if (local_req_fd < 0) {
		pr_perror("Unable to open cache to proxy UNIX socket");
		return -1;
	}

	if (init_daemon(wait_for_image)) {
		pr_perror("Unable to initialize daemon");
		return -1;
	}

	if (pthread_create(
	    &remote_req_thr,
	    NULL, accept_remote_image_connections,
	    (void *) &remote_req_fd)) {
		pr_perror("Unable to create remote requests thread");
		return -1;
	}
	if (pthread_create(
	    &local_req_thr,
	    NULL,
	    accept_local_image_connections,
	    (void *) &local_req_fd)) {
		pr_perror("Unable to create local requests thread");
		return -1;
	}

	join_workers();

	pthread_join(remote_req_thr, NULL);
	pthread_join(local_req_thr, NULL);
	return 0;
}