Esempio n. 1
0
void init(void)
{
	char cmd[128];
        sprintf(cmd, "renice -n -20 %d", getpid());
        system(cmd);
#ifdef USE_PIPE
	if (pipe(pipeA)) exit(-1);
	if (pipe(pipeB)) exit(-1);
#else
	ck_ring_init(&rbping, bufferping, RB_SZ);
	ck_ring_init(&rbpong, bufferpong, RB_SZ);
#endif
}
Esempio n. 2
0
int
main(int argc, char *argv[])
{
	int i, r;
	void *buffer;
	struct context *context;
	pthread_t *thread;

	if (argc != 4) {
		ck_error("Usage: validate <threads> <affinity delta> <size>\n");
	}

	a.request = 0;
	a.delta = atoi(argv[2]);

	nthr = atoi(argv[1]);
	assert(nthr >= 1);

	size = atoi(argv[3]);
	assert(size > 4 && (size & size - 1) == 0);
	size -= 1;

	ring = malloc(sizeof(ck_ring_t) * nthr);
	assert(ring);

	context = malloc(sizeof(*context) * nthr);
	assert(context);

	thread = malloc(sizeof(pthread_t) * nthr);
	assert(thread);

	for (i = 0; i < nthr; i++) {
		context[i].tid = i;
		if (i == 0) {
			context[i].previous = nthr - 1;
			context[i].next = i + 1;
		} else if (i == nthr - 1) {
			context[i].next = 0;
			context[i].previous = i - 1;
		} else {
			context[i].next = i + 1;
			context[i].previous = i - 1;
		}

		buffer = malloc(sizeof(void *) * (size + 1));
		assert(buffer);
		ck_ring_init(ring + i, buffer, size + 1);
		r = pthread_create(thread + i, NULL, test, context + i);
		assert(r == 0);
	}

	for (i = 0; i < nthr; i++)
		pthread_join(thread[i], NULL);

	return (0);
}
Esempio n. 3
0
int
main(int argc, char *argv[])
{
	int i, r, size;
	uint64_t s, e, e_a, d_a;
	struct entry entry = {0, 0};
	ck_ring_buffer_t *buf;
	ck_ring_t ring;

	if (argc != 2) {
		ck_error("Usage: latency <size>\n");
	}

	size = atoi(argv[1]);
	if (size <= 4 || (size & (size - 1))) {
		ck_error("ERROR: Size must be a power of 2 greater than 4.\n");
	}

	buf = malloc(sizeof(ck_ring_buffer_t) * size);
	if (buf == NULL) {
		ck_error("ERROR: Failed to allocate buffer\n");
	}

	ck_ring_init(&ring, size);

	e_a = d_a = s = e = 0;
	for (r = 0; r < ITERATIONS; r++) {
		for (i = 0; i < size / 4; i += 4) {
			s = rdtsc();
			ck_ring_enqueue_spsc(&ring, buf, &entry);
			ck_ring_enqueue_spsc(&ring, buf, &entry);
			ck_ring_enqueue_spsc(&ring, buf, &entry);
			ck_ring_enqueue_spsc(&ring, buf, &entry);
			e = rdtsc();
		}
		e_a += (e - s) / 4;

		for (i = 0; i < size / 4; i += 4) {
			s = rdtsc();
			ck_ring_dequeue_spsc(&ring, buf, &entry);
			ck_ring_dequeue_spsc(&ring, buf, &entry);
			ck_ring_dequeue_spsc(&ring, buf, &entry);
			ck_ring_dequeue_spsc(&ring, buf, &entry);
			e = rdtsc();
		}
		d_a += (e - s) / 4;
	}

	printf("spsc %10d %16" PRIu64 " %16" PRIu64 "\n", size, e_a / ITERATIONS, d_a / ITERATIONS);

	e_a = d_a = s = e = 0;
	for (r = 0; r < ITERATIONS; r++) {
		for (i = 0; i < size / 4; i += 4) {
			s = rdtsc();
			ck_ring_enqueue_spmc(&ring, buf, &entry);
			ck_ring_enqueue_spmc(&ring, buf, &entry);
			ck_ring_enqueue_spmc(&ring, buf, &entry);
			ck_ring_enqueue_spmc(&ring, buf, &entry);
			e = rdtsc();
		}
		e_a += (e - s) / 4;

		for (i = 0; i < size / 4; i += 4) {
			s = rdtsc();
			ck_ring_dequeue_spmc(&ring, buf, &entry);
			ck_ring_dequeue_spmc(&ring, buf, &entry);
			ck_ring_dequeue_spmc(&ring, buf, &entry);
			ck_ring_dequeue_spmc(&ring, buf, &entry);
			e = rdtsc();
		}
		d_a += (e - s) / 4;
	}

	printf("spmc %10d %16" PRIu64 " %16" PRIu64 "\n", size, e_a / ITERATIONS, d_a / ITERATIONS);

	ck_ring_init(&ring, size);
	e_a = d_a = s = e = 0;
	for (r = 0; r < ITERATIONS; r++) {
		for (i = 0; i < size / 4; i += 4) {
			s = rdtsc();
			ck_ring_enqueue_mpsc(&ring, buf, &entry);
			ck_ring_enqueue_mpsc(&ring, buf, &entry);
			ck_ring_enqueue_mpsc(&ring, buf, &entry);
			ck_ring_enqueue_mpsc(&ring, buf, &entry);
			e = rdtsc();
		}
		e_a += (e - s) / 4;

		for (i = 0; i < size / 4; i += 4) {
			s = rdtsc();
			ck_ring_dequeue_mpsc(&ring, buf, &entry);
			ck_ring_dequeue_mpsc(&ring, buf, &entry);
			ck_ring_dequeue_mpsc(&ring, buf, &entry);
			ck_ring_dequeue_mpsc(&ring, buf, &entry);
			e = rdtsc();
		}
		d_a += (e - s) / 4;
	}
	printf("mpsc %10d %16" PRIu64 " %16" PRIu64 "\n", size, e_a / ITERATIONS, d_a / ITERATIONS);
	ck_ring_init(&ring, size);
	e_a = d_a = s = e = 0;
	for (r = 0; r < ITERATIONS; r++) {
		for (i = 0; i < size / 4; i += 4) {
			s = rdtsc();
			ck_ring_enqueue_mpmc(&ring, buf, &entry);
			ck_ring_enqueue_mpmc(&ring, buf, &entry);
			ck_ring_enqueue_mpmc(&ring, buf, &entry);
			ck_ring_enqueue_mpmc(&ring, buf, &entry);
			e = rdtsc();
		}
		e_a += (e - s) / 4;

		for (i = 0; i < size / 4; i += 4) {
			s = rdtsc();
			ck_ring_dequeue_mpmc(&ring, buf, &entry);
			ck_ring_dequeue_mpmc(&ring, buf, &entry);
			ck_ring_dequeue_mpmc(&ring, buf, &entry);
			ck_ring_dequeue_mpmc(&ring, buf, &entry);
			e = rdtsc();
		}
		d_a += (e - s) / 4;
	}
	printf("mpmc %10d %16" PRIu64 " %16" PRIu64 "\n", size, e_a / ITERATIONS, d_a / ITERATIONS);
	return (0);
}
Esempio n. 4
0
int
main(int argc, char *argv[])
{
	int i, r;
	unsigned long l;
	pthread_t *thread;
	ck_ring_buffer_t *buffer;

	if (argc != 4) {
		ck_error("Usage: validate <threads> <affinity delta> <size>\n");
	}

	a.request = 0;
	a.delta = atoi(argv[2]);

	nthr = atoi(argv[1]);
	assert(nthr >= 1);

	size = atoi(argv[3]);
	assert(size >= 4 && (size & size - 1) == 0);
	size -= 1;

	ring = malloc(sizeof(ck_ring_t) * nthr);
	assert(ring);

	_context = malloc(sizeof(*_context) * nthr);
	assert(_context);

	thread = malloc(sizeof(pthread_t) * nthr);
	assert(thread);

	fprintf(stderr, "SPSC test:");
	for (i = 0; i < nthr; i++) {
		_context[i].tid = i;
		if (i == 0) {
			_context[i].previous = nthr - 1;
			_context[i].next = i + 1;
		} else if (i == nthr - 1) {
			_context[i].next = 0;
			_context[i].previous = i - 1;
		} else {
			_context[i].next = i + 1;
			_context[i].previous = i - 1;
		}

		buffer = malloc(sizeof(ck_ring_buffer_t) * (size + 1));
		assert(buffer);
		memset(buffer, 0, sizeof(ck_ring_buffer_t) * (size + 1));
		_context[i].buffer = buffer;
		ck_ring_init(ring + i, size + 1);
		r = pthread_create(thread + i, NULL, test, _context + i);
		assert(r == 0);
	}

	for (i = 0; i < nthr; i++)
		pthread_join(thread[i], NULL);

	fprintf(stderr, " done\n");

	fprintf(stderr, "SPMC test:\n");
	buffer = malloc(sizeof(ck_ring_buffer_t) * (size + 1));
	assert(buffer);
	memset(buffer, 0, sizeof(void *) * (size + 1));
	ck_ring_init(&ring_spmc, size + 1);
	for (i = 0; i < nthr - 1; i++) {
		_context[i].buffer = buffer;
		r = pthread_create(thread + i, NULL, test_spmc, _context + i);
		assert(r == 0);
	}

	for (l = 0; l < (unsigned long)size * ITERATIONS * (nthr - 1) ; l++) {
		struct entry *entry = malloc(sizeof *entry);

		assert(entry != NULL);
		entry->value_long = l;
		entry->value = (int)l;
		entry->tid = (int)l;
		entry->magic = 0xdead;
		entry->ref = 0;

		/* Wait until queue is not full. */
		if (l & 1) {
			while (ck_ring_enqueue_spmc(&ring_spmc,
			    buffer,
			    entry) == false)
				ck_pr_stall();
		} else {
			unsigned int s;

			while (ck_ring_enqueue_spmc_size(&ring_spmc,
			    buffer, entry, &s) == false) {
				ck_pr_stall();
			}

			if ((int)s >= (size * ITERATIONS * (nthr - 1))) {
				ck_error("MPMC: Unexpected size of %u\n", s);
			}
		}
	}

	for (i = 0; i < nthr - 1; i++)
		pthread_join(thread[i], NULL);

	return (0);
}